Search in sources :

Example 61 with JvmDeclaredType

use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.

the class XtendCompiler method _toJavaStatement.

@Override
protected void _toJavaStatement(final XConstructorCall expr, ITreeAppendable b, final boolean isReferenced) {
    for (XExpression arg : expr.getArguments()) {
        prepareExpression(arg, b);
    }
    if (!isReferenced) {
        b.newLine();
        constructorCallToJavaExpression(expr, b);
        if (expr.eContainer() instanceof AnonymousClass) {
            JvmConstructor constructor = expr.getConstructor();
            JvmDeclaredType declaringType = constructor.getDeclaringType();
            compileAnonymousClassBody((AnonymousClass) expr.eContainer(), declaringType, b);
        }
        b.append(";");
    } else if (isVariableDeclarationRequired(expr, b, true)) {
        Later later = new Later() {

            @Override
            public void exec(ITreeAppendable appendable) {
                constructorCallToJavaExpression(expr, appendable);
                if (expr.eContainer() instanceof AnonymousClass) {
                    JvmConstructor constructor = expr.getConstructor();
                    JvmDeclaredType declaringType = constructor.getDeclaringType();
                    compileAnonymousClassBody((AnonymousClass) expr.eContainer(), declaringType, appendable);
                }
            }
        };
        declareFreshLocalVariable(expr, b, later);
    }
}
Also used : Later(org.eclipse.xtext.xbase.compiler.Later) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) XExpression(org.eclipse.xtext.xbase.XExpression) ITreeAppendable(org.eclipse.xtext.xbase.compiler.output.ITreeAppendable)

Example 62 with JvmDeclaredType

use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.

the class XtendCompiler method isVariableDeclarationRequired.

@Override
protected boolean isVariableDeclarationRequired(XExpression expr, ITreeAppendable b, boolean recursive) {
    boolean result = super.isVariableDeclarationRequired(expr, b, recursive);
    if (result && expr instanceof XConstructorCall) {
        EObject container = expr.eContainer();
        if (container instanceof AnonymousClass) {
            AnonymousClass anonymousClass = (AnonymousClass) container;
            result = isVariableDeclarationRequired(anonymousClass, b, recursive);
            if (result) {
                JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor();
                JvmDeclaredType type = constructor.getDeclaringType();
                if (((JvmGenericType) type).isAnonymous()) {
                    return false;
                }
            }
        }
    }
    return result;
}
Also used : AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) EObject(org.eclipse.emf.ecore.EObject) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 63 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 64 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 65 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)

Aggregations

JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)138 Test (org.junit.Test)41 EObject (org.eclipse.emf.ecore.EObject)26 JvmType (org.eclipse.xtext.common.types.JvmType)24 JvmMember (org.eclipse.xtext.common.types.JvmMember)21 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)18 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)18 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)16 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)16 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)15 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)13 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)11 JvmAnnotationTarget (org.eclipse.xtext.common.types.JvmAnnotationTarget)10 TestAnnotation (org.eclipse.xtext.common.types.testSetups.TestAnnotation)10 Resource (org.eclipse.emf.ecore.resource.Resource)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)8 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)7 JvmArrayType (org.eclipse.xtext.common.types.JvmArrayType)7 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)6