Java Code Examples for org.eclipse.xtend.lib.macro.declaration.AnnotationReference#getValue()
The following examples show how to use
org.eclipse.xtend.lib.macro.declaration.AnnotationReference#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeclarationsTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testAnnotation3() { StringConcatenation _builder = new StringConcatenation(); _builder.append("@test.Annotation"); _builder.newLine(); _builder.append("class MyClass {"); _builder.newLine(); _builder.append("\t"); _builder.append("@test.Annotation2 String foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> { final AnnotationReference anno = IterableExtensions.head(it.getTypeLookup().findClass("MyClass").getAnnotations()); final AnnotationReference anno2 = IterableExtensions.head(IterableExtensions.head(it.getTypeLookup().findClass("MyClass").getDeclaredFields()).getAnnotations()); final Procedure1<AnnotationReferenceBuildContext> _function_1 = (AnnotationReferenceBuildContext it_1) -> { it_1.set("annotation2Value", anno2); }; it.getTypeLookup().findClass("MyClass").addAnnotation(it.getAnnotationReferenceProvider().newAnnotationReference(anno, _function_1)); it.getTypeLookup().findClass("MyClass").removeAnnotation(anno); Object _value = anno.getValue("annotation2Value"); Assert.assertEquals(IterableExtensions.head(IterableExtensions.head(it.getTypeLookup().findClass("MyClass").getDeclaredFields()).getAnnotations()).getAnnotationTypeDeclaration(), ((AnnotationReference) _value).getAnnotationTypeDeclaration()); }; this.asCompilationUnit(this.validFile(_builder), _function); }
Example 2
Source File: DotAttributeProcessor.java From gef with Eclipse Public License 2.0 | 5 votes |
private Object annotationValue(MutableFieldDeclaration field, TransformationContext context, String property) { for (AnnotationReference reference : field.getAnnotations()) { if (DotAttribute.class.getName().equals(reference .getAnnotationTypeDeclaration().getQualifiedName())) { return reference.getValue(property); } } throw new IllegalArgumentException("No DotAttribute annotation found."); }
Example 3
Source File: GetProcessor.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public void doTransform(final List<? extends MutableMethodDeclaration> methods, @Extension final TransformationContext context) { for (final MutableMethodDeclaration m : methods) { { final AnnotationReference annotation = m.findAnnotation(context.findTypeGlobally(Get.class)); final Object pattern = annotation.getValue("value"); if ((pattern == null)) { context.addError(annotation, "A URL pattern must be provided."); } else { } } } }
Example 4
Source File: DeclarationsTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@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); }
Example 5
Source File: DeclarationsTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Test public void testAnnotationReferenceValues() { 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(Integer.valueOf((((2 / 2) + (2 * 3)) - (4 % 1))), annoRef.getValue("intValue")); Assert.assertEquals(Integer.valueOf((((42 + 4) + (6 * 42)) - (4 / 45))), annoRef.getValue("longValue")); Assert.assertEquals("foobaz", annoRef.getValue("stringValue")); Object _value = annoRef.getValue("booleanArrayValue"); final boolean[] bools = ((boolean[]) _value); Assert.assertTrue(bools[0]); Assert.assertFalse(bools[1]); Object _value_1 = annoRef.getValue("intArrayValue"); Assert.assertArrayEquals(new int[] { (-1), (34 + 45), (2 - 6) }, ((int[]) _value_1)); Object _value_2 = annoRef.getValue("typeArrayValue"); final TypeReference[] type = ((TypeReference[]) _value_2); Assert.assertEquals(it.getTypeReferenceProvider().newTypeReference(Integer.class), type[1]); Object _value_3 = annoRef.getValue("annotation2Value"); final AnnotationReference anno = ((AnnotationReference) _value_3); Assert.assertEquals("foowuppa", anno.getValue("value")); Object _value_4 = annoRef.getValue("annotation2ArrayValue"); final AnnotationReference[] annoArray = ((AnnotationReference[]) _value_4); Assert.assertEquals("HUBBA BUBBA!", (annoArray[0]).getValue("value")); }; this.asCompilationUnit(this.validFile(_builder), _function); }