use of org.eclipse.xtend.lib.macro.TransformationContext in project xtext-xtend by eclipse.
the class AccessObjectProcessorTest method testWithoutPackage.
@Test
public void testWithoutPackage() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.eclipse.xtend.core.tests.macro.Accessors");
_builder.newLine();
_builder.newLine();
_builder.append("@org.eclipse.xtend.core.tests.macro.AccessObjectAnn");
_builder.newLine();
_builder.append("class A {");
_builder.newLine();
_builder.append("\t");
_builder.append("String field");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> {
final TransformationContext ctx = it.getTransformationContext();
final MutableClassDeclaration classA = ctx.findClass("A");
Assert.assertNotNull(classA.findDeclaredMethod("getField"));
final MutableClassDeclaration classPA = ctx.findClass("PA");
final Function1<TypeReference, Boolean> _function_1 = (TypeReference it_1) -> {
Type _type = it_1.getType();
Type _type_1 = ctx.newTypeReference(Serializable.class).getType();
return Boolean.valueOf(Objects.equal(_type, _type_1));
};
Assert.assertNotNull(IterableExtensions.findFirst(classPA.getImplementedInterfaces(), _function_1));
final MutableClassDeclaration classGA = ctx.findClass("GA");
final Function1<TypeReference, Boolean> _function_2 = (TypeReference it_1) -> {
Type _type = it_1.getType();
Type _type_1 = ctx.newTypeReference(Serializable.class).getType();
return Boolean.valueOf(Objects.equal(_type, _type_1));
};
Assert.assertNotNull(IterableExtensions.findFirst(classGA.getImplementedInterfaces(), _function_2));
};
this._xtendCompilerTester.compile(_builder, _function);
}
use of org.eclipse.xtend.lib.macro.TransformationContext in project xtext-xtend by eclipse.
the class AccessorsAnnotationTest method testProperty2.
@Test
public void testProperty2() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.eclipse.xtend.core.tests.macro.Accessors");
_builder.newLine();
_builder.newLine();
_builder.append("class A {");
_builder.newLine();
_builder.append("\t");
_builder.append("@Accessors String field");
_builder.newLine();
_builder.append("\t");
_builder.append("private def String getField() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return null");
_builder.newLine();
_builder.append("\t");
_builder.append("} ");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> {
final TransformationContext ctx = it.getTransformationContext();
final MutableClassDeclaration classA = ctx.findClass("A");
Assert.assertEquals(Visibility.PRIVATE, classA.findDeclaredMethod("getField").getVisibility());
Assert.assertEquals(Visibility.PUBLIC, classA.findDeclaredMethod("setField", ctx.getString()).getVisibility());
Assert.assertEquals(2, IterableExtensions.size(classA.getDeclaredMethods()));
};
this._xtendCompilerTester.compile(_builder, _function);
}
use of org.eclipse.xtend.lib.macro.TransformationContext in project xtext-xtend by eclipse.
the class AccessObjectProcessorTest method testWithPackage.
@Test
public void testWithPackage() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package my.pack");
_builder.newLine();
_builder.append("import org.eclipse.xtend.core.tests.macro.Accessors");
_builder.newLine();
_builder.newLine();
_builder.append("@org.eclipse.xtend.core.tests.macro.AccessObjectAnn");
_builder.newLine();
_builder.append("class A {");
_builder.newLine();
_builder.append("\t");
_builder.append("String field");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> {
final TransformationContext ctx = it.getTransformationContext();
final MutableClassDeclaration classA = ctx.findClass("my.pack.A");
Assert.assertNotNull(classA.findDeclaredMethod("getField"));
final MutableClassDeclaration classPA = ctx.findClass("my.pack.PA");
final Function1<TypeReference, Boolean> _function_1 = (TypeReference it_1) -> {
Type _type = it_1.getType();
Type _type_1 = ctx.newTypeReference(Serializable.class).getType();
return Boolean.valueOf(Objects.equal(_type, _type_1));
};
Assert.assertNotNull(IterableExtensions.findFirst(classPA.getImplementedInterfaces(), _function_1));
final MutableClassDeclaration classGA = ctx.findClass("my.pack.GA");
final Function1<TypeReference, Boolean> _function_2 = (TypeReference it_1) -> {
Type _type = it_1.getType();
Type _type_1 = ctx.newTypeReference(Serializable.class).getType();
return Boolean.valueOf(Objects.equal(_type, _type_1));
};
Assert.assertNotNull(IterableExtensions.findFirst(classGA.getImplementedInterfaces(), _function_2));
};
this._xtendCompilerTester.compile(_builder, _function);
}
use of org.eclipse.xtend.lib.macro.TransformationContext in project xtext-xtend by eclipse.
the class AccessorsAnnotationTest method testProperty.
@Test
public void testProperty() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.eclipse.xtend.core.tests.macro.Accessors");
_builder.newLine();
_builder.newLine();
_builder.append("class A {");
_builder.newLine();
_builder.append("\t");
_builder.append("@Accessors String field");
_builder.newLine();
_builder.append("\t");
_builder.append("@Accessors val String finalField = \'foo\'");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> {
final TransformationContext ctx = it.getTransformationContext();
final MutableClassDeclaration classA = ctx.findClass("A");
Assert.assertEquals(Visibility.PUBLIC, classA.findDeclaredMethod("getField").getVisibility());
Assert.assertEquals(Visibility.PUBLIC, classA.findDeclaredMethod("setField", ctx.getString()).getVisibility());
Assert.assertEquals(Visibility.PUBLIC, classA.findDeclaredMethod("getFinalField").getVisibility());
Assert.assertNull(classA.findDeclaredMethod("setFinalField", ctx.getString()));
};
this._xtendCompilerTester.compile(_builder, _function);
}
Aggregations