1 /* |
1 /* |
2 * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 6397298 6400986 6425592 6449798 6453386 6508401 6498938 6911854 |
26 * @bug 6397298 6400986 6425592 6449798 6453386 6508401 6498938 6911854 |
27 * @summary Tests that getElementsAnnotatedWith works properly. |
27 * @summary Tests that getElementsAnnotatedWith works properly. |
28 * @author Joseph D. Darcy |
28 * @author Joseph D. Darcy |
|
29 * @library ../../../lib |
|
30 * @build JavacTestingAbstractProcessor |
29 * @compile TestElementsAnnotatedWith.java |
31 * @compile TestElementsAnnotatedWith.java |
30 * @compile InheritedAnnotation.java |
32 * @compile InheritedAnnotation.java |
31 * @compile -processor TestElementsAnnotatedWith -proc:only SurfaceAnnotations.java |
33 * @compile -processor TestElementsAnnotatedWith -proc:only SurfaceAnnotations.java |
32 * @compile -processor TestElementsAnnotatedWith -proc:only BuriedAnnotations.java |
34 * @compile -processor TestElementsAnnotatedWith -proc:only BuriedAnnotations.java |
33 * @compile -processor TestElementsAnnotatedWith -proc:only Part1.java Part2.java |
35 * @compile -processor TestElementsAnnotatedWith -proc:only Part1.java Part2.java |
55 /** |
57 /** |
56 * This processor verifies that the information returned by |
58 * This processor verifies that the information returned by |
57 * getElementsAnnotatedWith is consistent with the expected results |
59 * getElementsAnnotatedWith is consistent with the expected results |
58 * stored in an AnnotatedElementInfo annotation. |
60 * stored in an AnnotatedElementInfo annotation. |
59 */ |
61 */ |
60 @SupportedAnnotationTypes("*") |
|
61 @AnnotatedElementInfo(annotationName="java.lang.SuppressWarnings", expectedSize=0, names={}) |
62 @AnnotatedElementInfo(annotationName="java.lang.SuppressWarnings", expectedSize=0, names={}) |
62 public class TestElementsAnnotatedWith extends AbstractProcessor { |
63 public class TestElementsAnnotatedWith extends JavacTestingAbstractProcessor { |
63 |
64 |
64 public boolean process(Set<? extends TypeElement> annotations, |
65 public boolean process(Set<? extends TypeElement> annotations, |
65 RoundEnvironment roundEnvironment) { |
66 RoundEnvironment roundEnvironment) { |
66 Elements elementUtils = processingEnv.getElementUtils(); |
|
67 |
|
68 TypeElement annotatedElementInfoElement = |
67 TypeElement annotatedElementInfoElement = |
69 elementUtils.getTypeElement("AnnotatedElementInfo"); |
68 elements.getTypeElement("AnnotatedElementInfo"); |
70 Set<? extends Element> resultsMeta = Collections.emptySet(); |
69 Set<? extends Element> resultsMeta = Collections.emptySet(); |
71 Set<? extends Element> resultsBase = Collections.emptySet(); |
70 Set<? extends Element> resultsBase = Collections.emptySet(); |
72 |
71 |
73 if (!roundEnvironment.processingOver()) { |
72 if (!roundEnvironment.processingOver()) { |
74 testNonAnnotations(roundEnvironment); |
73 testNonAnnotations(roundEnvironment); |
91 |
90 |
92 Set<String> expectedNames = new HashSet<String>(Arrays.asList(annotatedElementInfo.names())); |
91 Set<String> expectedNames = new HashSet<String>(Arrays.asList(annotatedElementInfo.names())); |
93 |
92 |
94 resultsMeta = |
93 resultsMeta = |
95 roundEnvironment. |
94 roundEnvironment. |
96 getElementsAnnotatedWith(elementUtils. |
95 getElementsAnnotatedWith(elements.getTypeElement(annotatedElementInfo.annotationName())); |
97 getTypeElement(annotatedElementInfo. |
|
98 annotationName())) ; |
|
99 |
96 |
100 System.err.println("Results: " + resultsMeta); |
97 System.err.println("Results: " + resultsMeta); |
101 |
98 |
102 if (resultsMeta.size() != annotatedElementInfo.expectedSize()) { |
99 if (resultsMeta.size() != annotatedElementInfo.expectedSize()) { |
103 failed = true; |
100 failed = true; |