Search in sources :

Example 96 with XBlockExpression

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

the class XtendHoverGenericsResolverTest method testGenerics_2.

@Test
public void testGenerics_2() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar(){");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("something(newArrayList(\"zonk\"), new Foo(),\"42\")");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <T,Y,E extends RuntimeException> Y something(Iterable<T> iterable, Y type1, T type2) throws E");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final Iterable<XtendClass> clazz = Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class);
        XtendMember _get = IterableExtensions.<XtendClass>head(clazz).getMembers().get(0);
        final XtendFunction function = ((XtendFunction) _get);
        XExpression _expression = function.getExpression();
        final XBlockExpression expression = ((XBlockExpression) _expression);
        XExpression _get_1 = expression.getExpressions().get(0);
        final XAbstractFeatureCall call = ((XAbstractFeatureCall) _get_1);
        final String resolvedSignature = this.signatureProvider.getSignature(call);
        Assert.assertEquals("<String, Foo, RuntimeException> Foo Foo.something(Iterable<String> iterable, Foo type1, String type2) throws RuntimeException", resolvedSignature);
    } 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) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 97 with XBlockExpression

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

the class XtendHoverSignatureProviderTest method testSignatureForAnonymousClassLocalVarTypeTest_02.

@Test
public void testSignatureForAnonymousClassLocalVarTypeTest_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("val r = new Runnable { override run() {} def void m() {} }");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("r");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
        XtendMember _get = clazz.getMembers().get(0);
        final XtendFunction function = ((XtendFunction) _get);
        XExpression _expression = function.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
        final XVariableDeclaration variable = ((XVariableDeclaration) _head);
        final String signature = this.signatureProvider.getSignature(variable);
        Assert.assertEquals("new Runnable(){} r", signature);
    } 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) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 98 with XBlockExpression

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

the class XtendHoverSignatureProviderTest method testSignatureForAnonymousClassLocalVarTypeTest_03.

@Test
public void testSignatureForAnonymousClassLocalVarTypeTest_03() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("val r = newArrayList(new Runnable { override run() {} })");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("r");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
        XtendMember _get = clazz.getMembers().get(0);
        final XtendFunction function = ((XtendFunction) _get);
        XExpression _expression = function.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
        final XVariableDeclaration variable = ((XVariableDeclaration) _head);
        final String signature = this.signatureProvider.getSignature(variable);
        Assert.assertEquals("ArrayList<new Runnable(){}> r", signature);
    } 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) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 99 with XBlockExpression

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

the class XtendHoverSignatureProviderTest method testAutcastExpressions_2.

@Test
public void testAutcastExpressions_2() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("CharSequence c = \"\"");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (c instanceof String) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("c.substring(1, 1)");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("switch(c){");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("String : c.length");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        Assert.assertEquals("CharSequence c", this.signatureProvider.getSignature(IterableExtensions.<XtendMember>head(((XtendClass) _head).getMembers())));
        XtendTypeDeclaration _head_1 = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        XtendMember _get = ((XtendClass) _head_1).getMembers().get(1);
        final XtendFunction func = ((XtendFunction) _get);
        XExpression _expression = func.getExpression();
        final XBlockExpression block = ((XBlockExpression) _expression);
        XExpression _head_2 = IterableExtensions.<XExpression>head(block.getExpressions());
        final XIfExpression ifexpr = ((XIfExpression) _head_2);
        final XExpression then = ifexpr.getThen();
        XExpression _head_3 = IterableExtensions.<XExpression>head(((XBlockExpression) then).getExpressions());
        final XExpression target = ((XMemberFeatureCall) _head_3).getMemberCallTarget();
        Assert.assertEquals("String Foo.c", this.signatureProvider.getSignature(target));
        XExpression _get_1 = block.getExpressions().get(1);
        final XSwitchExpression switchExpr = ((XSwitchExpression) _get_1);
        XExpression _then = IterableExtensions.<XCasePart>head(switchExpr.getCases()).getThen();
        final XExpression expr = ((XMemberFeatureCall) _then).getMemberCallTarget();
        Assert.assertEquals("String Foo.c", this.signatureProvider.getSignature(expr));
    } 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) XIfExpression(org.eclipse.xtext.xbase.XIfExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XSwitchExpression(org.eclipse.xtext.xbase.XSwitchExpression) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 100 with XBlockExpression

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

the class XtendHoverSignatureProviderTest method testSignatureForAnonymousClassLocalVarTypeTest.

@Test
public void testSignatureForAnonymousClassLocalVarTypeTest() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("val r = new Runnable { override run() {} }");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("r");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
        XtendMember _get = clazz.getMembers().get(0);
        final XtendFunction function = ((XtendFunction) _get);
        XExpression _expression = function.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
        final XVariableDeclaration variable = ((XVariableDeclaration) _head);
        final String signature = this.signatureProvider.getSignature(variable);
        Assert.assertEquals("new Runnable(){} r", signature);
    } 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) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Aggregations

XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)236 Test (org.junit.Test)210 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)198 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)169 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)126 XExpression (org.eclipse.xtext.xbase.XExpression)84 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)84 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)70 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)58 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)56 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)55 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)29 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)26 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)21 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)12 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)10 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)10 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)9 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)9