Search in sources :

Example 1 with AnnotationTypeElementDeclaration

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);
}
Also used : AnnotationTypeElementDeclaration(org.eclipse.xtend.lib.macro.declaration.AnnotationTypeElementDeclaration) ClassDeclaration(org.eclipse.xtend.lib.macro.declaration.ClassDeclaration) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) MutableMemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableMemberDeclaration) MemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MemberDeclaration) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) AnnotationTypeDeclaration(org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration) AccessibleObject(java.lang.reflect.AccessibleObject) AnnotationTypeDeclaration(org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration) TypeDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeDeclaration) MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) FieldDeclaration(org.eclipse.xtend.lib.macro.declaration.FieldDeclaration) Test(org.junit.Test)

Aggregations

AccessibleObject (java.lang.reflect.AccessibleObject)1 CompilationUnitImpl (org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)1 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)1 AnnotationTypeDeclaration (org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration)1 AnnotationTypeElementDeclaration (org.eclipse.xtend.lib.macro.declaration.AnnotationTypeElementDeclaration)1 ClassDeclaration (org.eclipse.xtend.lib.macro.declaration.ClassDeclaration)1 FieldDeclaration (org.eclipse.xtend.lib.macro.declaration.FieldDeclaration)1 MemberDeclaration (org.eclipse.xtend.lib.macro.declaration.MemberDeclaration)1 MutableClassDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration)1 MutableFieldDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration)1 MutableMemberDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableMemberDeclaration)1 TypeDeclaration (org.eclipse.xtend.lib.macro.declaration.TypeDeclaration)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 Test (org.junit.Test)1