1 /*
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.
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 *
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.
22 */
25 * @test
26 * @bug 6392818
27 * @summary Tests Elements.isDeprecated(Element)
28 * @author Joseph D. Darcy
29 * @library ../../../../lib
30 * @build JavacTestingAbstractProcessor
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 */
52 public class TestDeprecation extends JavacTestingAbstractProcessor {
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
71 private class DeprecationChecker extends ElementScanner7<Boolean,Void> {
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;
|
1 /*
2 * Copyright (c) 2006, 2011 Oracle and/or its affiliates. All rights reserved.
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 *
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.
22 */
25 * @test
26 * @bug 6392818
27 * @summary Tests Elements.isDeprecated(Element)
28 * @author Joseph D. Darcy
29 * @library ../../../../lib
30 * @build JavacTestingAbstractProcessor
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 static JavacTestingAbstractProcessor.*;
46 import java.io.Writer;
47
48 /**
49 * This processor verifies that the information returned by
50 * getElementsAnnotatedWith is consistent with the expected results
51 * stored in an AnnotatedElementInfo annotation.
52 */
53 public class TestDeprecation extends JavacTestingAbstractProcessor {
54
55 public boolean process(Set<? extends TypeElement> annotations,
56 RoundEnvironment roundEnv) {
57 boolean failure = false;
58 if (!roundEnv.processingOver()) {
59 DeprecationChecker deprecationChecker = new DeprecationChecker();
60
61 for(Element element: roundEnv.getRootElements() ) {
62 System.out.println("\nRoot Element: " + element.getSimpleName());
63 failure = deprecationChecker.scan(element);
64 }
65
66 if (failure)
67 processingEnv.getMessager().printMessage(ERROR, "Deprecation mismatch found!");
68 }
69 return true;
70 }
71
72 private class DeprecationChecker extends ElementScanner<Boolean,Void> {
73 private Elements elementUtils;
74 private boolean failure;
75 DeprecationChecker() {
76 super(false);
77 elementUtils = processingEnv.getElementUtils();
78 failure = false;
79 }
80
81 @Override
82 public Boolean scan(Element e, Void p) {
83 boolean expectedDeprecation = false;
84 ExpectedDeprecation tmp = e.getAnnotation(ExpectedDeprecation.class);
85 if (tmp != null)
86 expectedDeprecation = tmp.value();
87 boolean actualDeprecation = elementUtils.isDeprecated(e);
88
89 System.out.printf("\tVisiting %s\t%s%n", e.getKind(), e.getSimpleName());
90
91 if (expectedDeprecation != actualDeprecation) {
92 failure = true;
|