Search in sources :

Example 41 with XtendMember

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

the class NonOverridableTypesProviderTest method testInheritMiddleParam_01.

@Test
public void testInheritMiddleParam_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("import types.OuterClass");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo<InnerMostClass, T> extends OuterClass$MiddleClass<String> {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <InnerMostClass> foo() ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar() ");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendClass xtendClass = this.clazz(_builder.toString());
        final JvmGenericType inferredType = this.associations.getInferredType(xtendClass);
        this.assertTypeInScope("Foo", inferredType);
        this.assertTypeInScope("InnerMostClass", inferredType);
        this.assertTypeParameterInScope("T", inferredType);
        this.assertNotInScope("OuterClass.MiddleClass", inferredType);
        this.assertNotInScope("MiddleClass", inferredType);
        this.assertNotInScope("OuterClass", inferredType);
        final XtendMember method = xtendClass.getMembers().get(0);
        final JvmOperation operation = this.associations.getDirectlyInferredOperation(((XtendFunction) method));
        this.assertTypeInScope("Foo", operation);
        this.assertTypeParameterInScope("InnerMostClass", operation);
        this.assertTypeParameterInScope("T", operation);
        this.assertNotInScope("OuterClass.MiddleClass", operation);
        this.assertNotInScope("MiddleClass", operation);
        this.assertNotInScope("OuterClass", operation);
        final XtendMember method2 = xtendClass.getMembers().get(0);
        final JvmOperation operation2 = this.associations.getDirectlyInferredOperation(((XtendFunction) method2));
        this.assertTypeInScope("Foo", operation2);
        this.assertTypeInScope("InnerMostClass", operation2);
        this.assertTypeParameterInScope("T", operation2);
        this.assertNotInScope("OuterClass.MiddleClass", operation2);
        this.assertNotInScope("MiddleClass", operation2);
        this.assertNotInScope("OuterClass", operation2);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 42 with XtendMember

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

the class NonOverridableTypesProviderTest method testInheritOuterTypeParam.

@Test
public void testInheritOuterTypeParam() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("import types.OuterClass");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo<MiddleClass, T> extends OuterClass<String> {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <MiddleClass> foo() ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar()");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendClass xtendClass = this.clazz(_builder.toString());
        final JvmGenericType inferredType = this.associations.getInferredType(xtendClass);
        this.assertTypeInScope("Foo", inferredType);
        this.assertTypeInScope("MiddleClass", inferredType);
        this.assertNotInScope("MiddleClass.InnerMostClass", inferredType);
        this.assertTypeParameterInScope("T", inferredType);
        this.assertNotInScope("OuterClass", inferredType);
        final XtendMember method = xtendClass.getMembers().get(0);
        final JvmOperation operation = this.associations.getDirectlyInferredOperation(((XtendFunction) method));
        this.assertTypeInScope("Foo", operation);
        this.assertTypeParameterInScope("MiddleClass", operation);
        this.assertTypeParameterInScope("T", operation);
        this.assertNotInScope("MiddleClass.InnerMostClass", operation);
        this.assertNotInScope("OuterClass", operation);
        final XtendMember method2 = xtendClass.getMembers().get(0);
        final JvmOperation operation2 = this.associations.getDirectlyInferredOperation(((XtendFunction) method2));
        this.assertTypeInScope("Foo", operation2);
        this.assertTypeParameterInScope("MiddleClass", operation2);
        this.assertTypeParameterInScope("T", operation2);
        this.assertNotInScope("MiddleClass.InnerMostClass", operation2);
        this.assertNotInScope("OuterClass", operation2);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 43 with XtendMember

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

the class JavaConverterTest method testEnumCase1.

@Test
public void testEnumCase1() throws Exception {
    XtendClass enum_ = this.toValidXtendClass("public class MyClazz{\n\t \t\t\tenum MyEnum { NEW }\n\t\t\t}");
    XtendMember _get = enum_.getMembers().get(0);
    Assert.assertEquals(JvmVisibility.DEFAULT, ((XtendEnum) _get).getVisibility());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) Test(org.junit.Test)

Example 44 with XtendMember

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

the class JavaConverterTest method testStaticImportCase.

@Test
public void testStaticImportCase() throws Exception {
    XtendClass xtendClazz = this.toValidXtendClass("import static java.awt.AWTEvent.*; public class Test { long o= ACTION_EVENT_MASK;}");
    XtendMember _get = xtendClazz.getMembers().get(0);
    XtendField xtendMember = ((XtendField) _get);
    Assert.assertEquals("o", xtendMember.getName());
    XExpression _initialValue = xtendMember.getInitialValue();
    XFeatureCall xFeatureCall = ((XFeatureCall) _initialValue);
    Assert.assertEquals("ACTION_EVENT_MASK", xFeatureCall.getFeature().getSimpleName());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 45 with XtendMember

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

the class JavaConverterTest method testOverride.

@Test
public void testOverride() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.util.Iterator;");
    _builder.newLine();
    _builder.append("public class JavaToConvert implements Statement {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Iterable statements() { return null;} ");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public String toString() { return null;} ");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public void accept(JavaToConvert v){}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public <DH> Iterator<DH> doAnonymousClass() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return new Iterator<DH>() {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("public int hashCode() {return super.hashCode();}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("public boolean hasNext() { return true;}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("public DH next() { return null;}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("public void remove() {}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("};");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("interface Node {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("Iterable statements();");
    _builder.newLine();
    _builder.append("} ");
    _builder.newLine();
    _builder.append("interface Statement extends Node {");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("void accept(JavaToConvert v);");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    XtendClass xtendClazz = this.toValidXtendClass(_builder);
    EList<XtendMember> members = xtendClazz.getMembers();
    Assert.assertEquals("Simple methods count", 4, members.size());
    Assert.assertTrue(this.method(xtendClazz, 0).isOverride());
    Assert.assertTrue(this.method(xtendClazz, 1).isOverride());
    Assert.assertTrue(this.method(xtendClazz, 2).isOverride());
    Assert.assertFalse(this.method(xtendClazz, 3).isOverride());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Aggregations

XtendMember (org.eclipse.xtend.core.xtend.XtendMember)175 Test (org.junit.Test)140 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)131 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)119 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)101 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)91 XExpression (org.eclipse.xtext.xbase.XExpression)84 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)57 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)56 XtendField (org.eclipse.xtend.core.xtend.XtendField)33 EObject (org.eclipse.emf.ecore.EObject)17 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)14 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)12 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)12 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)10 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)9 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)9 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)8 JvmType (org.eclipse.xtext.common.types.JvmType)8