langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/util/Utils.java
author jjg
Fri, 27 May 2016 13:06:58 -0700
changeset 38617 d93a7f64e231
parent 36526 3b41f1c69604
permissions -rw-r--r--
8157606: deprecate com.sun.javadoc API Reviewed-by: ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 26270
diff changeset
     2
 * Copyright (c) 1999, 2015, 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.*;
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
    29
import java.lang.annotation.Documented;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
    30
import java.lang.annotation.ElementType;
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
    31
import java.lang.annotation.Target;
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
    32
import java.text.Collator;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1864
diff changeset
    33
import java.util.*;
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
    34
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 26270
diff changeset
    35
import javax.tools.JavaFileManager.Location;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1864
diff changeset
    36
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.doclets.internal.toolkit.*;
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 19667
diff changeset
    39
import com.sun.tools.javac.util.StringUtils;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * Utilities Class for Doclets.
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 9606
diff changeset
    44
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 9606
diff changeset
    45
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 9606
diff changeset
    46
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 9606
diff changeset
    47
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 */
38617
d93a7f64e231 8157606: deprecate com.sun.javadoc API
jjg
parents: 36526
diff changeset
    52
@Deprecated
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
    53
public class Utils {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     * Return array of class members whose documentation is to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     * If the member is deprecated do not include such a member in the
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     * returned array.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * @param  members             Array of members to choose from.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     * @return ProgramElementDoc[] Array of eligible members for whom
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     *                             documentation is getting generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
    63
    public ProgramElementDoc[] excludeDeprecatedMembers(
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        ProgramElementDoc[] members) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
            toProgramElementDocArray(excludeDeprecatedMembersAsList(members));
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     * Return array of class members whose documentation is to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     * If the member is deprecated do not include such a member in the
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     * returned array.
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * @param  members    Array of members to choose from.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * @return List       List of eligible members for whom
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     *                    documentation is getting generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
    78
    public List<ProgramElementDoc> excludeDeprecatedMembersAsList(
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        ProgramElementDoc[] members) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    80
        List<ProgramElementDoc> list = new ArrayList<>();
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
    81
        for (ProgramElementDoc member : members) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
    82
            if (member.tags("deprecated").length == 0) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
    83
                list.add(member);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        Collections.sort(list);
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        return list;
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     * Return the list of ProgramElementDoc objects as Array.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
    93
    public ProgramElementDoc[] toProgramElementDocArray(List<ProgramElementDoc> list) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        ProgramElementDoc[] pgmarr = new ProgramElementDoc[list.size()];
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        for (int i = 0; i < list.size(); i++) {
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
    96
            pgmarr[i] = list.get(i);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        return pgmarr;
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     * Return true if a non-public member found in the given array.
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * @param  members Array of members to look into.
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     * @return boolean True if non-public member found, false otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   107
    public boolean nonPublicMemberFound(ProgramElementDoc[] members) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   108
        for (ProgramElementDoc member : members) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   109
            if (!member.isPublic()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     * Search for the given method in the given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     * @param  cd        Class to search into.
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     * @param  method    Method to be searched.
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     * @return MethodDoc Method found, null otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   123
    public MethodDoc findMethod(ClassDoc cd, MethodDoc method) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        MethodDoc[] methods = cd.methods();
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   125
        for (MethodDoc m : methods) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   126
            if (executableMembersEqual(method, m)) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   127
                return m;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        return null;
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
     * @param member1 the first method to compare.
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * @param member2 the second method to compare.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     * @return true if member1 overrides/hides or is overriden/hidden by member2.
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   139
    public boolean executableMembersEqual(ExecutableMemberDoc member1,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
            ExecutableMemberDoc member2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        if (! (member1 instanceof MethodDoc && member2 instanceof MethodDoc))
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        MethodDoc method1 = (MethodDoc) member1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        MethodDoc method2 = (MethodDoc) member2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        if (method1.isStatic() && method2.isStatic()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
            Parameter[] targetParams = method1.parameters();
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
            Parameter[] currentParams;
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
            if (method1.name().equals(method2.name()) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
                   (currentParams = method2.parameters()).length ==
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
                targetParams.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
                int j;
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
                for (j = 0; j < targetParams.length; j++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
                    if (! (targetParams[j].typeName().equals(
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
                              currentParams[j].typeName()) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
                                   currentParams[j].type() instanceof TypeVariable ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                                   targetParams[j].type() instanceof TypeVariable)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
                if (j == targetParams.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
                    return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
                return method1.overrides(method2) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
                method2.overrides(method1) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
                                member1 == member2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    /**
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8631
diff changeset
   174
     * According to
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8631
diff changeset
   175
     * <cite>The Java&trade; Language Specification</cite>,
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8631
diff changeset
   176
     * all the outer classes and static inner classes are core classes.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   178
    public boolean isCoreClass(ClassDoc cd) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        return cd.containingClass() == null || cd.isStatic();
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   182
    public boolean matches(ProgramElementDoc doc1,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
            ProgramElementDoc doc2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        if (doc1 instanceof ExecutableMemberDoc &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
            doc2 instanceof ExecutableMemberDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
            ExecutableMemberDoc ed1 = (ExecutableMemberDoc)doc1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
            ExecutableMemberDoc ed2 = (ExecutableMemberDoc)doc2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
            return executableMembersEqual(ed1, ed2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
            return doc1.name().equals(doc2.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     * Copy the given directory contents from the source package directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     * to the generated documentation directory. For example for a package
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     * java.lang this method find out the source location of the package using
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     * {@link SourcePath} and if given directory is found in the source
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     * directory structure, copy the entire directory, to the generated
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     * documentation hierarchy.
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     * @param configuration The configuration of the current doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     * @param path The relative path to the directory to be copied.
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     * @param dir The original directory name to copy from.
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     * @param overwrite Overwrite files if true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   207
    public void copyDocFiles(Configuration configuration, PackageDoc pd) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 26270
diff changeset
   208
        Location locn = configuration.getLocationForPackage(pd);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 26270
diff changeset
   209
        copyDocFiles(configuration, locn, DocPath.forPackage(pd).resolve(DocPaths.DOC_FILES));
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   210
    }
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   211
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 26270
diff changeset
   212
    public void copyDocFiles(Configuration configuration, Location locn, DocPath dir) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        try {
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   214
            boolean first = true;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 26270
diff changeset
   215
            for (DocFile f : DocFile.list(configuration, locn, dir)) {
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   216
                if (!f.isDirectory()) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   217
                    continue;
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   218
                }
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   219
                DocFile srcdir = f;
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   220
                DocFile destdir = DocFile.createFileForOutput(configuration, dir);
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   221
                if (srcdir.isSameFile(destdir)) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   222
                    continue;
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   223
                }
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   224
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   225
                for (DocFile srcfile: srcdir.list()) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   226
                    DocFile destfile = destdir.resolve(srcfile.getName());
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   227
                    if (srcfile.isFile()) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   228
                        if (destfile.exists() && !first) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   229
                            configuration.message.warning((SourcePosition) null,
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   230
                                    "doclet.Copy_Overwrite_warning",
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   231
                                    srcfile.getPath(), destdir.getPath());
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   232
                        } else {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   233
                            configuration.message.notice(
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   234
                                    "doclet.Copying_File_0_To_Dir_1",
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   235
                                    srcfile.getPath(), destdir.getPath());
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   236
                            destfile.copyFile(srcfile);
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   237
                        }
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   238
                    } else if (srcfile.isDirectory()) {
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   239
                        if (configuration.copydocfilesubdirs
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   240
                                && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 26270
diff changeset
   241
                            copyDocFiles(configuration, locn, dir.resolve(srcfile.getName()));
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   242
                        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
                }
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   245
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   246
                first = false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
            }
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   248
        } catch (SecurityException | IOException exc) {
19667
fdfce85627a9 8001669: javadoc internal DocletAbortException should set cause when appropriate
jjg
parents: 19510
diff changeset
   249
            throw new DocletAbortException(exc);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
    }
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   252
    /**
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   253
     * Returns a TypeComparator object suitable for sorting Types.
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   254
     * @return a TypeComparator objectt
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   255
     */
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   256
    public Comparator<Type> makeTypeComparator() {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   257
        return new TypeComparator();
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   258
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     * We want the list of types in alphabetical order.  However, types are not
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
     * comparable.  We need a comparator for now.
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   263
    private static class TypeComparator implements Comparator<Type> {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   264
        public int compare(Type type1, Type type2) {
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   265
            return compareStrings(type1.qualifiedTypeName(), type2.qualifiedTypeName());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        }
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
     * For the class return all implemented interfaces including the
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     * superinterfaces of the implementing interfaces, also iterate over for
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     * all the superclasses. For interface return all the extended interfaces
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     * as well as superinterfaces for those extended interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     * @param  type       type whose implemented or
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
     *                    super interfaces are sought.
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
     * @param  configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
     * @param  sort if true, return list of interfaces sorted alphabetically.
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
     * @return List of all the required interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   281
    public List<Type> getAllInterfaces(Type type,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
            Configuration configuration, boolean sort) {
22165
ec53c8946fc2 8030807: langtools should still build using jdk 7
vromero
parents: 22163
diff changeset
   283
        Map<ClassDoc,Type> results = sort ?
ec53c8946fc2 8030807: langtools should still build using jdk 7
vromero
parents: 22163
diff changeset
   284
                new TreeMap<ClassDoc,Type>() :
ec53c8946fc2 8030807: langtools should still build using jdk 7
vromero
parents: 22163
diff changeset
   285
                new LinkedHashMap<ClassDoc,Type>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        Type[] interfaceTypes = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        Type superType = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        if (type instanceof ParameterizedType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
            interfaceTypes = ((ParameterizedType) type).interfaceTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
            superType = ((ParameterizedType) type).superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        } else if (type instanceof ClassDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
            interfaceTypes = ((ClassDoc) type).interfaceTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
            superType = ((ClassDoc) type).superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
            interfaceTypes = type.asClassDoc().interfaceTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
            superType = type.asClassDoc().superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   299
        for (Type interfaceType : interfaceTypes) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
            ClassDoc interfaceClassDoc = interfaceType.asClassDoc();
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   301
            if (!(interfaceClassDoc.isPublic() ||
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   302
                  (configuration == null ||
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   303
                   isLinkable(interfaceClassDoc, configuration)))) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            results.put(interfaceClassDoc, interfaceType);
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   307
            for (Type t : getAllInterfaces(interfaceType, configuration, sort)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
                results.put(t.asClassDoc(), t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        if (superType == null)
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   312
            return new ArrayList<>(results.values());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        //Try walking the tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        addAllInterfaceTypes(results,
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
            superType,
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   316
            interfaceTypesOf(superType),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
            false, configuration);
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   318
        List<Type> resultsList = new ArrayList<>(results.values());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
        if (sort) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
                Collections.sort(resultsList, new TypeComparator());
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        return resultsList;
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   325
    private Type[] interfaceTypesOf(Type type) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   326
        if (type instanceof AnnotatedType)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   327
            type = ((AnnotatedType)type).underlyingType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   328
        return type instanceof ClassDoc ?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   329
                ((ClassDoc)type).interfaceTypes() :
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   330
                ((ParameterizedType)type).interfaceTypes();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   331
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   332
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   333
    public List<Type> getAllInterfaces(Type type, Configuration configuration) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
        return getAllInterfaces(type, configuration, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   337
    private void findAllInterfaceTypes(Map<ClassDoc,Type> results, ClassDoc c, boolean raw,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
        Type superType = c.superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        if (superType == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
        addAllInterfaceTypes(results, superType,
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   343
                interfaceTypesOf(superType),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
                raw, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   347
    private void findAllInterfaceTypes(Map<ClassDoc,Type> results, ParameterizedType p,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        Type superType = p.superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        if (superType == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
        addAllInterfaceTypes(results, superType,
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   353
                interfaceTypesOf(superType),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
                false, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   357
    private void addAllInterfaceTypes(Map<ClassDoc,Type> results, Type type,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
            Type[] interfaceTypes, boolean raw,
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            Configuration configuration) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   360
        for (Type interfaceType : interfaceTypes) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
            ClassDoc interfaceClassDoc = interfaceType.asClassDoc();
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   362
            if (!(interfaceClassDoc.isPublic() ||
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   363
                  (configuration != null &&
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   364
                   isLinkable(interfaceClassDoc, configuration)))) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
            if (raw)
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
                interfaceType = interfaceType.asClassDoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
            results.put(interfaceClassDoc, interfaceType);
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   370
            List<Type> superInterfaces = getAllInterfaces(interfaceType, configuration);
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   371
            for (Type superInterface : superInterfaces) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
                results.put(superInterface.asClassDoc(), superInterface);
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   375
        if (type instanceof AnnotatedType)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   376
            type = ((AnnotatedType)type).underlyingType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   377
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
        if (type instanceof ParameterizedType)
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
            findAllInterfaceTypes(results, (ParameterizedType) type, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
        else if (((ClassDoc) type).typeParameters().length == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
            findAllInterfaceTypes(results, (ClassDoc) type, raw, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
            findAllInterfaceTypes(results, (ClassDoc) type, true, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
     * Enclose in quotes, used for paths and filenames that contains spaces
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   389
    public String quote(String filepath) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
        return ("\"" + filepath + "\"");
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
    /**
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14265
diff changeset
   394
     * Given a package, return its name.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
     * @param packageDoc the package to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
     * @return the name of the given package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   398
    public String getPackageName(PackageDoc packageDoc) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        return packageDoc == null || packageDoc.name().length() == 0 ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
            DocletConstants.DEFAULT_PACKAGE_NAME : packageDoc.name();
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
    /**
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14265
diff changeset
   404
     * Given a package, return its file name without the extension.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
     * @param packageDoc the package to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     * @return the file name of the given package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   408
    public String getPackageFileHeadName(PackageDoc packageDoc) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        return packageDoc == null || packageDoc.name().length() == 0 ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
            DocletConstants.DEFAULT_PACKAGE_FILE_NAME : packageDoc.name();
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
    /**
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14265
diff changeset
   414
     * Given a string, replace all occurrences of 'newStr' with 'oldStr'.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
     * @param originalStr the string to modify.
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
     * @param oldStr the string to replace.
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
     * @param newStr the string to insert in place of the old string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   419
    public String replaceText(String originalStr, String oldStr,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
            String newStr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        if (oldStr == null || newStr == null || oldStr.equals(newStr)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
            return originalStr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
        }
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   424
        return originalStr.replace(oldStr, newStr);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
     * Given an annotation, return true if it should be documented and false
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
     * otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
     * @param annotationDoc the annotation to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
     * @return true return true if it should be documented and false otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   435
    public boolean isDocumentedAnnotation(AnnotationTypeDoc annotationDoc) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   436
        for (AnnotationDesc anno : annotationDoc.annotations()) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   437
            if (anno.annotationType().qualifiedName().equals(
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   438
                    Documented.class.getName())) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   445
    private boolean isDeclarationTarget(AnnotationDesc targetAnno) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   446
        // The error recovery steps here are analogous to TypeAnnotations
38617
d93a7f64e231 8157606: deprecate com.sun.javadoc API
jjg
parents: 36526
diff changeset
   447
        AnnotationDesc.ElementValuePair[] elems = targetAnno.elementValues();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   448
        if (elems == null
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   449
            || elems.length != 1
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   450
            || !"value".equals(elems[0].element().name())
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   451
            || !(elems[0].value().value() instanceof AnnotationValue[]))
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   452
            return true;    // error recovery
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   453
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   454
        for (AnnotationValue aValue : (AnnotationValue[])elems[0].value().value()) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   455
            Object value = aValue.value();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   456
            if (!(value instanceof FieldDoc))
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   457
                return true; // error recovery
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   458
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   459
            FieldDoc eValue = (FieldDoc) value;
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   460
            if (isJava5DeclarationElementType(eValue)) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   461
                return true;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   462
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   463
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   464
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   465
        return false;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   466
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   467
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   468
    /**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   469
     * Returns true if the {@code annotationDoc} is to be treated
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   470
     * as a declaration annotation, when targeting the
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   471
     * {@code elemType} element type.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   472
     *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   473
     * @param annotationDoc the annotationDoc to check
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   474
     * @param elemType  the targeted elemType
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   475
     * @return true if annotationDoc is a declaration annotation
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   476
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   477
    public boolean isDeclarationAnnotation(AnnotationTypeDoc annotationDoc,
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   478
            boolean isJava5DeclarationLocation) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   479
        if (!isJava5DeclarationLocation)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   480
            return false;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   481
        AnnotationDesc[] annotationDescList = annotationDoc.annotations();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   482
        // Annotations with no target are treated as declaration as well
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   483
        if (annotationDescList.length==0)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   484
            return true;
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   485
        for (AnnotationDesc anno : annotationDescList) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   486
            if (anno.annotationType().qualifiedName().equals(
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   487
                    Target.class.getName())) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   488
                if (isDeclarationTarget(anno))
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   489
                    return true;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   490
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   491
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   492
        return false;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   493
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   494
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
     * Return true if this class is linkable and false if we can't link to the
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
     * desired class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
     * <br>
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
     * <b>NOTE:</b>  You can only link to external classes if they are public or
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
     * protected.
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
     * @param classDoc the class to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
     * @return true if this class is linkable and false if we can't link to the
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
     * desired class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   508
    public boolean isLinkable(ClassDoc classDoc,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
            ((classDoc.isIncluded() && configuration.isGeneratedDoc(classDoc))) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
            (configuration.extern.isExternal(classDoc) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
                (classDoc.isPublic() || classDoc.isProtected()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
     * Given a class, return the closest visible super class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
     * @param classDoc the class we are searching the parent for.
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
     * @return the closest visible super class.  Return null if it cannot
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
     *         be found (i.e. classDoc is java.lang.Object).
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   524
    public Type getFirstVisibleSuperClass(ClassDoc classDoc,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
        if (classDoc == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
        Type sup = classDoc.superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
        ClassDoc supClassDoc = classDoc.superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
        while (sup != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
                  (! (supClassDoc.isPublic() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
                              isLinkable(supClassDoc, configuration))) ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
            if (supClassDoc.superclass().qualifiedName().equals(supClassDoc.qualifiedName()))
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
            sup = supClassDoc.superclassType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
            supClassDoc = supClassDoc.superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
        if (classDoc.equals(supClassDoc)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
        return sup;
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
     * Given a class, return the closest visible super class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
     * @param classDoc the class we are searching the parent for.
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
     * @return the closest visible super class.  Return null if it cannot
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
     *         be found (i.e. classDoc is java.lang.Object).
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   553
    public ClassDoc getFirstVisibleSuperClassCD(ClassDoc classDoc,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
            Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
        if (classDoc == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
        ClassDoc supClassDoc = classDoc.superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
        while (supClassDoc != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
                  (! (supClassDoc.isPublic() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
                              isLinkable(supClassDoc, configuration))) ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
            supClassDoc = supClassDoc.superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
        if (classDoc.equals(supClassDoc)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
        return supClassDoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
     * Given a ClassDoc, return the name of its type (Class, Interface, etc.).
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
     * @param cd the ClassDoc to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
     * @param lowerCaseOnly true if you want the name returned in lower case.
14447
6f87132c2e54 8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
jjg
parents: 14368
diff changeset
   575
     *                      If false, the first letter of the name is capitalized.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
     * @return
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   578
    public String getTypeName(Configuration config,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
        ClassDoc cd, boolean lowerCaseOnly) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
        String typeName = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
        if (cd.isOrdinaryClass()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
            typeName = "doclet.Class";
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
        } else if (cd.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
            typeName = "doclet.Interface";
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
        } else if (cd.isException()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
            typeName = "doclet.Exception";
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
        } else if (cd.isError()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
            typeName = "doclet.Error";
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
        } else if (cd.isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
            typeName = "doclet.AnnotationType";
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
        } else if (cd.isEnum()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
            typeName = "doclet.Enum";
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
        return config.getText(
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 19667
diff changeset
   595
            lowerCaseOnly ? StringUtils.toLowerCase(typeName) : typeName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
    /**
17571
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   599
     * Replace all tabs in a string with the appropriate number of spaces.
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   600
     * The string may be a multi-line string.
14542
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   601
     * @param configuration the doclet configuration defining the setting for the
7062120649c2 8000800: javadoc uses static non-final fields
jjg
parents: 14447
diff changeset
   602
     *                      tab length.
17571
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   603
     * @param text the text for which the tabs should be expanded
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   604
     * @return the text with all tabs expanded
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   606
    public String replaceTabs(Configuration configuration, String text) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   607
        if (!text.contains("\t"))
17571
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   608
            return text;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   609
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   610
        final int tabLength = configuration.sourcetab;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   611
        final String whitespace = configuration.tabSpaces;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   612
        final int textLength = text.length();
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   613
        StringBuilder result = new StringBuilder(textLength);
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   614
        int pos = 0;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   615
        int lineLength = 0;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   616
        for (int i = 0; i < textLength; i++) {
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   617
            char ch = text.charAt(i);
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   618
            switch (ch) {
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   619
                case '\n': case '\r':
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   620
                    lineLength = 0;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   621
                    break;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   622
                case '\t':
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   623
                    result.append(text, pos, i);
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   624
                    int spaceCount = tabLength - lineLength % tabLength;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   625
                    result.append(whitespace, 0, spaceCount);
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   626
                    lineLength += spaceCount;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   627
                    pos = i + 1;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   628
                    break;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   629
                default:
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   630
                    lineLength++;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   631
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
        }
17571
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   633
        result.append(text, pos, textLength);
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
   634
        return result.toString();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   637
    public String normalizeNewlines(String text) {
19119
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   638
        StringBuilder sb = new StringBuilder();
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   639
        final int textLength = text.length();
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   640
        final String NL = DocletConstants.NL;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   641
        int pos = 0;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   642
        for (int i = 0; i < textLength; i++) {
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   643
            char ch = text.charAt(i);
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   644
            switch (ch) {
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   645
                case '\n':
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   646
                    sb.append(text, pos, i);
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   647
                    sb.append(NL);
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   648
                    pos = i + 1;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   649
                    break;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   650
                case '\r':
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   651
                    sb.append(text, pos, i);
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   652
                    sb.append(NL);
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   653
                    if (i + 1 < textLength && text.charAt(i + 1) == '\n')
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   654
                        i++;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   655
                    pos = i + 1;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   656
                    break;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   657
            }
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   658
        }
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   659
        sb.append(text, pos, textLength);
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   660
        return sb.toString();
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   661
    }
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
   662
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
     * The documentation for values() and valueOf() in Enums are set by the
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
     * doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   667
    public void setEnumDocumentation(Configuration configuration,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
            ClassDoc classDoc) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   669
        for (MethodDoc currentMethod : classDoc.methods()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
            if (currentMethod.name().equals("values") &&
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   671
                currentMethod.parameters().length == 0) {
19510
d2afcb89b0e7 8020663: Restructure some properties to facilitate better translation
jjg
parents: 19119
diff changeset
   672
                StringBuilder sb = new StringBuilder();
d2afcb89b0e7 8020663: Restructure some properties to facilitate better translation
jjg
parents: 19119
diff changeset
   673
                sb.append(configuration.getText("doclet.enum_values_doc.main", classDoc.name()));
d2afcb89b0e7 8020663: Restructure some properties to facilitate better translation
jjg
parents: 19119
diff changeset
   674
                sb.append("\n@return ");
d2afcb89b0e7 8020663: Restructure some properties to facilitate better translation
jjg
parents: 19119
diff changeset
   675
                sb.append(configuration.getText("doclet.enum_values_doc.return"));
d2afcb89b0e7 8020663: Restructure some properties to facilitate better translation
jjg
parents: 19119
diff changeset
   676
                currentMethod.setRawCommentText(sb.toString());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
            } else if (currentMethod.name().equals("valueOf") &&
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   678
                     currentMethod.parameters().length == 1) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
                Type paramType = currentMethod.parameters()[0].type();
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
                if (paramType != null &&
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   681
                    paramType.qualifiedTypeName().equals(String.class.getName())) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   682
                    StringBuilder sb = new StringBuilder();
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   683
                    sb.append(configuration.getText("doclet.enum_valueof_doc.main", classDoc.name()));
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   684
                    sb.append("\n@param name ");
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   685
                    sb.append(configuration.getText("doclet.enum_valueof_doc.param_name"));
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   686
                    sb.append("\n@return ");
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   687
                    sb.append(configuration.getText("doclet.enum_valueof_doc.return"));
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   688
                    sb.append("\n@throws IllegalArgumentException ");
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   689
                    sb.append(configuration.getText("doclet.enum_valueof_doc.throws_ila"));
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   690
                    sb.append("\n@throws NullPointerException ");
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   691
                    sb.append(configuration.getText("doclet.enum_valueof_doc.throws_npe"));
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   692
                    currentMethod.setRawCommentText(sb.toString());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
     *  Return true if the given Doc is deprecated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
     * @param doc the Doc to check.
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
     * @return true if the given Doc is deprecated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   704
    public boolean isDeprecated(Doc doc) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
        if (doc.tags("deprecated").length > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
        }
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 9303
diff changeset
   708
        AnnotationDesc[] annotationDescList;
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 9303
diff changeset
   709
        if (doc instanceof PackageDoc)
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 9303
diff changeset
   710
            annotationDescList = ((PackageDoc)doc).annotations();
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 9303
diff changeset
   711
        else
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 9303
diff changeset
   712
            annotationDescList = ((ProgramElementDoc)doc).annotations();
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   713
        for (AnnotationDesc anno : annotationDescList) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   714
            if (anno.annotationType().qualifiedName().equals(
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
   715
                    Deprecated.class.getName())) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   721
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   722
    /**
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   723
     * A convenience method to get property name from the name of the
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   724
     * getter or setter method.
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   725
     * @param name name of the getter or setter method.
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   726
     * @return the name of the property of the given setter of getter.
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   727
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   728
    public String propertyNameFromMethodName(Configuration configuration, String name) {
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   729
        String propertyName = null;
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   730
        if (name.startsWith("get") || name.startsWith("set")) {
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   731
            propertyName = name.substring(3);
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   732
        } else if (name.startsWith("is")) {
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   733
            propertyName = name.substring(2);
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   734
        }
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   735
        if ((propertyName == null) || propertyName.isEmpty()){
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   736
            return "";
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   737
        }
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 19667
diff changeset
   738
        return propertyName.substring(0, 1).toLowerCase(configuration.getLocale())
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   739
                + propertyName.substring(1);
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   740
    }
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   741
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   742
    /**
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   743
     * In case of JavaFX mode on, filters out classes that are private,
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   744
     * package private or having the @treatAsPrivate annotation. Those are not
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   745
     * documented in JavaFX mode.
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   746
     *
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   747
     * @param classes array of classes to be filtered.
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   748
     * @param javafx set to true if in JavaFX mode.
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   749
     * @return list of filtered classes.
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   750
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   751
    public ClassDoc[] filterOutPrivateClasses(final ClassDoc[] classes,
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   752
                                                     boolean javafx) {
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   753
        if (!javafx) {
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   754
            return classes;
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   755
        }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   756
        final List<ClassDoc> filteredOutClasses = new ArrayList<>(classes.length);
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   757
        for (ClassDoc classDoc : classes) {
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   758
            if (classDoc.isPrivate() || classDoc.isPackagePrivate()) {
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   759
                continue;
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   760
            }
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   761
            Tag[] aspTags = classDoc.tags("treatAsPrivate");
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   762
            if (aspTags != null && aspTags.length > 0) {
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   763
                continue;
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   764
            }
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   765
            filteredOutClasses.add(classDoc);
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   766
        }
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   767
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   768
        return filteredOutClasses.toArray(new ClassDoc[0]);
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   769
    }
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   770
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
   771
    /**
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   772
     * Test whether the given FieldDoc is one of the declaration annotation ElementTypes
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   773
     * defined in Java 5.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   774
     * Instead of testing for one of the new enum constants added in Java 8, test for
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   775
     * the old constants. This prevents bootstrapping problems.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   776
     *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   777
     * @param elt The FieldDoc to test
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   778
     * @return true, iff the given ElementType is one of the constants defined in Java 5
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   779
     * @since 1.8
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   780
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   781
    public boolean isJava5DeclarationElementType(FieldDoc elt) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   782
        return elt.name().contentEquals(ElementType.ANNOTATION_TYPE.name()) ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   783
                elt.name().contentEquals(ElementType.CONSTRUCTOR.name()) ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   784
                elt.name().contentEquals(ElementType.FIELD.name()) ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   785
                elt.name().contentEquals(ElementType.LOCAL_VARIABLE.name()) ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   786
                elt.name().contentEquals(ElementType.METHOD.name()) ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   787
                elt.name().contentEquals(ElementType.PACKAGE.name()) ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   788
                elt.name().contentEquals(ElementType.PARAMETER.name()) ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   789
                elt.name().contentEquals(ElementType.TYPE.name());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
   790
    }
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   791
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   792
    /**
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   793
     * A general purpose case insensitive String comparator, which compares two Strings using a Collator
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   794
     * strength of "TERTIARY".
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   795
     *
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   796
     * @param s1 first String to compare.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   797
     * @param s2 second String to compare.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   798
     * @return a negative integer, zero, or a positive integer as the first
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   799
     *         argument is less than, equal to, or greater than the second.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   800
     */
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   801
    public static int compareStrings(String s1, String s2) {
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   802
        return compareStrings(true, s1, s2);
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   803
    }
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   804
    /**
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   805
     * A general purpose case sensitive String comparator, which compares two Strings using a Collator
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   806
     * strength of "SECONDARY".
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   807
     *
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   808
     * @param s1 first String to compare.
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   809
     * @param s2 second String to compare.
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   810
     * @return a negative integer, zero, or a positive integer as the first
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   811
     *         argument is less than, equal to, or greater than the second.
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   812
     */
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   813
    public static int compareCaseCompare(String s1, String s2) {
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   814
        return compareStrings(false, s1, s2);
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   815
    }
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   816
    private static int compareStrings(boolean caseSensitive, String s1, String s2) {
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   817
        Collator collator = Collator.getInstance();
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   818
        collator.setStrength(caseSensitive ? Collator.TERTIARY : Collator.SECONDARY);
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   819
        return collator.compare(s1, s2);
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   820
    }
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   821
    /**
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   822
     * A simple comparator which compares simple names, then the fully qualified names
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   823
     * and finally the kinds, ClassUse comparator works well for this purpose.
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   824
     *
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   825
     * @return a simple general purpose doc comparator
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   826
     */
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   827
    public Comparator<Doc> makeGeneralPurposeComparator() {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   828
        return makeComparatorForClassUse();
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   829
    }
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   830
    /**
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   831
     * A comparator for index file presentations, and are sorted as follows:
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   832
     *  1. sort on simple names of entities
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   833
     *  2. if equal, then compare the DocKind ex: Package, Interface etc.
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   834
     *  3a. if equal and if the type is of ExecutableMemberDoc(Constructor, Methods),
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   835
     *      a case insensitive comparison of parameter the type signatures
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   836
     *  3b. if equal, case sensitive comparison of the type signatures
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   837
     *  4. finally, if equal, compare the FQNs of the entities
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   838
     * @return a comparator for index file use
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   839
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   840
    public Comparator<Doc> makeComparatorForIndexUse() {
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   841
        return new Utils.DocComparator<Doc>() {
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   842
            /**
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   843
             * Compare two given Doc entities, first sort on names, then on the kinds,
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   844
             * then on the parameters only if the type is an instance of ExecutableMemberDocs,
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   845
             * the parameters are compared and finally the fully qualified names.
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   846
             *
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   847
             * @param d1 - a Doc element.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   848
             * @param d2 - a Doc element.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   849
             * @return a negative integer, zero, or a positive integer as the first
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   850
             *         argument is less than, equal to, or greater than the second.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   851
             */
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   852
            public int compare(Doc d1, Doc d2) {
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   853
                int result = compareNames(d1, d2);
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   854
                if (result != 0) {
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   855
                    return result;
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   856
                }
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   857
                result = compareDocKinds(d1, d2);
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   858
                if (result != 0) {
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   859
                    return result;
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   860
                }
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   861
                if (hasParameters(d1)) {
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   862
                    Parameter[] param1 = ((ExecutableMemberDoc) d1).parameters();
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   863
                    Parameter[] param2 = ((ExecutableMemberDoc) d2).parameters();
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   864
                    result = compareParameters(false, param1, param2);
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   865
                    if (result != 0) {
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   866
                        return result;
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   867
                    }
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   868
                    result = compareParameters(true, param1, param2);
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   869
                    if (result != 0) {
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   870
                        return result;
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   871
                    }
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   872
                }
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   873
                return compareFullyQualifiedNames(d1, d2);
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   874
            }
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   875
        };
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   876
    }
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   877
    /**
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   878
     * Comparator for ClassUse presentations, and sorted as follows,
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   879
     * 1. compares simple names of entities
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   880
     * 2. if equal, the fully qualified names of the entities
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   881
     * 3. if equal and if applicable, the string representation of parameter types
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   882
     * 3a. first by using case insensitive comparison
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   883
     * 3b. second by using a case sensitive comparison
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   884
     * 4. finally the Doc kinds ie. package, class, interface etc.
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   885
     * @return a comparator to sort classes and members for class use
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   886
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   887
    public Comparator<Doc> makeComparatorForClassUse() {
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   888
        return new Utils.DocComparator<Doc>() {
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   889
            /**
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   890
             * Compares two given Doc entities, first sort on name, and if
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   891
             * applicable on the fully qualified name, and if applicable
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   892
             * on the parameter types, and finally the DocKind.
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   893
             * @param d1 - a Doc element.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   894
             * @param d2 - a Doc element.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   895
             * @return a negative integer, zero, or a positive integer as the first
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   896
             *         argument is less than, equal to, or greater than the second.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   897
             */
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   898
            public int compare(Doc d1, Doc d2) {
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   899
                int result = compareNames(d1, d2);
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   900
                if (result != 0) {
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   901
                    return result;
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   902
                }
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   903
                result = compareFullyQualifiedNames(d1, d2);
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   904
                if (result != 0) {
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   905
                    return result;
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   906
                }
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   907
                if (hasParameters(d1) && hasParameters(d2)) {
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   908
                    Parameter[] param1 = ((ExecutableMemberDoc) d1).parameters();
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   909
                    Parameter[] param2 = ((ExecutableMemberDoc) d2).parameters();
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   910
                    result = compareParameters(false, param1, param2);
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   911
                    if (result != 0) {
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   912
                        return result;
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   913
                    }
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   914
                    return compareParameters(true, param1, param2);
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   915
                }
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   916
                return compareDocKinds(d1, d2);
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   917
            }
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   918
        };
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   919
    }
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   920
    /**
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   921
     * A general purpose comparator to sort Doc entities, basically provides the building blocks
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   922
     * for creating specific comparators for an use-case.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   923
     * @param <T> a Doc entity
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   924
     */
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   925
    static abstract class DocComparator<T extends Doc> implements Comparator<Doc> {
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   926
        static enum DocKind {
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   927
           PACKAGE,
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   928
           CLASS,
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   929
           ENUM,
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   930
           INTERFACE,
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   931
           ANNOTATION,
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   932
           FIELD,
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   933
           CONSTRUCTOR,
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   934
           METHOD
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   935
        };
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   936
        boolean hasParameters(Doc d) {
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   937
            return d instanceof ExecutableMemberDoc;
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   938
        }
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   939
        DocKind getDocKind(Doc d) {
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   940
            if (d.isAnnotationType() || d.isAnnotationTypeElement()) {
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   941
                return DocKind.ANNOTATION;
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   942
            } else if (d.isEnum() || d.isEnumConstant()) {
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   943
                return DocKind.ENUM;
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   944
            } else if (d.isField()) {
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   945
                return DocKind.FIELD;
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   946
            } else if (d.isInterface()) {
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   947
                return DocKind.INTERFACE;
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   948
            } else if (d.isClass()) {
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   949
                return DocKind.CLASS;
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   950
            } else if (d.isConstructor()) {
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   951
                return DocKind.CONSTRUCTOR;
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   952
            } else if (d.isMethod()) {
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   953
                return DocKind.METHOD;
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   954
            } else {
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   955
                return DocKind.PACKAGE;
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   956
            }
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   957
        }
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   958
        /**
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   959
         * Compares two Doc entities' kinds, and these are ordered as defined in
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   960
         * the DocKind enumeration.
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   961
         * @param d1 the first Doc object
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   962
         * @param d2 the second Doc object
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   963
         * @return a negative integer, zero, or a positive integer as the first
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   964
         *         argument is less than, equal to, or greater than the second.
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   965
         */
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   966
        protected int compareDocKinds(Doc d1, Doc d2) {
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
   967
            return getDocKind(d1).compareTo(getDocKind(d2));
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   968
        }
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   969
        /**
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   970
         * Compares arrays of parameters as a string representation of their types.
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   971
         *
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
   972
         * @param ignoreCase specifies case sensitive or insensitive comparison.
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   973
         * @param params1 the first parameter array.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   974
         * @param params2 the first parameter array.
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   975
         * @return a negative integer, zero, or a positive integer as the first argument is less
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   976
         * than, equal to, or greater than the second.
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   977
         */
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   978
        protected int compareParameters(boolean caseSensitive,
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   979
                                        Parameter[] params1,
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   980
                                        Parameter[] params2) {
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   981
            String s1 = getParametersAsString(params1);
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   982
            String s2 = getParametersAsString(params2);
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   983
            return compareStrings(caseSensitive, s1, s2);
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   984
        }
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   985
        /*
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   986
         * This method returns a string representation solely for comparison purposes.
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   987
         */
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   988
        protected String getParametersAsString(Parameter[] params) {
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   989
            StringBuilder sb = new StringBuilder();
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   990
            for (Parameter param : params) {
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   991
                Type t = param.type();
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   992
                // add parameter type to arrays, as TypeMirror does.
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   993
                String tname = (t.asParameterizedType() != null && t.getElementType() != null)
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   994
                        ? t.getElementType() + t.dimension()
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   995
                        : t.toString();
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   996
                // prefix P for primitive and R for reference types, thus items will
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   997
                // be ordered naturally.
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
   998
                sb.append(t.isPrimitive() ? "P" : "R").append("-").append(tname).append("-");
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
   999
            }
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
  1000
            return sb.toString();
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1001
        }
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1002
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1003
        /**
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1004
         * Compares two Doc entities typically the simple name of a method,
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1005
         * field, constructor etc.
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1006
         * @param d1 the first Doc.
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1007
         * @param d2 the second Doc.
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1008
         * @return a negative integer, zero, or a positive integer as the first
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1009
         *         argument is less than, equal to, or greater than the second.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1010
         */
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1011
        protected int compareNames(Doc d1, Doc d2) {
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1012
            return compareStrings(d1.name(), d2.name());
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1013
        }
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1014
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1015
        /**
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1016
         * Compares the fully qualified names of the entities
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1017
         * @param d1 the first entity
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1018
         * @param d2 the second entity
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1019
         * @return a negative integer, zero, or a positive integer as the first
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1020
         *         argument is less than, equal to, or greater than the second.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1021
         */
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1022
        protected int compareFullyQualifiedNames(Doc d1, Doc d2) {
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1023
            String name1 = (d1 instanceof ProgramElementDoc)
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1024
                    ? ((ProgramElementDoc)d1).qualifiedName()
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1025
                    : d1.name();
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1026
            String name2 = (d2 instanceof ProgramElementDoc)
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1027
                    ? ((ProgramElementDoc)d2).qualifiedName()
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1028
                    : d2.name();
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1029
            return compareStrings(name1, name2);
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1030
        }
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1031
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
}