Java Code Examples for org.eclipse.xtext.xbase.typesystem.references.UnboundTypeReference#tryResolve()
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.references.UnboundTypeReference#tryResolve() .
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 |
protected int doIsConformant(LightweightTypeReference left, UnboundTypeReference right, int flags) { if (left.getType() == right.getType() || left.isType(Object.class)) { return flags | SUCCESS; } if ((flags & ALLOW_UNBOXING) == 0 && left.isPrimitive()) { return flags; } boolean doesNotHaveSignificantHints = false; if (((flags & RAW_TYPE) == 0) && (right.canResolveTo(left) || (flags & AS_TYPE_ARGUMENT) != 0 && (doesNotHaveSignificantHints = !right.hasSignificantHints()))) { if ((flags & UNBOUND_COMPUTATION_ADDS_HINTS) != 0 && doesNotHaveSignificantHints) { right.acceptHint(left, BoundTypeArgumentSource.INFERRED_LATER, left, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT); } return flags | SUCCESS; } right.tryResolve(false); LightweightTypeReference resolvedTo = right.getResolvedTo(); if (resolvedTo != null) { return doIsConformant(left, resolvedTo, flags); } return flags; }
Example 2
Source File: UnboundTypeParameterAwareTypeArgumentCollector.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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: ExpectationTypeParameterHintCollector.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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 4
Source File: ResolvingTypeParameterHintCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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 5
Source File: ResolvingTypeParameterHintCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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 6
Source File: ExpressionAwareStackedResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void tryResolveUnboundReferences() { for (UnboundTypeReference unbound : basicGetTypeParameters().values()) { if (unbound.getExpression() == expression) { // resolve all type parameters of the expression that // have already been annotated with significant hints // the type constraints themselves are not considered to // be significant 'enough' unbound.tryResolve(false); } } }
Example 7
Source File: UnboundTypeParameterAwareTypeArgumentCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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 8
Source File: DeferredTypeParameterHintCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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 9
Source File: AbstractTypeReferencePairWalker.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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 10
Source File: TypeArgumentFromComputedTypeCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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 11
Source File: StackedResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
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 12
Source File: ExpectationTypeParameterHintCollector.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@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 13
Source File: ExpectationTypeParameterHintCollector.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@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); } } }