Search in sources :

Example 96 with XExpression

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

the class XtendProposalProvider method completeType_Members.

@Override
public void completeType_Members(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if (isValidTypeForOverriding(model)) {
        INode node = context.getCurrentNode();
        EObject eObject = NodeModelUtils.findActualSemanticObjectFor(node);
        if (!(eObject instanceof AnonymousClass)) {
            // due to some optimizations in the CA parser, we get some bogus context here and have to
            // double check that an override proposal would be valid at this location
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=370955
            EObject prevModel = context.getPreviousModel();
            if (prevModel instanceof XExpression) {
                XtendMember containingMember = EcoreUtil2.getContainerOfType(prevModel, XtendMember.class);
                XBlockExpression blockExpression = EcoreUtil2.getContainerOfType(prevModel, XBlockExpression.class);
                if (blockExpression != null && blockExpression != prevModel) {
                    if (EcoreUtil.isAncestor(containingMember, blockExpression)) {
                        // still inside block
                        return;
                    }
                }
            }
            overrideAssist.createOverrideProposals((XtendTypeDeclaration) model, context, acceptor, getConflictHelper());
        }
    }
    super.completeType_Members(model, assignment, context, acceptor);
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) INode(org.eclipse.xtext.nodemodel.INode) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 97 with XExpression

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

the class XtendCopyQualifiedNameServiceTest method testJvmOperation_7.

@Test
public void testJvmOperation_7() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo () {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Bar<String>.bar(null)");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Bar<String>.bar(<String>newArrayList)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Bar<T> {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar (java.util.List<T> list) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendTypeDeclaration xtendType = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(xtendType.getMembers());
        XExpression _expression = ((XtendFunction) _head).getExpression();
        final XBlockExpression expression = ((XBlockExpression) _expression);
        this.assertCopyQualifiedName(expression.getExpressions().get(0), "Bar.bar(List<String>)");
        this.assertCopyQualifiedName(expression.getExpressions().get(1), "Bar.bar(ArrayList<String>)");
    } 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) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 98 with XExpression

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

the class XtendCopyQualifiedNameServiceTest method testJvmOperation_2.

@Test
public void testJvmOperation_2() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo(java.util.Map<? extends String, ? extends String> map) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("map.get(null)");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("map.put(null, null)");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("bar(map)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <K, V> void bar(java.util.Map<K, V> map) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendTypeDeclaration xtendType = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(xtendType.getMembers());
        XExpression _expression = ((XtendFunction) _head).getExpression();
        final XBlockExpression expression = ((XBlockExpression) _expression);
        this.assertCopyQualifiedName(expression.getExpressions().get(0), "java.util.Map.get(Object)");
        this.assertCopyQualifiedName(expression.getExpressions().get(1), "java.util.Map.put(? extends String, ? extends String)");
        this.assertCopyQualifiedName(expression.getExpressions().get(2), "Foo.bar(Map<? extends String, ? extends String>)");
    } 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) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 99 with XExpression

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

the class XtendCopyQualifiedNameServiceTest method testJvmOperation_6.

@Test
public void testJvmOperation_6() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo<T> extends java.util.ArrayList<T> {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("clear");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("add(null)");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("super.clear");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("super.add(null)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("override clear () {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("super.clear");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("override add(T value) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("super.add(value)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendTypeDeclaration xtendType = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(xtendType.getMembers());
        XExpression _expression = ((XtendFunction) _head).getExpression();
        final XBlockExpression expression = ((XBlockExpression) _expression);
        this.assertCopyQualifiedName(expression.getExpressions().get(0), "Foo.clear()");
        this.assertCopyQualifiedName(expression.getExpressions().get(1), "Foo.add(T)");
        this.assertCopyQualifiedName(expression.getExpressions().get(2), "java.util.ArrayList.clear()");
        this.assertCopyQualifiedName(expression.getExpressions().get(3), "java.util.ArrayList.add(T)");
    } 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) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 100 with XExpression

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

the class XtendHoverDocumentationProviderTest method testJavaDocWithLinkToXtendFunctionOnReference.

@Test
public void testJavaDocWithLinkToXtendFunctionOnReference() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testpackage");
        _builder.newLine();
        _builder.newLine();
        _builder.append("import java.util.List");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("/**");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("* SimpleJavaDoc");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("* {@link testpackage.Foo#foo(java.util.List)}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar(String a, String b){");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo(List a){");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("bar(\"42\",\"43\")");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        XtendMember _get = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers().get(1);
        final XtendFunction function = ((XtendFunction) _get);
        XExpression _expression = function.getExpression();
        XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
        final XAbstractFeatureCall call = ((XAbstractFeatureCall) _get_1);
        final String docu = this.documentationProvider.getDocumentation(call.getFeature());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("SimpleJavaDoc");
        _builder_1.newLine();
        _builder_1.append("<code><a href=\"eclipse-xtext-doc:__synthetic0.xtend%23/1/@members.2\">testpackage.Foo#foo(java.util.List)</a></code><dl><dt>Parameters:</dt><dd><b>a</b> </dd><dd><b>b</b> </dd></dl>");
        Assert.assertEquals(_builder_1.toString(), docu);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Aggregations

XExpression (org.eclipse.xtext.xbase.XExpression)266 Test (org.junit.Test)134 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)97 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)86 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)85 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)84 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)83 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)64 EObject (org.eclipse.emf.ecore.EObject)40 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)37 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)29 IFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)28 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)25 XtendField (org.eclipse.xtend.core.xtend.XtendField)24 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)23 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)22 XNumberLiteral (org.eclipse.xtext.xbase.XNumberLiteral)22 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)21 XtextResource (org.eclipse.xtext.resource.XtextResource)18 XClosure (org.eclipse.xtext.xbase.XClosure)18