Thu, 15 Nov 2012 19:54:20 -0800
8002079: update DocFile to use a JavaFileManager
Reviewed-by: darcy
duke@1 | 1 | /* |
jjg@1357 | 2 | * Copyright (c) 1998, 2012, 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 | |
jjg@1357 | 28 | import java.util.*; |
jjg@1357 | 29 | |
duke@1 | 30 | import com.sun.javadoc.*; |
bpatel@995 | 31 | import com.sun.tools.doclets.internal.toolkit.Configuration; |
duke@1 | 32 | |
duke@1 | 33 | /** |
bpatel@995 | 34 | * Build list of all the deprecated packages, classes, constructors, fields and methods. |
duke@1 | 35 | * |
jjg@1359 | 36 | * <p><b>This is NOT part of any supported API. |
jjg@1359 | 37 | * If you write code that depends on this, you do so at your own risk. |
jjg@1359 | 38 | * This code and its internal interfaces are subject to change or |
jjg@1359 | 39 | * deletion without notice.</b> |
jjg@1359 | 40 | * |
duke@1 | 41 | * @author Atul M Dambalkar |
duke@1 | 42 | */ |
duke@1 | 43 | public class DeprecatedAPIListBuilder { |
duke@1 | 44 | |
bpatel@995 | 45 | public static final int NUM_TYPES = 12; |
duke@1 | 46 | |
bpatel@995 | 47 | public static final int PACKAGE = 0; |
bpatel@995 | 48 | public static final int INTERFACE = 1; |
bpatel@995 | 49 | public static final int CLASS = 2; |
bpatel@995 | 50 | public static final int ENUM = 3; |
bpatel@995 | 51 | public static final int EXCEPTION = 4; |
bpatel@995 | 52 | public static final int ERROR = 5; |
bpatel@995 | 53 | public static final int ANNOTATION_TYPE = 6; |
bpatel@995 | 54 | public static final int FIELD = 7; |
bpatel@995 | 55 | public static final int METHOD = 8; |
bpatel@995 | 56 | public static final int CONSTRUCTOR = 9; |
bpatel@995 | 57 | public static final int ENUM_CONSTANT = 10; |
bpatel@995 | 58 | public static final int ANNOTATION_TYPE_MEMBER = 11; |
duke@1 | 59 | |
duke@1 | 60 | /** |
duke@1 | 61 | * List of deprecated type Lists. |
duke@1 | 62 | */ |
jjg@74 | 63 | private List<List<Doc>> deprecatedLists; |
duke@1 | 64 | |
duke@1 | 65 | |
duke@1 | 66 | /** |
duke@1 | 67 | * Constructor. |
duke@1 | 68 | * |
bpatel@995 | 69 | * @param configuration the current configuration of the doclet |
duke@1 | 70 | */ |
bpatel@995 | 71 | public DeprecatedAPIListBuilder(Configuration configuration) { |
jjg@74 | 72 | deprecatedLists = new ArrayList<List<Doc>>(); |
duke@1 | 73 | for (int i = 0; i < NUM_TYPES; i++) { |
jjg@74 | 74 | deprecatedLists.add(i, new ArrayList<Doc>()); |
duke@1 | 75 | } |
bpatel@995 | 76 | buildDeprecatedAPIInfo(configuration); |
duke@1 | 77 | } |
duke@1 | 78 | |
duke@1 | 79 | /** |
duke@1 | 80 | * Build the sorted list of all the deprecated APIs in this run. |
bpatel@995 | 81 | * Build separate lists for deprecated packages, classes, constructors, |
bpatel@995 | 82 | * methods and fields. |
duke@1 | 83 | * |
bpatel@995 | 84 | * @param configuration the current configuration of the doclet. |
duke@1 | 85 | */ |
bpatel@995 | 86 | private void buildDeprecatedAPIInfo(Configuration configuration) { |
bpatel@995 | 87 | PackageDoc[] packages = configuration.packages; |
bpatel@995 | 88 | PackageDoc pkg; |
bpatel@995 | 89 | for (int c = 0; c < packages.length; c++) { |
bpatel@995 | 90 | pkg = packages[c]; |
bpatel@995 | 91 | if (Util.isDeprecated(pkg)) { |
bpatel@995 | 92 | getList(PACKAGE).add(pkg); |
bpatel@995 | 93 | } |
bpatel@995 | 94 | } |
bpatel@995 | 95 | ClassDoc[] classes = configuration.root.classes(); |
duke@1 | 96 | for (int i = 0; i < classes.length; i++) { |
duke@1 | 97 | ClassDoc cd = classes[i]; |
duke@1 | 98 | if (Util.isDeprecated(cd)) { |
duke@1 | 99 | if (cd.isOrdinaryClass()) { |
duke@1 | 100 | getList(CLASS).add(cd); |
duke@1 | 101 | } else if (cd.isInterface()) { |
duke@1 | 102 | getList(INTERFACE).add(cd); |
duke@1 | 103 | } else if (cd.isException()) { |
duke@1 | 104 | getList(EXCEPTION).add(cd); |
duke@1 | 105 | } else if (cd.isEnum()) { |
duke@1 | 106 | getList(ENUM).add(cd); |
duke@1 | 107 | } else if (cd.isError()) { |
duke@1 | 108 | getList(ERROR).add(cd); |
bpatel@995 | 109 | } else if (cd.isAnnotationType()) { |
duke@1 | 110 | getList(ANNOTATION_TYPE).add(cd); |
duke@1 | 111 | } |
duke@1 | 112 | } |
duke@1 | 113 | composeDeprecatedList(getList(FIELD), cd.fields()); |
duke@1 | 114 | composeDeprecatedList(getList(METHOD), cd.methods()); |
duke@1 | 115 | composeDeprecatedList(getList(CONSTRUCTOR), cd.constructors()); |
duke@1 | 116 | if (cd.isEnum()) { |
duke@1 | 117 | composeDeprecatedList(getList(ENUM_CONSTANT), cd.enumConstants()); |
duke@1 | 118 | } |
duke@1 | 119 | if (cd.isAnnotationType()) { |
duke@1 | 120 | composeDeprecatedList(getList(ANNOTATION_TYPE_MEMBER), |
bpatel@995 | 121 | ((AnnotationTypeDoc) cd).elements()); |
duke@1 | 122 | } |
duke@1 | 123 | } |
duke@1 | 124 | sortDeprecatedLists(); |
duke@1 | 125 | } |
duke@1 | 126 | |
duke@1 | 127 | /** |
duke@1 | 128 | * Add the members into a single list of deprecated members. |
duke@1 | 129 | * |
duke@1 | 130 | * @param list List of all the particular deprecated members, e.g. methods. |
duke@1 | 131 | * @param members members to be added in the list. |
duke@1 | 132 | */ |
jjg@74 | 133 | private void composeDeprecatedList(List<Doc> list, MemberDoc[] members) { |
duke@1 | 134 | for (int i = 0; i < members.length; i++) { |
duke@1 | 135 | if (Util.isDeprecated(members[i])) { |
duke@1 | 136 | list.add(members[i]); |
duke@1 | 137 | } |
duke@1 | 138 | } |
duke@1 | 139 | } |
duke@1 | 140 | |
duke@1 | 141 | /** |
duke@1 | 142 | * Sort the deprecated lists for class kinds, fields, methods and |
duke@1 | 143 | * constructors. |
duke@1 | 144 | */ |
duke@1 | 145 | private void sortDeprecatedLists() { |
duke@1 | 146 | for (int i = 0; i < NUM_TYPES; i++) { |
duke@1 | 147 | Collections.sort(getList(i)); |
duke@1 | 148 | } |
duke@1 | 149 | } |
duke@1 | 150 | |
duke@1 | 151 | /** |
duke@1 | 152 | * Return the list of deprecated Doc objects of a given type. |
duke@1 | 153 | * |
jjg@1358 | 154 | * @param type the constant representing the type of list being returned. |
duke@1 | 155 | */ |
jjg@74 | 156 | public List<Doc> getList(int type) { |
jjg@74 | 157 | return deprecatedLists.get(type); |
duke@1 | 158 | } |
duke@1 | 159 | |
duke@1 | 160 | /** |
duke@1 | 161 | * Return true if the list of a given type has size greater than 0. |
duke@1 | 162 | * |
duke@1 | 163 | * @param type the type of list being checked. |
duke@1 | 164 | */ |
duke@1 | 165 | public boolean hasDocumentation(int type) { |
jjg@74 | 166 | return (deprecatedLists.get(type)).size() > 0; |
duke@1 | 167 | } |
duke@1 | 168 | } |