Search in sources :

Example 16 with JvmDeclaredType

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

the class XtendAnnotationReferenceImpl method getAnnotationTypeDeclaration.

@Override
public AnnotationTypeDeclaration getAnnotationTypeDeclaration() {
    AnnotationTypeDeclaration _switchResult = null;
    JvmType _annotationType = this.getAnnotationType();
    final JvmType type = _annotationType;
    boolean _matched = false;
    if (type instanceof JvmAnnotationType) {
        _matched = true;
        TypeDeclaration _typeDeclaration = this.getCompilationUnit().toTypeDeclaration(((JvmDeclaredType) type));
        _switchResult = ((AnnotationTypeDeclaration) _typeDeclaration);
    }
    if (!_matched) {
        _switchResult = null;
    }
    return _switchResult;
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) AnnotationTypeDeclaration(org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType) AnnotationTypeDeclaration(org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration) TypeDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeDeclaration)

Example 17 with JvmDeclaredType

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

the class AbstractXtendOutlineTreeBuilder method buildMembers.

protected void buildMembers(final JvmDeclaredType inferredType, final JvmDeclaredType baseType, @Extension final IXtendOutlineContext context) {
    EList<JvmMember> _members = inferredType.getMembers();
    for (final JvmMember member : _members) {
        boolean _isProcessed = context.isProcessed(member);
        boolean _not = (!_isProcessed);
        if (_not) {
            if ((member instanceof JvmDeclaredType)) {
                boolean _isShowInherited = context.isShowInherited();
                if (_isShowInherited) {
                    final IXtendOutlineContext typeContext = context.newContext();
                    final EObject sourceElement = this._iXtendJvmAssociations.getPrimarySourceElement(member);
                    if ((sourceElement instanceof XtendTypeDeclaration)) {
                        this.buildType(sourceElement, typeContext);
                    } else {
                        this.buildJvmType(((JvmDeclaredType) member), typeContext);
                    }
                } else {
                    this.buildJvmType(((JvmDeclaredType) member), context);
                }
            } else {
                if ((member instanceof JvmFeature)) {
                    boolean _skipFeature = this.skipFeature(((JvmFeature) member));
                    boolean _not_1 = (!_skipFeature);
                    if (_not_1) {
                        final IXtendOutlineContext featureContext = this.buildFeature(baseType, ((JvmFeature) member), member, context);
                        final Consumer<JvmGenericType> _function = (JvmGenericType it) -> {
                            this.buildJvmType(it, featureContext.newContext());
                        };
                        ((JvmFeature) member).getLocalClasses().forEach(_function);
                    }
                }
            }
            context.markAsProcessed(member);
        }
    }
    boolean _isShowInherited_1 = context.isShowInherited();
    if (_isShowInherited_1) {
        this.buildInheritedMembers(inferredType, context);
    }
}
Also used : JvmFeature(org.eclipse.xtext.common.types.JvmFeature) IXtendOutlineContext(org.eclipse.xtend.ide.common.outline.IXtendOutlineContext) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember)

Example 18 with JvmDeclaredType

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

the class JavaLinkingTest method testNavigateToXtendClassArray.

@Test
public void testNavigateToXtendClassArray() throws Exception {
    IFile xtendFile = testHelper.createFile("test/XtendClass", "package test\nclass XtendClass {}");
    IFile javaFile = testHelper.createFileImpl(WorkbenchTestHelper.TESTPROJECT_NAME + "/src/test/JavaClass.java", "package test;\npublic class JavaClass extends java.util.ArrayList<XtendClass[]> {}");
    waitForBuild();
    assertNumberOfMarkers(xtendFile, 0);
    assertNumberOfMarkers(javaFile, 0);
    ResourceSet resourceSet = resourceSetProvider.get(testHelper.getProject());
    IJvmTypeProvider jvmTypeProvider = typeProviderFactory.findOrCreateTypeProvider(resourceSet);
    JvmType javaType = jvmTypeProvider.findTypeByName("test.JavaClass");
    assertNotNull(javaType);
    assertTrue(javaType instanceof JvmDeclaredType);
    JvmDeclaredType declaredJavaType = (JvmDeclaredType) javaType;
    JvmParameterizedTypeReference arrayList = (JvmParameterizedTypeReference) declaredJavaType.getSuperTypes().get(0);
    JvmTypeReference arrayReference = arrayList.getArguments().get(0);
    assertTrue(arrayReference instanceof JvmGenericArrayTypeReference);
    JvmType arrayType = arrayReference.getType();
    assertTrue(arrayType instanceof JvmArrayType);
    JvmType xtendType = ((JvmArrayType) arrayType).getComponentType();
    assertNotNull(xtendType);
    assertEquals("test.XtendClass", xtendType.getQualifiedName());
    Resource xtendResource = xtendType.eResource();
    assertEquals("platform:/resource" + xtendFile.getFullPath(), xtendResource.getURI().toString());
}
Also used : JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) IFile(org.eclipse.core.resources.IFile) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Resource(org.eclipse.emf.ecore.resource.Resource) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JvmType(org.eclipse.xtext.common.types.JvmType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) IJvmTypeProvider(org.eclipse.xtext.common.types.access.IJvmTypeProvider) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType) Test(org.junit.Test)

Example 19 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 20 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)

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