Search in sources :

Example 1 with XVariableDeclaration

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

the class ParserTest method testRichStringFOR_03.

@Test
public void testRichStringFOR_03() throws Exception {
    XtendFunction function = function("def withForLoop(String it) '''�it��val it = 1..10��FOR i: it SEPARATOR it��ENDFOR�'''");
    final RichString richString = (RichString) function.getExpression();
    assertTrue(richString.getExpressions().get(0) instanceof RichStringLiteral);
    assertTrue(richString.getExpressions().get(1) instanceof XFeatureCall);
    JvmOperation operation = associations.getDirectlyInferredOperation(function);
    assertSame(operation.getParameters().get(0), ((XAbstractFeatureCall) richString.getExpressions().get(1)).getFeature());
    assertTrue(richString.getExpressions().get(2) instanceof RichStringLiteral);
    assertTrue(richString.getExpressions().get(3) instanceof XVariableDeclaration);
    assertTrue(richString.getExpressions().get(4) instanceof RichStringLiteral);
    assertTrue(richString.getExpressions().get(5) instanceof RichStringForLoop);
    final RichStringForLoop rsFor = (RichStringForLoop) richString.getExpressions().get(5);
    assertTrue(rsFor.getForExpression() instanceof XFeatureCall);
    assertSame(richString.getExpressions().get(3), ((XAbstractFeatureCall) rsFor.getForExpression()).getFeature());
    assertEquals("i", rsFor.getDeclaredParam().getName());
    assertTrue(rsFor.getSeparator() instanceof XFeatureCall);
    assertSame(richString.getExpressions().get(3), ((XAbstractFeatureCall) rsFor.getSeparator()).getFeature());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) RichString(org.eclipse.xtend.core.xtend.RichString) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) RichStringForLoop(org.eclipse.xtend.core.xtend.RichStringForLoop) Test(org.junit.Test)

Example 2 with XVariableDeclaration

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

the class UIStringsTest method testReferenceToString_0.

/**
 * Only the simple name of the type is specified.
 * The JvmTypeReference is not a proxy.
 */
@Test
public void testReferenceToString_0() throws Exception {
    XtendFile file = file("package org.eclipse.xtend.core.tests.validation.uistrings\n" + "public interface InterfaceA { }\n" + "public class ClassB implements InterfaceA { }\n" + "public class ClassC extends ClassB {\n" + "}\n" + "class XtendClass1 {\n" + "  def test() {\n" + "    val x = new List<ClassC>\n" + "  }\n" + "}\n");
    XtendClass clazz = (XtendClass) file.getXtendTypes().get(3);
    XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression();
    XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0);
    XConstructorCall cons = (XConstructorCall) declaration.getRight();
    JvmTypeReference reference = cons.getTypeArguments().get(0);
    assertNotNull(reference);
    assertNotNull(reference.getType());
    assertFalse(reference.getType().eIsProxy());
    assertNotNull(reference.eResource());
    assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label"));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) Test(org.junit.Test)

Example 3 with XVariableDeclaration

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

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

use of org.eclipse.xtext.xbase.XVariableDeclaration 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

XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)12 Test (org.junit.Test)9 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)8 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)7 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)6 XExpression (org.eclipse.xtext.xbase.XExpression)6 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)5 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)4 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)4 RichString (org.eclipse.xtend.core.xtend.RichString)3 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)3 EObject (org.eclipse.emf.ecore.EObject)2 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)2 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)2 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)2 CoreException (org.eclipse.core.runtime.CoreException)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 ParameterInfo (org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)1