Mon, 02 May 2011 02:13:02 -0700
6492694: @deprecated tag doesn't work in package-info files.
Reviewed-by: jjg
1 /*
2 * Copyright (c) 1998, 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. 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 */
26 package com.sun.tools.doclets.internal.toolkit.util;
28 import com.sun.javadoc.*;
29 import java.util.*;
30 import com.sun.tools.doclets.internal.toolkit.Configuration;
32 /**
33 * Build list of all the deprecated packages, classes, constructors, fields and methods.
34 *
35 * @author Atul M Dambalkar
36 */
37 public class DeprecatedAPIListBuilder {
39 public static final int NUM_TYPES = 12;
41 public static final int PACKAGE = 0;
42 public static final int INTERFACE = 1;
43 public static final int CLASS = 2;
44 public static final int ENUM = 3;
45 public static final int EXCEPTION = 4;
46 public static final int ERROR = 5;
47 public static final int ANNOTATION_TYPE = 6;
48 public static final int FIELD = 7;
49 public static final int METHOD = 8;
50 public static final int CONSTRUCTOR = 9;
51 public static final int ENUM_CONSTANT = 10;
52 public static final int ANNOTATION_TYPE_MEMBER = 11;
54 /**
55 * List of deprecated type Lists.
56 */
57 private List<List<Doc>> deprecatedLists;
60 /**
61 * Constructor.
62 *
63 * @param configuration the current configuration of the doclet
64 */
65 public DeprecatedAPIListBuilder(Configuration configuration) {
66 deprecatedLists = new ArrayList<List<Doc>>();
67 for (int i = 0; i < NUM_TYPES; i++) {
68 deprecatedLists.add(i, new ArrayList<Doc>());
69 }
70 buildDeprecatedAPIInfo(configuration);
71 }
73 /**
74 * Build the sorted list of all the deprecated APIs in this run.
75 * Build separate lists for deprecated packages, classes, constructors,
76 * methods and fields.
77 *
78 * @param configuration the current configuration of the doclet.
79 */
80 private void buildDeprecatedAPIInfo(Configuration configuration) {
81 PackageDoc[] packages = configuration.packages;
82 PackageDoc pkg;
83 for (int c = 0; c < packages.length; c++) {
84 pkg = packages[c];
85 if (Util.isDeprecated(pkg)) {
86 getList(PACKAGE).add(pkg);
87 }
88 }
89 ClassDoc[] classes = configuration.root.classes();
90 for (int i = 0; i < classes.length; i++) {
91 ClassDoc cd = classes[i];
92 if (Util.isDeprecated(cd)) {
93 if (cd.isOrdinaryClass()) {
94 getList(CLASS).add(cd);
95 } else if (cd.isInterface()) {
96 getList(INTERFACE).add(cd);
97 } else if (cd.isException()) {
98 getList(EXCEPTION).add(cd);
99 } else if (cd.isEnum()) {
100 getList(ENUM).add(cd);
101 } else if (cd.isError()) {
102 getList(ERROR).add(cd);
103 } else if (cd.isAnnotationType()) {
104 getList(ANNOTATION_TYPE).add(cd);
105 }
106 }
107 composeDeprecatedList(getList(FIELD), cd.fields());
108 composeDeprecatedList(getList(METHOD), cd.methods());
109 composeDeprecatedList(getList(CONSTRUCTOR), cd.constructors());
110 if (cd.isEnum()) {
111 composeDeprecatedList(getList(ENUM_CONSTANT), cd.enumConstants());
112 }
113 if (cd.isAnnotationType()) {
114 composeDeprecatedList(getList(ANNOTATION_TYPE_MEMBER),
115 ((AnnotationTypeDoc) cd).elements());
116 }
117 }
118 sortDeprecatedLists();
119 }
121 /**
122 * Add the members into a single list of deprecated members.
123 *
124 * @param list List of all the particular deprecated members, e.g. methods.
125 * @param members members to be added in the list.
126 */
127 private void composeDeprecatedList(List<Doc> list, MemberDoc[] members) {
128 for (int i = 0; i < members.length; i++) {
129 if (Util.isDeprecated(members[i])) {
130 list.add(members[i]);
131 }
132 }
133 }
135 /**
136 * Sort the deprecated lists for class kinds, fields, methods and
137 * constructors.
138 */
139 private void sortDeprecatedLists() {
140 for (int i = 0; i < NUM_TYPES; i++) {
141 Collections.sort(getList(i));
142 }
143 }
145 /**
146 * Return the list of deprecated Doc objects of a given type.
147 *
148 * @param the constant representing the type of list being returned.
149 */
150 public List<Doc> getList(int type) {
151 return deprecatedLists.get(type);
152 }
154 /**
155 * Return true if the list of a given type has size greater than 0.
156 *
157 * @param type the type of list being checked.
158 */
159 public boolean hasDocumentation(int type) {
160 return (deprecatedLists.get(type)).size() > 0;
161 }
162 }