duke@1: /* bpatel@995: * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.internal.toolkit.util; duke@1: duke@1: import com.sun.javadoc.*; duke@1: import java.util.*; bpatel@995: import com.sun.tools.doclets.internal.toolkit.Configuration; duke@1: duke@1: /** bpatel@995: * Build list of all the deprecated packages, classes, constructors, fields and methods. duke@1: * duke@1: * @author Atul M Dambalkar duke@1: */ duke@1: public class DeprecatedAPIListBuilder { duke@1: bpatel@995: public static final int NUM_TYPES = 12; duke@1: bpatel@995: public static final int PACKAGE = 0; bpatel@995: public static final int INTERFACE = 1; bpatel@995: public static final int CLASS = 2; bpatel@995: public static final int ENUM = 3; bpatel@995: public static final int EXCEPTION = 4; bpatel@995: public static final int ERROR = 5; bpatel@995: public static final int ANNOTATION_TYPE = 6; bpatel@995: public static final int FIELD = 7; bpatel@995: public static final int METHOD = 8; bpatel@995: public static final int CONSTRUCTOR = 9; bpatel@995: public static final int ENUM_CONSTANT = 10; bpatel@995: public static final int ANNOTATION_TYPE_MEMBER = 11; duke@1: duke@1: /** duke@1: * List of deprecated type Lists. duke@1: */ jjg@74: private List> deprecatedLists; duke@1: duke@1: duke@1: /** duke@1: * Constructor. duke@1: * bpatel@995: * @param configuration the current configuration of the doclet duke@1: */ bpatel@995: public DeprecatedAPIListBuilder(Configuration configuration) { jjg@74: deprecatedLists = new ArrayList>(); duke@1: for (int i = 0; i < NUM_TYPES; i++) { jjg@74: deprecatedLists.add(i, new ArrayList()); duke@1: } bpatel@995: buildDeprecatedAPIInfo(configuration); duke@1: } duke@1: duke@1: /** duke@1: * Build the sorted list of all the deprecated APIs in this run. bpatel@995: * Build separate lists for deprecated packages, classes, constructors, bpatel@995: * methods and fields. duke@1: * bpatel@995: * @param configuration the current configuration of the doclet. duke@1: */ bpatel@995: private void buildDeprecatedAPIInfo(Configuration configuration) { bpatel@995: PackageDoc[] packages = configuration.packages; bpatel@995: PackageDoc pkg; bpatel@995: for (int c = 0; c < packages.length; c++) { bpatel@995: pkg = packages[c]; bpatel@995: if (Util.isDeprecated(pkg)) { bpatel@995: getList(PACKAGE).add(pkg); bpatel@995: } bpatel@995: } bpatel@995: ClassDoc[] classes = configuration.root.classes(); duke@1: for (int i = 0; i < classes.length; i++) { duke@1: ClassDoc cd = classes[i]; duke@1: if (Util.isDeprecated(cd)) { duke@1: if (cd.isOrdinaryClass()) { duke@1: getList(CLASS).add(cd); duke@1: } else if (cd.isInterface()) { duke@1: getList(INTERFACE).add(cd); duke@1: } else if (cd.isException()) { duke@1: getList(EXCEPTION).add(cd); duke@1: } else if (cd.isEnum()) { duke@1: getList(ENUM).add(cd); duke@1: } else if (cd.isError()) { duke@1: getList(ERROR).add(cd); bpatel@995: } else if (cd.isAnnotationType()) { duke@1: getList(ANNOTATION_TYPE).add(cd); duke@1: } duke@1: } duke@1: composeDeprecatedList(getList(FIELD), cd.fields()); duke@1: composeDeprecatedList(getList(METHOD), cd.methods()); duke@1: composeDeprecatedList(getList(CONSTRUCTOR), cd.constructors()); duke@1: if (cd.isEnum()) { duke@1: composeDeprecatedList(getList(ENUM_CONSTANT), cd.enumConstants()); duke@1: } duke@1: if (cd.isAnnotationType()) { duke@1: composeDeprecatedList(getList(ANNOTATION_TYPE_MEMBER), bpatel@995: ((AnnotationTypeDoc) cd).elements()); duke@1: } duke@1: } duke@1: sortDeprecatedLists(); duke@1: } duke@1: duke@1: /** duke@1: * Add the members into a single list of deprecated members. duke@1: * duke@1: * @param list List of all the particular deprecated members, e.g. methods. duke@1: * @param members members to be added in the list. duke@1: */ jjg@74: private void composeDeprecatedList(List list, MemberDoc[] members) { duke@1: for (int i = 0; i < members.length; i++) { duke@1: if (Util.isDeprecated(members[i])) { duke@1: list.add(members[i]); duke@1: } duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Sort the deprecated lists for class kinds, fields, methods and duke@1: * constructors. duke@1: */ duke@1: private void sortDeprecatedLists() { duke@1: for (int i = 0; i < NUM_TYPES; i++) { duke@1: Collections.sort(getList(i)); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Return the list of deprecated Doc objects of a given type. duke@1: * duke@1: * @param the constant representing the type of list being returned. duke@1: */ jjg@74: public List getList(int type) { jjg@74: return deprecatedLists.get(type); duke@1: } duke@1: duke@1: /** duke@1: * Return true if the list of a given type has size greater than 0. duke@1: * duke@1: * @param type the type of list being checked. duke@1: */ duke@1: public boolean hasDocumentation(int type) { jjg@74: return (deprecatedLists.get(type)).size() > 0; duke@1: } duke@1: }