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);
}
}
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);
}
}
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());
}
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());
}
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());
}
Aggregations