org.eclipse.xtext.xbase.typesystem.references.UnboundTypeReference Java Examples

The following examples show how to use org.eclipse.xtext.xbase.typesystem.references.UnboundTypeReference. 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: AbstractClosureTypeHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void deferredBindTypeArgument(/* @Nullable */ LightweightTypeReference declared, LightweightTypeReference actual, final BoundTypeArgumentSource source) {
	if (declared != null) { 
		ExpectationTypeParameterHintCollector collector = new ResolvingTypeParameterHintCollector(expectation.getReferenceOwner(), source) {
			@Override
			protected void addHint(UnboundTypeReference typeParameter, LightweightTypeReference reference) {
				LightweightTypeReference wrapped = reference.getWrapperTypeIfPrimitive();
				if (source == BoundTypeArgumentSource.INFERRED_CONSTRAINT) {
					wrapped = getStricterConstraint(typeParameter, wrapped);
				}
				if (wrapped != null) {
					typeParameter.acceptHint(wrapped, source, getOrigin(), getExpectedVariance(), getActualVariance());	
				}
			}
		};
		collector.processPairedReferences(declared, actual);
	}
}
 
Example #2
Source File: UnboundTypeReferences.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public static JvmTypeParameter findMappedParameter(JvmTypeParameter parameter,
		Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping, Collection<JvmTypeParameter> visited) {
	for(Map.Entry<JvmTypeParameter, LightweightMergedBoundTypeArgument> entry: mapping.entrySet()) {
		LightweightTypeReference reference = entry.getValue().getTypeReference();
		JvmType type = null;
		if (reference instanceof UnboundTypeReference) {
			type = ((UnboundTypeReference) reference).getTypeParameter();
		} else {
			type = reference.getType();
		}
		if (parameter == type) {
			if (visited.add(entry.getKey()))
				return entry.getKey();
			return null;
		}
	}
	return null;
}
 
Example #3
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 #4
Source File: DeferredTypeParameterHintCollectorTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public void hasNoHintsFor(final Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping, final String typeParamName) {
  final Set<JvmTypeParameter> allKeys = mapping.keySet();
  for (final JvmTypeParameter key : allKeys) {
    String _simpleName = key.getSimpleName();
    boolean _equals = Objects.equal(_simpleName, typeParamName);
    if (_equals) {
      LightweightTypeReference _typeReference = mapping.get(key).getTypeReference();
      final UnboundTypeReference unbound = ((UnboundTypeReference) _typeReference);
      boolean _isEmpty = unbound.getAllHints().isEmpty();
      boolean _not = (!_isEmpty);
      if (_not) {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("Unexpected mapping for ");
        _builder.append(typeParamName);
        _builder.append(" in ");
        final Function1<JvmTypeParameter, String> _function = (JvmTypeParameter it) -> {
          return it.getSimpleName();
        };
        Iterable<String> _map = IterableExtensions.<JvmTypeParameter, String>map(mapping.keySet(), _function);
        _builder.append(_map);
        Assert.fail(_builder.toString());
      }
    }
  }
}
 
Example #5
Source File: ClosureTypeComputerUnitTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testHintsAfterPrepareComputation_01() throws Exception {
	JvmType iterableType = getTypeForName(Iterable.class, state);
	JvmTypeParameter typeParameter = createTypeParameter("ELEMENT", state);
	ParameterizedTypeReference iterableTypeReference = state.getReferenceOwner().newParameterizedTypeReference(iterableType);
	UnboundTypeReference elementReference = (UnboundTypeReference) createTypeReference(typeParameter, state);
	iterableTypeReference.addTypeArgument(elementReference);

	assertTrue(state.getResolvedTypes().getHints(elementReference.getHandle()).isEmpty());
	
	TypeExpectation expectation = new TypeExpectation(iterableTypeReference, state, false);
	ClosureTypeComputer computer = new ClosureTypeComputer(closure("[|]", getContextResourceSet()), expectation, state);
	computer.selectStrategy();
	FunctionTypeReference closureType = computer.getExpectedClosureType();
	assertEquals("java.lang.Iterable.iterator()", computer.getOperation().getIdentifier());
	assertEquals("Iterable<Unbound[T]>", getEquivalentSimpleName(closureType));
	assertEquals("()=>Iterator<Unbound[T]>", closureType.getSimpleName());
	
	assertEquals(1, state.getResolvedTypes().getHints(elementReference.getHandle()).size());
	UnboundTypeReference closureTypeArgument = (UnboundTypeReference) closureType.getTypeArguments().get(0);
	assertEquals(1, state.getResolvedTypes().getHints(closureTypeArgument.getHandle()).size());
}
 
Example #6
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 #7
Source File: RawTypeConformanceComputer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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 #8
Source File: ClosureTypeComputerUnitTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testHintsAfterPrepareComputation_03() throws Exception {
	JvmType iterableType = getTypeForName(Iterable.class, state);
	JvmType appendableType = getTypeForName(Appendable.class, state);
	JvmType charSequenceType = getTypeForName(CharSequence.class, state);
	ParameterizedTypeReference iterableTypeReference = state.getReferenceOwner().newParameterizedTypeReference(iterableType);
	WildcardTypeReference typeArgument = state.getReferenceOwner().newWildcardTypeReference();
	typeArgument.addUpperBound(state.getReferenceOwner().newParameterizedTypeReference(appendableType));
	typeArgument.addUpperBound(state.getReferenceOwner().newParameterizedTypeReference(charSequenceType));
	iterableTypeReference.addTypeArgument(typeArgument);
	
	TypeExpectation expectation = new TypeExpectation(iterableTypeReference, state, false);
	ClosureTypeComputer computer = new ClosureTypeComputer(closure("[|]", getContextResourceSet()), expectation, state);
	computer.selectStrategy();
	FunctionTypeReference closureType = computer.getExpectedClosureType();
	assertEquals("java.lang.Iterable.iterator()", computer.getOperation().getIdentifier());
	assertEquals("Iterable<Unbound[T]>", getEquivalentSimpleName(closureType));
	assertEquals("()=>Iterator<Unbound[T]>", closureType.getSimpleName());
	
	UnboundTypeReference closureTypeArgument = (UnboundTypeReference) closureType.getTypeArguments().get(0);
	List<LightweightBoundTypeArgument> hints = state.getResolvedTypes().getHints(closureTypeArgument.getHandle());
	assertEquals(hints.toString(), 2, hints.size());
}
 
Example #9
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public List<LightweightBoundTypeArgument> getAllHints(Object handle) {
	List<LightweightBoundTypeArgument> actualHints = getHints(handle);
	int i = 0;
	while(i < actualHints.size()) {
		LightweightBoundTypeArgument hint = actualHints.get(i);
		if (hint.getTypeReference() instanceof UnboundTypeReference) {
			break;
		}
		i++;
	}
	if (i >= actualHints.size())
		return actualHints;
	List<LightweightBoundTypeArgument> transitivity = Lists.newArrayList();
	Set<Object> seenHandles = Sets.newHashSet(handle); 
	transitivity.addAll(actualHints.subList(0, i));
	List<LightweightBoundTypeArgument> allRemaining = actualHints.subList(i, actualHints.size());
	addNonRecursiveHints(allRemaining, seenHandles, transitivity);
	return transitivity;
}
 
Example #10
Source File: CollectionLiteralsTypeComputer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isExpectedType(LightweightTypeReference expectation, Class<?> clazz) {
	if (expectation != null) {
		if (expectation.isResolved() && isSubtypeButNotSynonym(expectation, clazz)) {
			return true;
		}
		if (expectation instanceof UnboundTypeReference) {
			if (expectation.getOwner().newParameterizedTypeReference(((UnboundTypeReference) expectation).getTypeParameter()).isSubtypeOf(clazz)) {
				return true;
			}
			List<LightweightBoundTypeArgument> hints = ((UnboundTypeReference) expectation).getAllHints();
			for(LightweightBoundTypeArgument hint: hints) {
				LightweightTypeReference hintReference = hint.getTypeReference();
				if (hintReference != null && isSubtypeButNotSynonym(hintReference, clazz)) {
					return true;
				}
			}
		} else if (expectation instanceof ParameterizedTypeReference) {
			return isSubtypeButNotSynonym(expectation, clazz);
		}
	}
	return false;
}
 
Example #11
Source File: AbstractLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the substituted expected type for the argument at {@code argumentIndex}.
 * If the expected type is an unbound type parameter, a reference to the type parameter
 * itself is returned. 
 */
/* @Nullable */
protected LightweightTypeReference getSubstitutedExpectedType(int argumentIndex) {
	XExpression expression = arguments.getArgument(argumentIndex);
	if (expression == null)
		return null;
	LightweightTypeReference expectedType = getExpectedType(expression);
	if (expectedType != null) {
		// don't use UnboundTypeReference.getRawTypeReference since that would potentially resolve the unbound candidate
		if (expectedType instanceof UnboundTypeReference) {
			JvmTypeParameter typeParameter = ((UnboundTypeReference) expectedType).getTypeParameter();
			expectedType = expectedType.getOwner().newParameterizedTypeReference(typeParameter);
		}
	}
	return expectedType;
}
 
Example #12
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void addNonRecursiveHints(LightweightBoundTypeArgument original, List<LightweightBoundTypeArgument> hints, Set<Object> seenHandles,
		List<LightweightBoundTypeArgument> result) {
	for(LightweightBoundTypeArgument hint: hints) {
		LightweightTypeReference reference = hint.getTypeReference();
		if (reference instanceof UnboundTypeReference) {
			addNonRecursiveHints(original, (UnboundTypeReference)reference, seenHandles, result);
		} else {
			if (original.getDeclaredVariance() == VarianceInfo.IN && hint.getTypeReference() instanceof WildcardTypeReference) {
				LightweightTypeReference upperBound = hint.getTypeReference().getUpperBoundSubstitute();
				if (upperBound instanceof UnboundTypeReference) {
					addNonRecursiveHints(original, (UnboundTypeReference)upperBound, seenHandles, result);
				} else {
					LightweightBoundTypeArgument delegateHint = new LightweightBoundTypeArgument(
							upperBound, original.getSource(), hint.getOrigin(), hint.getDeclaredVariance(), original.getActualVariance());
					result.add(delegateHint);
				}
			} else {
				if (!result.isEmpty()) {
					if (original.getDeclaredVariance() == VarianceInfo.OUT && original.getActualVariance() == VarianceInfo.INVARIANT) {
						if (hint.getDeclaredVariance() == VarianceInfo.OUT && hint.getActualVariance() == VarianceInfo.INVARIANT) {
							continue;
						}
					}
					if (!result.contains(hint))
						result.add(hint);
				} else {
					result.add(hint);
				}
			}
		}
	}
}
 
Example #13
Source File: DeferredTypeParameterHintCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected LightweightTypeReference getStricterConstraint(final UnboundTypeReference typeParameter, LightweightTypeReference hint) {
	final JvmTypeParameter parameter = typeParameter.getTypeParameter();
	List<JvmTypeConstraint> constraints = parameter.getConstraints();
	for(JvmTypeConstraint constraint: constraints) {
		JvmTypeReference constraintReference = constraint.getTypeReference();
		if (constraintReference != null) {
			final boolean[] recursive = new boolean[] { false };
			LightweightTypeReferenceFactory factory = new LightweightTypeReferenceFactory(hint.getOwner()) {
				@Override
				public LightweightTypeReference doVisitParameterizedTypeReference(JvmParameterizedTypeReference reference) {
					JvmType type = reference.getType();
					if (type == parameter) {// recursively bound
						recursive[0] = true;
					}
					return super.doVisitParameterizedTypeReference(reference);
				}
			};
			LightweightTypeReference lightweightReference = factory.toLightweightReference(constraintReference);
			if (!recursive[0]) {
				if (hint.isAssignableFrom(lightweightReference)) {
					hint = lightweightReference;	
				} else if (hint.isResolved() && !lightweightReference.getRawTypeReference().isAssignableFrom(hint, TypeConformanceComputationArgument.RAW)) {
					return null;
				}
			}
		}
	}
	return hint;
}
 
Example #14
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void addNonRecursiveHints(List<LightweightBoundTypeArgument> hints, Set<Object> seenHandles,
		List<LightweightBoundTypeArgument> result) {
	for(LightweightBoundTypeArgument hint: hints) {
		LightweightTypeReference reference = hint.getTypeReference();
		if (reference instanceof UnboundTypeReference) {
			addNonRecursiveHints(hint, (UnboundTypeReference)reference, seenHandles, result);
		} else {
			if (!result.contains(hint))
				result.add(hint);
		}
	}
}
 
Example #15
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void addNonRecursiveHints(LightweightBoundTypeArgument original, UnboundTypeReference reference, Set<Object> seenHandles,
		List<LightweightBoundTypeArgument> result) {
	Object otherHandle = reference.getHandle();
	if (seenHandles.add(otherHandle)) {
		if (isResolved(otherHandle)) {
			result.addAll(getHints(otherHandle));
		} else {
			addNonRecursiveHints(original, getHints(otherHandle), seenHandles, result);
		}
	}
}
 
Example #16
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected UnboundTypeReference createUnboundTypeReference(XExpression expression, JvmTypeParameter type) {
	UnboundTypeReference result = new UnboundTypeReference(getReferenceOwner(), expression, type) {
		// the constructor is protected since this guides developers better
		// therefore we use an anonymous class, here
	};
	acceptUnboundTypeReference(result.getHandle(), result);
	return result;
}
 
Example #17
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 #18
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 #19
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 #20
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 #21
Source File: ValidatingStackedResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public UnboundTypeReference getUnboundTypeReference(Object handle) {
	UnboundTypeReference result = super.getUnboundTypeReference(handle);
	if (!result.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("result is not owned by this resolved types");
	}
	return result;
}
 
Example #22
Source File: ValidatingExpressionAwareResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public UnboundTypeReference getUnboundTypeReference(Object handle) {
	UnboundTypeReference result = super.getUnboundTypeReference(handle);
	if (!result.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("result is not owned by this resolved types");
	}
	return result;
}
 
Example #23
Source File: AbstractTypeReferencePairWalker.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doVisitWildcardTypeReference(WildcardTypeReference reference, UnboundTypeReference declaration) {
	LightweightTypeReference lowerBound = reference.getLowerBound();
	if (lowerBound != null) {
		outerVisit(declaration, lowerBound, declaration, getExpectedVariance(), VarianceInfo.IN);
	} else {
		for (LightweightTypeReference upperBound : reference.getUpperBounds()) {
			outerVisit(declaration, upperBound, declaration, getExpectedVariance(), VarianceInfo.OUT);
		}
	}
}
 
Example #24
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 #25
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 #26
Source File: TypeArgumentFromComputedTypeCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected UnboundTypeReferenceTraverser createUnboundTypeReferenceTraverser() {
	return new UnboundTypeParameterAwareUnboundTypeReferenceTraverser() {
		@Override
		protected void doVisitWildcardTypeReference(WildcardTypeReference reference,
				UnboundTypeReference declaration) {
			if (shouldProcess(declaration.getTypeParameter())) {
				declaration.acceptHint(boundByInference(reference));
			} else {
				super.doVisitWildcardTypeReference(reference, declaration);
			}
		}
	};
}
 
Example #27
Source File: FeatureScopes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isUnknownReceiverType(LightweightTypeReference receiverType) {
	if (receiverType.isUnknown()) {
		return true;
	}
	if (receiverType instanceof UnboundTypeReference) {
		List<LightweightBoundTypeArgument> hints = ((UnboundTypeReference) receiverType).getAllHints();
		for(LightweightBoundTypeArgument hint: hints) {
			LightweightTypeReference typeReference = hint.getTypeReference();
			if (typeReference != null && typeReference.isUnknown())
				return true;
		}
	}
	return false;
}
 
Example #28
Source File: ValidatingReassigningResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public UnboundTypeReference getUnboundTypeReference(Object handle) {
	UnboundTypeReference result = super.getUnboundTypeReference(handle);
	if (!result.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("result is not owned by this resolved types");
	}
	return result;
}
 
Example #29
Source File: ValidatingRootResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public UnboundTypeReference getUnboundTypeReference(Object handle) {
	UnboundTypeReference result = super.getUnboundTypeReference(handle);
	if (!result.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("result is not owned by this resolved types");
	}
	return result;
}
 
Example #30
Source File: ValidatingRootResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void acceptUnboundTypeReference(Object handle, UnboundTypeReference reference) {
	if (!reference.isOwnedBy(getReferenceOwner())) {
		throw new IllegalArgumentException("reference is not owned by this resolved types");
	}
	super.acceptUnboundTypeReference(handle, reference);
}