author | darcy |
Wed, 29 Sep 2010 23:27:57 -0700 | |
changeset 6720 | f16f91662ad8 |
parent 5841 | 7a8448425bb7 |
child 9744 | 3e48977e539d |
permissions | -rw-r--r-- |
10 | 1 |
/* |
6720 | 2 |
* Copyright (c) 2006, 2010 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 |
||
5841
7a8448425bb7
6933147: Provided new utility visitors supporting SourceVersion.RELEASE_7
darcy
parents:
5520
diff
changeset
|
71 |
private class DeprecationChecker extends ElementScanner7<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 |
} |