Java Code Examples for org.eclipse.xtext.xbase.typesystem.references.UnboundTypeReference#internalIsResolved()

The following examples show how to use org.eclipse.xtext.xbase.typesystem.references.UnboundTypeReference#internalIsResolved() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnboundTypeParameterAwareTypeArgumentCollector.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void doVisitUnboundTypeReference(UnboundTypeReference reference, UnboundTypeReference declaration) {
	if (declaration.internalIsResolved() || getOwner().isResolved(declaration.getHandle())) {
		declaration.tryResolve();
		outerVisit(declaration, reference, declaration, getExpectedVariance(), getActualVariance());
	} else {
		if (getParametersToProcess().contains(declaration.getTypeParameter()) && VarianceInfo.OUT == getActualVariance() && VarianceInfo.OUT == getExpectedVariance()) {
			if (getDefaultSource() == BoundTypeArgumentSource.EXPECTATION) {
				List<LightweightBoundTypeArgument> hints = reference.getAllHints();
				for(int i = 0; i < hints.size(); i++) {
					if (hints.get(i).getSource() == BoundTypeArgumentSource.INFERRED) {
						return;
					}
				}
			}
		}
		acceptHint(declaration, reference);
	}
}
 
Example 2
Source File: ExpectationTypeParameterHintCollector.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doVisitUnboundTypeReference(UnboundTypeReference reference,
		WildcardTypeReference declaration) {
	if (declaration.getLowerBound() == null) {
		if (!reference.internalIsResolved()) {
			List<LightweightTypeReference> upperBounds = declaration.getUpperBounds();
			for(LightweightTypeReference upperBound: upperBounds) {
				if (!upperBound.isResolved() || !reference.canResolveTo(upperBound)) {
					super.doVisitUnboundTypeReference(reference, declaration);
					return;
				}
			}
			reference.tryResolve();
			if (reference.internalIsResolved()) {
				outerVisit(reference, declaration);
			} else {
				addHint(reference, declaration);
			}
			return;
		}
	}
	super.doVisitUnboundTypeReference(reference, declaration);
}
 
Example 3
Source File: ResolvingTypeParameterHintCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doVisitUnboundTypeReference(UnboundTypeReference reference,
		ParameterizedTypeReference declaration) {
	if (reference.internalIsResolved() || getOwner().isResolved(reference.getHandle())) {
		reference.tryResolve();
		outerVisit(reference, declaration);
	} else {
		addHint(reference, declaration);
	}
}
 
Example 4
Source File: ResolvingTypeParameterHintCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doVisitUnboundTypeReference(UnboundTypeReference reference,
		ArrayTypeReference declaration) {
	if (reference.internalIsResolved() || getOwner().isResolved(reference.getHandle())) {
		reference.tryResolve();
		outerVisit(reference, declaration);
	} else {
		addHint(reference, declaration);
	}
}
 
Example 5
Source File: StackedResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected UnboundTypeReference getUnboundTypeReference(Object handle) {
	UnboundTypeReference result = basicGetTypeParameters().get(handle);
	if (result == null) {
		result = parent.getUnboundTypeReference(handle);
		if (result.internalIsResolved())
			throw new IllegalStateException("Cannot query unbound reference that was already resolved");
		return (UnboundTypeReference) result.copyInto(getReferenceOwner());
	}
	return result;
}
 
Example 6
Source File: AbstractLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void initializeConstraintMapping(JvmTypeParameter typeParameter, UnboundTypeParameterPreservingSubstitutor substitutor, UnboundTypeReference typeReference) {
	if (!typeReference.internalIsResolved()) {
		List<JvmTypeConstraint> constraints = typeParameter.getConstraints();
		for(JvmTypeConstraint constraint: constraints) {
			JvmTypeReference constraintReference = constraint.getTypeReference();
			if (constraintReference != null) {
				LightweightTypeReference substitute = substitutor.substitute(constraintReference);
				if (!substitute.isType(Object.class) && !substitute.isPrimitiveVoid()) {
					typeReference.acceptHint(substitute, BoundTypeArgumentSource.CONSTRAINT, constraint, VarianceInfo.OUT, VarianceInfo.OUT);
				}
			}
		}
	}
}
 
Example 7
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected UnboundTypeReference getUnboundTypeReference(Object handle) {
	UnboundTypeReference result = basicGetTypeParameters().get(handle);
	if (result == null) {
		throw new IllegalStateException("Could not find type parameter");
	}
	if (result.internalIsResolved())
		throw new IllegalStateException("Cannot query unbount type reference that was already resolved");
	return result;
}
 
Example 8
Source File: UnboundTypeParameterAwareTypeArgumentCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doVisitTypeReference(LightweightTypeReference reference, UnboundTypeReference declaration) {
	if (declaration.internalIsResolved() || getOwner().isResolved(declaration.getHandle())) {
		declaration.tryResolve();
		outerVisit(declaration, reference, declaration, getExpectedVariance(), getActualVariance());
	} else {
		acceptHint(declaration, reference);
	}
}
 
Example 9
Source File: DeferredTypeParameterHintCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doVisitTypeReference(LightweightTypeReference reference, UnboundTypeReference declaration) {
	if (declaration.internalIsResolved() || getOwner().isResolved(declaration.getHandle())) {
		declaration.tryResolve();
		outerVisit(declaration, reference, declaration, getExpectedVariance(), getActualVariance());
	} else if (reference.isValidHint()) {
		addHint(declaration, reference);
	}
}
 
Example 10
Source File: AbstractTypeReferencePairWalker.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doVisitTypeReference(LightweightTypeReference reference, UnboundTypeReference declaration) {
	if (declaration.internalIsResolved() || getOwner().isResolved(declaration.getHandle())) {
		declaration.tryResolve();
		outerVisit(declaration, reference, declaration, getExpectedVariance(), getActualVariance());
	} else {
		processTypeParameter(declaration.getTypeParameter(), reference);
	}
}
 
Example 11
Source File: TypeArgumentFromComputedTypeCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public static void resolveAgainstActualType(final LightweightTypeReference declaredType, LightweightTypeReference actualType,
		Collection<JvmTypeParameter> typeParameters, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping,
		BoundTypeArgumentSource source,
		ITypeReferenceOwner owner) {
	if (declaredType.isRawType() || actualType.isRawType())
		return;
	TypeArgumentFromComputedTypeCollector implementation = new TypeArgumentFromComputedTypeCollector(typeParameters, source, owner);
	implementation.populateTypeParameterMapping(declaredType, actualType);
	Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> parameterMapping = implementation.rawGetTypeParameterMapping();
	for(Map.Entry<JvmTypeParameter, List<LightweightBoundTypeArgument>> entry: parameterMapping.entrySet()) {
		LightweightMergedBoundTypeArgument boundTypeArgument = typeParameterMapping.get(entry.getKey());
		if (boundTypeArgument != null ) {
			List<LightweightBoundTypeArgument> computedBoundTypeArguments = entry.getValue();
			for(LightweightBoundTypeArgument computedBoundTypeArgument: computedBoundTypeArguments) { 
				if (computedBoundTypeArgument.getSource() == BoundTypeArgumentSource.RESOLVED) {
					VarianceInfo varianceInfo = computedBoundTypeArgument.getDeclaredVariance().mergeDeclaredWithActual(computedBoundTypeArgument.getActualVariance());
					typeParameterMapping.put(entry.getKey(), new LightweightMergedBoundTypeArgument(computedBoundTypeArgument.getTypeReference(), varianceInfo));
				} else if (boundTypeArgument.getTypeReference() instanceof UnboundTypeReference) {
					UnboundTypeReference typeReference = (UnboundTypeReference) boundTypeArgument.getTypeReference();
					if (!typeReference.internalIsResolved()) {
						if (!(computedBoundTypeArgument.getTypeReference() instanceof UnboundTypeReference) || 
								((UnboundTypeReference) computedBoundTypeArgument.getTypeReference()).getHandle() != typeReference.getHandle())
							typeReference.acceptHint(computedBoundTypeArgument);
					}
				}
			}
		}
	}
}
 
Example 12
Source File: TypeArgumentFromComputedTypeCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void acceptHint(UnboundTypeReference reference, LightweightTypeReference param) {
	if (!shouldProcess(reference.getTypeParameter())) {
		reference.tryResolve();
		if (reference.internalIsResolved()) {
			outerVisit(reference, param);
		} else {
			super.acceptHint(reference, param);
		}
	} else {
		reference.acceptHint(boundByInference(param));
	}
}
 
Example 13
Source File: StackedResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void mergeTypeParametersIntoParent(ResolvedTypes parent) {
	for(UnboundTypeReference unbound: basicGetTypeParameters().values()) {
		LightweightTypeReference resolvedTo = unbound.getResolvedTo();
		if (resolvedTo == null) {
			List<JvmTypeParameter> typeParameters = basicGetDeclardTypeParameters();
			if (typeParameters != null && typeParameters.contains(unbound.getTypeParameter())) {
				unbound.tryResolve();
				if (!unbound.internalIsResolved()) {
					if (unbound.getExpression() instanceof XConstructorCall) {
						unbound.resolve(); // resolve against constraints 
					} else {
						unbound.acceptHint(unbound.getOwner().newParameterizedTypeReference(unbound.getTypeParameter()), 
								BoundTypeArgumentSource.RESOLVED, unbound, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
					}
				}
			} else {
				LightweightTypeReference reference = unbound.copyInto(parent.getReferenceOwner());
				if (reference instanceof UnboundTypeReference) {
					parent.acceptUnboundTypeReference(unbound.getHandle(), (UnboundTypeReference) reference);
				}
			}
		}
	}
	Map<Object, List<LightweightBoundTypeArgument>> typeParameterHints = basicGetTypeParameterHints();
	for(Map.Entry<Object, List<LightweightBoundTypeArgument>> hint: typeParameterHints.entrySet()) {
		if (!parent.isResolved(hint.getKey())) {
			List<LightweightBoundTypeArgument> boundTypeArguments = hint.getValue();
			for(LightweightBoundTypeArgument boundTypeArgument: boundTypeArguments) {
				if (boundTypeArgument.getOrigin() instanceof VarianceInfo) {
					parent.acceptHint(hint.getKey(), boundTypeArgument);
				} else {
					LightweightBoundTypeArgument copy = new LightweightBoundTypeArgument(
							boundTypeArgument.getTypeReference().copyInto(parent.getReferenceOwner()), 
							boundTypeArgument.getSource(), boundTypeArgument.getOrigin(), 
							boundTypeArgument.getDeclaredVariance(), 
							boundTypeArgument.getActualVariance());
					parent.acceptHint(hint.getKey(), copy);
				}
			}
		}
	}
}
 
Example 14
Source File: ExpectationTypeParameterHintCollector.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void doVisitUnboundTypeReference(UnboundTypeReference reference,
		ParameterizedTypeReference declaration) {
	boolean constraintSeen = false;
	boolean constraintsMatch = true;
	boolean othersSeen = false;
	boolean declarationMatches = getExpectedVariance() != VarianceInfo.OUT;
	if (reference.getTypeParameter() != declaration.getType()) {
		List<LightweightBoundTypeArgument> hints = reference.getAllHints();
		for(int i = 0; i < hints.size(); i++) {
			LightweightBoundTypeArgument hint = hints.get(i);
			if (hint.getSource() == BoundTypeArgumentSource.CONSTRAINT) {
				constraintSeen = true;
				outerVisit(hint.getTypeReference(), declaration, hint.getSource(), hint.getDeclaredVariance(), hint.getActualVariance());
				if (constraintsMatch && !hint.getTypeReference().isAssignableFrom(declaration)) {
					constraintsMatch = false;
				}
			} else {
				othersSeen = true;
				// we don't break the list traversal here since we want to do the paired outerVisit for all constraints
				if (declarationMatches) {
					if (hint.getActualVariance() == VarianceInfo.OUT && hint.getDeclaredVariance() == VarianceInfo.OUT && 
							(hint.getSource() == BoundTypeArgumentSource.INFERRED || hint.getSource() == BoundTypeArgumentSource.INFERRED_EXPECTATION || hint.getSource() == BoundTypeArgumentSource.INFERRED_LATER)) {
						if (!declaration.isAssignableFrom(hint.getTypeReference())) {
							declarationMatches = false;
						}
					} else {
						declarationMatches = false;
					}
				}
			}
		}
	} else {
		if (getOwner().getDeclaredTypeParameters().contains(reference.getTypeParameter())) {
			reference.acceptHint(declaration, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
			return;
		}
	}
	if (constraintSeen && constraintsMatch && !othersSeen) {
		reference.acceptHint(declaration, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
	} else if (!constraintSeen && !reference.internalIsResolved() && declaration.isResolved() && !getOwner().isResolved(reference.getHandle()) && reference.canResolveTo(declaration)) {
		reference.acceptHint(declaration, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
	} else if (othersSeen && declarationMatches) {
		reference.acceptHint(declaration, BoundTypeArgumentSource.INFERRED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
	} else {
		reference.tryResolve();
		if (reference.internalIsResolved()) {
			outerVisit(reference, declaration);
		} else {
			addHint(reference, declaration);
		}
	}
}
 
Example 15
Source File: ExpectationTypeParameterHintCollector.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void doVisitUnboundTypeReference(UnboundTypeReference reference, ArrayTypeReference declaration) {
	boolean constraintSeen = false;
	boolean constraintsMatch = true;
	boolean othersSeen = false;
	boolean declarationMatches = getExpectedVariance() != VarianceInfo.OUT;
	List<LightweightBoundTypeArgument> hints = reference.getAllHints();
	for(int i = 0; i < hints.size(); i++) {
		LightweightBoundTypeArgument hint = hints.get(i);
		if (hint.getSource() == BoundTypeArgumentSource.CONSTRAINT) {
			constraintSeen = true;
			outerVisit(hint.getTypeReference(), declaration, hint.getSource(), hint.getDeclaredVariance(), hint.getActualVariance());
			if (constraintsMatch && !hint.getTypeReference().isAssignableFrom(declaration)) {
				constraintsMatch = false;
			}
		} else {
			othersSeen = true;
			// we don't break the list traversal here since we want to do the paired outerVisit for all constraints
			if (declarationMatches) {
				if (hint.getActualVariance() == VarianceInfo.OUT && hint.getDeclaredVariance() == VarianceInfo.OUT && 
						(hint.getSource() == BoundTypeArgumentSource.INFERRED || hint.getSource() == BoundTypeArgumentSource.INFERRED_LATER || hint.getSource() == BoundTypeArgumentSource.INFERRED_EXPECTATION)) {
					if (!declaration.isAssignableFrom(hint.getTypeReference())) {
						declarationMatches = false;
					}
				} else {
					declarationMatches = false;
				}
			}
		}
	}
	if (constraintSeen && constraintsMatch && !othersSeen) {
		reference.acceptHint(declaration, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
	} else if (!constraintSeen && !reference.internalIsResolved() && declaration.isResolved() && !getOwner().isResolved(reference.getHandle()) && reference.canResolveTo(declaration)) {
		reference.acceptHint(declaration, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
	} else if (othersSeen && declarationMatches) {
		reference.acceptHint(declaration, BoundTypeArgumentSource.INFERRED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT);
	} else {
		reference.tryResolve();
		if (reference.internalIsResolved()) {
			outerVisit(reference, declaration);
		} else {
			addHint(reference, declaration);
		}
	}
}