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

The following examples show how to use org.eclipse.xtext.xbase.typesystem.references.UnboundTypeReference#getAllHints() . 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: RawTypeConformanceComputer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected int doIsConformant(UnboundTypeReference left, UnboundTypeReference right, int flags) {
	if (left.getHandle().equals(right.getHandle())) {
		return flags | SUCCESS;
	}
	List<LightweightBoundTypeArgument> leftHints = left.getAllHints();
	List<LightweightBoundTypeArgument> rightHints = right.getAllHints();
	if ((flags & UNBOUND_COMPUTATION_ADDS_HINTS) != 0) {
		if (leftHints.isEmpty() || rightHints.isEmpty() || !left.hasSignificantHints(leftHints) || !right.hasSignificantHints()) {
			left.acceptHint(right, BoundTypeArgumentSource.INFERRED, this, VarianceInfo.OUT, VarianceInfo.OUT);
			return flags | SUCCESS;
		}
	}
	if (leftHints.equals(rightHints)) {
		return flags | SUCCESS;
	}
	return tryResolveAndCheckConformance(left, right, flags);
}
 
Example 2
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 3
Source File: RawTypeConformanceComputer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected int isConformantToConstraints(
		final UnboundTypeReference left, 
		final LightweightTypeReference right, 
		List<LightweightBoundTypeArgument> leftHints, 
		int flags) {
	int result = flags;
	for(LightweightBoundTypeArgument leftHint: leftHints) {
		if (leftHint.getSource() == BoundTypeArgumentSource.CONSTRAINT) {
			final LightweightTypeReference leftHintReference = leftHint.getTypeReference();
			if (!leftHintReference.getUniqueIdentifier().equals(right.getUniqueIdentifier())) {
				final LightweightMergedBoundTypeArgument rightTypeArgument = new LightweightMergedBoundTypeArgument(right.getWrapperTypeIfPrimitive(), VarianceInfo.INVARIANT);
				final UnboundTypeParameterPreservingSubstitutor unboundSubstitutor = new UnboundTypeParameterPreservingSubstitutor(
						Collections.singletonMap(left.getTypeParameter(), rightTypeArgument), right.getOwner()) {
					@Override
					public LightweightTypeReference doVisitUnboundTypeReference(UnboundTypeReference reference, Set<JvmTypeParameter> visiting) {
						if (reference.getHandle() == left.getHandle()) {
							if (right.getKind() == KIND_UNBOUND_TYPE_REFERENCE) {
								UnboundTypeReference rightUnbound = (UnboundTypeReference) right;
								List<LightweightBoundTypeArgument> rightHints = rightUnbound.getAllHints();
								for(LightweightBoundTypeArgument rightHint: rightHints) {
									LightweightTypeReference rightHintReference = rightHint.getTypeReference();
									if (rightHintReference != null && leftHintReference.getUniqueIdentifier().equals(rightHintReference.getUniqueIdentifier())) {
										return super.doVisitUnboundTypeReference(reference, visiting);
									}
								}
							}
							return rightTypeArgument.getTypeReference();
						}
						return super.doVisitUnboundTypeReference(reference, visiting);
					}
				};
				LightweightTypeReference constraintReference = unboundSubstitutor.substitute(leftHintReference);
				int constraintResult = doIsConformant(constraintReference, right, flags);
				if ((constraintResult & SUCCESS) == 0) {
					return flags;
				}
				result |= constraintResult;
			}
		}
	}
	return result | SUCCESS;
}
 
Example 4
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 5
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);
		}
	}
}