author | ksrini |
Sun, 15 Jun 2014 08:41:57 -0700 | |
changeset 25454 | 376a52c9540c |
parent 24221 | 2376793dd33b |
permissions | -rw-r--r-- |
10 | 1 |
/* |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
22165
diff
changeset
|
2 |
* Copyright (c) 1998, 2014, 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.doclets.internal.toolkit.util; |
|
27 |
||
14258 | 28 |
import java.util.*; |
29 |
||
10 | 30 |
import com.sun.javadoc.*; |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
31 |
import com.sun.tools.doclets.internal.toolkit.Configuration; |
10 | 32 |
|
33 |
/** |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
34 |
* Build list of all the deprecated packages, classes, constructors, fields and methods. |
10 | 35 |
* |
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
36 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
37 |
* If you write code that depends on this, you do so at your own risk. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
38 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
39 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
40 |
* |
10 | 41 |
* @author Atul M Dambalkar |
42 |
*/ |
|
43 |
public class DeprecatedAPIListBuilder { |
|
44 |
||
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
45 |
public static final int NUM_TYPES = 12; |
10 | 46 |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
47 |
public static final int PACKAGE = 0; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
48 |
public static final int INTERFACE = 1; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
49 |
public static final int CLASS = 2; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
50 |
public static final int ENUM = 3; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
51 |
public static final int EXCEPTION = 4; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
52 |
public static final int ERROR = 5; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
53 |
public static final int ANNOTATION_TYPE = 6; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
54 |
public static final int FIELD = 7; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
55 |
public static final int METHOD = 8; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
56 |
public static final int CONSTRUCTOR = 9; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
57 |
public static final int ENUM_CONSTANT = 10; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
58 |
public static final int ANNOTATION_TYPE_MEMBER = 11; |
10 | 59 |
|
60 |
/** |
|
61 |
* List of deprecated type Lists. |
|
62 |
*/ |
|
868 | 63 |
private List<List<Doc>> deprecatedLists; |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
64 |
private final Configuration configuration; |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
65 |
private final Utils utils; |
10 | 66 |
|
67 |
/** |
|
68 |
* Constructor. |
|
69 |
* |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
70 |
* @param configuration the current configuration of the doclet |
10 | 71 |
*/ |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
72 |
public DeprecatedAPIListBuilder(Configuration configuration) { |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
73 |
this.configuration = configuration; |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
74 |
this.utils = configuration.utils; |
22163 | 75 |
deprecatedLists = new ArrayList<>(); |
10 | 76 |
for (int i = 0; i < NUM_TYPES; i++) { |
22165
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
77 |
deprecatedLists.add(i, new ArrayList<Doc>()); |
10 | 78 |
} |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
79 |
buildDeprecatedAPIInfo(); |
10 | 80 |
} |
81 |
||
82 |
/** |
|
83 |
* Build the sorted list of all the deprecated APIs in this run. |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
84 |
* Build separate lists for deprecated packages, classes, constructors, |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
85 |
* methods and fields. |
10 | 86 |
* |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
87 |
* @param configuration the current configuration of the doclet. |
10 | 88 |
*/ |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
89 |
private void buildDeprecatedAPIInfo() { |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
22165
diff
changeset
|
90 |
Set<PackageDoc> packages = configuration.packages; |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14260
diff
changeset
|
91 |
for (PackageDoc pkg : packages) { |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
92 |
if (utils.isDeprecated(pkg)) { |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
93 |
getList(PACKAGE).add(pkg); |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
94 |
} |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
95 |
} |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14260
diff
changeset
|
96 |
for (ClassDoc cd : configuration.root.classes()) { |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
97 |
if (utils.isDeprecated(cd)) { |
10 | 98 |
if (cd.isOrdinaryClass()) { |
99 |
getList(CLASS).add(cd); |
|
100 |
} else if (cd.isInterface()) { |
|
101 |
getList(INTERFACE).add(cd); |
|
102 |
} else if (cd.isException()) { |
|
103 |
getList(EXCEPTION).add(cd); |
|
104 |
} else if (cd.isEnum()) { |
|
105 |
getList(ENUM).add(cd); |
|
106 |
} else if (cd.isError()) { |
|
107 |
getList(ERROR).add(cd); |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
108 |
} else if (cd.isAnnotationType()) { |
10 | 109 |
getList(ANNOTATION_TYPE).add(cd); |
110 |
} |
|
111 |
} |
|
112 |
composeDeprecatedList(getList(FIELD), cd.fields()); |
|
113 |
composeDeprecatedList(getList(METHOD), cd.methods()); |
|
114 |
composeDeprecatedList(getList(CONSTRUCTOR), cd.constructors()); |
|
115 |
if (cd.isEnum()) { |
|
116 |
composeDeprecatedList(getList(ENUM_CONSTANT), cd.enumConstants()); |
|
117 |
} |
|
118 |
if (cd.isAnnotationType()) { |
|
119 |
composeDeprecatedList(getList(ANNOTATION_TYPE_MEMBER), |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14260
diff
changeset
|
120 |
((AnnotationTypeDoc) cd).elements()); |
10 | 121 |
} |
122 |
} |
|
123 |
sortDeprecatedLists(); |
|
124 |
} |
|
125 |
||
126 |
/** |
|
127 |
* Add the members into a single list of deprecated members. |
|
128 |
* |
|
129 |
* @param list List of all the particular deprecated members, e.g. methods. |
|
130 |
* @param members members to be added in the list. |
|
131 |
*/ |
|
868 | 132 |
private void composeDeprecatedList(List<Doc> list, MemberDoc[] members) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14260
diff
changeset
|
133 |
for (MemberDoc member : members) { |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
134 |
if (utils.isDeprecated(member)) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14260
diff
changeset
|
135 |
list.add(member); |
10 | 136 |
} |
137 |
} |
|
138 |
} |
|
139 |
||
140 |
/** |
|
141 |
* Sort the deprecated lists for class kinds, fields, methods and |
|
142 |
* constructors. |
|
143 |
*/ |
|
144 |
private void sortDeprecatedLists() { |
|
145 |
for (int i = 0; i < NUM_TYPES; i++) { |
|
146 |
Collections.sort(getList(i)); |
|
147 |
} |
|
148 |
} |
|
149 |
||
150 |
/** |
|
151 |
* Return the list of deprecated Doc objects of a given type. |
|
152 |
* |
|
14259 | 153 |
* @param type the constant representing the type of list being returned. |
10 | 154 |
*/ |
868 | 155 |
public List<Doc> getList(int type) { |
156 |
return deprecatedLists.get(type); |
|
10 | 157 |
} |
158 |
||
159 |
/** |
|
160 |
* Return true if the list of a given type has size greater than 0. |
|
161 |
* |
|
162 |
* @param type the type of list being checked. |
|
163 |
*/ |
|
164 |
public boolean hasDocumentation(int type) { |
|
868 | 165 |
return (deprecatedLists.get(type)).size() > 0; |
10 | 166 |
} |
167 |
} |