author | darcy |
Tue, 05 Jul 2011 16:37:24 -0700 | |
changeset 10192 | 378321489bea |
parent 9744 | 3e48977e539d |
child 14963 | 974d4423c999 |
child 14870 | 1a2371de04d8 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
10192
378321489bea
7025809: Provided new utility visitors supporting SourceVersion.RELEASE_8
darcy
parents:
9744
diff
changeset
|
2 |
* Copyright (c) 2006, 2011 Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5520 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
10 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6392818 |
|
27 |
* @summary Tests Elements.isDeprecated(Element) |
|
28 |
* @author Joseph D. Darcy |
|
6720 | 29 |
* @library ../../../../lib |
30 |
* @build JavacTestingAbstractProcessor |
|
10 | 31 |
* @compile TestDeprecation.java |
32 |
* @compile -processor TestDeprecation -proc:only Dep1.java |
|
33 |
* @compile Dep1.java |
|
34 |
* @compile -processor TestDeprecation -proc:only Dep1 TestDeprecation.java |
|
35 |
*/ |
|
36 |
||
37 |
import java.util.Set; |
|
38 |
import java.util.HashSet; |
|
39 |
import java.util.Arrays; |
|
40 |
import javax.annotation.processing.*; |
|
41 |
import javax.lang.model.SourceVersion; |
|
42 |
import javax.lang.model.element.*; |
|
43 |
import javax.lang.model.util.*; |
|
44 |
import static javax.tools.Diagnostic.Kind.*; |
|
45 |
import java.io.Writer; |
|
46 |
||
47 |
/** |
|
48 |
* This processor verifies that the information returned by |
|
49 |
* getElementsAnnotatedWith is consistent with the expected results |
|
50 |
* stored in an AnnotatedElementInfo annotation. |
|
51 |
*/ |
|
6720 | 52 |
public class TestDeprecation extends JavacTestingAbstractProcessor { |
10 | 53 |
|
54 |
public boolean process(Set<? extends TypeElement> annotations, |
|
55 |
RoundEnvironment roundEnv) { |
|
56 |
boolean failure = false; |
|
57 |
if (!roundEnv.processingOver()) { |
|
58 |
DeprecationChecker deprecationChecker = new DeprecationChecker(); |
|
59 |
||
60 |
for(Element element: roundEnv.getRootElements() ) { |
|
61 |
System.out.println("\nRoot Element: " + element.getSimpleName()); |
|
62 |
failure = deprecationChecker.scan(element); |
|
63 |
} |
|
64 |
||
65 |
if (failure) |
|
66 |
processingEnv.getMessager().printMessage(ERROR, "Deprecation mismatch found!"); |
|
67 |
} |
|
68 |
return true; |
|
69 |
} |
|
70 |
||
10192
378321489bea
7025809: Provided new utility visitors supporting SourceVersion.RELEASE_8
darcy
parents:
9744
diff
changeset
|
71 |
private class DeprecationChecker extends ElementScanner<Boolean,Void> { |
10 | 72 |
private Elements elementUtils; |
73 |
private boolean failure; |
|
74 |
DeprecationChecker() { |
|
75 |
super(false); |
|
76 |
elementUtils = processingEnv.getElementUtils(); |
|
77 |
failure = false; |
|
78 |
} |
|
79 |
||
80 |
@Override |
|
81 |
public Boolean scan(Element e, Void p) { |
|
82 |
boolean expectedDeprecation = false; |
|
83 |
ExpectedDeprecation tmp = e.getAnnotation(ExpectedDeprecation.class); |
|
84 |
if (tmp != null) |
|
85 |
expectedDeprecation = tmp.value(); |
|
86 |
boolean actualDeprecation = elementUtils.isDeprecated(e); |
|
87 |
||
88 |
System.out.printf("\tVisiting %s\t%s%n", e.getKind(), e.getSimpleName()); |
|
89 |
||
90 |
if (expectedDeprecation != actualDeprecation) { |
|
91 |
failure = true; |
|
92 |
java.io.StringWriter w = new java.io.StringWriter(); |
|
93 |
elementUtils.printElements(w, e); |
|
94 |
System.out.printf("For the deprecation of %n\t%s\t, expected %b, got %b.%n", |
|
95 |
w.getBuffer().toString(), |
|
96 |
expectedDeprecation, actualDeprecation); |
|
97 |
} |
|
98 |
super.scan(e, p); |
|
99 |
return failure; |
|
100 |
} |
|
101 |
} |
|
102 |
} |