src/share/classes/com/sun/tools/doclets/internal/toolkit/util/DeprecatedAPIListBuilder.java

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 74
5a9172b251dd
child 554
9d9f26857129
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

duke@1 1 /*
xdono@117 2 * Copyright 1998-2008 Sun Microsystems, Inc. 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
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun 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 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any 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.*;
duke@1 30
duke@1 31 /**
duke@1 32 * Build list of all the deprecated classes, constructors, fields and methods.
duke@1 33 *
duke@1 34 * @author Atul M Dambalkar
duke@1 35 */
duke@1 36 public class DeprecatedAPIListBuilder {
duke@1 37
duke@1 38 public static final int NUM_TYPES = 11;
duke@1 39
duke@1 40 public static final int INTERFACE = 0;
duke@1 41 public static final int CLASS = 1;
duke@1 42 public static final int ENUM = 2;
duke@1 43 public static final int EXCEPTION = 3;
duke@1 44 public static final int ERROR = 4;
duke@1 45 public static final int ANNOTATION_TYPE = 5;
duke@1 46 public static final int FIELD = 6;
duke@1 47 public static final int METHOD = 7;
duke@1 48 public static final int CONSTRUCTOR = 8;
duke@1 49 public static final int ENUM_CONSTANT = 9;
duke@1 50 public static final int ANNOTATION_TYPE_MEMBER = 10;
duke@1 51
duke@1 52 /**
duke@1 53 * List of deprecated type Lists.
duke@1 54 */
jjg@74 55 private List<List<Doc>> deprecatedLists;
duke@1 56
duke@1 57
duke@1 58 /**
duke@1 59 * Constructor.
duke@1 60 *
duke@1 61 * @param root Root of the tree.
duke@1 62 */
duke@1 63 public DeprecatedAPIListBuilder(RootDoc root) {
jjg@74 64 deprecatedLists = new ArrayList<List<Doc>>();
duke@1 65 for (int i = 0; i < NUM_TYPES; i++) {
jjg@74 66 deprecatedLists.add(i, new ArrayList<Doc>());
duke@1 67 }
duke@1 68 buildDeprecatedAPIInfo(root);
duke@1 69 }
duke@1 70
duke@1 71 /**
duke@1 72 * Build the sorted list of all the deprecated APIs in this run.
duke@1 73 * Build separate lists for deprecated classes, constructors, methods and
duke@1 74 * fields.
duke@1 75 *
duke@1 76 * @param root Root of the tree.
duke@1 77 */
duke@1 78 private void buildDeprecatedAPIInfo(RootDoc root) {
duke@1 79 ClassDoc[] classes = root.classes();
duke@1 80 for (int i = 0; i < classes.length; i++) {
duke@1 81 ClassDoc cd = classes[i];
duke@1 82 if (Util.isDeprecated(cd)) {
duke@1 83 if (cd.isOrdinaryClass()) {
duke@1 84 getList(CLASS).add(cd);
duke@1 85 } else if (cd.isInterface()) {
duke@1 86 getList(INTERFACE).add(cd);
duke@1 87 } else if (cd.isException()) {
duke@1 88 getList(EXCEPTION).add(cd);
duke@1 89 } else if (cd.isEnum()) {
duke@1 90 getList(ENUM).add(cd);
duke@1 91 } else if (cd.isError()) {
duke@1 92 getList(ERROR).add(cd);
duke@1 93 }else if (cd.isAnnotationType()) {
duke@1 94 getList(ANNOTATION_TYPE).add(cd);
duke@1 95 }
duke@1 96 }
duke@1 97 composeDeprecatedList(getList(FIELD), cd.fields());
duke@1 98 composeDeprecatedList(getList(METHOD), cd.methods());
duke@1 99 composeDeprecatedList(getList(CONSTRUCTOR), cd.constructors());
duke@1 100 if (cd.isEnum()) {
duke@1 101 composeDeprecatedList(getList(ENUM_CONSTANT), cd.enumConstants());
duke@1 102 }
duke@1 103 if (cd.isAnnotationType()) {
duke@1 104 composeDeprecatedList(getList(ANNOTATION_TYPE_MEMBER),
duke@1 105 ((AnnotationTypeDoc) cd).elements());
duke@1 106 }
duke@1 107 }
duke@1 108 sortDeprecatedLists();
duke@1 109 }
duke@1 110
duke@1 111 /**
duke@1 112 * Add the members into a single list of deprecated members.
duke@1 113 *
duke@1 114 * @param list List of all the particular deprecated members, e.g. methods.
duke@1 115 * @param members members to be added in the list.
duke@1 116 */
jjg@74 117 private void composeDeprecatedList(List<Doc> list, MemberDoc[] members) {
duke@1 118 for (int i = 0; i < members.length; i++) {
duke@1 119 if (Util.isDeprecated(members[i])) {
duke@1 120 list.add(members[i]);
duke@1 121 }
duke@1 122 }
duke@1 123 }
duke@1 124
duke@1 125 /**
duke@1 126 * Sort the deprecated lists for class kinds, fields, methods and
duke@1 127 * constructors.
duke@1 128 */
duke@1 129 private void sortDeprecatedLists() {
duke@1 130 for (int i = 0; i < NUM_TYPES; i++) {
duke@1 131 Collections.sort(getList(i));
duke@1 132 }
duke@1 133 }
duke@1 134
duke@1 135 /**
duke@1 136 * Return the list of deprecated Doc objects of a given type.
duke@1 137 *
duke@1 138 * @param the constant representing the type of list being returned.
duke@1 139 */
jjg@74 140 public List<Doc> getList(int type) {
jjg@74 141 return deprecatedLists.get(type);
duke@1 142 }
duke@1 143
duke@1 144 /**
duke@1 145 * Return true if the list of a given type has size greater than 0.
duke@1 146 *
duke@1 147 * @param type the type of list being checked.
duke@1 148 */
duke@1 149 public boolean hasDocumentation(int type) {
jjg@74 150 return (deprecatedLists.get(type)).size() > 0;
duke@1 151 }
duke@1 152 }

mercurial