langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java
author ohair
Tue, 28 Dec 2010 15:54:52 -0800
changeset 7681 1f0819a3341f
parent 7641 8b552db25f99
child 8631 664f84942e74
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
7681
1f0819a3341f 6962318: Update copyright year
ohair
parents: 7641
diff changeset
     2
 * Copyright (c) 1999, 2010, 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.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * Utilities Class for Doclets.
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * This code is not part of an API.
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * It is implementation that is subject to change.
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * Do not use it as an API
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
public class Util {
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
     * A mapping between characters and their
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
     * corresponding HTML escape character.
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    public static final String[][] HTML_ESCAPE_CHARS =
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    {{"&", "&amp;"}, {"<", "&lt;"}, {">", "&gt;"}};
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    54
     * Name of the resource directory.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    55
     */
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    56
    public static final String RESOURCESDIR = "resources";
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    57
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    58
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * Return array of class members whose documentation is to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     * If the member is deprecated do not include such a member in the
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * returned array.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * @param  members             Array of members to choose from.
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * @return ProgramElementDoc[] Array of eligible members for whom
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     *                             documentation is getting generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    public static ProgramElementDoc[] excludeDeprecatedMembers(
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        ProgramElementDoc[] members) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
            toProgramElementDocArray(excludeDeprecatedMembersAsList(members));
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * Return array of class members whose documentation is to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * If the member is deprecated do not include such a member in the
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * returned array.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     * @param  members    Array of members to choose from.
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     * @return List       List of eligible members for whom
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
     *                    documentation is getting generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    82
    public static List<ProgramElementDoc> excludeDeprecatedMembersAsList(
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        ProgramElementDoc[] members) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    84
        List<ProgramElementDoc> list = new ArrayList<ProgramElementDoc>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        for (int i = 0; i < members.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
            if (members[i].tags("deprecated").length == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
                list.add(members[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        Collections.sort(list);
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        return list;
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     * Return the list of ProgramElementDoc objects as Array.
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     */
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
    97
    public static ProgramElementDoc[] toProgramElementDocArray(List<ProgramElementDoc> list) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        ProgramElementDoc[] pgmarr = new ProgramElementDoc[list.size()];
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        for (int i = 0; i < list.size(); i++) {
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   100
            pgmarr[i] = list.get(i);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        return pgmarr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     * Return true if a non-public member found in the given array.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     * @param  members Array of members to look into.
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * @return boolean True if non-public member found, false otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    public static boolean nonPublicMemberFound(ProgramElementDoc[] members) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        for (int i = 0; i < members.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
            if (!members[i].isPublic()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     * Search for the given method in the given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     * @param  cd        Class to search into.
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     * @param  method    Method to be searched.
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     * @return MethodDoc Method found, null otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    public static MethodDoc findMethod(ClassDoc cd, MethodDoc method) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        MethodDoc[] methods = cd.methods();
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        for (int i = 0; i < methods.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
            if (executableMembersEqual(method, methods[i])) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
                return methods[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     * @param member1 the first method to compare.
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     * @param member2 the second method to compare.
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     * @return true if member1 overrides/hides or is overriden/hidden by member2.
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    public static boolean executableMembersEqual(ExecutableMemberDoc member1,
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
            ExecutableMemberDoc member2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        if (! (member1 instanceof MethodDoc && member2 instanceof MethodDoc))
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        MethodDoc method1 = (MethodDoc) member1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        MethodDoc method2 = (MethodDoc) member2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        if (method1.isStatic() && method2.isStatic()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
            Parameter[] targetParams = method1.parameters();
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
            Parameter[] currentParams;
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
            if (method1.name().equals(method2.name()) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
                   (currentParams = method2.parameters()).length ==
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
                targetParams.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
                int j;
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                for (j = 0; j < targetParams.length; j++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                    if (! (targetParams[j].typeName().equals(
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
                              currentParams[j].typeName()) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
                                   currentParams[j].type() instanceof TypeVariable ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
                                   targetParams[j].type() instanceof TypeVariable)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
                if (j == targetParams.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
                    return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
                return method1.overrides(method2) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
                method2.overrides(method1) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
                                member1 == member2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     * According to the Java Language Specifications, all the outer classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     * and static inner classes are core classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    public static boolean isCoreClass(ClassDoc cd) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
        return cd.containingClass() == null || cd.isStatic();
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    public static boolean matches(ProgramElementDoc doc1,
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
            ProgramElementDoc doc2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        if (doc1 instanceof ExecutableMemberDoc &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
            doc2 instanceof ExecutableMemberDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
            ExecutableMemberDoc ed1 = (ExecutableMemberDoc)doc1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
            ExecutableMemberDoc ed2 = (ExecutableMemberDoc)doc2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
            return executableMembersEqual(ed1, ed2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
            return doc1.name().equals(doc2.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     * Copy source file to destination file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     * @throws SecurityException
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     * @throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    public static void copyFile(File destfile, File srcfile)
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        byte[] bytearr = new byte[512];
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        int len = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        FileInputStream input = new FileInputStream(srcfile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        File destDir = destfile.getParentFile();
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        destDir.mkdirs();
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        FileOutputStream output = new FileOutputStream(destfile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
            while ((len = input.read(bytearr)) != -1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
                output.write(bytearr, 0, len);
7641
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   214
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        } catch (FileNotFoundException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        } catch (SecurityException exc) {
7641
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   217
            } finally {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
            input.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
            output.close();
7641
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   220
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
     * Copy the given directory contents from the source package directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     * to the generated documentation directory. For example for a package
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
     * java.lang this method find out the source location of the package using
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     * {@link SourcePath} and if given directory is found in the source
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     * directory structure, copy the entire directory, to the generated
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     * documentation hierarchy.
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     * @param configuration The configuration of the current doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
     * @param path The relative path to the directory to be copied.
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
     * @param dir The original directory name to copy from.
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
     * @param overwrite Overwrite files if true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    public static void copyDocFiles(Configuration configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
            String path, String dir, boolean overwrite) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        if (checkCopyDocFilesErrors(configuration, path, dir)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        String destname = configuration.docFileDestDirName;
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        File srcdir = new File(path + dir);
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        if (destname.length() > 0 && !destname.endsWith(
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   244
               DirectoryManager.URL_FILE_SEPARATOR)) {
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   245
            destname += DirectoryManager.URL_FILE_SEPARATOR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        String dest = destname + dir;
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
            File destdir = new File(dest);
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            DirectoryManager.createDirectory(configuration, dest);
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            String[] files = srcdir.list();
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
            for (int i = 0; i < files.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
                File srcfile = new File(srcdir, files[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
                File destfile = new File(destdir, files[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
                if (srcfile.isFile()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
                    if(destfile.exists() && ! overwrite) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
                        configuration.message.warning((SourcePosition) null,
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
                                "doclet.Copy_Overwrite_warning",
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
                                srcfile.toString(), destdir.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                        configuration.message.notice(
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
                            "doclet.Copying_File_0_To_Dir_1",
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
                            srcfile.toString(), destdir.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
                        Util.copyFile(destfile, srcfile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
                } else if(srcfile.isDirectory()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
                    if(configuration.copydocfilesubdirs
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
                        && ! configuration.shouldExcludeDocFileDir(
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
                          srcfile.getName())){
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
                        copyDocFiles(configuration, path, dir +
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   271
                                    DirectoryManager.URL_FILE_SEPARATOR + srcfile.getName(),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
                                overwrite);
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        } catch (SecurityException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
            throw new DocletAbortException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        } catch (IOException exc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
            throw new DocletAbortException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
     * Given the parameters for copying doc-files, check for errors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
     * @param configuration The configuration of the current doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
     * @param path The relative path to the directory to be copied.
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
     * @param dirName The original directory name to copy from.
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
    private static boolean checkCopyDocFilesErrors (Configuration configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
            String path, String dirName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
        if ((configuration.sourcepath == null || configuration.sourcepath.length() == 0) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
               (configuration.destDirName == null || configuration.destDirName.length() == 0)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
            //The destination path and source path are definitely equal.
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        File sourcePath, destPath = new File(configuration.destDirName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        StringTokenizer pathTokens = new StringTokenizer(
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
            configuration.sourcepath == null ? "" : configuration.sourcepath,
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
            File.pathSeparator);
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        //Check if the destination path is equal to the source path.  If yes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        //do not copy doc-file directories.
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
        while(pathTokens.hasMoreTokens()){
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
            sourcePath = new File(pathTokens.nextToken());
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
            if(destPath.equals(sourcePath)){
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
        //Make sure the doc-file being copied exists.
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
        File srcdir = new File(path + dirName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        if (! srcdir.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
     * Copy a file in the resources directory to the destination
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
     * directory (if it is not there already).  If
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
     * <code>overwrite</code> is true and the destination file
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
     * already exists, overwrite it.
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
     * @param configuration  Holds the destination directory and error message
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
     * @param resourcefile   The name of the resource file to copy
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
     * @param overwrite      A flag to indicate whether the file in the
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
     *                       destination directory will be overwritten if
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
     *                       it already exists.
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
    public static void copyResourceFile(Configuration configuration,
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   330
            String resourcefile, boolean overwrite) {
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   331
        String destresourcesdir = configuration.destDirName + RESOURCESDIR;
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   332
        copyFile(configuration, resourcefile, RESOURCESDIR, destresourcesdir,
7641
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   333
                overwrite, false);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   334
    }
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   335
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   336
    /**
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   337
     * Copy a file from a source directory to a destination directory
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   338
     * (if it is not there already). If <code>overwrite</code> is true and
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   339
     * the destination file already exists, overwrite it.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   340
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   341
     * @param configuration Holds the error message
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   342
     * @param file The name of the file to copy
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   343
     * @param source The source directory
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   344
     * @param destination The destination directory where the file needs to be copied
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   345
     * @param overwrite A flag to indicate whether the file in the
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   346
     *                  destination directory will be overwritten if
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   347
     *                  it already exists.
7641
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   348
     * @param replaceNewLine true if the newline needs to be replaced with platform-
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   349
     *                  specific newline.
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   350
     */
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   351
    public static void copyFile(Configuration configuration, String file, String source,
7641
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   352
            String destination, boolean overwrite, boolean replaceNewLine) {
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   353
        DirectoryManager.createDirectory(configuration, destination);
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   354
        File destfile = new File(destination, file);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        if(destfile.exists() && (! overwrite)) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
            InputStream in = Configuration.class.getResourceAsStream(
7641
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   358
                    source + DirectoryManager.URL_FILE_SEPARATOR + file);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            if(in==null) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
            OutputStream out = new FileOutputStream(destfile);
7641
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   361
            try {
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   362
                if (!replaceNewLine) {
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   363
                    byte[] buf = new byte[2048];
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   364
                    int n;
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   365
                    while((n = in.read(buf))>0) out.write(buf,0,n);
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   366
                } else {
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   367
                    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   368
                    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   369
                    try {
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   370
                        String line;
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   371
                        while ((line = reader.readLine()) != null) {
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   372
                            writer.write(line);
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   373
                            writer.write(DocletConstants.NL);
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   374
                        }
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   375
                    } finally {
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   376
                        reader.close();
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   377
                        writer.close();
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   378
                    }
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   379
                }
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   380
            } finally {
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   381
                in.close();
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   382
                out.close();
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   383
            }
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   384
        } catch (IOException ie) {
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   385
            ie.printStackTrace();
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   386
            throw new DocletAbortException();
8b552db25f99 7006270: Several javadoc regression tests are failing on windows
bpatel
parents: 7614
diff changeset
   387
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
     * Given a PackageDoc, return the source path for that package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
     * @param configuration The Configuration for the current Doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
     * @param pkgDoc The package to seach the path for.
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
     * @return A string representing the path to the given package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
    public static String getPackageSourcePath(Configuration configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            PackageDoc pkgDoc){
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
        try{
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
            String pkgPath = DirectoryManager.getDirectoryPath(pkgDoc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
            String completePath = new SourcePath(configuration.sourcepath).
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   401
                getDirectory(pkgPath) + DirectoryManager.URL_FILE_SEPARATOR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
            //Make sure that both paths are using the same seperators.
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
            completePath = Util.replaceText(completePath, File.separator,
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   404
                    DirectoryManager.URL_FILE_SEPARATOR);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
            pkgPath = Util.replaceText(pkgPath, File.separator,
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   406
                    DirectoryManager.URL_FILE_SEPARATOR);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
            return completePath.substring(0, completePath.indexOf(pkgPath));
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        } catch (Exception e){
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
            return "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
     * We want the list of types in alphabetical order.  However, types are not
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
     * comparable.  We need a comparator for now.
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   417
    private static class TypeComparator implements Comparator<Type> {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   418
        public int compare(Type type1, Type type2) {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   419
            return type1.qualifiedTypeName().toLowerCase().compareTo(
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   420
                type2.qualifiedTypeName().toLowerCase());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
     * For the class return all implemented interfaces including the
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
     * superinterfaces of the implementing interfaces, also iterate over for
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
     * all the superclasses. For interface return all the extended interfaces
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
     * as well as superinterfaces for those extended interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
     * @param  type       type whose implemented or
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
     *                    super interfaces are sought.
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
     * @param  configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
     * @param  sort if true, return list of interfaces sorted alphabetically.
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
     * @return List of all the required interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   436
    public static List<Type> getAllInterfaces(Type type,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
            Configuration configuration, boolean sort) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   438
        Map<ClassDoc,Type> results = sort ? new TreeMap<ClassDoc,Type>() : new LinkedHashMap<ClassDoc,Type>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
        Type[] interfaceTypes = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
        Type superType = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        if (type instanceof ParameterizedType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
            interfaceTypes = ((ParameterizedType) type).interfaceTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
            superType = ((ParameterizedType) type).superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
        } else if (type instanceof ClassDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
            interfaceTypes = ((ClassDoc) type).interfaceTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
            superType = ((ClassDoc) type).superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
            interfaceTypes = type.asClassDoc().interfaceTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
            superType = type.asClassDoc().superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
        for (int i = 0; i < interfaceTypes.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
            Type interfaceType = interfaceTypes[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
            ClassDoc interfaceClassDoc = interfaceType.asClassDoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
            if (! (interfaceClassDoc.isPublic() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
                (configuration == null ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
                isLinkable(interfaceClassDoc, configuration)))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
            results.put(interfaceClassDoc, interfaceType);
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   461
            List<Type> superInterfaces = getAllInterfaces(interfaceType, configuration, sort);
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   462
            for (Iterator<Type> iter = superInterfaces.iterator(); iter.hasNext(); ) {
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   463
                Type t = iter.next();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
                results.put(t.asClassDoc(), t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
        if (superType == null)
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   468
            return new ArrayList<Type>(results.values());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
        //Try walking the tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
        addAllInterfaceTypes(results,
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
            superType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
            superType instanceof ClassDoc ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
                ((ClassDoc) superType).interfaceTypes() :
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
                ((ParameterizedType) superType).interfaceTypes(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
            false, configuration);
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   476
        List<Type> resultsList = new ArrayList<Type>(results.values());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
        if (sort) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
                Collections.sort(resultsList, new TypeComparator());
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
        return resultsList;
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   483
    public static List<Type> getAllInterfaces(Type type, Configuration configuration) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
        return getAllInterfaces(type, configuration, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   487
    private static void findAllInterfaceTypes(Map<ClassDoc,Type> results, ClassDoc c, boolean raw,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        Type superType = c.superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        if (superType == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        addAllInterfaceTypes(results, superType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
                superType instanceof ClassDoc ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
                ((ClassDoc) superType).interfaceTypes() :
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
                ((ParameterizedType) superType).interfaceTypes(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
                raw, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   499
    private static void findAllInterfaceTypes(Map<ClassDoc,Type> results, ParameterizedType p,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
        Type superType = p.superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
        if (superType == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
        addAllInterfaceTypes(results, superType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
                superType instanceof ClassDoc ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
                ((ClassDoc) superType).interfaceTypes() :
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
                ((ParameterizedType) superType).interfaceTypes(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
                false, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   511
    private static void addAllInterfaceTypes(Map<ClassDoc,Type> results, Type type,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
            Type[] interfaceTypes, boolean raw,
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
        for (int i = 0; i < interfaceTypes.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
            Type interfaceType = interfaceTypes[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
            ClassDoc interfaceClassDoc = interfaceType.asClassDoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
            if (! (interfaceClassDoc.isPublic() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
                (configuration != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
                isLinkable(interfaceClassDoc, configuration)))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
            if (raw)
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
                interfaceType = interfaceType.asClassDoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
            results.put(interfaceClassDoc, interfaceType);
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   525
            List<Type> superInterfaces = getAllInterfaces(interfaceType, configuration);
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   526
            for (Iterator<Type> iter = superInterfaces.iterator(); iter.hasNext(); ) {
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   527
                Type superInterface = iter.next();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
                results.put(superInterface.asClassDoc(), superInterface);
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
        if (type instanceof ParameterizedType)
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
            findAllInterfaceTypes(results, (ParameterizedType) type, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
        else if (((ClassDoc) type).typeParameters().length == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
            findAllInterfaceTypes(results, (ClassDoc) type, raw, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
            findAllInterfaceTypes(results, (ClassDoc) type, true, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   540
    public static <T extends ProgramElementDoc> List<T> asList(T[] members) {
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   541
        List<T> list = new ArrayList<T>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
        for (int i = 0; i < members.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
            list.add(members[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
        return list;
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
     * Enclose in quotes, used for paths and filenames that contains spaces
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
    public static String quote(String filepath) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
        return ("\"" + filepath + "\"");
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
     * Given a package, return it's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
     * @param packageDoc the package to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
     * @return the name of the given package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
    public static String getPackageName(PackageDoc packageDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
        return packageDoc == null || packageDoc.name().length() == 0 ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
            DocletConstants.DEFAULT_PACKAGE_NAME : packageDoc.name();
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
     * Given a package, return it's file name without the extension.
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
     * @param packageDoc the package to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
     * @return the file name of the given package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
    public static String getPackageFileHeadName(PackageDoc packageDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
        return packageDoc == null || packageDoc.name().length() == 0 ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
            DocletConstants.DEFAULT_PACKAGE_FILE_NAME : packageDoc.name();
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
     * Given a string, replace all occurraces of 'newStr' with 'oldStr'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
     * @param originalStr the string to modify.
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
     * @param oldStr the string to replace.
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
     * @param newStr the string to insert in place of the old string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
    public static String replaceText(String originalStr, String oldStr,
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
            String newStr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
        if (oldStr == null || newStr == null || oldStr.equals(newStr)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
            return originalStr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
        StringBuffer result = new StringBuffer(originalStr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
        int startIndex = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
        while ((startIndex = result.indexOf(oldStr, startIndex)) != -1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
            result = result.replace(startIndex, startIndex + oldStr.length(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
                    newStr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
            startIndex += newStr.length();
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
        return result.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
     * Given a string, escape all special html characters and
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
     * return the result.
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
     * @param s The string to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
     * @return the original string with all of the HTML characters
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
     * escaped.
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
     * @see #HTML_ESCAPE_CHARS
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
    public static String escapeHtmlChars(String s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
        String result = s;
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
        for (int i = 0; i < HTML_ESCAPE_CHARS.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
            result = Util.replaceText(result,
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
                    HTML_ESCAPE_CHARS[i][0], HTML_ESCAPE_CHARS[i][1]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   616
     * 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
   617
     * return the result.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   618
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   619
     * @param rawString The string to check.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   620
     * @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
   621
     * stripped.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   622
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   623
     */
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   624
    public static String stripHtml(String rawString) {
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   625
        // remove HTML tags
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   626
        rawString = rawString.replaceAll("\\<.*?>", " ");
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   627
        // 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
   628
        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
   629
        // remove extra whitespaces
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   630
        return rawString.trim();
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   631
    }
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   632
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   633
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
     * Create the directory path for the file to be generated, construct
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
     * FileOutputStream and OutputStreamWriter depending upon docencoding.
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
     * @param path The directory path to be created for this file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
     * @param filename File Name to which the PrintWriter will do the Output.
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
     * @param docencoding Encoding to be used for this file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
     * @exception IOException Exception raised by the FileWriter is passed on
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
     * to next level.
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1864
diff changeset
   642
     * @exception UnsupportedEncodingException Exception raised by the
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
     * OutputStreamWriter is passed on to next level.
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
     * @return Writer Writer for the file getting generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
     * @see java.io.FileOutputStream
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
     * @see java.io.OutputStreamWriter
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
    public static Writer genWriter(Configuration configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
            String path, String filename,
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
            String docencoding)
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
        throws IOException, UnsupportedEncodingException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
        FileOutputStream fos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
        if (path != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
            DirectoryManager.createDirectory(configuration, path);
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
            fos = new FileOutputStream(((path.length() > 0)?
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
                                                  path + File.separator: "") + filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
            fos = new FileOutputStream(filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
        if (docencoding == null) {
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1864
diff changeset
   661
            return new OutputStreamWriter(fos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
            return new OutputStreamWriter(fos, docencoding);
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
     * Given an annotation, return true if it should be documented and false
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
     * otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
     * @param annotationDoc the annotation to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
     * @return true return true if it should be documented and false otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
    public static boolean isDocumentedAnnotation(AnnotationTypeDoc annotationDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
        AnnotationDesc[] annotationDescList = annotationDoc.annotations();
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
        for (int i = 0; i < annotationDescList.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
            if (annotationDescList[i].annotationType().qualifiedName().equals(
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
                   java.lang.annotation.Documented.class.getName())){
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
     * Given a string, return an array of tokens.  The separator can be escaped
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
     * with the '\' character.  The '\' character may also be escaped by the
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
     * '\' character.
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
     * @param s         the string to tokenize.
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
     * @param separator the separator char.
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
     * @param maxTokens the maxmimum number of tokens returned.  If the
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
     *                  max is reached, the remaining part of s is appended
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
     *                  to the end of the last token.
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
     * @return an array of tokens.
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
    public static String[] tokenize(String s, char separator, int maxTokens) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   700
        List<String> tokens = new ArrayList<String>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
        StringBuilder  token = new StringBuilder ();
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
        boolean prevIsEscapeChar = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
        for (int i = 0; i < s.length(); i += Character.charCount(i)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
            int currentChar = s.codePointAt(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
            if (prevIsEscapeChar) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
                // Case 1:  escaped character
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
                token.appendCodePoint(currentChar);
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
                prevIsEscapeChar = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
            } else if (currentChar == separator && tokens.size() < maxTokens-1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
                // Case 2:  separator
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
                tokens.add(token.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
                token = new StringBuilder();
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
            } else if (currentChar == '\\') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
                // Case 3:  escape character
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
                prevIsEscapeChar = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
                // Case 4:  regular character
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
                token.appendCodePoint(currentChar);
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
        if (token.length() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
            tokens.add(token.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
        }
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   724
        return tokens.toArray(new String[] {});
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
     * Return true if this class is linkable and false if we can't link to the
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
     * desired class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
     * <br>
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
     * <b>NOTE:</b>  You can only link to external classes if they are public or
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
     * protected.
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
     * @param classDoc the class to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
     * @return true if this class is linkable and false if we can't link to the
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
     * desired class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
    public static boolean isLinkable(ClassDoc classDoc,
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
            ((classDoc.isIncluded() && configuration.isGeneratedDoc(classDoc))) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
            (configuration.extern.isExternal(classDoc) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
                (classDoc.isPublic() || classDoc.isProtected()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
     * Given a class, return the closest visible super class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
     * @param classDoc the class we are searching the parent for.
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
     * @return the closest visible super class.  Return null if it cannot
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
     *         be found (i.e. classDoc is java.lang.Object).
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
    public static Type getFirstVisibleSuperClass(ClassDoc classDoc,
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
        if (classDoc == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
        Type sup = classDoc.superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
        ClassDoc supClassDoc = classDoc.superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
        while (sup != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
                  (! (supClassDoc.isPublic() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
                              isLinkable(supClassDoc, configuration))) ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
            if (supClassDoc.superclass().qualifiedName().equals(supClassDoc.qualifiedName()))
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
            sup = supClassDoc.superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
            supClassDoc = supClassDoc.superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
        if (classDoc.equals(supClassDoc)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
        return sup;
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
     * Given a class, return the closest visible super class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
     * @param classDoc the class we are searching the parent for.
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
     * @return the closest visible super class.  Return null if it cannot
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
     *         be found (i.e. classDoc is java.lang.Object).
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
    public static ClassDoc getFirstVisibleSuperClassCD(ClassDoc classDoc,
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
        if (classDoc == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
        ClassDoc supClassDoc = classDoc.superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
        while (supClassDoc != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
                  (! (supClassDoc.isPublic() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
                              isLinkable(supClassDoc, configuration))) ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
            supClassDoc = supClassDoc.superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
        if (classDoc.equals(supClassDoc)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
        return supClassDoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
     * Given a ClassDoc, return the name of its type (Class, Interface, etc.).
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
     * @param cd the ClassDoc to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
     * @param lowerCaseOnly true if you want the name returned in lower case.
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
     *                      If false, the first letter of the name is capatilized.
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
     * @return
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
    public static String getTypeName(Configuration config,
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
        ClassDoc cd, boolean lowerCaseOnly) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
        String typeName = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
        if (cd.isOrdinaryClass()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
            typeName = "doclet.Class";
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
        } else if (cd.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
            typeName = "doclet.Interface";
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
        } else if (cd.isException()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
            typeName = "doclet.Exception";
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
        } else if (cd.isError()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
            typeName = "doclet.Error";
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
        } else if (cd.isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
            typeName = "doclet.AnnotationType";
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
        } else if (cd.isEnum()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
            typeName = "doclet.Enum";
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
        return config.getText(
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
            lowerCaseOnly ? typeName.toLowerCase() : typeName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
     * Given a string, replace all tabs with the appropriate
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
     * number of spaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
     * @param tabLength the length of each tab.
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
     * @param s the String to scan.
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
    public static void replaceTabs(int tabLength, StringBuffer s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
        int index, col;
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
        StringBuffer whitespace;
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
        while ((index = s.indexOf("\t")) != -1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
            whitespace = new StringBuffer();
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
            col = index;
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
            do {
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
                whitespace.append(" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
                col++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
            } while ((col%tabLength) != 0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
            s.replace(index, index+1, whitespace.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
     * The documentation for values() and valueOf() in Enums are set by the
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
     * doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
    public static void setEnumDocumentation(Configuration configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
            ClassDoc classDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
        MethodDoc[] methods = classDoc.methods();
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
        for (int j = 0; j < methods.length; j++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
            MethodDoc currentMethod = methods[j];
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
            if (currentMethod.name().equals("values") &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
                currentMethod.parameters().length == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
                currentMethod.setRawCommentText(
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
                    configuration.getText("doclet.enum_values_doc", classDoc.name()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
            } else if (currentMethod.name().equals("valueOf") &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
                currentMethod.parameters().length == 1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
                Type paramType = currentMethod.parameters()[0].type();
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
                if (paramType != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
                    paramType.qualifiedTypeName().equals(String.class.getName())) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
                    currentMethod.setRawCommentText(
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
                        configuration.getText("doclet.enum_valueof_doc"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
     *  Return true if the given Doc is deprecated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   878
     * @param doc the Doc to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
     * @return true if the given Doc is deprecated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   880
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   881
    public static boolean isDeprecated(ProgramElementDoc doc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
        if (doc.tags("deprecated").length > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
        AnnotationDesc[] annotationDescList = doc.annotations();
06bc494ca11e Initial load
duke
parents:
diff changeset
   886
        for (int i = 0; i < annotationDescList.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   887
            if (annotationDescList[i].annotationType().qualifiedName().equals(
06bc494ca11e Initial load
duke
parents:
diff changeset
   888
                   java.lang.Deprecated.class.getName())){
06bc494ca11e Initial load
duke
parents:
diff changeset
   889
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   890
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   891
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   892
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
}