use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class DeclarationsTest method testRemove.
@Test
public void testRemove() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void m() {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
final ClassDeclaration c = ((ClassDeclaration) _head);
final MutableClassDeclaration mutable = it.getTypeLookup().findClass(c.getQualifiedName());
final Consumer<MutableMemberDeclaration> _function_1 = (MutableMemberDeclaration it_1) -> {
it_1.remove();
};
mutable.getDeclaredMembers().forEach(_function_1);
Assert.assertTrue(IterableExtensions.isEmpty(mutable.getDeclaredMembers()));
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class DeclarationsTest method testAnnotationReferenceValues_2.
@Test
public void testAnnotationReferenceValues_2() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.append("@test.Annotation(");
_builder.newLine();
_builder.append("\t");
_builder.append("intValue = 2 / 2 + 2 * 3 - 4 % 1,");
_builder.newLine();
_builder.append("\t");
_builder.append("longValue = 42 + 4 + 6 * 42 - 4 / 45,");
_builder.newLine();
_builder.append("\t");
_builder.append("stringValue = \'foo\' + \'baz\',");
_builder.newLine();
_builder.append("\t");
_builder.append("booleanArrayValue = #[true, false],");
_builder.newLine();
_builder.append("\t");
_builder.append("intArrayValue = #[ -1, 34 + 45, 2 - 6 ],");
_builder.newLine();
_builder.append("\t");
_builder.append("longArrayValue = #[42, 5 * -3],");
_builder.newLine();
_builder.append("\t");
_builder.append("stringArrayValue = #[\'foo\', \'bla\' + \'buzz\'],");
_builder.newLine();
_builder.append("\t");
_builder.append("typeValue = String,");
_builder.newLine();
_builder.append("\t");
_builder.append("typeArrayValue = #[String, Integer],");
_builder.newLine();
_builder.append("\t");
_builder.append("annotation2Value = @test.Annotation2(\'foo\' + \'wuppa\'),");
_builder.newLine();
_builder.append("\t");
_builder.append("annotation2ArrayValue = #[@test.Annotation2, @test.Annotation2(\'foo\'+\'wuppa\')]");
_builder.newLine();
_builder.append("\t");
_builder.append(") class Bar {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final MutableClassDeclaration baseClass = it.getTypeLookup().findClass("foo.Bar");
final AnnotationReference annoRef = IterableExtensions.head(baseClass.getAnnotations());
Assert.assertEquals((((2 / 2) + (2 * 3)) - (4 % 1)), annoRef.getIntValue("intValue"));
Assert.assertEquals((((42 + 4) + (6 * 42)) - (4 / 45)), annoRef.getLongValue("longValue"));
Assert.assertEquals("foobaz", annoRef.getStringValue("stringValue"));
final boolean[] bools = annoRef.getBooleanArrayValue("booleanArrayValue");
Assert.assertTrue(bools[0]);
Assert.assertFalse(bools[1]);
Assert.assertArrayEquals(new int[] { (-1), (34 + 45), (2 - 6) }, annoRef.getIntArrayValue("intArrayValue"));
final TypeReference[] type = annoRef.getClassArrayValue("typeArrayValue");
Assert.assertEquals(it.getTypeReferenceProvider().newTypeReference(Integer.class), type[1]);
final AnnotationReference anno = annoRef.getAnnotationValue("annotation2Value");
Assert.assertEquals("foowuppa", anno.getStringValue("value"));
final AnnotationReference[] annoArray = annoRef.getAnnotationArrayValue("annotation2ArrayValue");
Assert.assertEquals("HUBBA BUBBA!", (annoArray[0]).getValue("value"));
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class DeclarationsTest method testMutableInterfaceDeclaration.
@Test
public void testMutableInterfaceDeclaration() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("interface MyInterface {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final MutableInterfaceDeclaration genInterface = it.getTypeLookup().findInterface("foo.MyInterface");
final Procedure1<MutableMethodDeclaration> _function_1 = (MutableMethodDeclaration it_1) -> {
};
final MutableMethodDeclaration m = genInterface.addMethod("newMethod", _function_1);
Assert.assertTrue(m.isAbstract());
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class DeclarationsTest method testSimpleClassWithField.
@Test
public void testSimpleClassWithField() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("class MyClass extends Object implements java.io.Serializable {");
_builder.newLine();
_builder.append("\t");
_builder.append("MyClass foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
Assert.assertEquals("foo", it.getPackageName());
TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
final ClassDeclaration clazz = ((ClassDeclaration) _head);
Assert.assertEquals("foo.MyClass", clazz.getQualifiedName());
Assert.assertEquals("Object", clazz.getExtendedClass().toString());
Assert.assertEquals("Serializable", IterableExtensions.head(clazz.getImplementedInterfaces()).toString());
MemberDeclaration _head_1 = IterableExtensions.head(clazz.getDeclaredMembers());
final FieldDeclaration field = ((FieldDeclaration) _head_1);
Assert.assertEquals("foo", field.getSimpleName());
Assert.assertSame(it.getTypeLookup().findClass("foo.MyClass"), field.getType().getType());
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
use of org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl in project xtext-xtend by eclipse.
the class DeclarationsTest method testAnnotation.
@Test
public void testAnnotation() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("@SuppressWarnings(\"unused\")");
_builder.newLine();
_builder.append("class MyClass {");
_builder.newLine();
_builder.append("\t");
_builder.append("@com.google.inject.Inject(optional=true) MyClass foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
Assert.assertNull(it.getPackageName());
TypeDeclaration _head = IterableExtensions.head(it.getSourceTypeDeclarations());
final ClassDeclaration clazz = ((ClassDeclaration) _head);
Assert.assertEquals("MyClass", clazz.getQualifiedName());
final AnnotationReference suppressWarning = IterableExtensions.head(clazz.getAnnotations());
final AnnotationTypeDeclaration supressWarningsDeclaration = suppressWarning.getAnnotationTypeDeclaration();
Assert.assertEquals("java.lang.SuppressWarnings", supressWarningsDeclaration.getQualifiedName());
Assert.assertEquals("unused", suppressWarning.getStringArrayValue("value")[0]);
Assert.assertEquals(2, IterableExtensions.size(supressWarningsDeclaration.getAnnotations()));
final AnnotationTypeElementDeclaration valueProperty = IterableExtensions.<AnnotationTypeElementDeclaration>head(Iterables.<AnnotationTypeElementDeclaration>filter(supressWarningsDeclaration.getDeclaredMembers(), AnnotationTypeElementDeclaration.class));
Assert.assertEquals("String[]", valueProperty.getType().toString());
Assert.assertEquals("value", valueProperty.getSimpleName());
MemberDeclaration _head_1 = IterableExtensions.head(clazz.getDeclaredMembers());
final FieldDeclaration field = ((FieldDeclaration) _head_1);
final AnnotationReference inject = IterableExtensions.head(field.getAnnotations());
Object _value = inject.getValue("optional");
Assert.assertTrue((((Boolean) _value)).booleanValue());
};
this.asCompilationUnit(this.validFile(_builder), _function);
}
Aggregations