Search in sources :

Example 66 with JvmType

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

the class XtendAnnotationReferenceImpl method translateAnnotationValue.

protected Object translateAnnotationValue(final XExpression value, final String property) {
    final JvmType annotationType = this.getDelegate().getAnnotationType();
    if ((annotationType instanceof JvmAnnotationType)) {
        final Function1<JvmOperation, Boolean> _function = (JvmOperation it) -> {
            String _simpleName = it.getSimpleName();
            return Boolean.valueOf(Objects.equal(_simpleName, property));
        };
        final JvmOperation operation = IterableExtensions.<JvmOperation>findFirst(Iterables.<JvmOperation>filter(((JvmAnnotationType) annotationType).getMembers(), JvmOperation.class), _function);
        if ((operation != null)) {
            final boolean array = this.getCompilationUnit().getTypeReferences().isArray(operation.getReturnType());
            return this.getCompilationUnit().translateAnnotationValue(value, operation.getReturnType(), array);
        }
    }
    return this.getCompilationUnit().translateAnnotationValue(value, null, false);
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 67 with JvmType

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

the class XtendResourceDescription method getImportedNames.

@Override
public Iterable<QualifiedName> getImportedNames() {
    if ((this.importedNames != null)) {
        return this.importedNames;
    }
    final HashSet<QualifiedName> result = CollectionLiterals.<QualifiedName>newHashSet();
    final EObject astRoot = IterableExtensions.<EObject>head(this.getResource().getContents());
    if ((astRoot != null)) {
        final IResolvedTypes types = this.typeResolver.resolveTypes(astRoot);
        Iterable<XExpression> _filter = Iterables.<XExpression>filter(IteratorExtensions.<Object>toIterable(EcoreUtil.<Object>getAllContents(astRoot, true)), XExpression.class);
        for (final XExpression expression : _filter) {
            {
                boolean _matched = false;
                if (expression instanceof XMemberFeatureCall) {
                    if ((((((XMemberFeatureCall) expression).getFeature() != null) && ((XMemberFeatureCall) expression).getFeature().eIsProxy()) && (!((XMemberFeatureCall) expression).isExplicitOperationCallOrBuilderSyntax()))) {
                        _matched = true;
                        final XExpression receiver = ((XMemberFeatureCall) expression).getActualReceiver();
                        boolean _matched_1 = false;
                        if (receiver instanceof XAbstractFeatureCall) {
                            boolean _isTypeLiteral = ((XAbstractFeatureCall) receiver).isTypeLiteral();
                            if (_isTypeLiteral) {
                                _matched_1 = true;
                                final JvmIdentifiableElement type = ((XAbstractFeatureCall) receiver).getFeature();
                                String _identifier = type.getIdentifier();
                                String _plus = (_identifier + "$");
                                String _concreteSyntaxFeatureName = ((XMemberFeatureCall) expression).getConcreteSyntaxFeatureName();
                                String _plus_1 = (_plus + _concreteSyntaxFeatureName);
                                QualifiedName _lowerCase = this.nameConverter.toQualifiedName(_plus_1).toLowerCase();
                                result.add(_lowerCase);
                            }
                        }
                    }
                }
                if (!_matched) {
                    if (expression instanceof XAbstractFeatureCall) {
                        boolean _isTypeLiteral = ((XAbstractFeatureCall) expression).isTypeLiteral();
                        if (_isTypeLiteral) {
                            _matched = true;
                            final JvmIdentifiableElement type = ((XAbstractFeatureCall) expression).getFeature();
                            if ((type instanceof JvmDeclaredType)) {
                                final Function1<String, Boolean> _function = (String it) -> {
                                    QualifiedName _lowerCase = this.nameConverter.toQualifiedName(it).toLowerCase();
                                    return Boolean.valueOf(result.add(_lowerCase));
                                };
                                this.registerAllTypes(((JvmType) type), _function);
                            }
                        }
                    }
                }
                final LightweightTypeReference typeRef = types.getActualType(expression);
                if ((typeRef != null)) {
                    final Function1<String, Boolean> _function = (String it) -> {
                        QualifiedName _lowerCase = this.nameConverter.toQualifiedName(it).toLowerCase();
                        return Boolean.valueOf(result.add(_lowerCase));
                    };
                    this.registerAllTypes(typeRef.getType(), _function);
                }
            }
        }
        EList<EObject> _contents = this.getResource().getContents();
        for (final EObject eobject : _contents) {
            {
                final Function1<JvmIdentifiableElement, LightweightTypeReference> _function = (JvmIdentifiableElement it) -> {
                    LightweightTypeReference _xifexpression = null;
                    if (((!(it instanceof JvmType)) || (it instanceof JvmDeclaredType))) {
                        _xifexpression = types.getActualType(it);
                    }
                    return _xifexpression;
                };
                final Iterable<LightweightTypeReference> typesOfIdentifiables = IteratorExtensions.<LightweightTypeReference>toIterable(IteratorExtensions.<JvmIdentifiableElement, LightweightTypeReference>map(Iterators.<JvmIdentifiableElement>filter(EcoreUtil.<Object>getAllContents(eobject, true), JvmIdentifiableElement.class), _function));
                for (final LightweightTypeReference typeRef : typesOfIdentifiables) {
                    if ((typeRef != null)) {
                        final Function1<String, Boolean> _function_1 = (String it) -> {
                            QualifiedName _lowerCase = this.nameConverter.toQualifiedName(it).toLowerCase();
                            return Boolean.valueOf(result.add(_lowerCase));
                        };
                        this.registerAllTypes(typeRef.getType(), _function_1);
                    }
                }
            }
        }
    }
    Iterables.<QualifiedName>addAll(result, super.getImportedNames());
    final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
        boolean _contains = XtendResourceDescription.primitivesFilter.contains(it.getLastSegment());
        return Boolean.valueOf((!_contains));
    };
    this.importedNames = IterableExtensions.<QualifiedName>toSet(IterableExtensions.<QualifiedName>filter(result, _function));
    return this.importedNames;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression) EObject(org.eclipse.emf.ecore.EObject)

Example 68 with JvmType

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

the class XtendResourceDescription method registerAllTypes.

public void registerAllTypes(final JvmType type, final Function1<? super String, ? extends Boolean> acceptor) {
    if (((type == null) || type.eIsProxy())) {
        return;
    }
    if (((!this.isLocal(type)) && (acceptor.apply(type.getIdentifier())).booleanValue())) {
        boolean _matched = false;
        if (type instanceof JvmGenericType) {
            _matched = true;
            this.registerAllTypes(((JvmGenericType) type).getDeclaringType(), acceptor);
            JvmTypeReference _extendedClass = null;
            if (((JvmGenericType) type) != null) {
                _extendedClass = ((JvmGenericType) type).getExtendedClass();
            }
            JvmType _type = null;
            if (_extendedClass != null) {
                _type = _extendedClass.getType();
            }
            this.registerAllTypes(_type, acceptor);
            final Consumer<JvmTypeReference> _function = (JvmTypeReference it) -> {
                JvmType _type_1 = null;
                if (it != null) {
                    _type_1 = it.getType();
                }
                this.registerAllTypes(_type_1, acceptor);
            };
            ((JvmGenericType) type).getExtendedInterfaces().forEach(_function);
        }
    }
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 69 with JvmType

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

the class JavaLinkingTest method testGetXtendClassDirectly.

@Test
public void testGetXtendClassDirectly() 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 xtendType = jvmTypeProvider.findTypeByName("test.XtendClass");
    assertNotNull(xtendType);
    assertEquals("test.XtendClass", xtendType.getQualifiedName());
    Resource xtendResource = xtendType.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) Test(org.junit.Test)

Example 70 with JvmType

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

the class JavaLinkingTest method testNavigateToXtendClass.

@Test
public void testNavigateToXtendClass() 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 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;
    JvmTypeReference superType = declaredJavaType.getSuperTypes().get(0);
    JvmType xtendType = superType.getType();
    assertNotNull(xtendType);
    assertEquals("test.XtendClass", xtendType.getQualifiedName());
    Resource xtendResource = xtendType.eResource();
    assertEquals("platform:/resource" + xtendFile.getFullPath(), xtendResource.getURI().toString());
}
Also used : 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) IJvmTypeProvider(org.eclipse.xtext.common.types.access.IJvmTypeProvider) Test(org.junit.Test)

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