Search in sources :

Example 16 with JvmType

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

the class XtendHighlightingCalculator method highlightDeprecatedXtendAnnotationTarget.

protected void highlightDeprecatedXtendAnnotationTarget(IHighlightedPositionAcceptor acceptor, XtendAnnotationTarget target, XAnnotation annotation) {
    JvmType annotationType = annotation.getAnnotationType();
    if (annotationType instanceof JvmAnnotationType && DeprecationUtil.isDeprecatedAnnotation((JvmAnnotationType) annotationType)) {
        if (target instanceof XtendConstructor) {
            ICompositeNode compositeNode = NodeModelUtils.getNode(target);
            for (ILeafNode leaf : compositeNode.getLeafNodes()) {
                if (leaf.getGrammarElement() == xtendGrammarAccess.getMemberAccess().getNewKeyword_2_2_2()) {
                    highlightNode(acceptor, leaf, XbaseHighlightingStyles.DEPRECATED_MEMBERS);
                    highlightNode(acceptor, leaf, HighlightingStyles.KEYWORD_ID);
                    return;
                }
            }
        } else {
            EStructuralFeature nameFeature = target.eClass().getEStructuralFeature("name");
            if (nameFeature != null) {
                highlightFeature(acceptor, target, nameFeature, XbaseHighlightingStyles.DEPRECATED_MEMBERS);
            }
        }
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 17 with JvmType

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

the class JavaLinkingTest method testGetXtendClassAsArray.

@Test
public void testGetXtendClassAsArray() throws Exception {
    IFile xtendFile = testHelper.createFile("test/XtendClass", "package test\nclass XtendClass {}");
    waitForBuild();
    assertNumberOfMarkers(xtendFile, 0);
    ResourceSet resourceSet = resourceSetProvider.get(testHelper.getProject());
    IJvmTypeProvider jvmTypeProvider = typeProviderFactory.findOrCreateTypeProvider(resourceSet);
    JvmType xtendArrayType = jvmTypeProvider.findTypeByName("test.XtendClass[][]");
    assertNotNull(xtendArrayType);
    assertTrue(xtendArrayType instanceof JvmArrayType);
    assertEquals("test.XtendClass[][]", xtendArrayType.getQualifiedName());
    Resource xtendResource = xtendArrayType.eResource();
    assertEquals("platform:/resource" + xtendFile.getFullPath(), xtendResource.getURI().toString());
}
Also used : IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JvmType(org.eclipse.xtext.common.types.JvmType) IJvmTypeProvider(org.eclipse.xtext.common.types.access.IJvmTypeProvider) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType) Test(org.junit.Test)

Example 18 with JvmType

use of org.eclipse.xtext.common.types.JvmType 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 JvmType

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

the class XtendCompiler method needSyntheticSelfVariable.

@Override
protected boolean needSyntheticSelfVariable(XClosure closure, LightweightTypeReference typeRef) {
    JvmType jvmType = typeRef.getType();
    TreeIterator<EObject> closureIterator = closure.eAllContents();
    while (closureIterator.hasNext()) {
        EObject obj1 = closureIterator.next();
        if (obj1 instanceof XClosure) {
            closureIterator.prune();
        } else if (obj1 instanceof XtendTypeDeclaration) {
            TreeIterator<EObject> typeIterator = obj1.eAllContents();
            while (typeIterator.hasNext()) {
                EObject obj2 = typeIterator.next();
                if (obj2 instanceof XClosure) {
                    typeIterator.prune();
                } else if (obj2 instanceof XFeatureCall && isReferenceToSelf((XFeatureCall) obj2, jvmType)) {
                    return true;
                }
            }
            closureIterator.prune();
        }
    }
    return false;
}
Also used : XClosure(org.eclipse.xtext.xbase.XClosure) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmType(org.eclipse.xtext.common.types.JvmType) TreeIterator(org.eclipse.emf.common.util.TreeIterator)

Example 20 with JvmType

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

the class XtendCompiler method appendExtensionAnnotation.

protected void appendExtensionAnnotation(EObject context, ITreeAppendable appendable, boolean newLine) {
    JvmType extension = findKnownTopLevelType(Extension.class, context);
    if (extension != null) {
        appendable.append("@");
        appendable.append(extension);
        if (!newLine)
            appendable.append(" ");
        else
            appendable.newLine();
    }
}
Also used : JvmType(org.eclipse.xtext.common.types.JvmType)

Aggregations

JvmType (org.eclipse.xtext.common.types.JvmType)73 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)29 EObject (org.eclipse.emf.ecore.EObject)18 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)17 Test (org.junit.Test)17 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)14 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 XExpression (org.eclipse.xtext.xbase.XExpression)12 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)11 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)10 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)9 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)9 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)8 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)8 Resource (org.eclipse.emf.ecore.resource.Resource)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)6 JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)6