@Override protected ParameterizedTypeReference doCopyInto(ITypeReferenceOwner owner) { ParameterizedTypeReference result = owner.newParameterizedTypeReference(type); copyTypeArguments(result, owner); return result; }
/** * Determines if this type reference denotes the same type or a supertype of * the given {@code type}. */ public boolean isAssignableFrom(JvmType type) { if (type == null) { throw new IllegalArgumentException("type may not be null"); } ParameterizedTypeReference other = getOwner().newParameterizedTypeReference(type); boolean result = isAssignableFrom(other); return result; }
private static LightweightTypeReference findTopLevelType(LightweightTypeReference context, String typeName) { ITypeReferenceOwner owner = context.getOwner(); ResourceSet resourceSet = owner.getContextResourceSet(); Resource typeResource = resourceSet.getResource(URIHelperConstants.OBJECTS_URI.appendSegment(typeName), true); EList<EObject> contents = typeResource.getContents(); if (contents.isEmpty()) { return null; } JvmType type = (JvmType) contents.get(0); if (type == null) return null; return owner.newParameterizedTypeReference(type); }
@Override protected void initializeMapping(JvmTypeParameter typeParameter, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> result) { ITypeReferenceOwner owner = getState().getReferenceOwner(); if (typeParameter.getDeclarator() instanceof JvmType && owner.getDeclaredTypeParameters().contains(typeParameter)) { LightweightTypeReference typeReference = owner.newParameterizedTypeReference(typeParameter); result.put(typeParameter, new LightweightMergedBoundTypeArgument(typeReference, VarianceInfo.INVARIANT)); } else { super.initializeMapping(typeParameter, result); } }
protected LightweightTypeReference createObjectReference(ITypeReferenceOwner owner, ResourceSet resourceSet) { // no upper bound found - seems to be an invalid - assume object as upper bound JvmType objectType = factory.createJvmGenericType(); String objectClassName = Object.class.getName(); ((InternalEObject) objectType).eSetProxyURI(URIHelperConstants.OBJECTS_URI.appendSegment(objectClassName).appendFragment(objectClassName)); objectType = (JvmType) EcoreUtil.resolve(objectType, resourceSet); return owner.newParameterizedTypeReference(objectType); } }
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); }
public LightweightTypeReference toPlainTypeReference(JvmType type) { if (type.eClass() == TypesPackage.Literals.JVM_ARRAY_TYPE) { JvmComponentType componentType = ((JvmArrayType) type).getComponentType(); LightweightTypeReference componentTypeReference = toPlainTypeReference(componentType); return owner.newArrayTypeReference(componentTypeReference); } return owner.newParameterizedTypeReference(type); }
@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(); }
protected void setUnboundCollectionType(XCollectionLiteral literal, JvmGenericType collectionType, ITypeExpectation expectation, LightweightTypeReference elementTypeExpectation, ITypeComputationState state) { ParameterizedTypeReference unboundCollectionType = state.getReferenceOwner().newParameterizedTypeReference(collectionType); if (elementTypeExpectation != null) { unboundCollectionType.addTypeArgument(elementTypeExpectation); } else { UnboundTypeReference unboundTypeArgument = expectation.createUnboundTypeReference(literal, collectionType.getTypeParameters().get(0)); unboundCollectionType.addTypeArgument(unboundTypeArgument); } expectation.acceptActualType(unboundCollectionType, ConformanceFlags.UNCHECKED); }
@Override public LightweightTypeReference enhance(ParameterizedTypeReference reference) { LightweightTypeReference argumentType = owner.newParameterizedTypeReference((JvmType) feature); if (argumentType.isPrimitiveVoid()) { argumentType = owner.newReferenceTo(Void.class); } else { argumentType = argumentType.getWrapperTypeIfPrimitive(); } reference.addTypeArgument(argumentType); return reference; } });
protected LightweightTypeReference getReceiverType(XAbstractFeatureCall featureCall, IResolvedTypes resolvedTypes, ITypeReferenceOwner owner) { XExpression receiver = featureCall.getActualReceiver(); if (receiver == null) { // static feature call JvmOperation operation = (JvmOperation) featureCall.getFeature(); JvmDeclaredType declaringType = operation.getDeclaringType(); return owner.newParameterizedTypeReference(declaringType); } return resolvedTypes.getActualType(receiver); } }
/** * Return all the cases that are associated with the given dispatch operation. */ public List<JvmOperation> getAllDispatchCases(JvmOperation dispatcherOperation) { DispatchSignature dispatchSignature = new DispatchSignature(dispatcherOperation.getSimpleName(), dispatcherOperation.getParameters().size()); JvmDeclaredType type = dispatcherOperation.getDeclaringType(); ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, type); ContextualVisibilityHelper contextualVisibilityHelper = new ContextualVisibilityHelper(visibilityHelper, owner.newParameterizedTypeReference(type)); return getAllDispatchMethods(dispatchSignature, type, contextualVisibilityHelper); }
protected void resolveAgainstConstraints() { TypeParameterByConstraintSubstitutor unboundSubstitutor = new TypeParameterByConstraintSubstitutor( Collections.<JvmTypeParameter, LightweightMergedBoundTypeArgument>emptyMap(), getOwner(), true); LightweightTypeReference substitute = unboundSubstitutor.substitute(getOwner().newParameterizedTypeReference(typeParameter)); getOwner().acceptHint(getHandle(), new LightweightBoundTypeArgument(substitute, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT)); resolvedTo = substitute; }
@Override protected void applyType() { JvmType type = (JvmType) getFeature(); if (type == null || type.eIsProxy()) { throw new IllegalStateException(); } ITypeReferenceOwner referenceOwner = getResolvedTypes().getReferenceOwner(); ParameterizedTypeReference result = referenceOwner.newParameterizedTypeReference(type); for(LightweightTypeReference typeArgument: getTypeArguments()) { result.addTypeArgument(typeArgument); } getState().acceptActualType(result); }
@Override public ParameterizedTypeReference toInstanceTypeReference() { ParameterizedTypeReference outerInstanceTypeReference = ((ParameterizedTypeReference) outer).toInstanceTypeReference(); InnerTypeReference result = getOwner().newParameterizedTypeReference(outerInstanceTypeReference, getType()); for(LightweightTypeReference typeArgument: getTypeArguments()) { result.addTypeArgument(typeArgument.getInvariantBoundSubstitute()); } return result; } }
protected void applyPackageFragment(XMemberFeatureCall memberFeatureCall, JvmDeclaredType type) { XExpression target = memberFeatureCall.getMemberCallTarget(); state.getResolvedTypes().acceptType( target, new NoExpectation(state, false), state.getReferenceOwner().newParameterizedTypeReference(type), false, ConformanceFlags.CHECKED_SUCCESS); if (target instanceof XMemberFeatureCall) { applyPackageFragment((XMemberFeatureCall) target, type); } }
@Override public LightweightTypeReference doVisitParameterizedTypeReference(JvmParameterizedTypeReference reference) { JvmType type = getType(reference); if (type == null || type.eIsProxy()) { return createUnknownTypeReference(reference); } ParameterizedTypeReference result = owner.newParameterizedTypeReference(type); for(JvmTypeReference argument: reference.getArguments()) { result.addTypeArgument(visit(argument).getWrapperTypeIfPrimitive()); } return result; }
@Override protected void addHint(UnboundTypeReference typeParameter, LightweightTypeReference reference) { LightweightTypeReference wrapped = reference.getWrapperTypeIfPrimitive(); typeParameter.acceptHint(wrapped, BoundTypeArgumentSource.RESOLVED, getOrigin(), getExpectedVariance(), getActualVariance()); LightweightTypeReference typeParameterReference = reference.getOwner().newParameterizedTypeReference(typeParameter.getTypeParameter()); if (validParameterTypes && !typeParameterReference.getRawTypeReference().isAssignableFrom(reference)) { validParameterTypes = false; } } }.processPairedReferences(operationParameterType, closureParameterType);
@Override protected LightweightTypeReference doVisitInnerTypeReference(InnerTypeReference reference, Visiting visiting) { if (reference.isResolved() && reference.isOwnedBy(getOwner())) return reference; LightweightTypeReference outer = reference.getOuter().accept(this, visiting); ParameterizedTypeReference result = getOwner().newParameterizedTypeReference(outer, reference.getType()); for(LightweightTypeReference argument: reference.getTypeArguments()) { result.addTypeArgument(visitTypeArgument(argument, visiting)); } return result; }
@Override public LightweightTypeReference getRawTypeReference() { if (isRawType()) { return this; } LightweightTypeReference rawOuter = outer.getRawTypeReference(); JvmType type = getType(); if (type.eClass() != TypesPackage.Literals.JVM_TYPE_PARAMETER) { return getOwner().newParameterizedTypeReference(rawOuter, type); } return getServices().getRawTypeHelper().getRawTypeReference(this, getOwner().getContextResourceSet()); }