Java Code Examples for org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference#isWildcard()

The following examples show how to use org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference#isWildcard() . 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 isConformantMergeResult(LightweightMergedBoundTypeArgument mergeResult, LightweightTypeReference right,
		int flags) {
	LightweightTypeReference mergeResultReference = mergeResult.getTypeReference();
	if (right.isWildcard() && mergeResultReference.isWildcard()) {
		if (right.getLowerBoundSubstitute().isAny()) {
			LightweightTypeReference lowerBoundMergeResult = mergeResultReference.getLowerBoundSubstitute();
			if (!lowerBoundMergeResult.isAny()) {
				mergeResultReference = lowerBoundMergeResult;
			}
		} else {
			flags = flags | AS_TYPE_ARGUMENT;
		}
	} else if (mergeResultReference.isWildcard()) {
		flags = flags | AS_TYPE_ARGUMENT;
	}
	return isConformant(mergeResultReference, right, flags);
}
 
Example 2
Source File: XbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected ITreeAppendable appendTypeArguments(XAbstractFeatureCall call, ITreeAppendable original) {
	if (!call.getTypeArguments().isEmpty()) {
		return super.appendTypeArguments(call, original);
	}
	ILocationData completeLocationData = getLocationWithTypeArguments(call);
	ITreeAppendable completeFeatureCallAppendable = completeLocationData != null ? original.trace(completeLocationData) : original;
	IResolvedTypes resolvedTypes = batchTypeResolver.resolveTypes(call);
	List<LightweightTypeReference> typeArguments = resolvedTypes.getActualTypeArguments(call);
	if (!typeArguments.isEmpty()) {
		for(LightweightTypeReference typeArgument: typeArguments) {
			if (typeArgument.isWildcard()) {
				return completeFeatureCallAppendable;
			}
		}
		completeFeatureCallAppendable.append("<");
		for (int i = 0; i < typeArguments.size(); i++) {
			if (i != 0) {
				completeFeatureCallAppendable.append(", ");
			}
			completeFeatureCallAppendable.append(typeArguments.get(i));
		}
		completeFeatureCallAppendable.append(">");
	}
	return completeFeatureCallAppendable;
}
 
Example 3
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void ensureNotPrimitiveNorWildcard(JvmTypeReference typeRef) {
	LightweightTypeReference reference = toLightweightTypeReference(typeRef);
	if (reference.isPrimitive()) {
		error("Primitives cannot be used as type arguments.", typeRef, null, INVALID_USE_OF_TYPE);
	}
	if (reference.isWildcard()) {
		error("Wildcard types are not allowed in this context", typeRef, null, INSIGNIFICANT_INDEX,
				INVALID_USE_OF_WILDCARD);
	}
}
 
Example 4
Source File: BoundTypeArgumentMerger.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public boolean isPossibleMergeResult(List<LightweightBoundTypeArgument> allArguments, LightweightTypeReference candidate) {
	if (allArguments.isEmpty())
		return false;
	
	if (allArguments.size() == 1 && !candidate.isWildcard()) {
		LightweightBoundTypeArgument singleArgument = allArguments.get(0);
		if (VarianceInfo.OUT.equals(singleArgument.getActualVariance()) && singleArgument.getActualVariance().equals(singleArgument.getDeclaredVariance())) {
			LightweightTypeReference singleReference = singleArgument.getTypeReference();
			if (singleReference.isResolved())
				return candidate.isAssignableFrom(singleReference, TypeConformanceComputationArgument.DEFAULT);
		}
	}
	LightweightMergedBoundTypeArgument merged = merge(allArguments, candidate.getOwner());
	if (merged == null)
		return false;
	VarianceInfo variance = merged.getVariance();
	LightweightTypeReference type = merged.getTypeReference();
	if (variance == null || type == null) {
		return false;
	}
	switch(variance) {
		case INVARIANT: {
			int result = candidate.internalIsAssignableFrom(type, new TypeConformanceComputationArgument(false, true, true, true, false, false));
			if ((result & ConformanceFlags.SUCCESS) != 0 && (result & ConformanceFlags.RAW_TYPE_CONVERSION) == 0) {
				return true;
			}
			return false;
		}
		case OUT: return type.isAssignableFrom(candidate, TypeConformanceComputationArgument.DEFAULT);
		case IN: return candidate.isAssignableFrom(type, TypeConformanceComputationArgument.DEFAULT);
		default: throw new IllegalStateException("Unknown variance info: " + variance);
	}
}
 
Example 5
Source File: TypeParameterSubstitutor.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected LightweightTypeReference doVisitWildcardTypeReference(WildcardTypeReference reference, Visiting visiting) {
	if (reference.isResolved() && reference.isOwnedBy(getOwner()))
		return reference;
	WildcardTypeReference result = getOwner().newWildcardTypeReference();
	LightweightTypeReference lowerBound = reference.getLowerBound();
	if (lowerBound != null) {
		LightweightTypeReference visited = visitTypeArgument(lowerBound, visiting, true);
		if (visited.isWildcard()) {
			LightweightTypeReference lowerBoundSubstitute = visited.getLowerBoundSubstitute();
			if (lowerBoundSubstitute.isAny()) {
				result.addUpperBound(getOwner().newReferenceToObject());
				return result;
			} else {
				result.setLowerBound(lowerBoundSubstitute);
			}
		} else {
			result.setLowerBound(visited.copyInto(result.getOwner()));
		}
	} 
	for(LightweightTypeReference upperBound: reference.getUpperBounds()) {
		LightweightTypeReference visitedArgument = visitTypeArgument(upperBound, visiting);
		LightweightTypeReference upperBoundSubstitute = visitedArgument.getUpperBoundSubstitute();
		result.addUpperBound(upperBoundSubstitute);
	}
	if (result.getUpperBounds().isEmpty()) {
		throw new IllegalStateException("UpperBounds may not be empty");
	}
	return result;
}
 
Example 6
Source File: CollectionLiteralsTypeComputer.java    From xtext-extras with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Implements fall-back strategy. If the expected type of a collection literal does not match the actual type, but the expected element
 * types would match the actual element type, the collection literal will be successfully typed according to the expectation.
 */
protected boolean matchesExpectation(LightweightTypeReference elementType, LightweightTypeReference expectation) {
	return expectation != null && expectation.isResolved() && !expectation.isWildcard() && expectation.isAssignableFrom(elementType);
}