Search in sources :

Example 66 with XAbstractFeatureCall

use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.

the class AbstractOverloadedInstanceMethodTest method linksTo.

protected void linksTo(final String invocation, final String method) {
    try {
        final XtendFile file = this.file(this.inMethodBody(invocation), false);
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        final XtendClass c = ((XtendClass) _head);
        XtendMember _head_1 = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head_1);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _last = IterableExtensions.<XExpression>last(body.getExpressions());
        final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
        JvmIdentifiableElement _feature = featureCall.getFeature();
        final JvmOperation operation = ((JvmOperation) _feature);
        final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, file);
        final ParameterizedTypeReference declaration = owner.newParameterizedTypeReference(operation.getDeclaringType());
        final BottomResolvedOperation resolved = new BottomResolvedOperation(operation, declaration, this.overrideTester);
        Assert.assertEquals(method, resolved.getSimpleSignature());
        Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
        Assert.assertNotNull(featureCall.getImplicitReceiver());
        Assert.assertNull(featureCall.getImplicitFirstArgument());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) ParameterizedTypeReference(org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) BottomResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 67 with XAbstractFeatureCall

use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.

the class AbstractOverloadedStaticMethodTest method linksTo.

protected void linksTo(final String invocation, final String method) {
    try {
        final XtendFile file = this.file(this.inMethodBody(invocation), false);
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        final XtendClass c = ((XtendClass) _head);
        XtendMember _head_1 = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head_1);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _last = IterableExtensions.<XExpression>last(body.getExpressions());
        final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
        JvmIdentifiableElement _feature = featureCall.getFeature();
        final JvmOperation operation = ((JvmOperation) _feature);
        final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, file);
        final ParameterizedTypeReference declaration = owner.newParameterizedTypeReference(operation.getDeclaringType());
        final BottomResolvedOperation resolved = new BottomResolvedOperation(operation, declaration, this.overrideTester);
        Assert.assertEquals(method, resolved.getSimpleSignature());
        Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
        Assert.assertNull(featureCall.getImplicitReceiver());
        Assert.assertNull(featureCall.getImplicitFirstArgument());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) ParameterizedTypeReference(org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) BottomResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 68 with XAbstractFeatureCall

use of org.eclipse.xtext.xbase.XAbstractFeatureCall 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 69 with XAbstractFeatureCall

use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.

the class LinkingTest method findSingleFeatureCall.

private XAbstractFeatureCall findSingleFeatureCall(XtendClass clazz) {
    XtendFunction function = (XtendFunction) clazz.getMembers().get(clazz.getMembers().size() - 1);
    XBlockExpression block = (XBlockExpression) function.getExpression();
    return (XAbstractFeatureCall) block.getExpressions().get(0);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall)

Example 70 with XAbstractFeatureCall

use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.

the class LinkingTest method testParameterizedExtension_08.

@Test
public void testParameterizedExtension_08() throws Exception {
    XtendFile file = file("package testPackage\n" + "import org.eclipse.xtext.testing.util.ParseHelper\n" + "import org.eclipse.xtend.core.xtend.XtendFile\n" + "class C<T extends XtendFile> extends ParseHelper<T> {\n" + "	def m() {" + "		parse('').xtendTypes\n" + "	}\n" + "}\n");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XAbstractFeatureCall substring = findSingleFeatureCall(c);
    assertEquals("org.eclipse.xtend.core.xtend.XtendFile.getXtendTypes()", substring.getFeature().getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Aggregations

XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)122 Test (org.junit.Test)105 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)104 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)42 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)23 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)21 XExpression (org.eclipse.xtext.xbase.XExpression)17 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)11 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)9 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)8 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)6 EObject (org.eclipse.emf.ecore.EObject)5 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)5 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)4 IFeatureLinkingCandidate (org.eclipse.xtext.xbase.typesystem.computation.IFeatureLinkingCandidate)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)3 AbstractDiagnostic (org.eclipse.xtext.diagnostics.AbstractDiagnostic)3 XClosure (org.eclipse.xtext.xbase.XClosure)3