use of org.eclipse.xtend.lib.macro.declaration.AnnotationTypeElementDeclaration 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