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 */
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 */
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 ElementScanner<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;
|