public boolean isOwnedBy(ITypeReferenceOwner owner) { if (isResolved()) { return true; } return owner == getOwner(); }
protected CommonTypeComputationServices getServices() { return getOwner().getServices(); }
/** * Logic was moved to inner class CommonSuperTypeFinder in the context of bug 495314. * * This method is scheduled for deletion in Xtext 2.15 * * @deprecated see {@link CommonSuperTypeFinder#isRecursiveRequest(List, Set)} */ @Deprecated protected final boolean isRecursiveRequest(List<LightweightTypeReference> types, Set<String> allNames, List<LightweightTypeReference> initiallyRequested) { CommonSuperTypeFinder typeFinder = newCommonSuperTypeFinder(types.get(0).getOwner()); typeFinder.requestsInProgress = Lists.newArrayList(); typeFinder.requestsInProgress.add(initiallyRequested); return typeFinder.isRecursiveRequest(types, allNames); }
/** * Logic was moved to inner class CommonSuperTypeFinder in the context of bug 495314. * * This method is scheduled for deletion in Xtext 2.15 * * @deprecated see {@link CommonSuperTypeFinder#enhanceSuperType(List, ParameterizedTypeReference)} */ @Deprecated protected final boolean enhanceSuperType(List<LightweightTypeReference> superTypes, List<LightweightTypeReference> initiallyRequested, ParameterizedTypeReference result) { CommonSuperTypeFinder typeFinder = newCommonSuperTypeFinder(superTypes.get(0).getOwner()); typeFinder.requestsInProgress = Lists.newArrayList(); typeFinder.requestsInProgress.add(initiallyRequested); return typeFinder.enhanceSuperType(superTypes, 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; }
protected TypeParameterSubstitutor<?> createSubstitutor() { DeclaratorTypeArgumentCollector collector = new DeclaratorTypeArgumentCollector() { @Override public Boolean doVisitArrayTypeReference(ArrayTypeReference reference, LightweightTraversalData data) { return reference.getComponentType().accept(this, data); } }; Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping = collector.getTypeParameterMapping(this); UnboundTypeParameterPreservingSubstitutor substitutor = new UnboundTypeParameterPreservingSubstitutor(mapping, getOwner()); return substitutor; }
protected TypesFactory getTypesFactory() { return getOwner().getServices().getTypesFactory(); }
protected LightweightTypeReference convertLocalType(LightweightTypeReference reference) { if (member instanceof JvmFeature) { List<JvmGenericType> localClasses = ((JvmFeature) member).getLocalClasses(); if (localClasses.isEmpty()) { return reference; } LocalTypeSubstitutor substitutor = new LocalTypeSubstitutor(reference.getOwner(), member); LightweightTypeReference result = substitutor.withoutLocalTypes(reference); return result; } else { return reference; } }
protected JvmTypeReference toJavaCompliantTypeReference(List<LightweightTypeReference> types, IVisibilityHelper visibilityHelper) { LightweightTypeReference type = getServices().getTypeConformanceComputer().getCommonSuperType(types, getOwner()); if (type == null) { return getOwner().getServices().getTypeReferences().getTypeForName(Object.class, getOwner().getContextResourceSet()); } return type.toJavaCompliantTypeReference(visibilityHelper); }
protected JvmTypeReference resolveSynonymType(JvmSynonymTypeReference reference, EObject context) { LightweightTypeReference lightweight = toLightweight(reference, context); LightweightTypeReference superType = lightweight.getOwner().getServices().getTypeConformanceComputer().getCommonSuperType(lightweight.getMultiTypeComponents(), lightweight.getOwner()); return superType.toJavaCompliantTypeReference(); }
public int internalIsAssignableFrom(LightweightTypeReference reference, TypeConformanceComputationArgument argument) { TypeConformanceComputer conformanceCompouter = getOwner().getServices().getTypeConformanceComputer(); int result = conformanceCompouter.isConformant(this, reference, argument); 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); }
private boolean isArrayTypeMismatch(LightweightTypeReference rawReceiverType, JvmType rawParameterType) { if (rawReceiverType.isArray()) { LightweightTypeReference parameterTypeReference = rawReceiverType.getOwner().toPlainTypeReference(rawParameterType); if (parameterTypeReference.getSuperType(Iterable.class) == null && isArrayTypeMismatch(rawReceiverType, parameterTypeReference)) { return true; } } return false; }
/** * @return the erasure type of this type reference */ public LightweightTypeReference getRawTypeReference() { return getServices().getRawTypeHelper().getRawTypeReference(this, getOwner().getContextResourceSet()); }
protected LightweightTypeReference getCollectionElementType(XCollectionLiteral literal) { LightweightTypeReference type = getLightweightType(literal); if (type == null) throw new IllegalStateException(); if(type.isArray()) { LightweightTypeReference result = type.getComponentType(); if (result == null) throw new IllegalStateException(); return result; } else if(type.isSubtypeOf(Collection.class) && type.hasTypeArguments()) { return type.getTypeArguments().get(0).getInvariantBoundSubstitute(); } return type.getOwner().newReferenceToObject(); }
protected JvmType findType(Class<?> type) { return getServices().getTypeReferences().findDeclaredType(type, getOwner().getContextResourceSet()); }
/** * 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; }
protected LightweightTypeReference getResolvedReference(/* @Nullable */ JvmTypeReference unresolved) { ITypeReferenceOwner owner = getContextType().getOwner(); if (unresolved == null) { return owner.newReferenceToObject(); } LightweightTypeReference unresolvedLightweight = owner.toLightweightTypeReference(unresolved); if (unresolvedLightweight.isPrimitive() || unresolvedLightweight.isPrimitiveVoid()) return unresolvedLightweight; TypeParameterSubstitutor<?> substitutor = getSubstitutor(); LightweightTypeReference result = substitutor.substitute(unresolvedLightweight); 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 boolean accept(LightweightTypeReference synonymType, int flags) { List<JvmType> rawTypes = synonymType.getRawTypes(); ConformanceFlags.sanityCheck(flags); SynonymTypeBucket bucket = new SynonymTypeBucket(id++, rawTypes, resolvedFeaturesProvider, flags); CompoundTypeReference compoundTypeReference = synonymType.getOwner().newCompoundTypeReference(true); compoundTypeReference.addComponent(featureDeclarator); compoundTypeReference.addComponent(synonymType); wrapper.set(createReceiverFeatureScope(featureCall, receiver, compoundTypeReference, receiverFeature, implicit, validStaticScope, bucket, wrapper.get(), session)); return true; }