Mon, 02 May 2011 02:13:02 -0700
6492694: @deprecated tag doesn't work in package-info files.
Reviewed-by: jjg
duke@1 | 1 | /* |
bpatel@995 | 2 | * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.doclets.internal.toolkit.util; |
duke@1 | 27 | |
duke@1 | 28 | import com.sun.javadoc.*; |
duke@1 | 29 | import java.util.*; |
bpatel@995 | 30 | import com.sun.tools.doclets.internal.toolkit.Configuration; |
duke@1 | 31 | |
duke@1 | 32 | /** |
bpatel@995 | 33 | * Build list of all the deprecated packages, classes, constructors, fields and methods. |
duke@1 | 34 | * |
duke@1 | 35 | * @author Atul M Dambalkar |
duke@1 | 36 | */ |
duke@1 | 37 | public class DeprecatedAPIListBuilder { |
duke@1 | 38 | |
bpatel@995 | 39 | public static final int NUM_TYPES = 12; |
duke@1 | 40 | |
bpatel@995 | 41 | public static final int PACKAGE = 0; |
bpatel@995 | 42 | public static final int INTERFACE = 1; |
bpatel@995 | 43 | public static final int CLASS = 2; |
bpatel@995 | 44 | public static final int ENUM = 3; |
bpatel@995 | 45 | public static final int EXCEPTION = 4; |
bpatel@995 | 46 | public static final int ERROR = 5; |
bpatel@995 | 47 | public static final int ANNOTATION_TYPE = 6; |
bpatel@995 | 48 | public static final int FIELD = 7; |
bpatel@995 | 49 | public static final int METHOD = 8; |
bpatel@995 | 50 | public static final int CONSTRUCTOR = 9; |
bpatel@995 | 51 | public static final int ENUM_CONSTANT = 10; |
bpatel@995 | 52 | public static final int ANNOTATION_TYPE_MEMBER = 11; |
duke@1 | 53 | |
duke@1 | 54 | /** |
duke@1 | 55 | * List of deprecated type Lists. |
duke@1 | 56 | */ |
jjg@74 | 57 | private List<List<Doc>> deprecatedLists; |
duke@1 | 58 | |
duke@1 | 59 | |
duke@1 | 60 | /** |
duke@1 | 61 | * Constructor. |
duke@1 | 62 | * |
bpatel@995 | 63 | * @param configuration the current configuration of the doclet |
duke@1 | 64 | */ |
bpatel@995 | 65 | public DeprecatedAPIListBuilder(Configuration configuration) { |
jjg@74 | 66 | deprecatedLists = new ArrayList<List<Doc>>(); |
duke@1 | 67 | for (int i = 0; i < NUM_TYPES; i++) { |
jjg@74 | 68 | deprecatedLists.add(i, new ArrayList<Doc>()); |
duke@1 | 69 | } |
bpatel@995 | 70 | buildDeprecatedAPIInfo(configuration); |
duke@1 | 71 | } |
duke@1 | 72 | |
duke@1 | 73 | /** |
duke@1 | 74 | * Build the sorted list of all the deprecated APIs in this run. |
bpatel@995 | 75 | * Build separate lists for deprecated packages, classes, constructors, |
bpatel@995 | 76 | * methods and fields. |
duke@1 | 77 | * |
bpatel@995 | 78 | * @param configuration the current configuration of the doclet. |
duke@1 | 79 | */ |
bpatel@995 | 80 | private void buildDeprecatedAPIInfo(Configuration configuration) { |
bpatel@995 | 81 | PackageDoc[] packages = configuration.packages; |
bpatel@995 | 82 | PackageDoc pkg; |
bpatel@995 | 83 | for (int c = 0; c < packages.length; c++) { |
bpatel@995 | 84 | pkg = packages[c]; |
bpatel@995 | 85 | if (Util.isDeprecated(pkg)) { |
bpatel@995 | 86 | getList(PACKAGE).add(pkg); |
bpatel@995 | 87 | } |
bpatel@995 | 88 | } |
bpatel@995 | 89 | ClassDoc[] classes = configuration.root.classes(); |
duke@1 | 90 | for (int i = 0; i < classes.length; i++) { |
duke@1 | 91 | ClassDoc cd = classes[i]; |
duke@1 | 92 | if (Util.isDeprecated(cd)) { |
duke@1 | 93 | if (cd.isOrdinaryClass()) { |
duke@1 | 94 | getList(CLASS).add(cd); |
duke@1 | 95 | } else if (cd.isInterface()) { |
duke@1 | 96 | getList(INTERFACE).add(cd); |
duke@1 | 97 | } else if (cd.isException()) { |
duke@1 | 98 | getList(EXCEPTION).add(cd); |
duke@1 | 99 | } else if (cd.isEnum()) { |
duke@1 | 100 | getList(ENUM).add(cd); |
duke@1 | 101 | } else if (cd.isError()) { |
duke@1 | 102 | getList(ERROR).add(cd); |
bpatel@995 | 103 | } else if (cd.isAnnotationType()) { |
duke@1 | 104 | getList(ANNOTATION_TYPE).add(cd); |
duke@1 | 105 | } |
duke@1 | 106 | } |
duke@1 | 107 | composeDeprecatedList(getList(FIELD), cd.fields()); |
duke@1 | 108 | composeDeprecatedList(getList(METHOD), cd.methods()); |
duke@1 | 109 | composeDeprecatedList(getList(CONSTRUCTOR), cd.constructors()); |
duke@1 | 110 | if (cd.isEnum()) { |
duke@1 | 111 | composeDeprecatedList(getList(ENUM_CONSTANT), cd.enumConstants()); |
duke@1 | 112 | } |
duke@1 | 113 | if (cd.isAnnotationType()) { |
duke@1 | 114 | composeDeprecatedList(getList(ANNOTATION_TYPE_MEMBER), |
bpatel@995 | 115 | ((AnnotationTypeDoc) cd).elements()); |
duke@1 | 116 | } |
duke@1 | 117 | } |
duke@1 | 118 | sortDeprecatedLists(); |
duke@1 | 119 | } |
duke@1 | 120 | |
duke@1 | 121 | /** |
duke@1 | 122 | * Add the members into a single list of deprecated members. |
duke@1 | 123 | * |
duke@1 | 124 | * @param list List of all the particular deprecated members, e.g. methods. |
duke@1 | 125 | * @param members members to be added in the list. |
duke@1 | 126 | */ |
jjg@74 | 127 | private void composeDeprecatedList(List<Doc> list, MemberDoc[] members) { |
duke@1 | 128 | for (int i = 0; i < members.length; i++) { |
duke@1 | 129 | if (Util.isDeprecated(members[i])) { |
duke@1 | 130 | list.add(members[i]); |
duke@1 | 131 | } |
duke@1 | 132 | } |
duke@1 | 133 | } |
duke@1 | 134 | |
duke@1 | 135 | /** |
duke@1 | 136 | * Sort the deprecated lists for class kinds, fields, methods and |
duke@1 | 137 | * constructors. |
duke@1 | 138 | */ |
duke@1 | 139 | private void sortDeprecatedLists() { |
duke@1 | 140 | for (int i = 0; i < NUM_TYPES; i++) { |
duke@1 | 141 | Collections.sort(getList(i)); |
duke@1 | 142 | } |
duke@1 | 143 | } |
duke@1 | 144 | |
duke@1 | 145 | /** |
duke@1 | 146 | * Return the list of deprecated Doc objects of a given type. |
duke@1 | 147 | * |
duke@1 | 148 | * @param the constant representing the type of list being returned. |
duke@1 | 149 | */ |
jjg@74 | 150 | public List<Doc> getList(int type) { |
jjg@74 | 151 | return deprecatedLists.get(type); |
duke@1 | 152 | } |
duke@1 | 153 | |
duke@1 | 154 | /** |
duke@1 | 155 | * Return true if the list of a given type has size greater than 0. |
duke@1 | 156 | * |
duke@1 | 157 | * @param type the type of list being checked. |
duke@1 | 158 | */ |
duke@1 | 159 | public boolean hasDocumentation(int type) { |
jjg@74 | 160 | return (deprecatedLists.get(type)).size() > 0; |
duke@1 | 161 | } |
duke@1 | 162 | } |