protected TypeReferences getTypeReferences() { return reentrantTypeResolver.getServices().getTypeReferences(); }
protected <Type extends JvmType> Type findDeclaredType(Class<?> clazz, ITypeReferenceOwner owner) { @SuppressWarnings("unchecked") Type result = (Type) services.getTypeReferences().findDeclaredType(clazz, owner.getContextResourceSet()); return result; }
/** * @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 JvmType getObjectType() { return owner.getServices().getTypeReferences().findDeclaredType(Object.class, owner.getContextResourceSet()); }
/** * Creates a references to the given class or returns an {@link UnknownTypeReference} if no * JRE is available. */ @Override public LightweightTypeReference newReferenceTo(Class<?> type) { JvmType rawType = getServices().getTypeReferences().findDeclaredType(type, getContextResourceSet()); if (rawType == null) { return newUnknownTypeReference(type.getName()); } return toPlainTypeReference(rawType); }
protected JvmType findType(Class<?> type) { return getServices().getTypeReferences().findDeclaredType(type, getOwner().getContextResourceSet()); }
/** * Creates a references to the given class or returns an {@link UnknownTypeReference} if no * JRE is available. If the type is available, the given acceptor is used to initialize it further. */ @Override public LightweightTypeReference newReferenceTo(Class<?> type, TypeReferenceInitializer<? super ParameterizedTypeReference> init) { if (init == null) { throw new NullPointerException("initializer"); } JvmType rawType = getServices().getTypeReferences().findDeclaredType(type, getContextResourceSet()); if (rawType == null) { return newUnknownTypeReference(type.getName()); } if (rawType.eClass() == TypesPackage.Literals.JVM_ARRAY_TYPE) { throw new IllegalArgumentException("given type is an array type: " + type); } ParameterizedTypeReference result = newParameterizedTypeReference(rawType); return init.enhance(result); }
@Check public void checkClassPath(XtendFile xtendFile) { TypeReferences typeReferences = getServices().getTypeReferences(); final JvmGenericType listType = (JvmGenericType) typeReferences.findDeclaredType(List.class, xtendFile); if (listType == null || listType.getTypeParameters().isEmpty()) { error("Couldn't find a JDK 1.5 or higher on the project's classpath.", xtendFile, XTEND_FILE__PACKAGE, IssueCodes.JDK_NOT_ON_CLASSPATH); } else if (typeReferences.findDeclaredType(ToStringBuilder.class, xtendFile) == null) { error("Couldn't find the mandatory library 'org.eclipse.xtext.xbase.lib' 2.8.0 or higher on the project's classpath.", xtendFile, XTEND_FILE__PACKAGE, IssueCodes.XBASE_LIB_NOT_ON_CLASSPATH); } }
@Override public JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper) { return getOwner().getServices().getTypeReferences().getTypeForName(Object.class, getOwner().getContextResourceSet()); }
protected JvmTypeReference getDeclaredType(JvmIdentifiableElement identifiable) { if (identifiable instanceof JvmOperation) { return ((JvmOperation) identifiable).getReturnType(); } if (identifiable instanceof JvmField) { return ((JvmField) identifiable).getType(); } if (identifiable instanceof JvmConstructor) { return shared.resolver.getServices().getTypeReferences().createTypeRef(((JvmConstructor) identifiable).getDeclaringType()); } if (identifiable instanceof JvmFormalParameter) { JvmTypeReference parameterType = ((JvmFormalParameter) identifiable).getParameterType(); return parameterType; } return null; }
|| Serializable.class.getName().equals(identifier) || Object.class.getName().equals(identifier)) { return getServices().getTypeReferences().createTypeRef(rawType);
private void checkExceptions(EObject context, List<JvmTypeReference> exceptions, EReference reference) { Set<String> declaredExceptionNames = Sets.newHashSet(); JvmTypeReference throwableType = getServices().getTypeReferences().getTypeForName(Throwable.class, context); if (throwableType == null) { return; } ITypeReferenceOwner owner = new StandardTypeReferenceOwner(getServices(), context); LightweightTypeReference throwableReference = owner.toLightweightTypeReference(throwableType); for(int i = 0; i < exceptions.size(); i++) { JvmTypeReference exception = exceptions.get(i); // throwables may not carry generics thus the raw comparison is sufficient if (exception.getType() != null && !exception.getType().eIsProxy()) { if(!throwableReference.isAssignableFrom(exception.getType())) error("No exception of type " + exception.getSimpleName() + " can be thrown; an exception type must be a subclass of Throwable", reference, i, EXCEPTION_NOT_THROWABLE); if(!declaredExceptionNames.add(exception.getQualifiedName())) error("Exception " + exception.getSimpleName() + " is declared twice", reference, i, EXCEPTION_DECLARED_TWICE); } } }
@SuppressWarnings("checkstyle:npathcomplexity") public void checkClassPath(XtendFile sarlScript) { final TypeReferences typeReferences = getServices().getTypeReferences();
if (inheritedParameterType != null) return typeResolver.toJavaCompliantTypeReference(inheritedParameterType, session); return typeResolver.getServices().getTypeReferences().getTypeForName(Object.class, operation);
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 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; }
typeAssigner.assignType(closureParameter, lightweight); } else { LightweightTypeReference objectType = typeAssigner.toLightweightTypeReference(getServices().getTypeReferences().getTypeForName(Object.class, closureParameter)); typeAssigner.assignType(closureParameter, objectType);
/** * 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; }
resultClosureType.addParameterType(lightweight); } else { LightweightTypeReference objectType = typeAssigner.toLightweightTypeReference(getServices().getTypeReferences().getTypeForName(Object.class, closureParameter)); typeAssigner.assignType(closureParameter, objectType);