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