protected LightweightTypeReference createRawTypeReference(JvmType rawType) { return getOwner().toPlainTypeReference(rawType); }
public void addTypeArgument(LightweightTypeReference argument) { if (argument == null) { throw new NullPointerException("argument may not be null"); } if (!argument.isOwnedBy(getOwner())) { throw new IllegalArgumentException("argument is not valid in current context"); } if (typeArguments == null) typeArguments = Lists.newArrayListWithCapacity(2); typeArguments.add(argument); resolved = resolved && argument.isResolved(); }
@Override protected List<JvmType> doVisitParameterizedTypeReference(ParameterizedTypeReference reference, ResourceSet resourceSet) { JvmType type = reference.getType(); if (!type.eIsProxy()) { if (type instanceof JvmTypeParameter) { return getRawTypesFromConstraints(reference.getOwner(), (JvmTypeParameter) type, resourceSet); } return Collections.singletonList(type); } return Collections.emptyList(); }
private LightweightTypeReference findPrimitive(String primitive) { JvmType result = (JvmType) getOwner().getContextResourceSet().getEObject(URIHelperConstants.PRIMITIVES_URI.appendFragment(primitive), true); if (result != null) { return getOwner().newParameterizedTypeReference(result); } throw new IllegalStateException("Cannot find primitive type: " + primitive); }
@Override protected LightweightTypeReference doVisitParameterizedTypeReference(ParameterizedTypeReference reference, ResourceSet resourceSet) { JvmType type = reference.getType(); if (reference.isRawType() && !(type instanceof JvmTypeParameter)) { return reference; } if (type instanceof JvmTypeParameter) { return getRawTypeFromConstraints(reference.getOwner(), (JvmTypeParameter) type, resourceSet); } return reference.getOwner().toPlainTypeReference(type); }
protected FunctionTypeReference getAsFunctionOrNull(ParameterizedTypeReference typeReference) { if (typeReference.isRawType()) return null; FunctionTypeReference functionType = new FunctionTypeReference(typeReference.getOwner(), typeReference.getType()); List<LightweightTypeReference> allTypeArguments = typeReference.getTypeArguments(); if (!tryAssignTypeArguments(allTypeArguments.subList(0, allTypeArguments.size() - 1), functionType)) return null; LightweightTypeReference lastTypeArgument = allTypeArguments.get(allTypeArguments.size() - 1); functionType.addTypeArgument(lastTypeArgument); LightweightTypeReference returnType = lastTypeArgument.getUpperBoundSubstitute(); functionType.setReturnType(returnType); return functionType; }
@Override public LightweightTypeReference getRawTypeReference() { if (typeArguments == null && type.eClass() != TypesPackage.Literals.JVM_TYPE_PARAMETER) { return this; } if (type.eClass() != TypesPackage.Literals.JVM_TYPE_PARAMETER) { return getOwner().newParameterizedTypeReference(type); } // TODO optimize return super.getRawTypeReference(); }
ResourceSet resourceSet = getOwner().getContextResourceSet(); Resource typeResource = resourceSet.getResource(URIHelperConstants.OBJECTS_URI.appendSegment(rawType.getName()), true); JvmType type = (JvmType) typeResource.getContents().get(0); if (type == null) return null; return getOwner().newParameterizedTypeReference(type); } catch(WrappedException e) {
List<JvmTypeReference> superTypes = ((JvmDeclaredType) type).getSuperTypes(); if (!superTypes.isEmpty()) { ITypeReferenceOwner owner = getOwner(); List<LightweightTypeReference> result = Lists.newArrayListWithCapacity(superTypes.size()); boolean isRawType = isRawType(); List<JvmTypeConstraint> constraints = ((JvmTypeParameter) type).getConstraints(); if (!constraints.isEmpty()) { ITypeReferenceOwner owner = getOwner(); List<LightweightTypeReference> result = Lists.newArrayListWithCapacity(constraints.size()); for(JvmTypeConstraint constraint: constraints) {
@Override protected Boolean doVisitParameterizedTypeReference(ParameterizedTypeReference reference) { if (reference.isResolved()) { return true; } if (reference.getOwner().getDeclaredTypeParameters().contains(reference.getType())) { return true; } if (!visit(reference.getTypeArguments())) { return false; } return !(reference.getType() instanceof JvmTypeParameter); }
private ArrayTypeReference doTryConvertToArray(ParameterizedTypeReference typeReference) { LightweightTypeReference parameterizedIterable = typeReference.getSuperType(Iterable.class); if (parameterizedIterable != null) { ITypeReferenceOwner owner = typeReference.getOwner(); if (parameterizedIterable.isRawType()) { // return Object[] List<LightweightTypeReference> superTypes = parameterizedIterable.getSuperTypes(); if (superTypes.isEmpty()) { return null; } LightweightTypeReference objectType = superTypes.get(0); ArrayTypeReference array = owner.newArrayTypeReference(objectType); return array; } else { LightweightTypeReference componentType = parameterizedIterable.getTypeArguments().get(0).getUpperBoundSubstitute(); ArrayTypeReference array = owner.newArrayTypeReference(componentType); return array; } } return null; }
List<JvmTypeParameter> typeParameters = ((JvmTypeParameterDeclarator) type).getTypeParameters(); for(JvmTypeParameter typeParameter: typeParameters) { addConstraintMapping(typeParameter, reference.getOwner(), data); ITypeReferenceOwner owner = reference.getOwner(); List<JvmTypeReference> superTypes = ((JvmDeclaredType) type).getSuperTypes(); for(JvmTypeReference superType: superTypes) { ITypeReferenceOwner owner = reference.getOwner(); List<JvmTypeConstraint> constraints = ((JvmTypeParameter) type).getConstraints(); for(JvmTypeConstraint constraint: constraints) {
protected boolean enhanceSuperType(List<LightweightTypeReference> superTypes, ParameterizedTypeReference result) { JvmType rawType = result.getType(); ITypeReferenceOwner owner = result.getOwner(); List<JvmTypeParameter> typeParameters = ((JvmTypeParameterDeclarator) rawType).getTypeParameters(); List<LightweightTypeReference> parameterSuperTypes = Lists.newArrayListWithCapacity(superTypes.size());
@Override /* @Nullable */ public LightweightTypeReference getSuperType(JvmType rawType) { Object rawResult = internalGetSuperType(rawType); if (rawResult instanceof ParameterizedTypeReference) { return (LightweightTypeReference) rawResult; } else if (rawResult != null) { JvmTypeReference superType = (JvmTypeReference) rawResult; if (isRawType()) { return createRawTypeReference(rawType); } if (superType.eClass() == TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE) { if (((JvmParameterizedTypeReference) superType).getArguments().isEmpty()) { return getOwner().newParameterizedTypeReference(rawType); } } LightweightTypeReference unresolved = getOwner().toLightweightTypeReference(rawType); TypeParameterSubstitutor<?> substitutor = createSubstitutor(); LightweightTypeReference result = substitutor.substitute(unresolved); return result; } return null; }
@Override protected LightweightTypeReference enhanceParameterizedTypeReference(ParameterizedTypeReference reference, JvmType type, ParameterizedTypeReference result, ConstraintVisitingInfo visiting) { boolean convertToWildcard = false; for(int i = 0; i < reference.getTypeArguments().size(); i++) { wasCapturedWildcard = false; LightweightTypeReference argument = reference.getTypeArguments().get(i); visiting.pushInfo(type instanceof JvmTypeParameterDeclarator ? (JvmTypeParameterDeclarator) type : null, i); LightweightTypeReference visitedArgument = argument.accept(this, visiting); if (wasCapturedWildcard) convertToWildcard = true; wasCapturedWildcard = false; result.addTypeArgument(visitedArgument); } if (convertToWildcard) { WildcardTypeReference wildcard = result.getOwner().newWildcardTypeReference(); wildcard.addUpperBound(result); return wildcard; } return result; }
/** * Returns a projection of this type to the instance level. That is, type arguments will * be replaced by their invariant bounds. * * The instance projection of <code>ArrayList<? extends Iterable<? extends String>></code> * is <code>ArrayList<Iterable<? extends String>></code> since it is possible to create instances * of <code>ArrayList<Iterable<? extends String>></code>. */ public ParameterizedTypeReference toInstanceTypeReference() { ParameterizedTypeReference result = getOwner().newParameterizedTypeReference(getType()); for(LightweightTypeReference typeArgument: getTypeArguments()) { result.addTypeArgument(typeArgument.getInvariantBoundSubstitute()); } return result; } }
private LightweightTypeReference getSuperTypeByName(String typeName, boolean interfaceType) { JvmTypeReference superType = getSuperTypeByName(typeName, interfaceType, type, new RecursionGuard<JvmType>()); if (superType != null) { JvmType rawType = superType.getType(); if (isRawType()) { return createRawTypeReference(rawType); } if (superType.eClass() == TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE) { if (((JvmParameterizedTypeReference) superType).getArguments().isEmpty()) { return getOwner().newParameterizedTypeReference(rawType); } } LightweightTypeReference unresolved = getOwner().toLightweightTypeReference(rawType); TypeParameterSubstitutor<?> substitutor = createSubstitutor(); LightweightTypeReference result = substitutor.substitute(unresolved); return result; } return null; }
protected FunctionTypeReference getAsProcedureOrNull(ParameterizedTypeReference typeReference) { ITypeReferenceOwner owner = typeReference.getOwner(); JvmType type = typeReference.getType(); FunctionTypeReference functionType = new FunctionTypeReference(owner, type); if (!tryAssignTypeArguments(typeReference.getTypeArguments(), functionType)) return null; JvmType voidType = (JvmType) owner.getContextResourceSet().getEObject(URIHelperConstants.PRIMITIVES_URI.appendFragment("void"), true); functionType.setReturnType(owner.newParameterizedTypeReference(voidType)); return functionType; }
if (otherEClass != TypesPackage.Literals.JVM_TYPE_PARAMETER) { if (Object.class.getName().equals(rawType.getIdentifier())) { return getOwner().newParameterizedTypeReference(rawType);
if (operation == null) return null; ITypeReferenceOwner owner = typeReference.getOwner(); LightweightTypeReference declaredReturnType = owner.toLightweightTypeReference(operation.getReturnType()); if (rawType) {