Search in sources :

Example 71 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class CompilationUnitImpl method toLightweightTypeReference.

public LightweightTypeReference toLightweightTypeReference(final TypeReference typeRef) {
    this.checkCanceled();
    LightweightTypeReference _switchResult = null;
    boolean _matched = false;
    if (typeRef instanceof TypeReferenceImpl) {
        _matched = true;
        _switchResult = ((TypeReferenceImpl) typeRef).getLightweightTypeReference();
    }
    if (!_matched) {
        if (typeRef instanceof InferredTypeReferenceImpl) {
            _matched = true;
            _switchResult = ((InferredTypeReferenceImpl) typeRef).getLightweightTypeReference();
        }
    }
    return _switchResult;
}
Also used : InferredTypeReferenceImpl(org.eclipse.xtend.core.macro.declaration.InferredTypeReferenceImpl) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) TypeReferenceImpl(org.eclipse.xtend.core.macro.declaration.TypeReferenceImpl) InferredTypeReferenceImpl(org.eclipse.xtend.core.macro.declaration.InferredTypeReferenceImpl)

Example 72 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class TypeReferenceImpl method getType.

@Override
public Type getType() {
    Type _switchResult = null;
    LightweightTypeReference _delegate = this.getDelegate();
    final LightweightTypeReference it = _delegate;
    boolean _matched = false;
    boolean _isUnknown = it.isUnknown();
    if (_isUnknown) {
        _matched = true;
        CompilationUnitImpl _compilationUnit = this.getCompilationUnit();
        String _packageName = this.getCompilationUnit().getPackageName();
        String _plus = (_packageName + ".");
        String _simpleName = it.getSimpleName();
        String _plus_1 = (_plus + _simpleName);
        _switchResult = new UnknownType(_compilationUnit, _plus_1);
    }
    if (!_matched) {
        _switchResult = this.getCompilationUnit().toType(it.getType());
    }
    return _switchResult;
}
Also used : UnknownType(org.eclipse.xtend.core.macro.declaration.UnknownType) UnknownType(org.eclipse.xtend.core.macro.declaration.UnknownType) Type(org.eclipse.xtend.lib.macro.declaration.Type) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)

Example 73 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference 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 74 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class AbstractXtendOutlineTreeBuilder method buildInheritedMembers.

protected void buildInheritedMembers(final JvmDeclaredType inferredType, final IXtendOutlineContext context) {
    ResourceSet _resourceSet = inferredType.eResource().getResourceSet();
    final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, _resourceSet);
    final LightweightTypeReference typeReference = owner.toLightweightTypeReference(inferredType);
    final List<LightweightTypeReference> superTypes = typeReference.getAllSuperTypes();
    IXtendOutlineContext superTypeContext = context;
    for (final LightweightTypeReference superTypeRef : superTypes) {
        {
            superTypeContext = superTypeContext.increaseInheritanceDepth();
            final ResolvedFeatures resolvedFeatures = new ResolvedFeatures(superTypeRef);
            List<IResolvedField> _declaredFields = resolvedFeatures.getDeclaredFields();
            for (final IResolvedField jvmField : _declaredFields) {
                boolean _skipFeature = this.skipFeature(jvmField.getDeclaration());
                boolean _not = (!_skipFeature);
                if (_not) {
                    this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, jvmField, superTypeContext);
                }
            }
            List<IResolvedConstructor> _declaredConstructors = resolvedFeatures.getDeclaredConstructors();
            for (final IResolvedConstructor constructor : _declaredConstructors) {
                boolean _skipFeature_1 = this.skipFeature(constructor.getDeclaration());
                boolean _not_1 = (!_skipFeature_1);
                if (_not_1) {
                    this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, constructor, superTypeContext);
                }
            }
            List<IResolvedOperation> _declaredOperations = resolvedFeatures.getDeclaredOperations();
            for (final IResolvedOperation operation : _declaredOperations) {
                if (((!this.skipFeature(operation.getDeclaration())) && (!superTypeContext.isProcessed(operation.getDeclaration())))) {
                    this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, operation, superTypeContext);
                }
            }
            final JvmType declaredType = superTypeRef.getType();
            if ((declaredType instanceof JvmDeclaredType)) {
                final IXtendOutlineContext nestedTypeContext = superTypeContext.hideInherited();
                final Consumer<JvmDeclaredType> _function = (JvmDeclaredType it) -> {
                    this.buildJvmType(it, nestedTypeContext);
                };
                Iterables.<JvmDeclaredType>filter(((JvmDeclaredType) declaredType).getMembers(), JvmDeclaredType.class).forEach(_function);
            }
        }
    }
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) ResolvedFeatures(org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures) IResolvedField(org.eclipse.xtext.xbase.typesystem.override.IResolvedField) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JvmType(org.eclipse.xtext.common.types.JvmType) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation) IResolvedConstructor(org.eclipse.xtext.xbase.typesystem.override.IResolvedConstructor) Consumer(java.util.function.Consumer) IXtendOutlineContext(org.eclipse.xtend.ide.common.outline.IXtendOutlineContext) EList(org.eclipse.emf.common.util.EList) List(java.util.List) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 75 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class LinkingTest method testBug345433_02.

@Test
public void testBug345433_02() throws Exception {
    String classAsString = "import static extension org.eclipse.xtext.GrammarUtil.*\n" + "class Foo {" + "	org.eclipse.xtext.Grammar grammar\n" + "	def function1() {\n" + "		grammar.containedRuleCalls.filter(e0 | " + "			!e0.isAssigned() && !e0.isEObjectRuleCall()" + "		).map(e1 | e1.rule)\n" + "	}\n" + "}";
    XtendClass clazz = clazz(classAsString);
    IResourceValidator validator = ((XtextResource) clazz.eResource()).getResourceServiceProvider().getResourceValidator();
    List<Issue> issues = validator.validate(clazz.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
    assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
    XtendFunction function = (XtendFunction) clazz.getMembers().get(1);
    XExpression body = function.getExpression();
    LightweightTypeReference bodyType = getType(body);
    assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", bodyType.getIdentifier());
    XBlockExpression block = (XBlockExpression) body;
    XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(0);
    XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0);
    JvmFormalParameter e1 = closure.getFormalParameters().get(0);
    assertEquals("e1", e1.getSimpleName());
    assertEquals("org.eclipse.xtext.RuleCall", getType(e1).getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) Issue(org.eclipse.xtext.validation.Issue) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) XClosure(org.eclipse.xtext.xbase.XClosure) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Aggregations

LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)83 Test (org.junit.Test)28 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)23 XExpression (org.eclipse.xtext.xbase.XExpression)22 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)20 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)19 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)16 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)13 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)10 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)10 IFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)10 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)9 XNumberLiteral (org.eclipse.xtext.xbase.XNumberLiteral)9 JvmType (org.eclipse.xtext.common.types.JvmType)8 ITypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner)8 EObject (org.eclipse.emf.ecore.EObject)7 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)7 StandardTypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)7 RichString (org.eclipse.xtend.core.xtend.RichString)6 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)6