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

The following examples show how to use org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference#getRawTypeReference() . 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: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Check
public void checkTypeGuardsOrderWithGenerics(XSwitchExpression expression) {
	if (isIgnored(IssueCodes.UNREACHABLE_CASE)) {
		return;
	}
	ITypeReferenceOwner owner = new StandardTypeReferenceOwner(getServices(), expression);
	List<LightweightTypeReference> previousTypeReferences = new ArrayList<LightweightTypeReference>();
	for (XCasePart casePart : expression.getCases()) {
		JvmTypeReference typeGuard = casePart.getTypeGuard();
		if (typeGuard == null) {
			continue;
		}
		LightweightTypeReference typeReference = owner.toLightweightTypeReference(typeGuard);
		LightweightTypeReference actualType = typeReference.getRawTypeReference();
		if (actualType == null || typeReference == actualType) {
			continue;
		}
		if (isHandled(actualType, previousTypeReferences)) {
			addIssue("Unreachable code: The case can never match. It is already handled by a previous condition (with the same type erasure).", typeGuard, IssueCodes.UNREACHABLE_CASE);
			continue;
		}
		if (casePart.getCase() == null) {
			previousTypeReferences.add(actualType);
		}
	}
}
 
Example 2
Source File: XbaseTypeComputer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void _computeTypes(XInstanceOfExpression object, ITypeComputationState state) {
	ITypeComputationState expressionState = state.withExpectation(state.getReferenceOwner().newReferenceToObject());
	expressionState.computeTypes(object.getExpression());
	JvmTypeReference type = object.getType();
	if (isReferenceToTypeParameter(type)) {
		LightweightTypeReference lightweightReference = state.getReferenceOwner().toLightweightTypeReference(type);
		LightweightTypeReference rawTypeRef = lightweightReference.getRawTypeReference();
		state.addDiagnostic(new EObjectDiagnosticImpl(
				Severity.ERROR,
				IssueCodes.INVALID_USE_OF_TYPE_PARAMETER,
				"Cannot perform instanceof check against type parameter "+lightweightReference.getHumanReadableName()+". Use its erasure "+rawTypeRef.getHumanReadableName()+" instead since further generic type information will be erased at runtime.",
				object.getType(),
				null,
				-1,
				new String[] { 
				}));
	}
	LightweightTypeReference bool = getRawTypeForName(Boolean.TYPE, state);
	state.acceptActualType(bool);
}
 
Example 3
Source File: ElementOrComponentTypeComputer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public LightweightTypeReference doVisitParameterizedTypeReference(ParameterizedTypeReference reference) {
	DeclaratorTypeArgumentCollector typeArgumentCollector = new ConstraintAwareTypeArgumentCollector(owner);
	Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping = typeArgumentCollector.getTypeParameterMapping(reference);
	TypeParameterSubstitutor<?> substitutor = new UnboundTypeParameterPreservingSubstitutor(typeParameterMapping, owner);
	JvmGenericType iterable = (JvmGenericType) owner.getServices().getTypeReferences().findDeclaredType(Iterable.class, owner.getContextResourceSet());
	if (iterable == null) {
		return owner.newReferenceToObject();
	}
	LightweightTypeReference substituteMe = owner.newParameterizedTypeReference(iterable.getTypeParameters().get(0));
	LightweightTypeReference substitutedArgument = substitutor.substitute(substituteMe).getUpperBoundSubstitute();
	if (substitutedArgument.getType() instanceof JvmTypeParameter && 
			!(owner.getDeclaredTypeParameters().contains(substitutedArgument.getType()))) {
		return substitutedArgument.getRawTypeReference();
	}
	return substitutedArgument;
}
 
Example 4
Source File: ConstructorLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected LightweightTypeReference deferredBindTypeArgument(ITypeExpectation expectation, LightweightTypeReference type) {
	LightweightTypeReference result = super.deferredBindTypeArgument(expectation, type);
	LightweightTypeReference expectedType = expectation.getExpectedType();
	if (expectedType != null && getConstructorCall().getTypeArguments().isEmpty() && !result.isRawType() && !getDeclaredTypeParameters().isEmpty()) {
		if (!expectedType.isAssignableFrom(result, TypeConformanceComputationArgument.DEFAULT)) {
			LightweightTypeReference rawFeatureType = result.getRawTypeReference();
			if (expectedType.isAssignableFrom(rawFeatureType)) {
				result = rawFeatureType;
				getTypeParameterMapping().clear();
			}
		}
	}
	return result;
}
 
Example 5
Source File: AbstractPendingLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected CandidateCompareResult compareExpectedArgumentTypes(AbstractPendingLinkingCandidate<?> right) {
	int result = 0;
	int upTo = Math.max(arguments.getArgumentCount(), right.arguments.getArgumentCount());
	for(int leftIdx = hasReceiver() ? 0 : -1, rightIdx = right.hasReceiver() ? 0 : -1; leftIdx < upTo && rightIdx < upTo; leftIdx++, rightIdx++) {
		LightweightTypeReference expectedArgumentType = getSubstitutedExpectedType(leftIdx);
		LightweightTypeReference rightExpectedArgumentType = right.getSubstitutedExpectedType(rightIdx);
		if (expectedArgumentType == null) {
			if (rightExpectedArgumentType != null)
				return CandidateCompareResult.OTHER;
		} else {
			if (rightExpectedArgumentType == null) {
				return CandidateCompareResult.THIS;
			}
			boolean leftResolved = expectedArgumentType.isResolved();
			if (!leftResolved) {
				expectedArgumentType = expectedArgumentType.getRawTypeReference();
			}
			boolean rightResolved = rightExpectedArgumentType.isResolved();
			if (!rightResolved) {
				rightExpectedArgumentType = rightExpectedArgumentType.getRawTypeReference();
			}
			result += compareDeclaredTypes(expectedArgumentType, rightExpectedArgumentType, leftResolved, rightResolved);
		}
	}
	if (result == 0) {
		if (!getDeclaredTypeParameters().isEmpty() || !right.getDeclaredTypeParameters().isEmpty()) {
			return compareDeclaredParameterTypes(right);
		}
		return CandidateCompareResult.AMBIGUOUS;
	} else if (result < 0) {
		return CandidateCompareResult.THIS;
	} else {
		return getExpectedTypeCompareResultOther(right);
	}
}
 
Example 6
Source File: TypeConvertingCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private void convertListToArray(
		final LightweightTypeReference arrayTypeReference, 
		final ITreeAppendable appendable,
		final Later expression) {
	appendable.append("((");
	appendable.append(arrayTypeReference);
	appendable.append(")");
	appendable.append(Conversions.class);
	appendable.append(".unwrapArray(");
	expression.exec(appendable);
	LightweightTypeReference rawTypeArrayReference = arrayTypeReference.getRawTypeReference();
	appendable.append(", ");
	appendable.append(rawTypeArrayReference.getComponentType());
	appendable.append(".class))");
}
 
Example 7
Source File: RawTypeSubstitutor.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public LightweightTypeReference substitute(LightweightTypeReference original) {
	return original.getRawTypeReference();
}
 
Example 8
Source File: ExtensionScopeHelper.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public ExtensionScopeHelper(LightweightTypeReference argumentType) {
	this.argumentType = argumentType;
	this.rawArgumentType = argumentType.getRawTypeReference();
	
}