use of org.eclipse.xtend.lib.macro.declaration.CompilationUnit in project xtext-xtend by eclipse.
the class DeclarationsTest method testMutableClassDeclaration.
@Test
public void testMutableClassDeclaration() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("class MyClass<T extends CharSequence> {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("String myField");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("new(String initial) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("this.myField = initial");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("def <T2 extends CharSequence> MyClass myMethod(T2 a, T b) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("myField = myField + a + b");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return this");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final MutableClassDeclaration genClazz = it.getTypeLookup().findClass("foo.MyClass");
final Procedure1<MutableMethodDeclaration> _function_1 = (MutableMethodDeclaration it_1) -> {
CompilationUnit _compilationUnit = genClazz.getCompilationUnit();
it_1.setReturnType(((CompilationUnitImpl) _compilationUnit).getTypeReferenceProvider().getString());
it_1.setVisibility(Visibility.PRIVATE);
final CompilationStrategy _function_2 = (CompilationStrategy.CompilationContext it_2) -> {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("return \"foo\";");
_builder_1.newLine();
return _builder_1;
};
it_1.setBody(_function_2);
};
genClazz.addMethod("newMethod", _function_1);
final MutableMethodDeclaration mutableMethod = genClazz.findDeclaredMethod("newMethod");
Assert.assertSame(mutableMethod, ((Object[]) Conversions.unwrapArray(genClazz.getDeclaredMethods(), Object.class))[1]);
Assert.assertEquals("String", mutableMethod.getReturnType().toString());
Assert.assertEquals(Visibility.PRIVATE, mutableMethod.getVisibility());
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
Aggregations