public boolean isFunctionAndProcedureAvailable(ITypeReferenceOwner owner) { JvmType type = typeReferences.findDeclaredType(Procedures.Procedure1.class, owner.getContextResourceSet()); if (type == null) { return false; } if (type instanceof JvmTypeParameterDeclarator) { return !((JvmTypeParameterDeclarator) type).getTypeParameters().isEmpty(); } return false; }
/** * @param clazzName FQN of the type to find. see {@link org.eclipse.xtext.common.types.access.IJvmTypeProvider#findTypeByName(String)}. * @param owner the reference owner * * @since 2.14 */ protected <Type extends JvmType> Type findDeclaredType(String clazzName, ITypeReferenceOwner owner) { @SuppressWarnings("unchecked") Type result = (Type) services.getTypeReferences().findDeclaredType(clazzName, owner.getContextResourceSet()); return result; }
protected <Type extends JvmType> Type findDeclaredType(Class<?> clazz, ITypeReferenceOwner owner) { @SuppressWarnings("unchecked") Type result = (Type) services.getTypeReferences().findDeclaredType(clazz, owner.getContextResourceSet()); 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); }
protected JvmType getObjectType() { return owner.getServices().getTypeReferences().findDeclaredType(Object.class, owner.getContextResourceSet()); }
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); }
/** * @noreference This method is not intended to be referenced by clients. */ /* @Nullable */ protected LightweightTypeReference internalFindTopLevelType(Class<?> rawType) { try { ResourceSet resourceSet = getOwner().getContextResourceSet(); Resource typeResource = resourceSet.getResource(URIHelperConstants.OBJECTS_URI.appendSegment(rawType.getName()), true); List<EObject> resourceContents = typeResource.getContents(); if (resourceContents.isEmpty()) return null; JvmType type = (JvmType) resourceContents.get(0); return getOwner().newParameterizedTypeReference(type); } catch(WrappedException e) { /* no java project / class path context available, e.g. opened from history view */ return null; } }
/** * @return the erasure type of this type reference */ public LightweightTypeReference getRawTypeReference() { return getServices().getRawTypeHelper().getRawTypeReference(this, getOwner().getContextResourceSet()); }
protected JvmType findType(Class<?> type) { return getServices().getTypeReferences().findDeclaredType(type, getOwner().getContextResourceSet()); }
public List<JvmType> getRawTypes() { return getServices().getRawTypeHelper().getAllRawTypes(this, getOwner().getContextResourceSet()); }
ResourceSet resourceSet = getOwner().getContextResourceSet(); Resource typeResource = resourceSet.getResource(URIHelperConstants.OBJECTS_URI.appendSegment(rawType.getName()), true); JvmType type = (JvmType) typeResource.getContents().get(0);
@Override public JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper) { return getOwner().getServices().getTypeReferences().getTypeForName(Object.class, getOwner().getContextResourceSet()); }
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; }
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); }
@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()); }
@Override public LightweightTypeReference doVisitParameterizedTypeReference(ParameterizedTypeReference reference) { DeclaratorTypeArgumentCollector typeArgumentCollector = new ConstraintAwareTypeArgumentCollector(owner); Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping = typeArgumentCollector.getTypeParameterMapping(reference); TypeParameterSubstitutor<?> substitutor = new UnboundTypeParameterPreservingSubstitutor(typeParameterMapping, owner); JvmGenericType iterable = (JvmGenericType) owner.getServices().getTypeReferences().findDeclaredType(Iterable.class, owner.getContextResourceSet()); if (iterable == null) { return owner.newReferenceToObject(); } LightweightTypeReference substituteMe = owner.newParameterizedTypeReference(iterable.getTypeParameters().get(0)); LightweightTypeReference substitutedArgument = substitutor.substitute(substituteMe).getUpperBoundSubstitute(); if (substitutedArgument.getType() instanceof JvmTypeParameter && !(owner.getDeclaredTypeParameters().contains(substitutedArgument.getType()))) { return substitutedArgument.getRawTypeReference(); } return substitutedArgument; }
@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()); }
/** * Same as {@link LightweightTypeReference#isSubtypeOf(Class)} but does not accept synonym types as subtypes. */ protected boolean isSubtypeButNotSynonym(LightweightTypeReference expectation, Class<?> clazz) { if (expectation.isType(clazz)) { return true; } ITypeReferenceOwner owner = expectation.getOwner(); JvmType declaredType = owner.getServices().getTypeReferences().findDeclaredType(clazz, owner.getContextResourceSet()); if (declaredType == null) { return false; } LightweightTypeReference superType = owner.newParameterizedTypeReference(declaredType); // don't allow synonyms, e.g. Iterable is not considered to be a supertype of Functions.Function0 boolean result = superType.isAssignableFrom(expectation.getRawTypeReference(), new TypeConformanceComputationArgument(false, false, true, true, false, false)); return result; }