Search in sources :

Example 16 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class XtendHoverSignatureProviderTest method testSignatureDelegateConstructorCall_02.

@Ignore
@Test
public void testSignatureDelegateConstructorCall_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo<S extends CharSequence> {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new(int i) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("this(StringBuilder)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new<X>(Class<X> c) {}");
        _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 XtendConstructor xtendConstructor = ((XtendConstructor) _get);
        XExpression _expression = xtendConstructor.getExpression();
        XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
        final XFeatureCall featureCall = ((XFeatureCall) _get_1);
        final String signature = this.signatureProvider.getSignature(featureCall);
        Assert.assertEquals("Foo<S>()", signature);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class XtendHoverSignatureProviderTest method testSignatureDelegateConstructorCall_01.

@Ignore
@Test
public void testSignatureDelegateConstructorCall_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo<S extends CharSequence> {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new(int i) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("this()");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new() {}");
        _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 XtendConstructor xtendConstructor = ((XtendConstructor) _get);
        XExpression _expression = xtendConstructor.getExpression();
        XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
        final XFeatureCall featureCall = ((XFeatureCall) _get_1);
        final String signature = this.signatureProvider.getSignature(featureCall);
        Assert.assertEquals("Foo<S>()", signature);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class JavaConverterTest method testForceStatementForTargetObject.

@Test
public void testForceStatementForTargetObject() {
    Assert.assertFalse("Not a statement before annotation", this.j2x.shouldForceStatementMode(new XAnnotationsFactoryImpl().createXAnnotation()));
    final XtendConstructor xc = new XtendFactoryImpl().createXtendConstructor();
    Assert.assertFalse("Not a statement before constructor", this.j2x.shouldForceStatementMode(xc));
    final XBlockExpression block = new XbaseFactoryImpl().createXBlockExpression();
    xc.setExpression(block);
    Assert.assertTrue("Force statement when parent is executable", this.j2x.shouldForceStatementMode(block));
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XAnnotationsFactoryImpl(org.eclipse.xtext.xbase.annotations.xAnnotations.impl.XAnnotationsFactoryImpl) XbaseFactoryImpl(org.eclipse.xtext.xbase.impl.XbaseFactoryImpl) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XtendFactoryImpl(org.eclipse.xtend.core.xtend.impl.XtendFactoryImpl) Test(org.junit.Test)

Example 19 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class RenameStrategyTest method testXtendConstructorIgnored.

@Test
public void testXtendConstructorIgnored() throws Exception {
    XtendConstructor constructor = (XtendConstructor) ((XtendClass) testHelper.xtendFile("Foo", "class Foo { new() {} }").getXtendTypes().get(0)).getMembers().get(0);
    IRenameStrategy renameStrategy = createRenameStrategy(constructor);
    assertNull(renameStrategy);
}
Also used : IRenameStrategy(org.eclipse.xtext.ui.refactoring.IRenameStrategy) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Test(org.junit.Test)

Example 20 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class LinkingTest method testDeclaredConstructor_01.

@Test
public void testDeclaredConstructor_01() throws Exception {
    XtendClass clazz = clazz("class Foo { " + "  int i" + "  new(int i) { this.i = i }" + "}");
    assertEquals(2, clazz.getMembers().size());
    XtendConstructor constructor = (XtendConstructor) clazz.getMembers().get(1);
    XAssignment assignment = (XAssignment) ((XBlockExpression) constructor.getExpression()).getExpressions().get(0);
    JvmField field = (JvmField) assignment.getFeature();
    assertEquals("i", field.getSimpleName());
    XFeatureCall target = (XFeatureCall) assignment.getAssignable();
    JvmDeclaredType identifiableElement = (JvmDeclaredType) target.getFeature();
    assertEquals("Foo", identifiableElement.getSimpleName());
    XFeatureCall value = (XFeatureCall) assignment.getValue();
    JvmFormalParameter parameter = (JvmFormalParameter) value.getFeature();
    assertEquals("i", parameter.getSimpleName());
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmField(org.eclipse.xtext.common.types.JvmField) XAssignment(org.eclipse.xtext.xbase.XAssignment) Test(org.junit.Test)

Aggregations

XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)28 Test (org.junit.Test)18 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)9 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)9 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)7 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)7 XExpression (org.eclipse.xtext.xbase.XExpression)7 XtendField (org.eclipse.xtend.core.xtend.XtendField)6 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)6 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)5 XtendEnumLiteral (org.eclipse.xtend.core.xtend.XtendEnumLiteral)3 EObject (org.eclipse.emf.ecore.EObject)2 XtendAnnotationType (org.eclipse.xtend.core.xtend.XtendAnnotationType)2 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)2 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)2 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)2 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2