protected StandardTypeReferenceOwner newTypeReferenceOwner(final EObject context) { return new StandardTypeReferenceOwner(this.services, context); } }
protected LightweightTypeReference toLightweightTypeReference(final JvmTypeReference typeRef) { return new StandardTypeReferenceOwner(this.services, typeRef).toLightweightTypeReference(typeRef); }
/** * Creates a references to the given class or returns an {@link UnknownTypeReference} if no * JRE is available. */ @Override public LightweightTypeReference newReferenceTo(Class<?> type) { JvmType rawType = getServices().getTypeReferences().findDeclaredType(type, getContextResourceSet()); if (rawType == null) { return newUnknownTypeReference(type.getName()); } return toPlainTypeReference(rawType); }
/** * Static helper method that is used from within the super call in the constructor of * {@link RawResolvedFeatures}. */ private static LightweightTypeReference createTypeReference(JvmDeclaredType type, CommonTypeComputationServices services) { StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, type); return owner.newParameterizedTypeReference(type); }
/** * Creates a new wildcard type reference with the given type as the upper bound. * For example: * <pre>wildcardExtends(typeRef(CharSequence))</pre> * would create a type reference representing * <pre>? extends CharSequence</pre> * * @param extendsBound * the upper bound of the wildcard * @return the newly created wildcard type reference */ public JvmTypeReference wildcardExtends(JvmTypeReference extendsBound) { WildcardTypeReference wildcardTypeReference = typeReferenceOwner.newWildcardTypeReference(); wildcardTypeReference.addUpperBound(typeReferenceOwner.toLightweightTypeReference(extendsBound)); return wildcardTypeReference.toTypeReference(); }
/** * Creates a references to the given class or returns an {@link UnknownTypeReference} if no * JRE is available. If the type is available, the given acceptor is used to initialize it further. */ @Override public LightweightTypeReference newReferenceTo(Class<?> type, TypeReferenceInitializer<? super ParameterizedTypeReference> init) { if (init == null) { throw new NullPointerException("initializer"); } JvmType rawType = getServices().getTypeReferences().findDeclaredType(type, getContextResourceSet()); if (rawType == null) { return newUnknownTypeReference(type.getName()); } if (rawType.eClass() == TypesPackage.Literals.JVM_ARRAY_TYPE) { throw new IllegalArgumentException("given type is an array type: " + type); } ParameterizedTypeReference result = newParameterizedTypeReference(rawType); return init.enhance(result); }
/** * Creates a new {@link JvmTypeReference} pointing to the given class and containing the given type arguments. * * @param type * the type the reference shall point to. * @param typeArgs * type arguments * @return the newly created {@link JvmTypeReference} */ public JvmTypeReference typeRef(JvmType type, JvmTypeReference... typeArgs) { int typeParams = 0; if (type instanceof JvmGenericType) { typeParams = ((JvmGenericType) type).getTypeParameters().size(); } if (typeParams < typeArgs.length) { throw new IllegalArgumentException("The type "+type.getIdentifier()+" only declares "+typeParams+" type parameters. You passed "+typeArgs.length+"."); } LightweightTypeReference reference = typeReferenceOwner.toPlainTypeReference(type); for (JvmTypeReference jvmTypeReference : typeArgs) { ((ParameterizedTypeReference)reference).addTypeArgument(typeReferenceOwner.toLightweightTypeReference(jvmTypeReference)); } return reference.toJavaCompliantTypeReference(); }
public LightweightTypeReference toLightweightTypeReference(final JvmTypeReference typeRef, final EObject context) { return this.newTypeReferenceOwner(context).toLightweightTypeReference(typeRef); }
@Override public ParameterizedTypeReference newParameterizedTypeReference(JvmType type) { ParameterizedTypeReference result; if (factory.isInner(type)) { ParameterizedTypeReference outer = newParameterizedTypeReference((JvmDeclaredType)type.eContainer()); result = new InnerTypeReference(this, outer, type); } else { result = new ParameterizedTypeReference(this, type); } return result; }
/** * Creates a references to {@link Object} or returns an {@link UnknownTypeReference} if no * JRE is available. */ @Override public LightweightTypeReference newReferenceToObject() { return newReferenceTo(Object.class); }
/** * Creates a new wildcard type reference with the given type as the lower bound and {@link Object} as upper bound. * * For example: * <pre>wildcardSuper(typeRef(CharSequence))</pre> * would create a type reference representing * <pre>? super CharSequence</pre> * * @param superBound * the super bound of the wildcard * @return the newly created wildcard type reference */ public JvmTypeReference wildcardSuper(JvmTypeReference superBound) { WildcardTypeReference wildcardTypeReference = typeReferenceOwner.newWildcardTypeReference(); wildcardTypeReference.addUpperBound(typeReferenceOwner.toLightweightTypeReference(typeRef(Object.class))); wildcardTypeReference.setLowerBound(typeReferenceOwner.toLightweightTypeReference(superBound)); return wildcardTypeReference.toTypeReference(); }
@Override public FunctionTypeReference newFunctionTypeReference(JvmType type) { FunctionTypeReference result; if (factory.isInner(type)) { ParameterizedTypeReference outer = newParameterizedTypeReference((JvmDeclaredType)type.eContainer()); result = new InnerFunctionTypeReference(this, outer, type); } else { result = new FunctionTypeReference(this, type); } return result; }
protected ITypeReferenceOwner newTypeReferenceOwner(EObject context) { return new StandardTypeReferenceOwner(services, context); }
public boolean isAssignableFrom(final JvmTypeReference target, final JvmTypeReference source, final TypeConformanceComputationArgument argument) { if (((target == null) || (source == null))) { throw new RuntimeException("For testing assignment source and target types must not be null"); } if ((this.typeReferenceOwner == null)) { StandardTypeReferenceOwner _standardTypeReferenceOwner = new StandardTypeReferenceOwner(this.services, this.resourceSet); this.typeReferenceOwner = _standardTypeReferenceOwner; } final LightweightTypeReference lleft = this.typeReferenceOwner.toLightweightTypeReference(target); LightweightTypeReference lright = this.typeReferenceOwner.toLightweightTypeReference(source); final boolean assignable = lleft.isAssignableFrom(lright, argument); return assignable; }
protected LightweightTypeReferenceFactory getTypeConverter(final XtextResource context) { StandardTypeReferenceOwner _standardTypeReferenceOwner = new StandardTypeReferenceOwner(this.typeComputationServices, context); return new LightweightTypeReferenceFactory(_standardTypeReferenceOwner) { @Override public LightweightTypeReference doVisitParameterizedTypeReference(final JvmParameterizedTypeReference reference) { final LightweightTypeReference result = super.doVisitParameterizedTypeReference(reference); boolean _isFunctionType = result.isFunctionType(); if (_isFunctionType) { return result.tryConvertToFunctionTypeReference(false); } return result; } }; }
/** * @since 2.4 */ public String referenceToString(JvmTypeReference typeRef, String defaultLabel) { if (typeRef == null) return defaultLabel; if (typeRef.eResource() == null) { if (typeRef instanceof JvmAnyTypeReference) { return "Object"; } return typeRef.getSimpleName(); } StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, typeRef); LightweightTypeReference reference = owner.toLightweightTypeReference(typeRef); return referenceToString(reference); }
public JvmTypeReferenceBuilder create(ResourceSet context) { if (context == null) { throw new NullPointerException("'context' cannot be null."); } JvmTypeReferenceBuilder result = builderProvider.get(); result.context = context; result.typeReferenceOwner = new StandardTypeReferenceOwner(services, context); return result; } }
@Check public void checkTypesAreDisjoint(JvmSynonymTypeReference typeRef) { List<JvmTypeReference> references = typeRef.getReferences(); StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, typeRef); CompoundTypeReference lightweightTypeReference = (CompoundTypeReference) owner.toLightweightTypeReference(typeRef); List<LightweightTypeReference> components = lightweightTypeReference.getMultiTypeComponents(); for(int left = 0; left < components.size(); left++) {
public InvokedResolvedOperation resolve(XAbstractFeatureCall featureCall) { IResolvedTypes resolvedTypes = batchTypeResolver.resolveTypes(featureCall); ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, featureCall); return resolve(featureCall, resolvedTypes, owner); }
protected Object _doEvaluate(XCastedExpression castedExpression, IEvaluationContext context, CancelIndicator indicator) { Object result = internalEvaluate(castedExpression.getTarget(), context, indicator); StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, castedExpression); LightweightTypeReference targetType = owner.toLightweightTypeReference(castedExpression.getType()); result = wrapOrUnwrapArray(result, targetType); result = coerceArgumentType(result, castedExpression.getType()); JvmType castType = castedExpression.getType().getType(); if (castType instanceof JvmPrimitiveType) { if (result == null) { throwNullPointerException(castedExpression, "Cannot cast null to primitive " + castType.getIdentifier()); } return castToPrimitiveType(result, services.getPrimitives().primitiveKind((JvmPrimitiveType) castType)); } else { String typeName = castType.getQualifiedName(); Class<?> expectedType = null; try { expectedType = getJavaType(castType); } catch (ClassNotFoundException e) { throw new EvaluationException(new NoClassDefFoundError(typeName)); } try { expectedType.cast(result); } catch (ClassCastException e) { throw new EvaluationException(new ClassCastException(typeName)); } return result; } }