Search in sources :

Example 21 with JvmDeclaredType

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;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 22 with JvmDeclaredType

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;
}
Also used : JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 23 with JvmDeclaredType

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;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) EObject(org.eclipse.emf.ecore.EObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 24 with JvmDeclaredType

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);
}
Also used : JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 25 with JvmDeclaredType

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;
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType)

Aggregations

JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)74 EObject (org.eclipse.emf.ecore.EObject)21 JvmType (org.eclipse.xtext.common.types.JvmType)18 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)12 JvmMember (org.eclipse.xtext.common.types.JvmMember)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)10 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)8 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 Test (org.junit.Test)8 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)7 Resource (org.eclipse.emf.ecore.resource.Resource)5 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)5 XExpression (org.eclipse.xtext.xbase.XExpression)5 List (java.util.List)4 EList (org.eclipse.emf.common.util.EList)4 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)4