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

The following examples show how to use org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference#getMultiTypeComponents() . 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: FeatureLinkHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public LightweightTypeReference getExpectedReceiverType(JvmIdentifiableElement linkedFeature, LightweightTypeReference receiverType) {
	if (receiverType.isMultiType() && linkedFeature instanceof JvmMember) {
		LightweightTypeReference declaratorReference = receiverType.getOwner().newParameterizedTypeReference(((JvmMember) linkedFeature).getDeclaringType());
		if (!declaratorReference.isAssignableFrom(receiverType.toJavaType())) {
			for(LightweightTypeReference multiTypeComponent: receiverType.getMultiTypeComponents()) {
				if (declaratorReference.isAssignableFrom(multiTypeComponent)) {
					return multiTypeComponent;
				}
			}
		} else {
			return declaratorReference;
		}
	} else if (receiverType.isSynonym() && linkedFeature instanceof JvmMember) {
		List<LightweightTypeReference> components = receiverType.getMultiTypeComponents();
		return components.get(components.size() - 1);
	}
	return receiverType;
}
 
Example 2
Source File: XbaseTypeComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected LightweightTypeReference normalizedMultiType(ITypeReferenceOwner referenceOwner, JvmTypeReference ref) {
	LightweightTypeReference result = referenceOwner.toLightweightTypeReference(ref);
	if (result.isSynonym()) {
		List<LightweightTypeReference> components = result.getMultiTypeComponents();
		result = referenceOwner.getServices().getTypeConformanceComputer().getCommonSuperType(components, referenceOwner);
	}
	return result;
}
 
Example 3
Source File: XbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void _toJavaExpression(XListLiteral literal, ITreeAppendable b) {
	LightweightTypeReference literalType = batchTypeResolver.resolveTypes(literal).getActualType(literal);
	if (literalType == null) {
		b.append("error - couldn't compute type for literal : "+literal);
		return;
	} 
	if (literalType.isArray()) {
		LightweightTypeReference expectedType = batchTypeResolver.resolveTypes(literal).getExpectedType(literal);
		boolean skipTypeName = false;
		if (expectedType != null && expectedType.isArray()) {
			if (canUseArrayInitializer(literal, b)) {
				skipTypeName = true;
			}
		}
		if (!skipTypeName) {
			if (literalType instanceof CompoundTypeReference) {
				for (LightweightTypeReference c : literalType.getMultiTypeComponents()) {
					if (c.isArray()) {
						b.append("new ")
						.append(c.getType()) // append raw type since we cannot create generic arrays
						.append(" ");
						break;
					}
				}
			} else {
				b.append("new ")
					.append(literalType.getType()) // append raw type since we cannot create generic arrays
					.append(" ");
			}
		}
		if (literal.getElements().isEmpty()) {
			b.append("{}");
		} else {
			b.append("{ ");
			boolean isFirst = true;
			for(XExpression element: literal.getElements())  {
				if(!isFirst)
					b.append(", ");
				isFirst = false;
				internalToJavaExpression(element, b);
			}
			b.append(" }");
		}
		return;
	} else {
		appendImmutableCollectionExpression(literal, b, "unmodifiableList", CollectionLiterals.class, "newArrayList");
	}
}