Java Code Examples for org.eclipse.xtext.common.types.JvmParameterizedTypeReference#getArguments()

The following examples show how to use org.eclipse.xtext.common.types.JvmParameterizedTypeReference#getArguments() . 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: ProxyAwareUIStrings.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the type arguments including the surrounding angular brackets.
 * If the typeRef is invalid in the sense that it contains unresolved proxies,
 * null is returned.
 */
/* @Nullable */
public StringBuilder appendTypeArguments(JvmParameterizedTypeReference typeRef, StringBuilder result) {
	List<JvmTypeReference> typeArguments = typeRef.getArguments();
	if (typeArguments.isEmpty()) {
		throw new IllegalArgumentException("typeRef is not parameterized");
	}
	result.append("<");
	for(int i = 0, size = typeArguments.size(); i < size; i++) {
		if (i != 0) {
			result.append(", ");
		}
		result = visit(typeArguments.get(i), result);
		if (result == null)
			return null;
	}
	result.append(">");
	return result;
}
 
Example 2
Source File: ProxyAwareUIStrings.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public StringBuilder doVisitParameterizedTypeReference(JvmParameterizedTypeReference reference, StringBuilder param) {
	JvmType type = reference.getType();
	if (type == null || type.eIsProxy()) {
		return null;
	}
	param.append(type.getSimpleName());
	List<JvmTypeReference> typeArguments = reference.getArguments();
	if (typeArguments.isEmpty())
		return param;
	param.append("<");
	for(int i = 0, size = typeArguments.size(); i < size; i++) {
		if (i != 0) {
			param.append(", ");
		}
		param = visit(typeArguments.get(i), param);
		if (param == null) {
			return null;
		}
	}
	param.append(">");
	return param;
}
 
Example 3
Source File: JvmTypeReferencesValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkTypeArgumentsNotPrimitive(JvmParameterizedTypeReference typeRef) {
	EList<JvmTypeReference> arguments = typeRef.getArguments();
	for (int i=0;i<arguments.size();i++) {
		JvmTypeReference jvmTypeReference = arguments.get(i);
		checkNotPrimitive(jvmTypeReference);
	}
}
 
Example 4
Source File: LightweightTypeReferenceFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public LightweightTypeReference doVisitParameterizedTypeReference(JvmParameterizedTypeReference reference) {
	JvmType type = getType(reference);
	if (type == null || type.eIsProxy()) {
		return createUnknownTypeReference(reference);
	}
	ParameterizedTypeReference result = owner.newParameterizedTypeReference(type);
	for(JvmTypeReference argument: reference.getArguments()) {
		result.addTypeArgument(visit(argument).getWrapperTypeIfPrimitive());
	}
	return result;
}
 
Example 5
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private JvmTypeReference enhanceTypeReference(ParameterizedType parameterizedType,
		JvmParameterizedTypeReference result) {
	result.setType(createProxy(parameterizedType.getRawType()));
	Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
	if (actualTypeArguments.length != 0) {
		InternalEList<JvmTypeReference> arguments = (InternalEList<JvmTypeReference>)result.getArguments();
		for (Type actualTypeArgument : actualTypeArguments) {
			JvmTypeReference argument = createTypeArgument(actualTypeArgument);
			arguments.addUnique(argument);
		}
	}
	return result;
}
 
Example 6
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns a type reference for the given type binding. If the binding is null, an {@link JvmUnknownTypeReference unknown}
 * type reference is returned.
 */
// @NonNull 
protected JvmTypeReference createTypeReference(/* @Nullable */ ITypeBinding typeBinding) {
	if (typeBinding == null) {
		return TypesFactory.eINSTANCE.createJvmUnknownTypeReference();
	}
	if (typeBinding.isArray()) {
		ITypeBinding componentType = typeBinding.getComponentType();
		JvmTypeReference componentTypeReference = createTypeReference(componentType);
		JvmGenericArrayTypeReference typeReference = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference();
		typeReference.setComponentType(componentTypeReference);
		return typeReference;
	}
	ITypeBinding outer = null;
	if (typeBinding.isMember() && !Modifier.isStatic(typeBinding.getModifiers())) {
		outer = typeBinding.getDeclaringClass();
	}
	JvmParameterizedTypeReference result;
	if (outer != null) {
		JvmParameterizedTypeReference outerReference = (JvmParameterizedTypeReference) createTypeReference(outer);
		result = TypesFactory.eINSTANCE.createJvmInnerTypeReference();
		((JvmInnerTypeReference) result).setOuter(outerReference);
	} else {
		result = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
	}
	ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
	if (typeArguments.length != 0) {
		ITypeBinding erasure = typeBinding.getErasure();
		result.setType(createProxy(erasure));
		InternalEList<JvmTypeReference> arguments = (InternalEList<JvmTypeReference>)result.getArguments();
		for (int i = 0; i < typeArguments.length; i++) {
			JvmTypeReference argument = createTypeArgument(typeArguments[i]);
			arguments.addUnique(argument);
		}
	} else {
		result.setType(createProxy(typeBinding));
	}
	return result;
}
 
Example 7
Source File: MissedMethodAddModification.java    From sarl with Apache License 2.0 5 votes vote down vote up
private Map<String, JvmTypeReference> buildTypeParameterMapping(XtendTypeDeclaration container) {
	final Map<String, JvmTypeReference> map = new TreeMap<>();
	final EObject obj = this.associations.getPrimaryJvmElement(container);
	if (obj instanceof JvmGenericType) {
		final JvmGenericType genType = (JvmGenericType) obj;

		final Set<String> encounteredTypes = new TreeSet<>();

		final LinkedList<JvmGenericType> expectedReferences = new LinkedList<>();
		expectedReferences.add(genType);

		final String objectId = Object.class.getName();

		while (!expectedReferences.isEmpty()) {
			final JvmGenericType type = expectedReferences.removeFirst();
			if (encounteredTypes.add(type.getIdentifier())) {

				for (final JvmTypeReference superType : type.getSuperTypes()) {
					if (!objectId.equals(superType.getIdentifier()) && superType instanceof JvmParameterizedTypeReference) {
						final JvmParameterizedTypeReference parametizedReference = (JvmParameterizedTypeReference) superType;
						if (!parametizedReference.getArguments().isEmpty()) {
							final JvmGenericType genericSuperType = (JvmGenericType) parametizedReference.getType();
							int i = 0;
							for (final JvmTypeReference refInstance : parametizedReference.getArguments()) {
								final JvmTypeParameter typeParameter = genericSuperType.getTypeParameters().get(i);
								map.put(
										typeParameterId(typeParameter, genericSuperType.getQualifiedName()),
										refInstance);
								++i;
							}
							expectedReferences.add((JvmGenericType) parametizedReference.getType());
						}
					}
				}

			}
		}
	}
	return map;
}