Java Code Examples for org.eclipse.xtext.common.types.JvmParameterizedTypeReference#setType()
The following examples show how to use
org.eclipse.xtext.common.types.JvmParameterizedTypeReference#setType() .
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: XFunctionTypeRefImplCustom.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected JvmTypeReference getJavaLangObjectTypeRef(JvmType rawType, TypesFactory typesFactory) { ResourceSet rs = EcoreUtil2.getResourceSet(rawType); JvmParameterizedTypeReference refToObject = typesFactory.createJvmParameterizedTypeReference(); if (rs != null) { EObject javaLangObject = rs.getEObject(javaLangObjectURI, true); if (javaLangObject instanceof JvmType) { JvmType objectDeclaration = (JvmType) javaLangObject; refToObject.setType(objectDeclaration); return refToObject; } } JvmGenericType proxy = typesFactory.createJvmGenericType(); ((InternalEObject)proxy).eSetProxyURI(javaLangObjectURI); refToObject.setType(proxy); return refToObject; }
Example 2
Source File: AbstractConstantExpressionsInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected JvmTypeReference toTypeReference(final JvmType type, final int arrayDimensions) { if ((type == null)) { return null; } JvmParameterizedTypeReference _createJvmParameterizedTypeReference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference(); final Procedure1<JvmParameterizedTypeReference> _function = (JvmParameterizedTypeReference it) -> { it.setType(type); }; JvmTypeReference resultTypeRef = ObjectExtensions.<JvmParameterizedTypeReference>operator_doubleArrow(_createJvmParameterizedTypeReference, _function); ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, arrayDimensions, true); for (final Integer i : _doubleDotLessThan) { { final JvmGenericArrayTypeReference arrayRef = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference(); arrayRef.setComponentType(resultTypeRef); resultTypeRef = arrayRef; } } return resultTypeRef; }
Example 3
Source File: RawTypeHelper.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public JvmTypeReference doVisitParameterizedTypeReference(JvmParameterizedTypeReference reference, Resource resource) { JvmType type = reference.getType(); if (type != null && !type.eIsProxy()) { if (type instanceof JvmTypeParameterDeclarator) { if (!((JvmTypeParameterDeclarator) type).getTypeParameters().isEmpty()) { JvmParameterizedTypeReference result = factory.createJvmParameterizedTypeReference(); result.setType(type); return result; } } else if (type instanceof JvmTypeParameter) { return getRawTypeFromConstraints(((JvmTypeParameter) type).getConstraints(), resource); } } return reference; }
Example 4
Source File: RawTypeReferenceComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public JvmTypeReference doVisitParameterizedTypeReference(JvmParameterizedTypeReference reference, Pair<Resource, Set<JvmType>> context) { JvmType type = reference.getType(); if (type != null && !type.eIsProxy()) { if (type instanceof JvmTypeParameterDeclarator) { if (!((JvmTypeParameterDeclarator) type).getTypeParameters().isEmpty()) { JvmParameterizedTypeReference result = factory.createJvmParameterizedTypeReference(); result.setType(type); return result; } } else if (type instanceof JvmTypeParameter) { Set<JvmType> recursionGuard = context.getSecond(); if (recursionGuard.add(type)) { return getRawTypeFromConstraints(((JvmTypeParameter) type).getConstraints(), context); } else { return createObjectReference(context.getFirst()); } } } return reference; }
Example 5
Source File: TypeReferenceProviderImpl.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public JvmParameterizedTypeReference createTypeRef(final JvmType type, final JvmTypeReference... typeArgs) { if ((type == null)) { throw new NullPointerException("type"); } final JvmParameterizedTypeReference reference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference(); reference.setType(type); for (final JvmTypeReference typeArg : typeArgs) { reference.getArguments().add(EcoreUtil2.<JvmTypeReference>cloneIfContained(typeArg)); } if ((type instanceof JvmGenericType)) { final EList<JvmTypeParameter> list = ((JvmGenericType)type).getTypeParameters(); if (((!reference.getArguments().isEmpty()) && (list.size() != reference.getArguments().size()))) { String _identifier = ((JvmGenericType)type).getIdentifier(); String _plus = ("The type " + _identifier); String _plus_1 = (_plus + " expects "); int _size = list.size(); String _plus_2 = (_plus_1 + Integer.valueOf(_size)); String _plus_3 = (_plus_2 + " type arguments, but was "); int _size_1 = reference.getArguments().size(); String _plus_4 = (_plus_3 + Integer.valueOf(_size_1)); String _plus_5 = (_plus_4 + ". Either pass zero arguments (raw type) or the correct number."); throw new IllegalArgumentException(_plus_5); } } return reference; }
Example 6
Source File: ParameterizedTypeReference.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public JvmTypeReference toTypeReference() { JvmParameterizedTypeReference result = getTypesFactory().createJvmParameterizedTypeReference(); result.setType(type); if (typeArguments != null) { for(LightweightTypeReference typeArgument: typeArguments) { result.getArguments().add(typeArgument.toTypeReference()); } } return result; }
Example 7
Source File: ParameterizedTypeReference.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper) { if (isTypeVisible(visibilityHelper)) { JvmParameterizedTypeReference result = getTypesFactory().createJvmParameterizedTypeReference(); result.setType(type); if (typeArguments != null) { for(LightweightTypeReference typeArgument: typeArguments) { result.getArguments().add(typeArgument.toJavaCompliantTypeReference()); } } return result; } else { return toJavaCompliantTypeReference(getSuperTypes(), visibilityHelper); } }
Example 8
Source File: JvmTypesBuilder.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private JvmTypeReference newObjectReference() { JvmType objectType = typesFactory.createJvmGenericType(); String objectClassName = Object.class.getName(); ((InternalEObject) objectType).eSetProxyURI(URIHelperConstants.OBJECTS_URI.appendSegment(objectClassName).appendFragment(objectClassName)); JvmParameterizedTypeReference result = typesFactory.createJvmParameterizedTypeReference(); result.setType(objectType); return result; }
Example 9
Source File: ReflectionTypeFactory.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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 10
Source File: ReflectionTypeFactory.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected JvmTypeReference createLocalTypeReference(Type type, JvmTypeParameterDeclarator container, GenericDeclaration member) { if (type instanceof GenericArrayType) { GenericArrayType arrayType = (GenericArrayType) type; Type componentType = arrayType.getGenericComponentType(); return createLocalArrayTypeReference(componentType, container, member); } else if (type instanceof TypeVariable<?>) { TypeVariable<?> typeVariable = (TypeVariable<?>) type; JvmParameterizedTypeReference result = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference(); int idx = Arrays.asList(member.getTypeParameters()).indexOf(typeVariable); result.setType(container.getTypeParameters().get(idx)); return result; } throw new IllegalArgumentException(type.toString()); }
Example 11
Source File: JdtTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testBug300216() { JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName("java.lang.Object"); assertTrue(type.getSuperTypes().isEmpty()); URI unresolveableType = URI.createURI("java:/Objects/Something#Something"); JvmVoid proxy = TypesFactory.eINSTANCE.createJvmVoid(); JvmParameterizedTypeReference typeReference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference(); typeReference.setType(proxy); ((InternalEObject) proxy).eSetProxyURI(unresolveableType); type.getSuperTypes().add(typeReference); assertTrue(type.getSuperTypes().get(0).getType().eIsProxy()); assertEquals(2, type.eResource().getResourceSet().getResources().size()); }
Example 12
Source File: JdtBasedTypeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * 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 13
Source File: XtendReentrantTypeResolver.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected JvmParameterizedTypeReference createSuperTypeReference(JvmType superType, XConstructorCall constructorCall) { JvmParameterizedTypeReference result = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference(); result.setType(superType); for(JvmTypeReference typeReference: constructorCall.getTypeArguments()) { result.getArguments().add(typesBuilder.cloneWithProxies(typeReference)); } return result; }
Example 14
Source File: TypeReferences.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
/** * @return a fresh {@link JvmParameterizedTypeReference} for the given {@link JvmType} parameterized with the given * typeArgs. This method does not check whether the given type can handle the given type arguments. */ public JvmParameterizedTypeReference createTypeRef(JvmType type, JvmTypeReference... typeArgs) { if (type == null) throw new NullPointerException("type"); List<JvmTypeReference> typeReferences = Collections.emptyList(); if (typeArgs != null && typeArgs.length > 0) { typeReferences = Lists.newArrayListWithCapacity(typeArgs.length); for (int i = 0; i < typeArgs.length; i++) { JvmTypeReference jvmTypeReference = typeArgs[i]; typeReferences.add(EcoreUtil2.cloneIfContained(jvmTypeReference)); } } JvmParameterizedTypeReference reference; if (type instanceof JvmGenericType) { JvmGenericType casted = (JvmGenericType) type; List<JvmTypeParameter> list = casted.getTypeParameters(); if (!typeReferences.isEmpty() && list.size() != typeReferences.size()) { throw new IllegalArgumentException("The type " + type.getIdentifier() + " expects " + list.size() + " type arguments, but was " + typeReferences.size() + ". Either pass zero arguments (raw type) or the correct number."); } // Raw type -> create type references to type param if (typeReferences.isEmpty() && !list.isEmpty()) { typeReferences = Lists.newArrayListWithCapacity(list.size()); for (JvmTypeParameter typeParameter : list) { typeReferences.add(createTypeRef(typeParameter)); } } if (!casted.isStatic() && casted.eContainer() instanceof JvmType) { JvmParameterizedTypeReference outer = createTypeRef((JvmType)casted.eContainer()); reference = factory.createJvmInnerTypeReference(); ((JvmInnerTypeReference) reference).setOuter(outer); } else { reference = factory.createJvmParameterizedTypeReference(); } } else { reference = factory.createJvmParameterizedTypeReference(); } reference.setType(type); if (!typeReferences.isEmpty()) reference.getArguments().addAll(typeReferences); return reference; }
Example 15
Source File: JdtBasedTypeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.4 */ protected JvmTypeReference createObjectClassReference() { JvmParameterizedTypeReference result = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference(); result.setType(OBJECT_CLASS_PROXY); return result; }