use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class XtendImportsConfiguration method getLocallyDefinedTypes.
@Override
public Iterable<JvmDeclaredType> getLocallyDefinedTypes(XtextResource resource) {
XtendFile xtendFile = getXtendFile(resource);
if (xtendFile == null)
return emptyList();
final List<JvmDeclaredType> locallyDefinedTypes = newArrayList();
for (XtendTypeDeclaration xtendType : xtendFile.getXtendTypes()) {
for (EObject inferredElement : associations.getJvmElements(xtendType)) {
if (inferredElement instanceof JvmDeclaredType) {
JvmDeclaredType declaredType = (JvmDeclaredType) inferredElement;
locallyDefinedTypes.add(declaredType);
addInnerTypes(declaredType, new IAcceptor<JvmDeclaredType>() {
@Override
public void accept(JvmDeclaredType t) {
locallyDefinedTypes.add(t);
}
});
}
}
}
return locallyDefinedTypes;
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class AnonymousClassUtil method getSuperType.
/* @Nullable */
public JvmGenericType getSuperType(AnonymousClass anonymousClass) {
JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor();
if (constructor != null && !constructor.eIsProxy()) {
JvmDeclaredType declaringType = constructor.getDeclaringType();
JvmType superType = Iterables.getLast(declaringType.getSuperTypes()).getType();
if (superType instanceof JvmGenericType)
return (JvmGenericType) superType;
}
return null;
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class AnonymousClassUtil method getSuperTypeNonResolving.
public JvmDeclaredType getSuperTypeNonResolving(AnonymousClass anonymousClass, IScope typeScope) {
XConstructorCall constructorCall = anonymousClass.getConstructorCall();
EObject constructorProxy = (EObject) constructorCall.eGet(XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, false);
IEObjectDescription description = null;
if (constructorProxy != null) {
if (!constructorProxy.eIsProxy()) {
return getSuperType(anonymousClass);
}
String fragment = EcoreUtil.getURI(constructorProxy).fragment();
INode node = uriEncoder.getNode(constructorCall, fragment);
String name = linkingHelper.getCrossRefNodeAsString(node, true);
QualifiedName superTypeName = qualifiedNameConverter.toQualifiedName(name);
description = typeScope.getSingleElement(superTypeName);
}
if (description == null || !EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_DECLARED_TYPE, description.getEClass())) {
description = typeScope.getSingleElement(QualifiedName.create("java", "lang", "Object"));
}
if (description != null && EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_DECLARED_TYPE, description.getEClass())) {
JvmDeclaredType type = (JvmDeclaredType) description.getEObjectOrProxy();
if (!type.eIsProxy())
return type;
return (JvmDeclaredType) EcoreUtil.resolve(type, anonymousClass);
}
return null;
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class DispatchHelper method getLocalDispatchCases.
/**
* Return the local cases that contribute to the given dispatch operation (in no particular order, but usually as defined in the file).
*/
public List<JvmOperation> getLocalDispatchCases(JvmOperation dispatcherOperation) {
DispatchSignature dispatchSignature = new DispatchSignature(dispatcherOperation.getSimpleName(), dispatcherOperation.getParameters().size());
JvmDeclaredType type = dispatcherOperation.getDeclaringType();
return getLocalDispatchCases(type, dispatchSignature);
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class DispatchHelper method getMaxDistanceToObject.
protected int getMaxDistanceToObject(JvmTypeReference type) {
type = primitives.asWrapperTypeIfPrimitive(type);
if (typeRefs.is(type, Object.class))
return 0;
JvmType jvmType = type.getType();
int maxDistance = 1;
if (jvmType instanceof JvmDeclaredType) {
EList<JvmTypeReference> list = ((JvmDeclaredType) jvmType).getSuperTypes();
for (JvmTypeReference jvmTypeReference : list) {
int result = 1 + getMaxDistanceToObject(jvmTypeReference);
if (result > maxDistance)
maxDistance = result;
}
}
return maxDistance;
}
Aggregations