@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; }
/** * A function type reference may be known to have the type argument {@link Number} but still use a more * specific return type {@link Integer}. Normalization converts such a reference to the return type {@link Number}. */ protected LightweightTypeReference normalizeFunctionTypeReference(LightweightTypeReference type) { if (type.getKind() == LightweightTypeReference.KIND_FUNCTION_TYPE_REFERENCE) { ParameterizedTypeReference parameterized = new ParameterizedTypeReference(type.getOwner(), type.getType()); for(LightweightTypeReference argument: type.getTypeArguments()) { parameterized.addTypeArgument(argument); } type = parameterized.tryConvertToFunctionTypeReference(false); } return type; }
/** * The map type may be constructed from different pairs, e.g. the pair's type arguments don't need to be as strict * as the map suggests. The pair's expectation is adjusted accordingly. */ protected LightweightTypeReference createNormalizedPairType(LightweightTypeReference pairType, LightweightTypeReference mapType, ITypeReferenceOwner owner) { ParameterizedTypeReference result = new ParameterizedTypeReference(owner, pairType.getType()); LightweightTypeReference keyType = mapType.getTypeArguments().get(0); if (keyType.getKind() != LightweightTypeReference.KIND_WILDCARD_TYPE_REFERENCE) { WildcardTypeReference wc = new WildcardTypeReference(owner); wc.addUpperBound(keyType); keyType = wc; } LightweightTypeReference valueType = mapType.getTypeArguments().get(1); if (valueType.getKind() != LightweightTypeReference.KIND_WILDCARD_TYPE_REFERENCE) { WildcardTypeReference wc = new WildcardTypeReference(owner); wc.addUpperBound(valueType); valueType = wc; } result.addTypeArgument(keyType); result.addTypeArgument(valueType); return result; }
/** * Creates a collection type reference that comes as close as possible / necessary to its expected type. */ protected LightweightTypeReference createCollectionTypeReference(JvmGenericType collectionType, LightweightTypeReference elementType, LightweightTypeReference expectedType, ITypeReferenceOwner owner) { ParameterizedTypeReference result = new ParameterizedTypeReference(owner, collectionType); result.addTypeArgument(elementType); if (isIterableExpectation(expectedType) && !expectedType.isAssignableFrom(result)) { // avoid to assign a set literal to a list and viceversa: // at least the raw types must be assignable // https://bugs.eclipse.org/bugs/show_bug.cgi?id=498779 if (expectedType.getRawTypeReference().isAssignableFrom(result.getRawTypeReference())) { LightweightTypeReference expectedElementType = getElementOrComponentType(expectedType, owner); if (matchesExpectation(elementType, expectedElementType)) { return expectedType; } } } return result; }