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 LightweightTypeReference toLightweightTypeReference(final JvmTypeReference typeRef) { return new StandardTypeReferenceOwner(this.services, typeRef).toLightweightTypeReference(typeRef); }
public LightweightTypeReference toLightweightTypeReference(final JvmTypeReference typeRef, final EObject context) { return this.newTypeReferenceOwner(context).toLightweightTypeReference(typeRef); }
/** * 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(); }
/** * 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(); }
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++) {
/** * 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(); }
/** * @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); }
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; } }