langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java
author jjg
Thu, 15 Nov 2012 09:18:36 -0800
changeset 14542 7062120649c2
parent 14447 6f87132c2e54
child 15385 ee1eebe7e210
permissions -rw-r--r--
8000800: javadoc uses static non-final fields Reviewed-by: bpatel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 9606
diff changeset
     2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.doclets.internal.toolkit.util;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1864
diff changeset
    28
import java.io.*;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1864
diff changeset
    29
import java.util.*;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1864
diff changeset
    30
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.doclets.internal.toolkit.*;
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
    33
import javax.tools.StandardLocation;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * Utilities Class for Doclets.
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 9606
diff changeset
    38
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 9606
diff changeset
    39
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 9606
diff changeset
    40
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 9606
diff changeset
    41
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
public class Util {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     * Return array of class members whose documentation is to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     * If the member is deprecated do not include such a member in the
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     * returned array.
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * @param  members             Array of members to choose from.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     * @return ProgramElementDoc[] Array of eligible members for whom
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     *                             documentation is getting generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    public static ProgramElementDoc[] excludeDeprecatedMembers(
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        ProgramElementDoc[] members) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
            toProgramElementDocArray(excludeDeprecatedMembersAsList(members));
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * Return array of class members whose documentation is to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * If the member is deprecated do not include such a member in the
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * returned array.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * @param  members    Array of members to choose from.
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     * @return List       List of eligible members for whom
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     *                    documentation is getting generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    72
    public static List<ProgramElementDoc> excludeDeprecatedMembersAsList(
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        ProgramElementDoc[] members) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    74
        List<ProgramElementDoc> list = new ArrayList<ProgramElementDoc>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        for (int i = 0; i < members.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
            if (members[i].tags("deprecated").length == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
                list.add(members[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        Collections.sort(list);
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        return list;
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     * Return the list of ProgramElementDoc objects as Array.
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     */
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
    87
    public static ProgramElementDoc[] toProgramElementDocArray(List<ProgramElementDoc> list) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        ProgramElementDoc[] pgmarr = new ProgramElementDoc[list.size()];
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        for (int i = 0; i < list.size(); i++) {
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
    90
            pgmarr[i] = list.get(i);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        return pgmarr;
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * Return true if a non-public member found in the given array.
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     * @param  members Array of members to look into.
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     * @return boolean True if non-public member found, false otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    public static boolean nonPublicMemberFound(ProgramElementDoc[] members) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        for (int i = 0; i < members.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            if (!members[i].isPublic()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     * Search for the given method in the given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     * @param  cd        Class to search into.
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     * @param  method    Method to be searched.
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     * @return MethodDoc Method found, null otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    public static MethodDoc findMethod(ClassDoc cd, MethodDoc method) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        MethodDoc[] methods = cd.methods();
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        for (int i = 0; i < methods.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
            if (executableMembersEqual(method, methods[i])) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
                return methods[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * @param member1 the first method to compare.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     * @param member2 the second method to compare.
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     * @return true if member1 overrides/hides or is overriden/hidden by member2.
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    public static boolean executableMembersEqual(ExecutableMemberDoc member1,
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
            ExecutableMemberDoc member2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        if (! (member1 instanceof MethodDoc && member2 instanceof MethodDoc))
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        MethodDoc method1 = (MethodDoc) member1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        MethodDoc method2 = (MethodDoc) member2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        if (method1.isStatic() && method2.isStatic()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
            Parameter[] targetParams = method1.parameters();
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            Parameter[] currentParams;
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            if (method1.name().equals(method2.name()) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
                   (currentParams = method2.parameters()).length ==
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
                targetParams.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
                int j;
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
                for (j = 0; j < targetParams.length; j++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
                    if (! (targetParams[j].typeName().equals(
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
                              currentParams[j].typeName()) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
                                   currentParams[j].type() instanceof TypeVariable ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
                                   targetParams[j].type() instanceof TypeVariable)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
                if (j == targetParams.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
                    return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
                return method1.overrides(method2) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
                method2.overrides(method1) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
                                member1 == member2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    /**
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8631
diff changeset
   168
     * According to
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8631
diff changeset
   169
     * <cite>The Java&trade; Language Specification</cite>,
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8631
diff changeset
   170
     * all the outer classes and static inner classes are core classes.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    public static boolean isCoreClass(ClassDoc cd) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        return cd.containingClass() == null || cd.isStatic();
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    public static boolean matches(ProgramElementDoc doc1,
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
            ProgramElementDoc doc2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        if (doc1 instanceof ExecutableMemberDoc &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
            doc2 instanceof ExecutableMemberDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
            ExecutableMemberDoc ed1 = (ExecutableMemberDoc)doc1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
            ExecutableMemberDoc ed2 = (ExecutableMemberDoc)doc2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
            return executableMembersEqual(ed1, ed2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
            return doc1.name().equals(doc2.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * Copy the given directory contents from the source package directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * to the generated documentation directory. For example for a package
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     * java.lang this method find out the source location of the package using
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     * {@link SourcePath} and if given directory is found in the source
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     * directory structure, copy the entire directory, to the generated
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
     * documentation hierarchy.
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     * @param configuration The configuration of the current doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     * @param path The relative path to the directory to be copied.
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     * @param dir The original directory name to copy from.
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     * @param overwrite Overwrite files if true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     */
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   201
    public static void copyDocFiles(Configuration configuration, PackageDoc pd) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   202
        copyDocFiles(configuration, DocPath.forPackage(pd).resolve(DocPaths.DOC_FILES));
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   203
    }
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   204
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   205
    public static void copyDocFiles(Configuration configuration, DocPath dir) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        try {
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   207
            boolean first = true;
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   208
            for (DocFile f : DocFile.list(configuration, StandardLocation.SOURCE_PATH, dir)) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   209
                if (!f.isDirectory()) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   210
                    continue;
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   211
                }
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   212
                DocFile srcdir = f;
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   213
                DocFile destdir = DocFile.createFileForOutput(configuration, dir);
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   214
                if (srcdir.isSameFile(destdir)) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   215
                    continue;
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   216
                }
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   217
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   218
                for (DocFile srcfile: srcdir.list()) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   219
                    DocFile destfile = destdir.resolve(srcfile.getName());
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   220
                    if (srcfile.isFile()) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   221
                        if (destfile.exists() && !first) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   222
                            configuration.message.warning((SourcePosition) null,
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   223
                                    "doclet.Copy_Overwrite_warning",
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   224
                                    srcfile.getPath(), destdir.getPath());
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   225
                        } else {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   226
                            configuration.message.notice(
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   227
                                    "doclet.Copying_File_0_To_Dir_1",
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   228
                                    srcfile.getPath(), destdir.getPath());
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   229
                            destfile.copyFile(srcfile);
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   230
                        }
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   231
                    } else if (srcfile.isDirectory()) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   232
                        if (configuration.copydocfilesubdirs
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   233
                                && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   234
                            copyDocFiles(configuration, dir.resolve(srcfile.getName()));
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   235
                        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
                }
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   238
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   239
                first = false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        } catch (SecurityException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
            throw new DocletAbortException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        } catch (IOException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
            throw new DocletAbortException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
     * We want the list of types in alphabetical order.  However, types are not
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     * comparable.  We need a comparator for now.
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   252
    private static class TypeComparator implements Comparator<Type> {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   253
        public int compare(Type type1, Type type2) {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   254
            return type1.qualifiedTypeName().toLowerCase().compareTo(
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   255
                type2.qualifiedTypeName().toLowerCase());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     * For the class return all implemented interfaces including the
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
     * superinterfaces of the implementing interfaces, also iterate over for
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     * all the superclasses. For interface return all the extended interfaces
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     * as well as superinterfaces for those extended interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     * @param  type       type whose implemented or
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     *                    super interfaces are sought.
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     * @param  configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     * @param  sort if true, return list of interfaces sorted alphabetically.
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     * @return List of all the required interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   271
    public static List<Type> getAllInterfaces(Type type,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
            Configuration configuration, boolean sort) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   273
        Map<ClassDoc,Type> results = sort ? new TreeMap<ClassDoc,Type>() : new LinkedHashMap<ClassDoc,Type>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        Type[] interfaceTypes = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        Type superType = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        if (type instanceof ParameterizedType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
            interfaceTypes = ((ParameterizedType) type).interfaceTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
            superType = ((ParameterizedType) type).superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        } else if (type instanceof ClassDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
            interfaceTypes = ((ClassDoc) type).interfaceTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            superType = ((ClassDoc) type).superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
            interfaceTypes = type.asClassDoc().interfaceTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
            superType = type.asClassDoc().superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        for (int i = 0; i < interfaceTypes.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
            Type interfaceType = interfaceTypes[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
            ClassDoc interfaceClassDoc = interfaceType.asClassDoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
            if (! (interfaceClassDoc.isPublic() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
                (configuration == null ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
                isLinkable(interfaceClassDoc, configuration)))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
            results.put(interfaceClassDoc, interfaceType);
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   296
            List<Type> superInterfaces = getAllInterfaces(interfaceType, configuration, sort);
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   297
            for (Iterator<Type> iter = superInterfaces.iterator(); iter.hasNext(); ) {
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   298
                Type t = iter.next();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
                results.put(t.asClassDoc(), t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        if (superType == null)
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   303
            return new ArrayList<Type>(results.values());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        //Try walking the tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        addAllInterfaceTypes(results,
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            superType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
            superType instanceof ClassDoc ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
                ((ClassDoc) superType).interfaceTypes() :
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
                ((ParameterizedType) superType).interfaceTypes(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
            false, configuration);
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   311
        List<Type> resultsList = new ArrayList<Type>(results.values());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        if (sort) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
                Collections.sort(resultsList, new TypeComparator());
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        return resultsList;
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   318
    public static List<Type> getAllInterfaces(Type type, Configuration configuration) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
        return getAllInterfaces(type, configuration, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   322
    private static void findAllInterfaceTypes(Map<ClassDoc,Type> results, ClassDoc c, boolean raw,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
        Type superType = c.superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
        if (superType == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
        addAllInterfaceTypes(results, superType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
                superType instanceof ClassDoc ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
                ((ClassDoc) superType).interfaceTypes() :
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
                ((ParameterizedType) superType).interfaceTypes(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
                raw, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   334
    private static void findAllInterfaceTypes(Map<ClassDoc,Type> results, ParameterizedType p,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        Type superType = p.superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        if (superType == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
        addAllInterfaceTypes(results, superType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
                superType instanceof ClassDoc ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
                ((ClassDoc) superType).interfaceTypes() :
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
                ((ParameterizedType) superType).interfaceTypes(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
                false, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   346
    private static void addAllInterfaceTypes(Map<ClassDoc,Type> results, Type type,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
            Type[] interfaceTypes, boolean raw,
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        for (int i = 0; i < interfaceTypes.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
            Type interfaceType = interfaceTypes[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
            ClassDoc interfaceClassDoc = interfaceType.asClassDoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
            if (! (interfaceClassDoc.isPublic() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
                (configuration != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
                isLinkable(interfaceClassDoc, configuration)))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
            if (raw)
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                interfaceType = interfaceType.asClassDoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            results.put(interfaceClassDoc, interfaceType);
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   360
            List<Type> superInterfaces = getAllInterfaces(interfaceType, configuration);
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   361
            for (Iterator<Type> iter = superInterfaces.iterator(); iter.hasNext(); ) {
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   362
                Type superInterface = iter.next();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
                results.put(superInterface.asClassDoc(), superInterface);
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        if (type instanceof ParameterizedType)
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
            findAllInterfaceTypes(results, (ParameterizedType) type, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        else if (((ClassDoc) type).typeParameters().length == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
            findAllInterfaceTypes(results, (ClassDoc) type, raw, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
            findAllInterfaceTypes(results, (ClassDoc) type, true, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
     * Enclose in quotes, used for paths and filenames that contains spaces
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
    public static String quote(String filepath) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
        return ("\"" + filepath + "\"");
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
    /**
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14265
diff changeset
   382
     * Given a package, return its name.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
     * @param packageDoc the package to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
     * @return the name of the given package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
    public static String getPackageName(PackageDoc packageDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
        return packageDoc == null || packageDoc.name().length() == 0 ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
            DocletConstants.DEFAULT_PACKAGE_NAME : packageDoc.name();
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
    /**
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14265
diff changeset
   392
     * Given a package, return its file name without the extension.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
     * @param packageDoc the package to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
     * @return the file name of the given package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
    public static String getPackageFileHeadName(PackageDoc packageDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
        return packageDoc == null || packageDoc.name().length() == 0 ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
            DocletConstants.DEFAULT_PACKAGE_FILE_NAME : packageDoc.name();
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
    /**
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14265
diff changeset
   402
     * Given a string, replace all occurrences of 'newStr' with 'oldStr'.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
     * @param originalStr the string to modify.
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
     * @param oldStr the string to replace.
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
     * @param newStr the string to insert in place of the old string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
    public static String replaceText(String originalStr, String oldStr,
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
            String newStr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        if (oldStr == null || newStr == null || oldStr.equals(newStr)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
            return originalStr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
        }
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   412
        return originalStr.replace(oldStr, newStr);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
     * Given a string, escape all special html characters and
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
     * return the result.
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
     * @param s The string to check.
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   420
     * @return the original string with all of the HTML characters escaped.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
    public static String escapeHtmlChars(String s) {
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   423
        for (int i = 0; i < s.length(); i++) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   424
            char ch = s.charAt(i);
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   425
            switch (ch) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   426
                // only start building a new string if we need to
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   427
                case '<': case '>': case '&':
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   428
                    StringBuilder sb = new StringBuilder(s.substring(0, i));
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   429
                    for ( ; i < s.length(); i++) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   430
                        ch = s.charAt(i);
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   431
                        switch (ch) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   432
                            case '<': sb.append("&lt;");  break;
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   433
                            case '>': sb.append("&gt;");  break;
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   434
                            case '&': sb.append("&amp;"); break;
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   435
                            default:  sb.append(ch);      break;
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   436
                        }
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   437
                    }
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   438
                    return sb.toString();
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   439
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
        }
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   441
        return s;
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   442
    }
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   443
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   444
    /**
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   445
     * Escape all special html characters in a string buffer.
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   446
     *
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   447
     * @param sb The string buffer to update
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   448
     */
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   449
    public static void escapeHtmlChars(StringBuilder sb) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   450
        // scan backwards, replacing characters as needed.
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   451
        for (int i = sb.length() - 1; i >= 0; i--) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   452
            switch (sb.charAt(i)) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   453
                case '<': sb.replace(i, i+1, "&lt;"); break;
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   454
                case '>': sb.replace(i, i+1, "&gt;"); break;
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   455
                case '&': sb.replace(i, i+1, "&amp;"); break;
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   456
            }
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   457
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   461
     * Given a string, strips all html characters and
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   462
     * return the result.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   463
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   464
     * @param rawString The string to check.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   465
     * @return the original string with all of the HTML characters
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   466
     * stripped.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   467
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   468
     */
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   469
    public static String stripHtml(String rawString) {
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   470
        // remove HTML tags
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   471
        rawString = rawString.replaceAll("\\<.*?>", " ");
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   472
        // consolidate multiple spaces between a word to a single space
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   473
        rawString = rawString.replaceAll("\\b\\s{2,}\\b", " ");
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   474
        // remove extra whitespaces
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   475
        return rawString.trim();
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   476
    }
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   477
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   478
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
     * Given an annotation, return true if it should be documented and false
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
     * otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
     * @param annotationDoc the annotation to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
     * @return true return true if it should be documented and false otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
    public static boolean isDocumentedAnnotation(AnnotationTypeDoc annotationDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
        AnnotationDesc[] annotationDescList = annotationDoc.annotations();
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
        for (int i = 0; i < annotationDescList.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
            if (annotationDescList[i].annotationType().qualifiedName().equals(
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
                   java.lang.annotation.Documented.class.getName())){
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
     * Return true if this class is linkable and false if we can't link to the
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
     * desired class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
     * <br>
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
     * <b>NOTE:</b>  You can only link to external classes if they are public or
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
     * protected.
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
     * @param classDoc the class to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
     * @return true if this class is linkable and false if we can't link to the
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
     * desired class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
    public static boolean isLinkable(ClassDoc classDoc,
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
            ((classDoc.isIncluded() && configuration.isGeneratedDoc(classDoc))) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
            (configuration.extern.isExternal(classDoc) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
                (classDoc.isPublic() || classDoc.isProtected()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
     * Given a class, return the closest visible super class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
     * @param classDoc the class we are searching the parent for.
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
     * @return the closest visible super class.  Return null if it cannot
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
     *         be found (i.e. classDoc is java.lang.Object).
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
    public static Type getFirstVisibleSuperClass(ClassDoc classDoc,
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
        if (classDoc == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
        Type sup = classDoc.superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
        ClassDoc supClassDoc = classDoc.superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
        while (sup != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
                  (! (supClassDoc.isPublic() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
                              isLinkable(supClassDoc, configuration))) ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
            if (supClassDoc.superclass().qualifiedName().equals(supClassDoc.qualifiedName()))
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
            sup = supClassDoc.superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
            supClassDoc = supClassDoc.superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
        if (classDoc.equals(supClassDoc)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
        return sup;
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
     * Given a class, return the closest visible super class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
     * @param classDoc the class we are searching the parent for.
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
     * @return the closest visible super class.  Return null if it cannot
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
     *         be found (i.e. classDoc is java.lang.Object).
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
    public static ClassDoc getFirstVisibleSuperClassCD(ClassDoc classDoc,
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
        if (classDoc == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
        ClassDoc supClassDoc = classDoc.superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
        while (supClassDoc != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
                  (! (supClassDoc.isPublic() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
                              isLinkable(supClassDoc, configuration))) ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
            supClassDoc = supClassDoc.superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
        if (classDoc.equals(supClassDoc)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
        return supClassDoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
     * Given a ClassDoc, return the name of its type (Class, Interface, etc.).
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
     * @param cd the ClassDoc to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
     * @param lowerCaseOnly true if you want the name returned in lower case.
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents: 14368
diff changeset
   577
     *                      If false, the first letter of the name is capitalized.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
     * @return
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
    public static String getTypeName(Configuration config,
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
        ClassDoc cd, boolean lowerCaseOnly) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
        String typeName = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
        if (cd.isOrdinaryClass()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
            typeName = "doclet.Class";
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
        } else if (cd.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
            typeName = "doclet.Interface";
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
        } else if (cd.isException()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
            typeName = "doclet.Exception";
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
        } else if (cd.isError()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
            typeName = "doclet.Error";
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
        } else if (cd.isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
            typeName = "doclet.AnnotationType";
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
        } else if (cd.isEnum()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
            typeName = "doclet.Enum";
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
        return config.getText(
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
            lowerCaseOnly ? typeName.toLowerCase() : typeName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
    /**
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   601
     * Replace all tabs with the appropriate number of spaces.
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   602
     * @param configuration the doclet configuration defining the setting for the
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   603
     *                      tab length.
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   604
     * @param sb the StringBuilder in which to replace the tabs
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
     */
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   606
    public static void replaceTabs(Configuration configuration, StringBuilder sb) {
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   607
        int tabLength = configuration.sourcetab;
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   608
        String whitespace = configuration.tabSpaces;
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   609
        int index = 0;
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   610
        while ((index = sb.indexOf("\t", index)) != -1) {
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   611
            int spaceCount = tabLength - index % tabLength;
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   612
            sb.replace(index, index+1, whitespace.substring(0, spaceCount));
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   613
            index += spaceCount;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
     * The documentation for values() and valueOf() in Enums are set by the
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
     * doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
    public static void setEnumDocumentation(Configuration configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
            ClassDoc classDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
        MethodDoc[] methods = classDoc.methods();
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
        for (int j = 0; j < methods.length; j++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
            MethodDoc currentMethod = methods[j];
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
            if (currentMethod.name().equals("values") &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
                currentMethod.parameters().length == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
                currentMethod.setRawCommentText(
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
                    configuration.getText("doclet.enum_values_doc", classDoc.name()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
            } else if (currentMethod.name().equals("valueOf") &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
                currentMethod.parameters().length == 1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
                Type paramType = currentMethod.parameters()[0].type();
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
                if (paramType != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
                    paramType.qualifiedTypeName().equals(String.class.getName())) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
                    currentMethod.setRawCommentText(
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
                        configuration.getText("doclet.enum_valueof_doc"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
     *  Return true if the given Doc is deprecated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
     * @param doc the Doc to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
     * @return true if the given Doc is deprecated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
     */
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 9303
diff changeset
   648
    public static boolean isDeprecated(Doc doc) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
        if (doc.tags("deprecated").length > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
        }
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 9303
diff changeset
   652
        AnnotationDesc[] annotationDescList;
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 9303
diff changeset
   653
        if (doc instanceof PackageDoc)
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 9303
diff changeset
   654
            annotationDescList = ((PackageDoc)doc).annotations();
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 9303
diff changeset
   655
        else
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 9303
diff changeset
   656
            annotationDescList = ((ProgramElementDoc)doc).annotations();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
        for (int i = 0; i < annotationDescList.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
            if (annotationDescList[i].annotationType().qualifiedName().equals(
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
                   java.lang.Deprecated.class.getName())){
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
}