1 /*
2 * Copyright (c) 2016, 2017, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.jdeprscan;
27
28 import java.lang.annotation.IncompleteAnnotationException;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Set;
32 import java.util.stream.Collectors;
33
34 import javax.annotation.processing.AbstractProcessor;
35 import javax.annotation.processing.Messager;
36 import javax.annotation.processing.ProcessingEnvironment;
37 import javax.annotation.processing.RoundEnvironment;
38 import javax.annotation.processing.SupportedAnnotationTypes;
39 import javax.annotation.processing.SupportedSourceVersion;
40
41 import javax.lang.model.element.Element;
42 import javax.lang.model.element.ElementKind;
43 import javax.lang.model.element.ExecutableElement;
44 import javax.lang.model.element.TypeElement;
45 import javax.lang.model.type.ArrayType;
46 import javax.lang.model.type.DeclaredType;
47 import javax.lang.model.type.ExecutableType;
48 import javax.lang.model.type.TypeMirror;
49 import javax.lang.model.util.Elements;
50
51 import javax.tools.Diagnostic;
52
53 import static javax.lang.model.SourceVersion.RELEASE_11;
54
55 /**
56 * Annotation processor for the Deprecation Scanner tool.
57 * Examines APIs for deprecated elements and records information
58 *
59 */
60 @SupportedAnnotationTypes("java.lang.Deprecated")
61 @SupportedSourceVersion(RELEASE_11)
62 public class LoadProc extends AbstractProcessor {
63 Elements elements;
64 Messager messager;
65 final List<DeprData> deprList = new ArrayList<>();
66
67 public LoadProc() {
68 }
69
70 @Override
71 public void init(ProcessingEnvironment pe) {
72 super.init(pe);
73 elements = pe.getElementUtils();
74 messager = pe.getMessager();
75 }
76
77 @Override
78 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
79 if (roundEnv.processingOver()) {
80 return false;
81 }
82
83 // Assume annotations contains only @Deprecated.
84 // Note: no way to get deprecated packages, since
85 // @Deprecated is ignored in package-info.java files.
86
87 Set<? extends Element> set = roundEnv.getElementsAnnotatedWith(Deprecated.class);
88 for (Element e : set) {
89 ElementKind kind = e.getKind();
90 Deprecated depr = e.getAnnotation(Deprecated.class);
91 switch (kind) {
92 case CLASS:
93 case INTERFACE:
94 case ENUM:
95 case ANNOTATION_TYPE:
96 addType(kind, (TypeElement)e, depr);
97 break;
|
1 /*
2 * Copyright (c) 2016, 2018, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.jdeprscan;
27
28 import java.lang.annotation.IncompleteAnnotationException;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Set;
32 import java.util.stream.Collectors;
33
34 import javax.annotation.processing.AbstractProcessor;
35 import javax.annotation.processing.Messager;
36 import javax.annotation.processing.ProcessingEnvironment;
37 import javax.annotation.processing.RoundEnvironment;
38 import javax.annotation.processing.SupportedAnnotationTypes;
39 import javax.annotation.processing.SupportedSourceVersion;
40
41 import javax.lang.model.SourceVersion;
42 import javax.lang.model.element.Element;
43 import javax.lang.model.element.ElementKind;
44 import javax.lang.model.element.ExecutableElement;
45 import javax.lang.model.element.TypeElement;
46 import javax.lang.model.type.ArrayType;
47 import javax.lang.model.type.DeclaredType;
48 import javax.lang.model.type.ExecutableType;
49 import javax.lang.model.type.TypeMirror;
50 import javax.lang.model.util.Elements;
51
52 import javax.tools.Diagnostic;
53
54 /**
55 * Annotation processor for the Deprecation Scanner tool.
56 * Examines APIs for deprecated elements and records information
57 *
58 */
59 @SupportedAnnotationTypes("java.lang.Deprecated")
60 public class LoadProc extends AbstractProcessor {
61 Elements elements;
62 Messager messager;
63 final List<DeprData> deprList = new ArrayList<>();
64
65 public LoadProc() {
66 }
67
68 @Override
69 public void init(ProcessingEnvironment pe) {
70 super.init(pe);
71 elements = pe.getElementUtils();
72 messager = pe.getMessager();
73 }
74
75 @Override
76 public SourceVersion getSupportedSourceVersion() {
77 return SourceVersion.latest();
78 }
79
80 @Override
81 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
82 if (roundEnv.processingOver()) {
83 return false;
84 }
85
86 // Assume annotations contains only @Deprecated.
87 // Note: no way to get deprecated packages, since
88 // @Deprecated is ignored in package-info.java files.
89
90 Set<? extends Element> set = roundEnv.getElementsAnnotatedWith(Deprecated.class);
91 for (Element e : set) {
92 ElementKind kind = e.getKind();
93 Deprecated depr = e.getAnnotation(Deprecated.class);
94 switch (kind) {
95 case CLASS:
96 case INTERFACE:
97 case ENUM:
98 case ANNOTATION_TYPE:
99 addType(kind, (TypeElement)e, depr);
100 break;
|