langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
author mcimadamore
Fri, 16 Dec 2016 15:27:34 +0000
changeset 42827 36468b5fa7f4
parent 42824 89b14017e8d6
child 42831 feff6f296019
permissions -rw-r--r--
8181370: Convert anonymous inner classes into lambdas/method references Reviewed-by: jjg, rfield, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
     2
 * Copyright (c) 1999, 2016, 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
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    26
package jdk.javadoc.internal.doclets.toolkit.util;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
    28
import java.lang.annotation.Documented;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    29
import java.lang.ref.SoftReference;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    30
import java.text.CollationKey;
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
    31
import java.text.Collator;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1864
diff changeset
    32
import java.util.*;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    33
import java.util.AbstractMap.SimpleEntry;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    34
import java.util.Map.Entry;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    35
import java.util.stream.Collectors;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    36
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    37
import javax.lang.model.SourceVersion;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    38
import javax.lang.model.element.AnnotationMirror;
42816
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
    39
import javax.lang.model.element.AnnotationValue;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    40
import javax.lang.model.element.Element;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    41
import javax.lang.model.element.ElementKind;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    42
import javax.lang.model.element.ExecutableElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    43
import javax.lang.model.element.Modifier;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
    44
import javax.lang.model.element.ModuleElement;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    45
import javax.lang.model.element.PackageElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    46
import javax.lang.model.element.TypeElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    47
import javax.lang.model.element.TypeParameterElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    48
import javax.lang.model.element.VariableElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    49
import javax.lang.model.type.ArrayType;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    50
import javax.lang.model.type.DeclaredType;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    51
import javax.lang.model.type.ErrorType;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    52
import javax.lang.model.type.ExecutableType;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    53
import javax.lang.model.type.NoType;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    54
import javax.lang.model.type.PrimitiveType;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    55
import javax.lang.model.type.TypeMirror;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    56
import javax.lang.model.util.ElementFilter;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    57
import javax.lang.model.util.ElementKindVisitor9;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    58
import javax.lang.model.util.Elements;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    59
import javax.lang.model.util.SimpleElementVisitor9;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    60
import javax.lang.model.util.SimpleTypeVisitor9;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    61
import javax.lang.model.util.TypeKindVisitor9;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    62
import javax.lang.model.util.Types;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    63
import javax.tools.FileObject;
40605
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
    64
import javax.tools.JavaFileManager;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
    65
import javax.tools.JavaFileManager.Location;
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 19667
diff changeset
    66
import javax.tools.StandardLocation;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1864
diff changeset
    67
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    68
import com.sun.source.doctree.DocCommentTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    69
import com.sun.source.doctree.DocTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    70
import com.sun.source.doctree.DocTree.Kind;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    71
import com.sun.source.doctree.ParamTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    72
import com.sun.source.doctree.SerialFieldTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    73
import com.sun.source.tree.CompilationUnitTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    74
import com.sun.source.tree.LineMap;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    75
import com.sun.source.util.DocSourcePositions;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    76
import com.sun.source.util.DocTrees;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    77
import com.sun.source.util.TreePath;
42816
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
    78
import com.sun.tools.javac.model.JavacTypes;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    79
import jdk.javadoc.internal.doclets.toolkit.CommentUtils.DocCommentDuo;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    80
import jdk.javadoc.internal.doclets.toolkit.Configuration;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
    81
import jdk.javadoc.internal.doclets.toolkit.Messages;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    82
import jdk.javadoc.internal.doclets.toolkit.WorkArounds;
42816
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
    83
import jdk.javadoc.internal.tool.DocEnvImpl;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    84
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    85
import static javax.lang.model.element.ElementKind.*;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    86
import static javax.lang.model.element.Modifier.*;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    87
import static javax.lang.model.type.TypeKind.*;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    88
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    89
import static com.sun.source.doctree.DocTree.Kind.*;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    90
import static jdk.javadoc.internal.doclets.toolkit.builders.ConstantsSummaryBuilder.MAX_CONSTANT_VALUE_INDEX_LENGTH;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
    91
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
 * Utilities Class for Doclets.
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 9606
diff changeset
    96
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 9606
diff changeset
    97
 *  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
    98
 *  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
    99
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
 */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
   104
public class Utils {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   105
    public final Configuration configuration;
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
   106
    public final Messages messages;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   107
    public final DocTrees docTrees;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   108
    public final Elements elementUtils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   109
    public final Types typeUtils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   110
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   111
    public Utils(Configuration c) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   112
        configuration = c;
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 39364
diff changeset
   113
        messages = configuration.getMessages();
39364
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 38617
diff changeset
   114
        elementUtils = c.docEnv.getElementUtils();
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 38617
diff changeset
   115
        typeUtils = c.docEnv.getTypeUtils();
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 38617
diff changeset
   116
        docTrees = c.docEnv.getDocTrees();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   117
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   118
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   119
    // our own little symbol table
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   120
    private HashMap<String, TypeMirror> symtab = new HashMap<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   121
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   122
    public TypeMirror getSymbol(String signature) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   123
        TypeMirror type = symtab.get(signature);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   124
        if (type == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   125
            TypeElement typeElement = elementUtils.getTypeElement(signature);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   126
            if (typeElement == null)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   127
                return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   128
            type = typeElement.asType();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   129
            if (type == null)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   130
                return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   131
            symtab.put(signature, type);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   132
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   133
        return type;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   134
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   135
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   136
    public TypeMirror getObjectType() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   137
        return getSymbol("java.lang.Object");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   138
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   139
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   140
    public TypeMirror getExceptionType() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   141
        return getSymbol("java.lang.Exception");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   142
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   143
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   144
    public TypeMirror getErrorType() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   145
        return getSymbol("java.lang.Error");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   146
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   147
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   148
    public TypeMirror getSerializableType() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   149
        return getSymbol("java.io.Serializable");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   150
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   151
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   152
    public TypeMirror getExternalizableType() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   153
        return getSymbol("java.io.Externalizable");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   154
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   155
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   156
    public TypeMirror getIllegalArgumentExceptionType() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   157
        return getSymbol("java.lang.IllegalArgumentException");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   158
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   159
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   160
    public TypeMirror getNullPointerExceptionType() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   161
        return getSymbol("java.lang.NullPointerException");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   162
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   163
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   164
    public TypeMirror getDeprecatedType() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   165
        return getSymbol("java.lang.Deprecated");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   166
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   167
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   168
    public TypeMirror getFunctionalInterface() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   169
        return getSymbol("java.lang.FunctionalInterface");
10
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
     * Return array of class members whose documentation is to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * If the member is deprecated do not include such a member in the
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     * returned array.
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     * @param  members    Array of members to choose from.
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     * @return List       List of eligible members for whom
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     *                    documentation is getting generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   181
    public List<Element> excludeDeprecatedMembers(List<? extends Element> members) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   182
        List<Element> excludeList = members.stream()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   183
                .filter((member) -> (!isDeprecated(member)))
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   184
                .sorted(makeGeneralPurposeComparator())
36043
0a4c7a4fde8d 8150077: Due to a javac type inference issue, javadoc doesn't compile with a jdk prior to 8u40
simonis
parents: 35426
diff changeset
   185
                .collect(Collectors.<Element, List<Element>>toCollection(ArrayList::new));
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   186
        return excludeList;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * Search for the given method in the given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   192
     * @param  te        Class to search into.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     * @param  method    Method to be searched.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   194
     * @return ExecutableElement Method found, null otherwise.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   196
    public ExecutableElement findMethod(TypeElement te, ExecutableElement method) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   197
        for (Element m : getMethods(te)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   198
            if (executableMembersEqual(method, (ExecutableElement)m)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   199
                return (ExecutableElement)m;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   206
     * Test whether a class is a subclass of another class.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   207
     *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   208
     * @param t1 the candidate superclass.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   209
     * @param t2 the target
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   210
     * @return true if t1 is a superclass of t2.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   211
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   212
    public boolean isSubclassOf(TypeElement t1, TypeElement t2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   213
        return typeUtils.isSubtype(t1.asType(), t2.asType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   214
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   215
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   216
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   217
     * @param e1 the first method to compare.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   218
     * @param e2 the second method to compare.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     * @return true if member1 overrides/hides or is overriden/hidden by member2.
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   221
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   222
    public boolean executableMembersEqual(ExecutableElement e1, ExecutableElement e2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   223
        // TODO: investigate if Elements.hides(..) will work here.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   224
        if (isStatic(e1) && isStatic(e2)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   225
            List<? extends VariableElement> parameters1 = e1.getParameters();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   226
            List<? extends VariableElement> parameters2 = e2.getParameters();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   227
            if (e1.getSimpleName().equals(e2.getSimpleName()) &&
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   228
                    parameters1.size() == parameters2.size()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
                int j;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   230
                for (j = 0 ; j < parameters1.size(); j++) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   231
                    VariableElement v1 = parameters1.get(j);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   232
                    VariableElement v2 = parameters2.get(j);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   233
                    String t1 = getTypeName(v1.asType(), true);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   234
                    String t2 = getTypeName(v2.asType(), true);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   235
                    if (!(t1.equals(t2) ||
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   236
                            isTypeVariable(v1.asType()) || isTypeVariable(v2.asType()))) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
                }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   240
                if (j == parameters1.size()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   241
                return true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        } else {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   246
            return elementUtils.overrides(e1, e2, getEnclosingTypeElement(e1)) ||
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   247
                    elementUtils.overrides(e2, e1, getEnclosingTypeElement(e2)) ||
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   248
                    e1.equals(e2);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
    /**
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8631
diff changeset
   253
     * According to
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8631
diff changeset
   254
     * <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
   255
     * all the outer classes and static inner classes are core classes.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   257
    public boolean isCoreClass(TypeElement e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   258
        return getEnclosingTypeElement(e) == null || isStatic(e);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    /**
40605
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   262
     * Copy doc-files directory and its contents from the source
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   263
     * package directory to the generated documentation directory.
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   264
     * For example, given a package java.lang, this method will copy
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   265
     * the doc-files directory, found in the package directory to the
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   266
     * generated documentation hierarchy.
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   267
     *
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   268
     * @param pe the package containing the doc files to be copied
40605
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   269
     * @throws DocFileIOException if there is a problem while copying
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   270
     *         the documentation files
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   272
    public void copyDocFiles(PackageElement pe) throws DocFileIOException {
40605
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   273
        Location sourceLoc = getLocationForPackage(pe);
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   274
        copyDirectory(sourceLoc, DocPath.forPackage(pe).resolve(DocPaths.DOC_FILES));
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   275
    }
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   276
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   277
    /**
40605
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   278
     * Copy the given directory contents from the source package directory
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   279
     * to the generated documentation directory. For example, given a package
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   280
     * java.lang, this method will copy the entire directory, to the generated
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   281
     * documentation hierarchy.
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   282
     *
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   283
     * @param pe the package containing the directory to be copied
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   284
     * @param dir the directory to be copied
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   285
     * @throws DocFileIOException if there is a problem while copying
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   286
     *         the documentation files
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   287
     */
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   288
    public void copyDirectory(PackageElement pe, DocPath dir) throws DocFileIOException {
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   289
        copyDirectory(getLocationForPackage(pe), dir);
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   290
    }
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   291
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   292
    /**
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   293
     * Copy the given directory and its contents from the source
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   294
     * module directory to the generated documentation directory.
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   295
     * For example, given a package java.lang, this method will
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   296
     * copy the entire directory, to the generated documentation
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   297
     * hierarchy.
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   298
     *
40605
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   299
     * @param mdle the module containing the directory to be copied
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   300
     * @param dir the directory to be copied
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   301
     * @throws DocFileIOException if there is a problem while copying
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   302
     *         the documentation files
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   303
     */
40605
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   304
    public void copyDirectory(ModuleElement mdle, DocPath dir) throws DocFileIOException  {
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   305
        copyDirectory(getLocationForModule(mdle), dir);
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   306
    }
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   307
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   308
    /**
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   309
     * Copy files from a doc path location to the output.
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   310
     *
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   311
     * @param locn the location from which to read files
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   312
     * @param dir the directory to be copied
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   313
     * @throws DocFileIOException if there is a problem
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   314
     *         copying the files
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   315
     */
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   316
    public void copyDirectory(Location locn, DocPath dir)  throws DocFileIOException {
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   317
        boolean first = true;
40605
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   318
        for (DocFile f : DocFile.list(configuration, locn, dir)) {
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   319
            if (!f.isDirectory()) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   320
                continue;
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   321
            }
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   322
            DocFile srcdir = f;
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   323
            DocFile destdir = DocFile.createFileForOutput(configuration, dir);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   324
            if (srcdir.isSameFile(destdir)) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   325
                continue;
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   326
            }
14368
6f4c62de6985 8001664: refactor javadoc to use abstraction to handle files
jjg
parents: 14366
diff changeset
   327
40605
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   328
            for (DocFile srcfile: srcdir.list()) {
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   329
                DocFile destfile = destdir.resolve(srcfile.getName());
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   330
                if (srcfile.isFile()) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   331
                    if (destfile.exists() && !first) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   332
                        messages.warning("doclet.Copy_Overwrite_warning",
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   333
                                srcfile.getPath(), destdir.getPath());
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   334
                    } else {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   335
                        messages.notice("doclet.Copying_File_0_To_Dir_1",
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   336
                                srcfile.getPath(), destdir.getPath());
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   337
                        destfile.copyFile(srcfile);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   338
                    }
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   339
                } else if (srcfile.isDirectory()) {
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   340
                    if (configuration.copydocfilesubdirs
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   341
                            && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
40605
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   342
                        copyDirectory(locn, dir.resolve(srcfile.getName()));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
            }
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   346
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40511
diff changeset
   347
            first = false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
    }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   350
40605
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   351
    protected Location getLocationForPackage(PackageElement pd) {
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42816
diff changeset
   352
        ModuleElement mdle = configuration.docEnv.getElementUtils().getModuleOf(pd);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42816
diff changeset
   353
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42816
diff changeset
   354
        if (mdle == null)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42816
diff changeset
   355
            return defaultLocation();
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42816
diff changeset
   356
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42816
diff changeset
   357
        return getLocationForModule(mdle);
40605
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   358
    }
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   359
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   360
    protected Location getLocationForModule(ModuleElement mdle) {
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   361
        Location loc = configuration.workArounds.getLocationForModule(mdle);
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   362
        if (loc != null)
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   363
            return loc;
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   364
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42816
diff changeset
   365
        return defaultLocation();
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42816
diff changeset
   366
    }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42816
diff changeset
   367
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42816
diff changeset
   368
    private Location defaultLocation() {
40605
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   369
        JavaFileManager fm = configuration.docEnv.getJavaFileManager();
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   370
        return fm.hasLocation(StandardLocation.SOURCE_PATH)
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   371
                ? StandardLocation.SOURCE_PATH
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   372
                : StandardLocation.CLASS_PATH;
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   373
    }
926c13175b67 8157349: Missing doc-files in javadoc documentation
ksrini
parents: 40587
diff changeset
   374
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   375
    public boolean isAnnotated(TypeMirror e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   376
        return !e.getAnnotationMirrors().isEmpty();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   377
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   378
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   379
    public boolean isAnnotated(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   380
        return !e.getAnnotationMirrors().isEmpty();
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   381
    }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   382
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   383
    public boolean isAnnotationType(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   384
        return new SimpleElementVisitor9<Boolean, Void>() {
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   385
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   386
            public Boolean visitExecutable(ExecutableElement e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   387
                return visit(e.getEnclosingElement());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   388
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   389
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   390
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   391
            public Boolean visitUnknown(Element e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   392
                return false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   393
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   394
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   395
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   396
            protected Boolean defaultAction(Element e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   397
                return e.getKind() == ANNOTATION_TYPE;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   398
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   399
        }.visit(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   400
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   401
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   403
     * An Enum implementation is almost identical, thus this method returns if
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   404
     * this element represents a CLASS or an ENUM
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   405
     * @param e element
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   406
     * @return true if class or enum
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   407
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   408
    public boolean isClass(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   409
        return e.getKind().isClass();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   410
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   411
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   412
    public boolean isConstructor(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   413
         return e.getKind() == CONSTRUCTOR;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   414
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   415
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   416
    public boolean isEnum(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   417
        return e.getKind() == ENUM;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   418
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   419
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   420
    boolean isEnumConstant(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   421
        return e.getKind() == ENUM_CONSTANT;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   422
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   423
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   424
    public boolean isField(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   425
        return e.getKind() == FIELD;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   426
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   427
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   428
    public boolean isInterface(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   429
        return e.getKind() == INTERFACE;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   430
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   431
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   432
    public boolean isMethod(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   433
        return e.getKind() == METHOD;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   434
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   435
40511
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
   436
    public boolean isModule(Element e) {
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
   437
        return e.getKind() == ElementKind.MODULE;
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
   438
    }
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
   439
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   440
    public boolean isPackage(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   441
        return e.getKind() == ElementKind.PACKAGE;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   442
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   443
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   444
    public boolean isAbstract(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   445
        return e.getModifiers().contains(Modifier.ABSTRACT);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   446
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   447
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   448
    public boolean isDefault(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   449
        return e.getModifiers().contains(Modifier.DEFAULT);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   450
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   451
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   452
    public boolean isPackagePrivate(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   453
        return !(isPublic(e) || isPrivate(e) || isProtected(e));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   454
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   455
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   456
    public boolean isPrivate(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   457
        return e.getModifiers().contains(Modifier.PRIVATE);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   458
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   459
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   460
    public boolean isProtected(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   461
        return e.getModifiers().contains(Modifier.PROTECTED);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   462
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   463
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   464
    public boolean isPublic(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   465
        return e.getModifiers().contains(Modifier.PUBLIC);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   466
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   467
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   468
    public boolean isProperty(String name) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   469
        return configuration.javafx && name.endsWith("Property");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   470
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   471
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   472
    public String getPropertyName(String name) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   473
        return isProperty(name)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   474
                ? name.substring(0, name.length() - "Property".length())
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   475
                : name;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   476
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   477
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   478
    public String getPropertyLabel(String name) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   479
        return name.substring(0, name.lastIndexOf("Property"));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   480
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   481
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   482
    public boolean isOverviewElement(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   483
        return e.getKind() == ElementKind.OTHER;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   484
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   485
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   486
    public boolean isStatic(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   487
        return e.getModifiers().contains(Modifier.STATIC);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   488
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   489
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   490
    public boolean isSerializable(TypeElement e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   491
        return typeUtils.isSubtype(e.asType(), getSerializableType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   492
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   493
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   494
    public boolean isExternalizable(TypeElement e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   495
        return typeUtils.isSubtype(e.asType(), getExternalizableType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   496
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   497
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   498
    public SortedSet<VariableElement> serializableFields(TypeElement aclass) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   499
        return configuration.workArounds.getSerializableFields(this, aclass);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   500
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   501
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   502
    public SortedSet<ExecutableElement> serializationMethods(TypeElement aclass) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   503
        return configuration.workArounds.getSerializationMethods(this, aclass);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   504
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   505
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   506
    public boolean definesSerializableFields(TypeElement aclass) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   507
        return configuration.workArounds.definesSerializableFields(this, aclass);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   508
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   509
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   510
    public String modifiersToString(Element e, boolean trailingSpace) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   511
        SortedSet<Modifier> set = new TreeSet<>(e.getModifiers());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   512
        set.remove(Modifier.NATIVE);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   513
        set.remove(Modifier.STRICTFP);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   514
        set.remove(Modifier.SYNCHRONIZED);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   515
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   516
        return new ElementKindVisitor9<String, SortedSet<Modifier>>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   517
            final StringBuilder sb = new StringBuilder();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   518
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   519
            void addVisibilityModifier(Set<Modifier> modifiers) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   520
                if (modifiers.contains(PUBLIC)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   521
                    sb.append("public").append(" ");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   522
                } else if (modifiers.contains(PROTECTED)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   523
                    sb.append("protected").append(" ");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   524
                } else if (modifiers.contains(PRIVATE)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   525
                    sb.append("private").append(" ");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   526
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   527
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   528
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   529
            void addStatic(Set<Modifier> modifiers) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   530
                if (modifiers.contains(STATIC)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   531
                    sb.append("static").append(" ");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   532
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   533
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   534
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   535
            void addModifers(Set<Modifier> modifiers) {
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42824
diff changeset
   536
                String s = set.stream().map(Modifier::toString).collect(Collectors.joining(" "));
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   537
                sb.append(s);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   538
                if (!s.isEmpty())
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   539
                    sb.append(" ");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   540
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   541
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   542
            String finalString(String s) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   543
                sb.append(s);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   544
                if (trailingSpace) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   545
                    if (sb.lastIndexOf(" ") == sb.length() - 1) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   546
                        return sb.toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   547
                    } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   548
                        return sb.append(" ").toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   549
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   550
                } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   551
                    return sb.toString().trim();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   552
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   553
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   554
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   555
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   556
            public String visitTypeAsInterface(TypeElement e, SortedSet<Modifier> p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   557
                addVisibilityModifier(p);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   558
                addStatic(p);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   559
                return finalString("interface");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   560
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   561
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   562
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   563
            public String visitTypeAsEnum(TypeElement e, SortedSet<Modifier> p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   564
                addVisibilityModifier(p);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   565
                addStatic(p);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   566
                return finalString("enum");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   567
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   568
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   569
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   570
            public String visitTypeAsAnnotationType(TypeElement e, SortedSet<Modifier> p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   571
                addVisibilityModifier(p);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   572
                addStatic(p);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   573
                return finalString("@interface");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   574
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   575
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   576
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   577
            public String visitTypeAsClass(TypeElement e, SortedSet<Modifier> p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   578
                addModifers(p);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   579
                return finalString("class");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   580
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   581
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   582
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   583
            protected String defaultAction(Element e, SortedSet<Modifier> p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   584
                addModifers(p);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   585
                return sb.toString().trim();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   586
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   587
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   588
        }.visit(e, set);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   589
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   590
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   591
    public boolean isFunctionalInterface(AnnotationMirror amirror) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   592
        return amirror.getAnnotationType().equals(getFunctionalInterface()) &&
39364
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 38617
diff changeset
   593
                configuration.docEnv.getSourceVersion()
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   594
                        .compareTo(SourceVersion.RELEASE_8) >= 0;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   595
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   596
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   597
    public boolean isNoType(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   598
        return t.getKind() == NONE;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   599
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   600
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   601
    public boolean isOrdinaryClass(TypeElement te) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   602
        if (isEnum(te) || isInterface(te) || isAnnotationType(te)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   603
            return false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   604
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   605
        if (isError(te) || isException(te)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   606
            return false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   607
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   608
        return true;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   609
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   610
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   611
    public boolean isError(TypeElement te) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   612
        if (isEnum(te) || isInterface(te) || isAnnotationType(te)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   613
            return false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   614
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   615
        return typeUtils.isSubtype(te.asType(), getErrorType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   616
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   617
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   618
    public boolean isException(TypeElement te) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   619
        if (isEnum(te) || isInterface(te) || isAnnotationType(te)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   620
            return false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   621
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   622
        return typeUtils.isSubtype(te.asType(), getExceptionType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   623
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   624
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   625
    public boolean isPrimitive(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   626
        return new SimpleTypeVisitor9<Boolean, Void>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   627
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   628
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   629
            public Boolean visitNoType(NoType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   630
                return t.getKind() == VOID;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   631
            }
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   632
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   633
            public Boolean visitPrimitive(PrimitiveType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   634
                return true;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   635
            }
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   636
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   637
            public Boolean visitArray(ArrayType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   638
                return visit(t.getComponentType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   639
            }
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   640
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   641
            protected Boolean defaultAction(TypeMirror e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   642
                return false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   643
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   644
        }.visit(t);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   645
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   646
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   647
    public boolean isExecutableElement(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   648
        ElementKind kind = e.getKind();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   649
        switch (kind) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   650
            case CONSTRUCTOR: case METHOD: case INSTANCE_INIT:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   651
                return true;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   652
            default:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   653
                return false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   654
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   655
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   656
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   657
    public boolean isVariableElement(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   658
        ElementKind kind = e.getKind();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   659
        switch(kind) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   660
              case ENUM_CONSTANT: case EXCEPTION_PARAMETER: case FIELD:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   661
              case LOCAL_VARIABLE: case PARAMETER:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   662
              case RESOURCE_VARIABLE:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   663
                  return true;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   664
              default:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   665
                  return false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   666
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   667
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   668
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   669
    public boolean isTypeElement(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   670
        switch (e.getKind()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   671
            case CLASS: case ENUM: case INTERFACE: case ANNOTATION_TYPE:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   672
                return true;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   673
            default:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   674
                return false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   675
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   676
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   677
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   678
   /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   679
     * Get the signature. It is the parameter list, type is qualified.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   680
     * For instance, for a method {@code mymethod(String x, int y)},
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   681
     * it will return {@code(java.lang.String,int)}.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   682
     * @param e
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   683
     * @return String
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   685
    public String signature(ExecutableElement e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   686
        return makeSignature(e, true);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   687
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   688
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   689
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   690
     * Get flat signature.  All types are not qualified.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   691
     * Return a String, which is the flat signature of this member.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   692
     * It is the parameter list, type is not qualified.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   693
     * For instance, for a method {@code mymethod(String x, int y)},
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   694
     * it will return {@code (String, int)}.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   695
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   696
    public String flatSignature(ExecutableElement e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   697
        return makeSignature(e, false);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   698
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   699
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   700
    public String makeSignature(ExecutableElement e, boolean full) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   701
        return makeSignature(e, full, false);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   702
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   703
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   704
    public String makeSignature(ExecutableElement e, boolean full, boolean ignoreTypeParameters) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   705
        StringBuilder result = new StringBuilder();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   706
        result.append("(");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   707
        Iterator<? extends VariableElement> iterator = e.getParameters().iterator();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   708
        while (iterator.hasNext()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   709
            VariableElement next = iterator.next();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   710
            TypeMirror type = next.asType();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   711
            result.append(getTypeSignature(type, full, ignoreTypeParameters));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   712
            if (iterator.hasNext()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   713
                result.append(", ");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   714
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   715
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   716
        if (e.isVarArgs()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   717
            int len = result.length();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   718
            result.replace(len - 2, len, "...");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   720
        result.append(")");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   721
        return result.toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   722
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   723
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   724
    private String getTypeSignature(TypeMirror t, boolean qualifiedName, boolean noTypeParameters) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   725
        return new SimpleTypeVisitor9<StringBuilder, Void>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   726
            final StringBuilder sb = new StringBuilder();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   727
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   728
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   729
            public StringBuilder visitArray(ArrayType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   730
                TypeMirror componentType = t.getComponentType();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   731
                visit(componentType);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   732
                sb.append("[]");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   733
                return sb;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   734
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   735
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   736
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   737
            public StringBuilder visitDeclared(DeclaredType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   738
                Element e = t.asElement();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   739
                sb.append(qualifiedName ? getFullyQualifiedName(e) : getSimpleName(e));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   740
                List<? extends TypeMirror> typeArguments = t.getTypeArguments();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   741
                if (typeArguments.isEmpty() || noTypeParameters) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   742
                    return sb;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   743
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   744
                sb.append("<");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   745
                Iterator<? extends TypeMirror> iterator = typeArguments.iterator();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   746
                while (iterator.hasNext()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   747
                    TypeMirror ta = iterator.next();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   748
                    visit(ta);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   749
                    if (iterator.hasNext()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   750
                        sb.append(", ");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   751
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   752
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   753
                sb.append(">");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   754
                return sb;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   755
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   756
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   757
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   758
            public StringBuilder visitTypeVariable(javax.lang.model.type.TypeVariable t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   759
                Element e = t.asElement();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   760
                sb.append(qualifiedName ? getFullyQualifiedName(e, false) : getSimpleName(e));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   761
                return sb;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   762
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   763
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   764
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   765
            public StringBuilder visitWildcard(javax.lang.model.type.WildcardType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   766
                sb.append("?");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   767
                TypeMirror upperBound = t.getExtendsBound();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   768
                if (upperBound != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   769
                    sb.append(" extends ");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   770
                    visit(upperBound);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   771
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   772
                TypeMirror superBound = t.getSuperBound();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   773
                if (superBound != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   774
                    sb.append(" super ");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   775
                    visit(superBound);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   776
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   777
                return sb;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   778
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   779
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
   780
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   781
            protected StringBuilder defaultAction(TypeMirror e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   782
                return sb.append(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   783
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   784
        }.visit(t).toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   785
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   786
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   787
    public boolean isArrayType(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   788
        return t.getKind() == ARRAY;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   789
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   790
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   791
    public boolean isDeclaredType(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   792
        return t.getKind() == DECLARED;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   793
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   794
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   795
    public boolean isErrorType(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   796
        return t.getKind() == ERROR;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   797
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   798
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   799
    public boolean isIntersectionType(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   800
        return t.getKind() == INTERSECTION;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   801
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   802
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   803
    public boolean isTypeParameterElement(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   804
        return e.getKind() == TYPE_PARAMETER;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   805
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   806
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   807
    public boolean isTypeVariable(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   808
        return t.getKind() == TYPEVAR;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   809
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   810
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   811
    public boolean isVoid(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   812
        return t.getKind() == VOID;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   813
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   814
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   815
    public boolean isWildCard(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   816
        return t.getKind() == WILDCARD;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   817
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   818
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   819
    public boolean ignoreBounds(TypeMirror bound) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   820
        return bound.equals(getObjectType()) && !isAnnotated(bound);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   821
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   822
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   823
    /*
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   824
     * a direct port of TypeVariable.getBounds
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   825
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   826
    public List<? extends TypeMirror> getBounds(TypeParameterElement tpe) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   827
        List<? extends TypeMirror> bounds = tpe.getBounds();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   828
        if (!bounds.isEmpty()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   829
            TypeMirror upperBound = bounds.get(bounds.size() - 1);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   830
            if (ignoreBounds(upperBound)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   831
                return Collections.emptyList();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   832
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   833
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   834
        return bounds;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   835
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   836
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   837
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   838
     * Returns the TypeMirror of the ExecutableElement for all methods,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   839
     * a null if constructor.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   840
     * @param ee the ExecutableElement
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   841
     * @return
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   842
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   843
    public TypeMirror getReturnType(ExecutableElement ee) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   844
        return ee.getKind() == CONSTRUCTOR ? null : ee.getReturnType();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   845
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   846
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   847
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   848
     * Return the type containing the method that this method overrides.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   849
     * It may be a {@code TypeElement} or a {@code TypeParameterElement}.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   850
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   851
    public TypeMirror overriddenType(ExecutableElement method) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   852
        return configuration.workArounds.overriddenType(method);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   853
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   854
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   855
    private  TypeMirror getType(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   856
        return (isNoType(t)) ? getObjectType() : t;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   857
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   858
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   859
    public TypeMirror getSuperType(TypeElement te) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   860
        TypeMirror t = te.getSuperclass();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   861
        return getType(t);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   862
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   863
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   864
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   865
     * Return the class that originally defined the method that
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   866
     * is overridden by the current definition, or null if no
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   867
     * such class exists.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   868
     *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   869
     * @return a TypeElement representing the superclass that
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   870
     * originally defined this method, null if this method does
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   871
     * not override a definition in a superclass.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   872
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   873
    public TypeElement overriddenClass(ExecutableElement ee) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   874
        TypeMirror type = overriddenType(ee);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   875
        return (type != null) ? asTypeElement(type) : null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   876
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   877
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   878
    public ExecutableElement overriddenMethod(ExecutableElement method) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   879
        if (isStatic(method)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   880
            return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   881
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   882
        final TypeElement origin = getEnclosingTypeElement(method);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   883
        for (TypeMirror t = getSuperType(origin);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   884
                t.getKind() == DECLARED;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   885
                t = getSuperType(asTypeElement(t))) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   886
            TypeElement te = asTypeElement(t);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   887
            if (te == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   888
                return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   889
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   890
            List<? extends Element> methods = te.getEnclosedElements();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   891
            for (ExecutableElement ee : ElementFilter.methodsIn(methods)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   892
                if (elementUtils.overrides(method, ee, origin)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   893
                    return ee;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   894
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   895
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   896
            if (t.equals(getObjectType()))
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   897
                return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   898
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   899
        return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   900
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   901
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   902
    public SortedSet<TypeElement> getTypeElementsAsSortedSet(Iterable<TypeElement> typeElements) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   903
        SortedSet<TypeElement> set = new TreeSet<>(makeGeneralPurposeComparator());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   904
        for (TypeElement te : typeElements) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   905
            set.add(te);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   906
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   907
        return set;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   908
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   909
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   910
    public List<? extends DocTree> getSerialDataTrees(ExecutableElement member) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   911
        return getBlockTags(member, SERIAL_DATA);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   912
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   913
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   914
    public FileObject getFileObject(TypeElement te) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   915
        return docTrees.getPath(te).getCompilationUnit().getSourceFile();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   916
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   917
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   918
    public TypeMirror getDeclaredType(TypeElement enclosing, TypeMirror target) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   919
        return getDeclaredType(Collections.emptyList(), enclosing, target);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   920
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   921
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   922
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   923
     * Finds the declaration of the enclosing's type parameter.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   924
     *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   925
     * @param values
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   926
     * @param enclosing a TypeElement whose type arguments  we desire
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   927
     * @param target the TypeMirror of the type as described by the enclosing
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   928
     * @return
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   929
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   930
    public TypeMirror getDeclaredType(Collection<TypeMirror> values,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   931
            TypeElement enclosing, TypeMirror target) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   932
        TypeElement targetElement = asTypeElement(target);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   933
        List<? extends TypeParameterElement> targetTypeArgs = targetElement.getTypeParameters();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   934
        if (targetTypeArgs.isEmpty()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   935
            return target;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   936
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   937
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   938
        List<? extends TypeParameterElement> enclosingTypeArgs = enclosing.getTypeParameters();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   939
        List<TypeMirror> targetTypeArgTypes = new ArrayList<>(targetTypeArgs.size());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   940
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   941
        if (enclosingTypeArgs.isEmpty()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   942
            for (TypeMirror te : values) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   943
                List<? extends TypeMirror> typeArguments = ((DeclaredType)te).getTypeArguments();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   944
                if (typeArguments.size() >= targetTypeArgs.size()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   945
                    for (int i = 0 ; i < targetTypeArgs.size(); i++) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   946
                        targetTypeArgTypes.add(typeArguments.get(i));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   947
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   948
                    break;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   949
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   950
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   951
            // we found no matches in the hierarchy
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   952
            if (targetTypeArgTypes.isEmpty()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   953
                return target;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   954
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   955
        } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   956
            if (targetTypeArgs.size() > enclosingTypeArgs.size()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   957
                return target;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   958
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   959
            for (int i = 0; i < targetTypeArgs.size(); i++) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   960
                TypeParameterElement tpe = enclosingTypeArgs.get(i);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   961
                targetTypeArgTypes.add(tpe.asType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   962
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   963
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   964
        TypeMirror dt = typeUtils.getDeclaredType(targetElement,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   965
                targetTypeArgTypes.toArray(new TypeMirror[targetTypeArgTypes.size()]));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   966
        return dt;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
     * For the class return all implemented interfaces including the
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
     * superinterfaces of the implementing interfaces, also iterate over for
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
     * all the superclasses. For interface return all the extended interfaces
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
     * as well as superinterfaces for those extended interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
     *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   975
     * @param  te the class to get the interfaces for
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
     * @return List of all the required interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   978
    public Set<TypeMirror> getAllInterfaces(TypeElement te) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   979
        Set<TypeMirror> results = new LinkedHashSet<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   980
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   981
        List<? extends TypeMirror> interfaceTypes = te.getInterfaces();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   982
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   983
        for (TypeMirror interfaceType : interfaceTypes) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   984
            TypeElement intfc = asTypeElement(interfaceType);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   985
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   986
            if (isPublic(intfc) || isLinkable(intfc)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   987
                results.add(interfaceType);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   988
                TypeElement klass = asTypeElement(interfaceType);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   989
                for (TypeMirror t : getAllInterfaces(klass)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   990
                    t = getDeclaredType(results, te, t);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   991
                    results.add(t);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   992
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   995
        // TypeMirror contains the modified TypeParameterElement's types represented
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   996
        // in the local Class'es elements types. ex: Foo<E> implements Bar<V> and the
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   997
        // class being considered is Foo then TypeParameters will be represented as <E>
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   998
        // note that any conversion might revert back to the old signature. For this
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
   999
        // very reason we get the superType, and find its interfaces.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1000
        TypeMirror superType = getSuperType(te);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1001
        if (superType == getObjectType())
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1002
            return results;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1003
        // Try walking the tree
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1004
        addAllInterfaceTypes(results, te, superType,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1005
                configuration.workArounds.interfaceTypesOf(superType));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1006
        return results;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1009
    private void findAllInterfaceTypes(Set<TypeMirror> results, final TypeElement baseClass,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1010
            TypeMirror p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1011
        TypeMirror superType = getSuperType(asTypeElement(p));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1012
        if (superType == p) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
            return;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1014
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1015
        addAllInterfaceTypes(results, baseClass, superType,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1016
                configuration.workArounds.interfaceTypesOf(superType));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1017
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1019
    private void addAllInterfaceTypes(Set<TypeMirror> results,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1020
            final TypeElement baseClass, TypeMirror type,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1021
            List<TypeMirror> interfaceTypes) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1022
        for (TypeMirror interfaceType : interfaceTypes) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1023
            TypeElement iElement = asTypeElement(interfaceType);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1024
            if (isPublic(iElement) && isLinkable(iElement)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1025
                interfaceType = getDeclaredType(results, baseClass, interfaceType);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1026
                results.add(interfaceType);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1027
                Set<TypeMirror> superInterfaces = getAllInterfaces(iElement);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1028
                for (TypeMirror superInterface : superInterfaces) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1029
                    superInterface = getDeclaredType(results, baseClass, superInterface);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1030
                    results.add(superInterface);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1031
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1034
        findAllInterfaceTypes(results, baseClass, type);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1035
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1036
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1037
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1038
     * Lookup for a class within this package.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1039
     *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1040
     * @return TypeElement of found class, or null if not found.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1041
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1042
    public TypeElement findClassInPackageElement(PackageElement pkg, String className) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1043
        for (TypeElement c : getAllClasses(pkg)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1044
            if (getSimpleName(c).equals(className)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1045
                return c;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1046
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1047
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1048
        return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1049
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1050
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1051
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1052
     * TODO: FIXME: port to javax.lang.model
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1053
     * Find a class within the context of this class. Search order: qualified name, in this class
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1054
     * (inner), in this package, in the class imports, in the package imports. Return the
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1055
     * TypeElement if found, null if not found.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1056
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1057
    //### The specified search order is not the normal rule the
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1058
    //### compiler would use.  Leave as specified or change it?
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1059
    public TypeElement findClass(Element element, String className) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1060
        TypeElement encl = getEnclosingTypeElement(element);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1061
        TypeElement searchResult = configuration.workArounds.searchClass(encl, className);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1062
        if (searchResult == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1063
            encl = getEnclosingTypeElement(encl);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1064
            //Expand search space to include enclosing class.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1065
            while (encl != null && getEnclosingTypeElement(encl) != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1066
                encl = getEnclosingTypeElement(encl);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1067
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1068
            searchResult = encl == null
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1069
                    ? null
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1070
                    : configuration.workArounds.searchClass(encl, className);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1071
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1072
        return searchResult;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1073
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
     * Enclose in quotes, used for paths and filenames that contains spaces
06bc494ca11e Initial load
duke
parents:
diff changeset
  1077
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
  1078
    public String quote(String filepath) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
        return ("\"" + filepath + "\"");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1081
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1083
     * Parse the package name.  We only want to display package name up to
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1084
     * 2 levels.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1086
    public String parsePackageName(PackageElement p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1087
        String pkgname = p.isUnnamed() ? "" : getPackageName(p);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1088
        int index = -1;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1089
        for (int j = 0; j < MAX_CONSTANT_VALUE_INDEX_LENGTH; j++) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1090
            index = pkgname.indexOf(".", index + 1);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1091
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1092
        if (index != -1) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1093
            pkgname = pkgname.substring(0, index);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1094
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1095
        return pkgname;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
    /**
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14265
diff changeset
  1099
     * Given a string, replace all occurrences of 'newStr' with 'oldStr'.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
     * @param originalStr the string to modify.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
     * @param oldStr the string to replace.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
     * @param newStr the string to insert in place of the old string.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 25449
diff changeset
  1104
    public String replaceText(String originalStr, String oldStr,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1105
            String newStr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
        if (oldStr == null || newStr == null || oldStr.equals(newStr)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1107
            return originalStr;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
        }
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
  1109
        return originalStr.replace(oldStr, newStr);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
     * Given an annotation, return true if it should be documented and false
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
     * otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
     *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1116
     * @param annotation the annotation to check.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
     * @return true return true if it should be documented and false otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1120
    public boolean isDocumentedAnnotation(TypeElement annotation) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1121
        for (AnnotationMirror anno : annotation.getAnnotationMirrors()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1122
            if (getFullyQualifiedName(anno.getAnnotationType().asElement()).equals(
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
  1123
                    Documented.class.getName())) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1131
     * Return true if this class is linkable and false if we can't link to the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1132
     * desired class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1133
     * <br>
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
     * <b>NOTE:</b>  You can only link to external classes if they are public or
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
     * protected.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
     * @return true if this class is linkable and false if we can't link to the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
     * desired class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1140
    public boolean isLinkable(TypeElement typeElem) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
        return
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1142
            (typeElem != null &&
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1143
                (isIncluded(typeElem) && configuration.isGeneratedDoc(typeElem))) ||
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1144
            (configuration.extern.isExternal(typeElem) &&
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1145
                (isPublic(typeElem) || isProtected(typeElem)));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1146
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1147
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1148
    List<TypeMirror> asErasureTypes(Collection<TypeElement> inList) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1149
        List<TypeMirror> out = new ArrayList<>(inList.size());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1150
        inList.stream().forEach((te) -> {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1151
            out.add(typeUtils.erasure(te.asType()));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1152
        });
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1153
        return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1154
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1155
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1156
    List<TypeMirror> asTypes(Collection<TypeElement> inList) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1157
        List<TypeMirror> out = new ArrayList<>(inList.size());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1158
        inList.stream().forEach((te) -> {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1159
            out.add(te.asType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1160
        });
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1161
        return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1162
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1163
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1164
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1165
     * Return this type as a {@code TypeElement} if it represents a class
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1166
     * interface or annotation.  Array dimensions are ignored.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1167
     * If this type {@code ParameterizedType} or {@code WildcardType}, return
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1168
     * the {@code TypeElement} of the type's erasure.  If this is an
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1169
     * annotation, return this as a {@code TypeElement}.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1170
     * If this is a primitive type, return null.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1171
     *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1172
     * @return the {@code TypeElement} of this type,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1173
     *         or null if it is a primitive type.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1174
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1175
    public TypeElement asTypeElement(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1176
        return new SimpleTypeVisitor9<TypeElement, Void>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1177
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1178
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1179
            public TypeElement visitDeclared(DeclaredType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1180
                return (TypeElement) t.asElement();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1181
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1182
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1183
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1184
            public TypeElement visitArray(ArrayType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1185
                return visit(t.getComponentType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1186
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1187
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1188
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1189
            public TypeElement visitTypeVariable(javax.lang.model.type.TypeVariable t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1190
               /*
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1191
                * TODO: Check with JJG.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1192
                * if we have an annotated type @A $B T, then erasure returns a
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1193
                * none, in this case we use asElement instead.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1194
                */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1195
                if (isAnnotated(t)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1196
                    return visit(typeUtils.asElement(t).asType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1197
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1198
                return visit(typeUtils.erasure(t));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1199
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1200
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1201
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1202
            public TypeElement visitWildcard(javax.lang.model.type.WildcardType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1203
                return visit(typeUtils.erasure(t));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1204
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1205
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1206
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1207
            public TypeElement visitError(ErrorType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1208
                return (TypeElement)t.asElement();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1209
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1210
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1211
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1212
            protected TypeElement defaultAction(TypeMirror e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1213
                return super.defaultAction(e, p);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1214
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1215
        }.visit(t);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1216
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1217
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1218
    public TypeMirror getComponentType(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1219
        while (isArrayType(t)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1220
            t = ((ArrayType) t).getComponentType();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1221
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1222
        return t;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1223
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1224
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1225
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1226
     * Return the type's dimension information, as a string.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1227
     * <p>
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1228
     * For example, a two dimensional array of String returns "{@code [][]}".
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1229
     *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1230
     * @return the type's dimension information as a string.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1231
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1232
    public String getDimension(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1233
        return new SimpleTypeVisitor9<String, Void>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1234
            StringBuilder dimension = new StringBuilder("");
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1235
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1236
            public String visitArray(ArrayType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1237
                dimension.append("[]");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1238
                return visit(t.getComponentType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1239
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1240
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1241
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1242
            protected String defaultAction(TypeMirror e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1243
                return dimension.toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1244
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1245
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1246
        }.visit(t);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1247
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1248
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1249
    public TypeElement getSuperClass(TypeElement te) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1250
        if (isInterface(te) || isAnnotationType(te) ||
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1251
                te.asType().equals(getObjectType())) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1252
            return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1253
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1254
        TypeMirror superclass = te.getSuperclass();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1255
        if (isNoType(superclass) && isClass(te)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1256
            superclass = getObjectType();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1257
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1258
        return asTypeElement(superclass);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1259
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1260
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1261
    public TypeElement getFirstVisibleSuperClassAsTypeElement(TypeElement te) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1262
        if (isAnnotationType(te) || isInterface(te) ||
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1263
                te.asType().equals(getObjectType())) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1264
            return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1265
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1266
        TypeMirror firstVisibleSuperClass = getFirstVisibleSuperClass(te);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1267
        return firstVisibleSuperClass == null ? null : asTypeElement(firstVisibleSuperClass);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1268
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1269
06bc494ca11e Initial load
duke
parents:
diff changeset
  1270
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1271
     * Given a class, return the closest visible super class.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1272
     * @param type the TypeMirror to be interrogated
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1273
     * @return  the closest visible super class.  Return null if it cannot
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1274
     *          be found.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1275
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1276
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1277
    public TypeMirror getFirstVisibleSuperClass(TypeMirror type) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1278
        return getFirstVisibleSuperClass(asTypeElement(type));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1279
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1280
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1281
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1282
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1283
     * Given a class, return the closest visible super class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1284
     *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1285
     * @param te the TypeElement to be interrogated
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1286
     * @return the closest visible super class.  Return null if it cannot
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1287
     *         be found..
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1289
    public TypeMirror getFirstVisibleSuperClass(TypeElement te) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1290
        TypeMirror superType = te.getSuperclass();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1291
        if (isNoType(superType)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1292
            superType = getObjectType();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1293
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1294
        TypeElement superClass = asTypeElement(superType);
37009
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1295
        // skip "hidden" classes
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1296
        while ((superClass != null && isHidden(superClass))
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1297
                || (superClass != null &&  !isPublic(superClass) && !isLinkable(superClass))) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1298
            TypeMirror supersuperType = superClass.getSuperclass();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1299
            TypeElement supersuperClass = asTypeElement(supersuperType);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1300
            if (supersuperClass == null
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1301
                    || supersuperClass.getQualifiedName().equals(superClass.getQualifiedName())) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1302
                break;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1303
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1304
            superType = supersuperType;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1305
            superClass = supersuperClass;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1306
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1307
        if (te.asType().equals(superType)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1308
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1309
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1310
        return superType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1311
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1312
06bc494ca11e Initial load
duke
parents:
diff changeset
  1313
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1314
     * Given a TypeElement, return the name of its type (Class, Interface, etc.).
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1315
     *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1316
     * @param te the TypeElement to check.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1317
     * @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
  1318
     *                      If false, the first letter of the name is capitalized.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1319
     * @return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1320
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1321
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1322
    public String getTypeElementName(TypeElement te, boolean lowerCaseOnly) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1323
        String typeName = "";
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1324
        if (isInterface(te)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1325
            typeName = "doclet.Interface";
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1326
        } else if (isException(te)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1327
            typeName = "doclet.Exception";
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1328
        } else if (isError(te)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1329
            typeName = "doclet.Error";
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1330
        } else if (isAnnotationType(te)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1331
            typeName = "doclet.AnnotationType";
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1332
        } else if (isEnum(te)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1333
            typeName = "doclet.Enum";
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1334
        } else if (isOrdinaryClass(te)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1335
            typeName = "doclet.Class";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1336
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1337
        typeName = lowerCaseOnly ? toLowerCase(typeName) : typeName;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1338
        return typeNameMap.computeIfAbsent(typeName, configuration :: getText);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1339
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1340
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1341
    private final Map<String, String> typeNameMap = new HashMap<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1342
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1343
    public String getTypeName(TypeMirror t, boolean fullyQualified) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1344
        return new SimpleTypeVisitor9<String, Void>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1345
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1346
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1347
            public String visitArray(ArrayType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1348
                return visit(t.getComponentType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1349
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1350
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1351
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1352
            public String visitDeclared(DeclaredType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1353
                TypeElement te = asTypeElement(t);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1354
                return fullyQualified
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1355
                        ? te.getQualifiedName().toString()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1356
                        : getSimpleName(te);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1357
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1358
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1359
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1360
            public String visitExecutable(ExecutableType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1361
                return t.toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1362
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1363
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1364
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1365
            public String visitPrimitive(PrimitiveType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1366
                return t.toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1367
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1368
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1369
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1370
            public String visitTypeVariable(javax.lang.model.type.TypeVariable t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1371
                return getSimpleName(t.asElement());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1372
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1373
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1374
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1375
            public String visitWildcard(javax.lang.model.type.WildcardType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1376
                return t.toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1377
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1378
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1379
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1380
            protected String defaultAction(TypeMirror e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1381
                return e.toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1382
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1383
        }.visit(t);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1384
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1385
06bc494ca11e Initial load
duke
parents:
diff changeset
  1386
    /**
17571
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1387
     * Replace all tabs in a string with the appropriate number of spaces.
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1388
     * The string may be a multi-line string.
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1389
     * @param text the text for which the tabs should be expanded
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1390
     * @return the text with all tabs expanded
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1391
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1392
    public String replaceTabs(String text) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 22153
diff changeset
  1393
        if (!text.contains("\t"))
17571
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1394
            return text;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1395
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1396
        final int tabLength = configuration.sourcetab;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1397
        final String whitespace = configuration.tabSpaces;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1398
        final int textLength = text.length();
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1399
        StringBuilder result = new StringBuilder(textLength);
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1400
        int pos = 0;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1401
        int lineLength = 0;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1402
        for (int i = 0; i < textLength; i++) {
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1403
            char ch = text.charAt(i);
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1404
            switch (ch) {
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1405
                case '\n': case '\r':
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1406
                    lineLength = 0;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1407
                    break;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1408
                case '\t':
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1409
                    result.append(text, pos, i);
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1410
                    int spaceCount = tabLength - lineLength % tabLength;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1411
                    result.append(whitespace, 0, spaceCount);
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1412
                    lineLength += spaceCount;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1413
                    pos = i + 1;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1414
                    break;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1415
                default:
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1416
                    lineLength++;
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1417
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1418
        }
17571
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1419
        result.append(text, pos, textLength);
50895ba58e0d 8012180: Speed up removeNonInlineHtmlTags
jjg
parents: 17569
diff changeset
  1420
        return result.toString();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1421
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1422
36500
d31e4986dc8b 8149139: [javadoc] Modify Content to accept CharSequence
ksrini
parents: 36043
diff changeset
  1423
    public CharSequence normalizeNewlines(CharSequence text) {
19119
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1424
        StringBuilder sb = new StringBuilder();
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1425
        final int textLength = text.length();
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1426
        final String NL = DocletConstants.NL;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1427
        int pos = 0;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1428
        for (int i = 0; i < textLength; i++) {
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1429
            char ch = text.charAt(i);
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1430
            switch (ch) {
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1431
                case '\n':
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1432
                    sb.append(text, pos, i);
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1433
                    sb.append(NL);
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1434
                    pos = i + 1;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1435
                    break;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1436
                case '\r':
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1437
                    sb.append(text, pos, i);
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1438
                    sb.append(NL);
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1439
                    if (i + 1 < textLength && text.charAt(i + 1) == '\n')
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1440
                        i++;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1441
                    pos = i + 1;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1442
                    break;
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1443
            }
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1444
        }
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1445
        sb.append(text, pos, textLength);
36500
d31e4986dc8b 8149139: [javadoc] Modify Content to accept CharSequence
ksrini
parents: 36043
diff changeset
  1446
        return sb;
19119
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1447
    }
3c2e9a2bbed6 8014636: TestLiteralCodeInPre fails on windows
jjg
parents: 17571
diff changeset
  1448
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1449
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1450
     * The documentation for values() and valueOf() in Enums are set by the
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1451
     * doclet only iff the user or overridden methods are missing.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1452
     * @param elem
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1453
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1454
    public void setEnumDocumentation(TypeElement elem) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1455
        for (Element e : getMethods(elem)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1456
            ExecutableElement ee = (ExecutableElement)e;
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 40606
diff changeset
  1457
            if (!getFullBody(e).isEmpty()) // ignore if already set
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1458
                continue;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1459
            if (ee.getSimpleName().contentEquals("values") && ee.getParameters().isEmpty()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1460
                configuration.cmtUtils.setEnumValuesTree(configuration, e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1461
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1462
            if (ee.getSimpleName().contentEquals("valueOf") && ee.getParameters().size() == 1) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1463
                configuration.cmtUtils.setEnumValueOfTree(configuration, e);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1464
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1465
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1466
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1467
06bc494ca11e Initial load
duke
parents:
diff changeset
  1468
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1469
     * Returns a locale independent lower cased String. That is, it
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1470
     * always uses US locale, this is a clone of the one in StringUtils.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1471
     * @param s to convert
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1472
     * @return converted String
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1473
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1474
    public static String toLowerCase(String s) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1475
        return s.toLowerCase(Locale.US);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1476
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1477
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1478
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1479
     * Return true if the given Element is deprecated.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1480
     *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1481
     * @param e the Element to check.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1482
     * @return true if the given Element is deprecated.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1483
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1484
    public boolean isDeprecated(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1485
        if (isPackage(e)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1486
            return configuration.workArounds.isDeprecated0(e);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1487
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1488
        return elementUtils.isDeprecated(e);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1489
    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
  1490
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
  1491
    /**
42816
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1492
     * Return true if the given Element is deprecated for removal.
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1493
     *
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1494
     * @param e the Element to check.
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1495
     * @return true if the given Element is deprecated for removal.
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1496
     */
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1497
    public boolean isDeprecatedForRemoval(Element e) {
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1498
        List<? extends AnnotationMirror> annotationList = e.getAnnotationMirrors();
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1499
        JavacTypes jctypes = ((DocEnvImpl) configuration.docEnv).toolEnv.typeutils;
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1500
        for (AnnotationMirror anno : annotationList) {
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1501
            if (jctypes.isSameType(anno.getAnnotationType().asElement().asType(), getDeprecatedType())) {
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1502
                Map<? extends ExecutableElement, ? extends AnnotationValue> pairs = anno.getElementValues();
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1503
                if (!pairs.isEmpty()) {
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1504
                    for (ExecutableElement element : pairs.keySet()) {
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1505
                        if (element.getSimpleName().contentEquals("forRemoval")) {
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1506
                            return Boolean.parseBoolean((pairs.get(element)).toString());
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1507
                        }
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1508
                    }
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1509
                }
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1510
            }
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1511
        }
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1512
        return false;
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1513
    }
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1514
3638773ff1b0 8162674: change javadoc output text and style emitted by for-removal deprecations
bpatel
parents: 42277
diff changeset
  1515
    /**
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1516
     * 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
  1517
     * getter or setter method.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1518
     * @param e the input method.
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1519
     * @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
  1520
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1521
    public String propertyName(ExecutableElement e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1522
        String name = getSimpleName(e);
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1523
        String propertyName = null;
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1524
        if (name.startsWith("get") || name.startsWith("set")) {
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1525
            propertyName = name.substring(3);
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1526
        } else if (name.startsWith("is")) {
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1527
            propertyName = name.substring(2);
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1528
        }
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1529
        if ((propertyName == null) || propertyName.isEmpty()){
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1530
            return "";
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1531
        }
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 19667
diff changeset
  1532
        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
  1533
                + propertyName.substring(1);
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1534
    }
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1535
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1536
    /**
37009
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1537
     * Returns true if the element is included, contains &#64;hidden tag,
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1538
     * or if javafx flag is present and element contains &#64;treatAsPrivate
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1539
     * tag.
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1540
     * @param e the queried element
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1541
     * @return true if it exists, false otherwise
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1542
     */
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1543
    public boolean isHidden(Element e) {
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1544
        // prevent needless tests on elements which are not included
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1545
        if (!isIncluded(e)) {
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1546
            return false;
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1547
        }
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1548
        if (configuration.javafx &&
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1549
                hasBlockTag(e, DocTree.Kind.UNKNOWN_BLOCK_TAG, "treatAsPrivate")) {
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1550
            return true;
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1551
        }
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1552
        return hasBlockTag(e, DocTree.Kind.HIDDEN);
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1553
    }
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1554
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1555
    /**
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1556
     * In case of JavaFX mode on, filters out classes that are private,
37009
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1557
     * package private, these are not documented in JavaFX mode, also
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1558
     * remove those classes that have &#64;hidden or &#64;treatAsPrivate comment tag.
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1559
     *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1560
     * @param classlist a collection of TypeElements
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1561
     * @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
  1562
     * @return list of filtered classes.
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1563
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1564
    public SortedSet<TypeElement> filterOutPrivateClasses(Iterable<TypeElement> classlist,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1565
            boolean javafx) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1566
        SortedSet<TypeElement> filteredOutClasses =
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1567
                new TreeSet<>(makeGeneralPurposeComparator());
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1568
        if (!javafx) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1569
            for (Element te : classlist) {
37009
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1570
                if (!isHidden(te)) {
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1571
                    filteredOutClasses.add((TypeElement)te);
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1572
                }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1573
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1574
            return filteredOutClasses;
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1575
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1576
        for (Element e : classlist) {
37009
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  1577
            if (isPrivate(e) || isPackagePrivate(e) || isHidden(e)) {
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1578
                continue;
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1579
            }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1580
            filteredOutClasses.add((TypeElement)e);
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1581
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1582
        return filteredOutClasses;
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1583
    }
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1584
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 15385
diff changeset
  1585
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1586
     * Compares two elements.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1587
     * @param e1 first Element
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1588
     * @param e2 second Element
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1589
     * @return a true if they are the same, false otherwise.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
  1590
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1591
    public boolean elementsEqual(Element e1, Element e2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1592
        if (e1.getKind() != e2.getKind()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1593
            return false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1594
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1595
        String s1 = getSimpleName(e1);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1596
        String s2 = getSimpleName(e2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1597
        if (compareStrings(s1, s2) == 0) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1598
            String f1 = getFullyQualifiedName(e1, true);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1599
            String f2 = getFullyQualifiedName(e2, true);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1600
            return compareStrings(f1, f2) == 0;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1601
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1602
        return false;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14542
diff changeset
  1603
    }
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1604
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1605
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1606
     * A general purpose case insensitive String comparator, which compares
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1607
     * two Strings using a Collator strength of "TERTIARY".
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1608
     *
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1609
     * @param s1 first String to compare.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1610
     * @param s2 second String to compare.
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1611
     * @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
  1612
     *         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
  1613
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1614
    public int compareStrings(String s1, String s2) {
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1615
        return compareStrings(true, s1, s2);
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1616
    }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1617
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1618
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1619
     * A general purpose case sensitive String comparator, which
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1620
     * compares two Strings using a Collator strength of "SECONDARY".
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1621
     *
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1622
     * @param s1 first String to compare.
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1623
     * @param s2 second String to compare.
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1624
     * @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
  1625
     *         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
  1626
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1627
    public int compareCaseCompare(String s1, String s2) {
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1628
        return compareStrings(false, s1, s2);
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1629
    }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1630
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1631
    private DocCollator tertiaryCollator = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1632
    private DocCollator secondaryCollator = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1633
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1634
    private int compareStrings(boolean caseSensitive, String s1, String s2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1635
        if (caseSensitive) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1636
            if (tertiaryCollator == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1637
                tertiaryCollator = new DocCollator(configuration.locale, Collator.TERTIARY);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1638
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1639
            return tertiaryCollator.compare(s1, s2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1640
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1641
        if (secondaryCollator == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1642
            secondaryCollator = new DocCollator(configuration.locale, Collator.SECONDARY);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1643
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1644
        return secondaryCollator.compare(s1, s2);
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1645
    }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1646
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1647
    private static class DocCollator {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1648
        private final Map<String, CollationKey> keys;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1649
        private final Collator instance;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1650
        private final int MAX_SIZE = 1000;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1651
        private DocCollator(Locale locale, int strength) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1652
            instance = Collator.getInstance(locale);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1653
            instance.setStrength(strength);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1654
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1655
            keys = new LinkedHashMap<String, CollationKey>(MAX_SIZE + 1, 0.75f, true) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1656
                private static final long serialVersionUID = 1L;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1657
                @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1658
                protected boolean removeEldestEntry(Entry<String, CollationKey> eldest) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1659
                    return size() > MAX_SIZE;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1660
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1661
            };
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1662
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1663
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1664
        CollationKey getKey(String s) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1665
            return keys.computeIfAbsent(s, instance :: getCollationKey);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1666
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1667
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1668
        public int compare(String s1, String s2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1669
            return getKey(s1).compareTo(getKey(s2));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1670
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1671
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1672
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
  1673
    /**
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  1674
     * Comparator for ModuleElements, simply compares the fully qualified names
37752
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1675
     * @return a Comparator
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  1676
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  1677
    public Comparator<Element> makeModuleComparator() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  1678
        return new Utils.ElementComparator<Element>() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  1679
            @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  1680
            public int compare(Element mod1, Element mod2) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  1681
                return compareFullyQualifiedNames(mod1, mod2);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  1682
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  1683
        };
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  1684
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  1685
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  1686
    /**
37752
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1687
     * Returns a Comparator for all classes, compares the simple names of
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1688
     * TypeElement, if equal then the fully qualified names.
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1689
     *
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1690
     * @return Comparator
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1691
     */
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1692
    public Comparator<Element> makeAllClassesComparator() {
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1693
        return new Utils.ElementComparator<Element>() {
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1694
            @Override
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1695
            public int compare(Element e1, Element e2) {
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1696
                int result =  compareNames(e1, e2);
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1697
                if (result == 0)
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1698
                    result =  compareFullyQualifiedNames(e1, e2);
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1699
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1700
                return result;
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1701
            }
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1702
        };
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1703
    }
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1704
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1705
    /**
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1706
     * Returns a Comparator for packages, by comparing the fully qualified names.
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1707
     *
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1708
     * @return a Comparator
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1709
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1710
    public Comparator<Element> makePackageComparator() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1711
        return new Utils.ElementComparator<Element>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1712
            @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1713
            public int compare(Element pkg1, Element pkg2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1714
                return compareFullyQualifiedNames(pkg1, pkg2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1715
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1716
        };
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1717
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1718
37752
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1719
    /**
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1720
     * Returns a Comparator for SerialFieldTree.
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1721
     * @return a Comparator
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1722
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1723
    public Comparator<SerialFieldTree> makeSerialFieldTreeComparator() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1724
        return (SerialFieldTree o1, SerialFieldTree o2) -> {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1725
            String s1 = o1.getName().toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1726
            String s2 = o2.getName().toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1727
            return s1.compareTo(s2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1728
        };
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1729
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1730
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1731
    /**
37752
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1732
     * Returns a general purpose comparator.
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1733
     * @return a Comparator
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
  1734
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1735
    public Comparator<Element> makeGeneralPurposeComparator() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1736
        return makeClassUseComparator();
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
  1737
    }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1738
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1739
    /**
37752
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1740
     * Returns a Comparator for overrides and implements,
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1741
     * used primarily on methods, compares the name first,
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1742
     * then compares the simple names of the enclosing
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1743
     * TypeElement and the fully qualified name of the enclosing TypeElement.
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1744
     * @return a Comparator
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1745
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1746
    public Comparator<Element> makeOverrideUseComparator() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1747
        return new Utils.ElementComparator<Element>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1748
            @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1749
            public int compare(Element o1, Element o2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1750
                int result = compareStrings(getSimpleName(o1), getSimpleName(o2));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1751
                if (result != 0) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1752
                    return result;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1753
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1754
                if (!isTypeElement(o1) && !isTypeElement(o2) && !isPackage(o1) && !isPackage(o2)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1755
                    TypeElement t1 = getEnclosingTypeElement(o1);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1756
                    TypeElement t2 = getEnclosingTypeElement(o2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1757
                    result = compareStrings(getSimpleName(t1), getSimpleName(t2));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1758
                    if (result != 0)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1759
                        return result;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1760
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1761
                result = compareStrings(getFullyQualifiedName(o1), getFullyQualifiedName(o2));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1762
                if (result != 0)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1763
                    return result;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1764
                return compareElementTypeKinds(o1, o2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1765
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1766
        };
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1767
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1768
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1769
    /**
37752
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1770
     * Returns a Comparator for index file presentations, and are sorted as follows.
40511
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1771
     *  If comparing modules then simply compare the simple names,
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1772
     *  comparing packages then simply compare the qualified names, otherwise
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1773
     *  1. if equal, then compare the ElementKind ex: Module, Package, Interface etc.
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1774
     *  2. sort on simple names of entities
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1775
     *  3a. if equal and if the type is of ExecutableElement(Constructor, Methods),
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
  1776
     *      a case insensitive comparison of parameter the type signatures
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
  1777
     *  3b. if equal, case sensitive comparison of the type signatures
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
  1778
     *  4. finally, if equal, compare the FQNs of the entities
37752
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1779
     * Iff comparing packages then simply sort on qualified names.
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1780
     * @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
  1781
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1782
    public Comparator<Element> makeIndexUseComparator() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1783
        return new Utils.ElementComparator<Element>() {
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1784
            /**
40511
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1785
             * Compare two given elements, if comparing two modules, return the
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1786
             * comparison of SimpleName, if comparing two packages, return the
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1787
             * comparison of FullyQualifiedName, first sort on kinds, then on the
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1788
             * names, then on the parameters only if the type is an ExecutableElement,
37752
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1789
             * the parameters are compared and finally the qualified names.
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1790
             *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1791
             * @param e1 - an element.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1792
             * @param e2 - an element.
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1793
             * @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
  1794
             *         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
  1795
             */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1796
            @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1797
            public int compare(Element e1, Element e2) {
37752
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1798
                int result = 0;
40511
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1799
                if (isModule(e1) && isModule(e2)) {
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1800
                    return compareNames(e1, e2);
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1801
                }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1802
                if (isPackage(e1) && isPackage(e2)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1803
                    return compareFullyQualifiedNames(e1, e2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1804
                }
40511
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1805
                result = compareElementTypeKinds(e1, e2);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1806
                if (result != 0) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1807
                    return result;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1808
                }
40511
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1809
                result = compareNames(e1, e2);
37752
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1810
                if (result != 0) {
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1811
                    return result;
4243173b58db 8155061: javadoc incorrectly sorted items in All Classes list and Index files
ksrini
parents: 37009
diff changeset
  1812
                }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1813
                if (hasParameters(e1)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1814
                    List<? extends VariableElement> parameters1 = ((ExecutableElement)e1).getParameters();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1815
                    List<? extends VariableElement> parameters2 = ((ExecutableElement)e2).getParameters();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1816
                    result = compareParameters(false, parameters1, parameters2);
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1817
                    if (result != 0) {
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1818
                        return result;
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1819
                    }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1820
                    result = compareParameters(true, parameters1, parameters2);
25300
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
  1821
                    if (result != 0) {
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
  1822
                        return result;
3b8a5067fe29 8047162: [javadoc] index files are non deterministic
ksrini
parents: 25004
diff changeset
  1823
                    }
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1824
                }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1825
                return compareFullyQualifiedNames(e1, e2);
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1826
            }
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1827
        };
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1828
    }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1829
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1830
    /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1831
     * Compares the FullyQualifiedNames of two TypeMirrors
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1832
     * @return
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1833
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1834
    public Comparator<TypeMirror> makeTypeMirrorClassUseComparator() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1835
        return (TypeMirror type1, TypeMirror type2) -> {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1836
            String s1 = getQualifiedTypeName(type1);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1837
            String s2 = getQualifiedTypeName(type2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1838
            return compareStrings(s1, s2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1839
        };
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1840
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1841
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1842
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1843
     * Compares the SimpleNames of TypeMirrors if equal then the
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1844
     * FullyQualifiedNames of TypeMirrors.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1845
     *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1846
     * @return
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1847
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1848
    public Comparator<TypeMirror> makeTypeMirrorIndexUseComparator() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1849
        return (TypeMirror t1, TypeMirror t2) -> {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1850
            int result = compareStrings(getTypeName(t1, false), getTypeName(t2, false));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1851
            if (result != 0)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1852
                return result;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1853
            return compareStrings(getQualifiedTypeName(t1), getQualifiedTypeName(t2));
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1854
        };
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1855
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1856
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1857
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1858
     * Get the qualified type name of a TypeMiror compatible with the Element's
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1859
     * getQualified name, returns  the qualified name of the Reference type
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1860
     * otherwise the primitive name.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1861
     * @param t the type whose name is to be obtained.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1862
     * @return the fully qualified name of Reference type or the primitive name
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1863
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1864
    public String getQualifiedTypeName(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1865
        return new SimpleTypeVisitor9<String, Void>() {
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1866
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1867
            public String visitDeclared(DeclaredType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1868
                return getFullyQualifiedName(t.asElement());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1869
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1870
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1871
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1872
            public String visitArray(ArrayType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1873
               return visit(t.getComponentType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1874
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1875
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1876
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1877
            public String visitPrimitive(PrimitiveType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1878
                return t.toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1879
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1880
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1881
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1882
            public String visitTypeVariable(javax.lang.model.type.TypeVariable t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1883
                // The knee jerk reaction is to do this but don't!, as we would like
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1884
                // it to be compatible with the old world, now if we decide to do so
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1885
                // care must be taken to avoid collisions.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1886
                // return getFullyQualifiedName(t.asElement());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1887
                return t.toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1888
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1889
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  1890
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1891
            protected String defaultAction(TypeMirror e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1892
                throw new UnsupportedOperationException("should not happen");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1893
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1894
        }.visit(t);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1895
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1896
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1897
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1898
     * A generic utility which returns the fully qualified names of an entity,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1899
     * if the entity is not qualifiable then its enclosing entity, it is upto
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1900
     * the caller to add the elements name as required.
36500
d31e4986dc8b 8149139: [javadoc] Modify Content to accept CharSequence
ksrini
parents: 36043
diff changeset
  1901
     * @param e the element to get FQN for.
d31e4986dc8b 8149139: [javadoc] Modify Content to accept CharSequence
ksrini
parents: 36043
diff changeset
  1902
     * @return the name
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1903
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1904
    public String getFullyQualifiedName(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1905
        return getFullyQualifiedName(e, true);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1906
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1907
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1908
    public String getFullyQualifiedName(Element e, final boolean outer) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1909
        return new SimpleElementVisitor9<String, Void>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1910
            @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1911
            public String visitPackage(PackageElement e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1912
                return e.getQualifiedName().toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1913
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1914
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1915
            @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1916
            public String visitType(TypeElement e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1917
                return e.getQualifiedName().toString();
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1918
            }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1919
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1920
            @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1921
            protected String defaultAction(Element e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1922
                return outer ? visit(e.getEnclosingElement()) : e.getSimpleName().toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1923
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1924
        }.visit(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1925
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1926
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1927
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1928
     * Comparator for ClassUse presentations, and sorts as follows:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1929
     * 1. member names
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1930
     * 2. then fully qualified member names
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1931
     * 3. then parameter types if applicable
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1932
     * 4. finally the element kinds ie. package, class, interface etc.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1933
     * @return a comparator to sort classes and members for class use
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1934
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1935
    public Comparator<Element> makeClassUseComparator() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1936
        return new Utils.ElementComparator<Element>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1937
            /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1938
             * Compare two Elements, first sort on simple name, and if
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1939
             * applicable on the fully qualified name, and finally if applicable
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1940
             * on the parameter types.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1941
             * @param e1 - an element.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1942
             * @param e2 - an element.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1943
             * @return a negative integer, zero, or a positive integer as the first
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1944
             *         argument is less than, equal to, or greater than the second.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1945
             */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1946
            @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1947
            public int compare(Element e1, Element e2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1948
                int result = compareNames(e1, e2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1949
                if (result != 0) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1950
                    return result;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1951
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1952
                result = compareFullyQualifiedNames(e1, e2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1953
                if (result != 0) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1954
                    return result;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1955
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1956
                if (hasParameters(e1) && hasParameters(e2)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1957
                    @SuppressWarnings("unchecked")
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1958
                    List<VariableElement> parameters1 = (List<VariableElement>) ((ExecutableElement)e1).getParameters();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1959
                    @SuppressWarnings("unchecked")
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1960
                    List<VariableElement> parameters2 = (List<VariableElement>) ((ExecutableElement)e2).getParameters();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1961
                    result =  compareParameters(false, parameters1, parameters2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1962
                    if (result != 0) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1963
                        return result;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1964
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1965
                    result =  compareParameters(true, parameters1, parameters2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1966
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1967
                if (result != 0) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1968
                    return result;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1969
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1970
                return compareElementTypeKinds(e1, e2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1971
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1972
        };
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1973
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1974
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1975
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1976
     * A general purpose comparator to sort Element entities, basically provides the building blocks
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1977
     * for creating specific comparators for an use-case.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1978
     * @param <T> an Element
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1979
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1980
    private abstract class ElementComparator<T extends Element> implements Comparator<Element> {
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  1981
        /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1982
         * compares two parameter arrays by first comparing the length of the arrays, and
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1983
         * then each Type of the parameter in the array.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1984
         * @param params1 the first parameter array.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1985
         * @param params2 the first parameter array.
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  1986
         * @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
  1987
         *         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
  1988
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1989
        final EnumMap<ElementKind, Integer> elementKindOrder;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1990
        public ElementComparator() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  1991
            elementKindOrder = new EnumMap<>(ElementKind.class);
40511
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1992
            elementKindOrder.put(ElementKind.MODULE, 0);
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1993
            elementKindOrder.put(ElementKind.PACKAGE, 1);
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1994
            elementKindOrder.put(ElementKind.CLASS, 2);
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1995
            elementKindOrder.put(ElementKind.ENUM, 3);
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1996
            elementKindOrder.put(ElementKind.ENUM_CONSTANT, 4);
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1997
            elementKindOrder.put(ElementKind.INTERFACE, 5);
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1998
            elementKindOrder.put(ElementKind.ANNOTATION_TYPE, 6);
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  1999
            elementKindOrder.put(ElementKind.FIELD, 7);
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  2000
            elementKindOrder.put(ElementKind.CONSTRUCTOR, 8);
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  2001
            elementKindOrder.put(ElementKind.METHOD, 9);
25004
b33effe4f252 8042829: [javadoc] index-file output is not sorted correctly
ksrini
parents: 24394
diff changeset
  2002
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2003
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2004
        protected int compareParameters(boolean caseSensitive, List<? extends VariableElement> params1,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2005
                                                               List<? extends VariableElement> params2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2006
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2007
            return compareStrings(caseSensitive, getParametersAsString(params1),
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2008
                                                 getParametersAsString(params2));
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
  2009
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2010
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2011
        String getParametersAsString(List<? extends VariableElement> params) {
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
  2012
            StringBuilder sb = new StringBuilder();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2013
            for (VariableElement param : params) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2014
                TypeMirror t = param.asType();
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
  2015
                // prefix P for primitive and R for reference types, thus items will
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2016
                // be ordered lexically and correctly.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2017
                sb.append(getTypeCode(t)).append("-").append(t).append("-");
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  2018
            }
25449
3c14a2e16bd6 8049393: [javadoc] parameters are not sorted correctly
ksrini
parents: 25300
diff changeset
  2019
            return sb.toString();
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  2020
        }
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  2021
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2022
        private String getTypeCode(TypeMirror t) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2023
            return new SimpleTypeVisitor9<String, Void>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2024
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2025
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2026
                public String visitPrimitive(PrimitiveType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2027
                    return "P";
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2028
                }
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2029
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2030
                public String visitArray(ArrayType t, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2031
                    return visit(t.getComponentType());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2032
                }
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2033
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2034
                protected String defaultAction(TypeMirror e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2035
                    return "R";
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2036
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2037
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2038
            }.visit(t);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2039
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2040
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  2041
        /**
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2042
         * Compares two Elements, typically the name of a method,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2043
         * field or constructor.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2044
         * @param e1 the first Element.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2045
         * @param e2 the second Element.
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  2046
         * @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
  2047
         *         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
  2048
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2049
        protected int compareNames(Element e1, Element e2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2050
            return compareStrings(getSimpleName(e1), getSimpleName(e2));
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  2051
        }
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  2052
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  2053
        /**
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  2054
         * Compares the fully qualified names of the entities
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2055
         * @param e1 the first Element.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2056
         * @param e2 the first Element.
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  2057
         * @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
  2058
         *         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
  2059
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2060
        protected int compareFullyQualifiedNames(Element e1, Element e2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2061
            // add simplename to be compatible
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2062
            String thisElement = getFullyQualifiedName(e1);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2063
            String thatElement = getFullyQualifiedName(e2);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2064
            return compareStrings(thisElement, thatElement);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2065
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2066
        protected int compareElementTypeKinds(Element e1, Element e2) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2067
            return Integer.compare(elementKindOrder.get(e1.getKind()),
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2068
                                   elementKindOrder.get(e2.getKind()));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2069
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2070
        boolean hasParameters(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2071
            return new SimpleElementVisitor9<Boolean, Void>() {
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2072
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2073
                public Boolean visitExecutable(ExecutableElement e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2074
                    return true;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2075
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2076
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2077
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2078
                protected Boolean defaultAction(Element e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2079
                    return false;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2080
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2081
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2082
            }.visit(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2083
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2084
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2085
        /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2086
         * The fully qualified names of the entities, used solely by the comparator.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2087
         *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2088
         * @param p1 the first Element.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2089
         * @param p2 the first Element.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2090
         * @return a negative integer, zero, or a positive integer as the first argument is less
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2091
         * than, equal to, or greater than the second.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2092
         */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2093
        private String getFullyQualifiedName(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2094
            return new SimpleElementVisitor9<String, Void>() {
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2095
                @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  2096
                public String visitModule(ModuleElement e, Void p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  2097
                    return e.getQualifiedName().toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  2098
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36500
diff changeset
  2099
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2100
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2101
                public String visitPackage(PackageElement e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2102
                    return e.getQualifiedName().toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2103
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2104
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2105
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2106
                public String visitExecutable(ExecutableElement e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2107
                    // For backward compatibility
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2108
                    return getFullyQualifiedName(e.getEnclosingElement())
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2109
                            + "." + e.getSimpleName().toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2110
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2111
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2112
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2113
                public String visitType(TypeElement e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2114
                    return e.getQualifiedName().toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2115
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2116
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2117
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2118
                protected String defaultAction(Element e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2119
                    return getEnclosingTypeElement(e).getQualifiedName().toString()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2120
                            + "." + e.getSimpleName().toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2121
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2122
            }.visit(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2123
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2124
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2125
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2126
    public Iterable<TypeElement> getEnclosedTypeElements(PackageElement pkg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2127
        List<TypeElement> out = getInterfaces(pkg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2128
        out.addAll(getClasses(pkg));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2129
        out.addAll(getEnums(pkg));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2130
        out.addAll(getAnnotationTypes(pkg));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2131
        return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2132
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2133
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2134
    // Element related methods
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2135
    public List<Element> getAnnotationMembers(TypeElement aClass) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2136
        List<Element> members = getAnnotationFields(aClass);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2137
        members.addAll(getAnnotationMethods(aClass));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2138
        return members;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2139
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2140
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2141
    public List<Element> getAnnotationFields(TypeElement aClass) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2142
        return getItems0(aClass, true, FIELD);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2143
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2144
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2145
    List<Element> getAnnotationFieldsUnfiltered(TypeElement aClass) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2146
        return getItems0(aClass, true, FIELD);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2147
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2148
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2149
    public List<Element> getAnnotationMethods(TypeElement aClass) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2150
        return getItems0(aClass, true, METHOD);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2151
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2152
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2153
    public List<TypeElement> getAnnotationTypes(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2154
        return convertToTypeElement(getItems(e, true, ANNOTATION_TYPE));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2155
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2156
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2157
    public List<TypeElement> getAnnotationTypesUnfiltered(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2158
        return convertToTypeElement(getItems(e, false, ANNOTATION_TYPE));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2159
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2160
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2161
    public List<VariableElement> getFields(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2162
        return convertToVariableElement(getItems(e, true, FIELD));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2163
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2164
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2165
    public List<VariableElement> getFieldsUnfiltered(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2166
        return convertToVariableElement(getItems(e, false, FIELD));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2167
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2168
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2169
    public List<TypeElement> getClasses(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2170
       return convertToTypeElement(getItems(e, true, CLASS));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2171
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2172
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2173
    public List<TypeElement> getClassesUnfiltered(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2174
       return convertToTypeElement(getItems(e, false, CLASS));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2175
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2176
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2177
    public List<ExecutableElement> getConstructors(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2178
        return convertToExecutableElement(getItems(e, true, CONSTRUCTOR));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2179
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2180
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2181
    public List<ExecutableElement> getMethods(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2182
        return convertToExecutableElement(getItems(e, true, METHOD));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2183
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2184
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2185
    List<ExecutableElement> getMethodsUnfiltered(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2186
        return convertToExecutableElement(getItems(e, false, METHOD));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2187
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2188
42000
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 41452
diff changeset
  2189
    public int getOrdinalValue(VariableElement member) {
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 41452
diff changeset
  2190
        if (member == null || member.getKind() != ENUM_CONSTANT) {
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 41452
diff changeset
  2191
            throw new IllegalArgumentException("must be an enum constant: " + member);
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 41452
diff changeset
  2192
        }
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 41452
diff changeset
  2193
        return member.getEnclosingElement().getEnclosedElements().indexOf(member);
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 41452
diff changeset
  2194
    }
8b7412f7eecd 8167967: javadoc should identify the ordinal value of enum constants
ksrini
parents: 41452
diff changeset
  2195
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2196
    public long getLineNumber(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2197
        TreePath path = getTreePath(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2198
        if (path == null) { // maybe null if synthesized
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2199
            TypeElement encl = getEnclosingTypeElement(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2200
            path = getTreePath(encl);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2201
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2202
        CompilationUnitTree cu = path.getCompilationUnit();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2203
        LineMap lineMap = cu.getLineMap();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2204
        DocSourcePositions spos = docTrees.getSourcePositions();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2205
        long pos = spos.getStartPosition(cu, path.getLeaf());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2206
        return lineMap.getLineNumber(pos);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2207
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2208
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2209
    public List<ExecutableElement> convertToExecutableElement(List<Element> list) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2210
        List<ExecutableElement> out = new ArrayList<>(list.size());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2211
        for (Element e : list) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2212
            out.add((ExecutableElement)e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2213
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2214
        return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2215
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2216
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2217
    public List<TypeElement> convertToTypeElement(List<Element> list) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2218
        List<TypeElement> out = new ArrayList<>(list.size());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2219
        for (Element e : list) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2220
            out.add((TypeElement)e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2221
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2222
        return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2223
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2224
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2225
    public List<VariableElement> convertToVariableElement(List<Element> list) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2226
        List<VariableElement> out = new ArrayList<>(list.size());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2227
        for (Element e : list) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2228
            out.add((VariableElement) e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2229
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2230
        return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2231
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2232
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2233
    public List<TypeElement> getInterfaces(Element e)  {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2234
        return convertToTypeElement(getItems(e, true, INTERFACE));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2235
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2236
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2237
    public List<TypeElement> getInterfacesUnfiltered(Element e)  {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2238
        return convertToTypeElement(getItems(e, false, INTERFACE));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2239
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2240
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2241
    List<Element> getNestedClasses(TypeElement e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2242
        List<Element> result = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2243
        recursiveGetItems(result, e, true, CLASS);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2244
        return result;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2245
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2246
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2247
    List<Element> getNestedClassesUnfiltered(TypeElement e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2248
        List<Element> result = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2249
        recursiveGetItems(result, e, false, CLASS);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2250
        return result;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2251
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2252
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2253
    public List<Element> getEnumConstants(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2254
        return getItems(e, true, ENUM_CONSTANT);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2255
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2256
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2257
    public List<TypeElement> getEnums(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2258
        return convertToTypeElement(getItems(e, true, ENUM));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2259
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2260
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2261
    public List<TypeElement> getEnumsUnfiltered(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2262
        return convertToTypeElement(getItems(e, false, ENUM));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2263
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2264
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2265
    public SortedSet<TypeElement> getAllClassesUnfiltered(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2266
        List<TypeElement> clist = getClassesUnfiltered(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2267
        clist.addAll(getInterfacesUnfiltered(e));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2268
        clist.addAll(getAnnotationTypesUnfiltered(e));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2269
        SortedSet<TypeElement> oset = new TreeSet<>(makeGeneralPurposeComparator());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2270
        oset.addAll(clist);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2271
        return oset;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2272
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2273
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2274
    private final HashMap<Element, SortedSet<TypeElement>> cachedClasses = new HashMap<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2275
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2276
     * Returns a list containing classes and interfaces,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2277
     * including annotation types.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2278
     * @param e Element
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2279
     * @return List
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2280
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2281
    public SortedSet<TypeElement> getAllClasses(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2282
        SortedSet<TypeElement> oset = cachedClasses.get(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2283
        if (oset != null)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2284
            return oset;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2285
        List<TypeElement> clist = getClasses(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2286
        clist.addAll(getInterfaces(e));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2287
        clist.addAll(getAnnotationTypes(e));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2288
        clist.addAll(getEnums(e));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2289
        oset = new TreeSet<>(makeGeneralPurposeComparator());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2290
        oset.addAll(clist);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2291
        cachedClasses.put(e, oset);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2292
        return oset;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2293
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2294
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2295
    /*
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2296
     * Get all the elements unfiltered and filter them finally based
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2297
     * on its visibility, this works differently from the other getters.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2298
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2299
    private List<TypeElement> getInnerClasses(Element e, boolean filter) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2300
        List<TypeElement> olist = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2301
        for (TypeElement te : getClassesUnfiltered(e)) {
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2302
            if (!filter || configuration.docEnv.isSelected(te)) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2303
                olist.add(te);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2304
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2305
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2306
        for (TypeElement te : getInterfacesUnfiltered(e)) {
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2307
            if (!filter || configuration.docEnv.isSelected(te)) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2308
                olist.add(te);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2309
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2310
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2311
        for (TypeElement te : getAnnotationTypesUnfiltered(e)) {
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2312
            if (!filter || configuration.docEnv.isSelected(te)) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2313
                olist.add(te);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2314
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2315
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2316
        for (TypeElement te : getEnumsUnfiltered(e)) {
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2317
            if (!filter || configuration.docEnv.isSelected(te)) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2318
                olist.add(te);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2319
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2320
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2321
        return olist;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2322
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2323
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2324
    public List<TypeElement> getInnerClasses(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2325
        return getInnerClasses(e, true);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2326
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2327
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2328
    public List<TypeElement> getInnerClassesUnfiltered(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2329
        return getInnerClasses(e, false);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2330
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2331
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2332
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2333
     * Returns a list of classes that are not errors or exceptions
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2334
     * @param e Element
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2335
     * @return List
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2336
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2337
    public List<TypeElement> getOrdinaryClasses(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2338
        return getClasses(e).stream()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2339
                .filter(te -> (!isException(te) && !isError(te)))
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2340
                .collect(Collectors.toList());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2341
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2342
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2343
    public List<TypeElement> getErrors(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2344
        return getClasses(e)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2345
                .stream()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2346
                .filter(this::isError)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2347
                .collect(Collectors.toList());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2348
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2349
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2350
    public List<TypeElement> getExceptions(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2351
        return getClasses(e)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2352
                .stream()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2353
                .filter(this::isException)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2354
                .collect(Collectors.toList());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2355
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2356
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2357
    List<Element> getItems(Element e, boolean filter, ElementKind select) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2358
        List<Element> elements = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2359
        // maintain backward compatibility by returning a null list, see AnnotationDocType.methods().
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2360
        if (configuration.backwardCompatibility && e.getKind() == ANNOTATION_TYPE)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2361
            return elements;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2362
        return new SimpleElementVisitor9<List<Element>, Void>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2363
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2364
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2365
            public List<Element> visitPackage(PackageElement e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2366
                recursiveGetItems(elements, e, filter, select);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2367
                return elements;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2368
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2369
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2370
            @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2371
            protected List<Element> defaultAction(Element e0, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2372
                return getItems0(e0, filter, select);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2373
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2374
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2375
        }.visit(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2376
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2377
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2378
    EnumSet<ElementKind> nestedKinds = EnumSet.of(ANNOTATION_TYPE, CLASS, ENUM, INTERFACE);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2379
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2380
    void recursiveGetItems(Collection<Element> list, Element e, boolean filter, ElementKind... select) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2381
        list.addAll(getItems0(e, filter, select));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2382
        List<Element> classes = getItems0(e, filter, nestedKinds);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2383
        for (Element c : classes) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2384
            list.addAll(getItems0(c, filter, select));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2385
            if (isTypeElement(c)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2386
                recursiveGetItems(list, c, filter, select);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2387
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2388
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2389
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2390
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2391
    private List<Element> getItems0(Element te, boolean filter, ElementKind... select) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2392
        EnumSet<ElementKind> kinds = EnumSet.copyOf(Arrays.asList(select));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2393
        return getItems0(te, filter, kinds);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2394
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2395
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2396
    private List<Element> getItems0(Element te, boolean filter, Set<ElementKind> kinds) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2397
        List<Element> elements = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2398
        for (Element e : te.getEnclosedElements()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2399
            if (kinds.contains(e.getKind())) {
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2400
                if (!filter || shouldDocument(e)) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2401
                    elements.add(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2402
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2403
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2404
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2405
        return elements;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2406
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2407
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2408
    private SimpleElementVisitor9<Boolean, Void> shouldDocumentVisitor = null;
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2409
    private boolean shouldDocument(Element e) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2410
        if (shouldDocumentVisitor == null) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2411
            shouldDocumentVisitor = new SimpleElementVisitor9<Boolean, Void>() {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2412
                private boolean hasSource(TypeElement e) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2413
                    return configuration.docEnv.getFileKind(e) ==
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2414
                            javax.tools.JavaFileObject.Kind.SOURCE;
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2415
                }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2416
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2417
                // handle types
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2418
                @Override
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2419
                public Boolean visitType(TypeElement e, Void p) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2420
                    return configuration.docEnv.isSelected(e) && hasSource(e);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2421
                }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2422
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2423
                // handle everything else
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2424
                @Override
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2425
                protected Boolean defaultAction(Element e, Void p) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2426
                    return configuration.docEnv.isSelected(e);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2427
                }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2428
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2429
                @Override
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2430
                public Boolean visitUnknown(Element e, Void p) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2431
                    throw new AssertionError("unkown element: " + p);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2432
                }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2433
            };
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2434
        }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2435
        return shouldDocumentVisitor.visit(e);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2436
    }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2437
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2438
    /*
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2439
     * nameCache is maintained for improving the comparator
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2440
     * performance, noting that the Collator used by the comparators
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2441
     * use Strings, as of this writing.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2442
     * TODO: when those APIs handle charSequences, the use of
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2443
     * this nameCache must be re-investigated and removed.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2444
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2445
    private final Map<Element, String> nameCache = new LinkedHashMap<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2446
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2447
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2448
     * Returns the name of the element after the last dot of the package name.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2449
     * This emulates the behavior of the old doclet.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2450
     * @param e an element whose name is required
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2451
     * @return the name
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2452
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2453
    public String getSimpleName(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2454
        return nameCache.computeIfAbsent(e, this::getSimpleName0);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2455
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2456
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2457
    private SimpleElementVisitor9<String, Void> snvisitor = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2458
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2459
    private String getSimpleName0(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2460
        if (snvisitor == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2461
            snvisitor = new SimpleElementVisitor9<String, Void>() {
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2462
                @Override
40511
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  2463
                public String visitModule(ModuleElement e, Void p) {
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  2464
                    return e.getSimpleName().toString();
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  2465
                }
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  2466
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2467
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2468
                public String visitType(TypeElement e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2469
                    StringBuilder sb = new StringBuilder(e.getSimpleName());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2470
                    Element enclosed = e.getEnclosingElement();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2471
                    while (enclosed != null
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2472
                            && (enclosed.getKind().isClass() || enclosed.getKind().isInterface())) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2473
                        sb.insert(0, enclosed.getSimpleName() + ".");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2474
                        enclosed = enclosed.getEnclosingElement();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2475
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2476
                    return sb.toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2477
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2478
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2479
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2480
                public String visitExecutable(ExecutableElement e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2481
                    if (e.getKind() == CONSTRUCTOR || e.getKind() == STATIC_INIT) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2482
                        return e.getEnclosingElement().getSimpleName().toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2483
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2484
                    return e.getSimpleName().toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2485
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2486
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2487
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2488
                protected String defaultAction(Element e, Void p) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2489
                    return e.getSimpleName().toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2490
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2491
            };
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2492
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2493
        return snvisitor.visit(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2494
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2495
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2496
    public TypeElement getEnclosingTypeElement(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2497
        if (e.getKind() == ElementKind.PACKAGE)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2498
            return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2499
        Element encl = e.getEnclosingElement();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2500
        ElementKind kind = encl.getKind();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2501
        if (kind == ElementKind.PACKAGE)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2502
            return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2503
        while (!(kind.isClass() || kind.isInterface())) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2504
            encl = encl.getEnclosingElement();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2505
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2506
        return (TypeElement)encl;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2507
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2508
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2509
    private ConstantValueExpression cve = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2510
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2511
    public String constantValueExpresion(VariableElement ve) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2512
        if (cve == null)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2513
            cve = new ConstantValueExpression();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2514
        return cve.constantValueExpression(configuration.workArounds, ve);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2515
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2516
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2517
    private static class ConstantValueExpression {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2518
        public String constantValueExpression(WorkArounds workArounds, VariableElement ve) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2519
            return new TypeKindVisitor9<String, Object>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2520
                /* TODO: we need to fix this correctly.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2521
                 * we have a discrepancy here, note the use of getConstValue
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2522
                 * vs. getConstantValue, at some point we need to use
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2523
                 * getConstantValue.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2524
                 * In the legacy world byte and char primitives appear as Integer values,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2525
                 * thus a byte value of 127 will appear as 127, but in the new world,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2526
                 * a byte value appears as Byte thus 0x7f will be printed, similarly
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2527
                 * chars will be  translated to \n, \r etc. however, in the new world,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2528
                 * they will be printed as decimal values. The new world is correct,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2529
                 * and we should fix this by using getConstantValue and the visitor to
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2530
                 * address this in the future.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2531
                 */
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2532
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2533
                public String visitPrimitiveAsBoolean(PrimitiveType t, Object val) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2534
                    return (int)val == 0 ? "false" : "true";
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2535
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2536
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2537
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2538
                public String visitPrimitiveAsDouble(PrimitiveType t, Object val) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2539
                    return sourceForm(((Double)val), 'd');
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2540
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2541
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2542
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2543
                public String visitPrimitiveAsFloat(PrimitiveType t, Object val) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2544
                    return sourceForm(((Float)val).doubleValue(), 'f');
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2545
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2546
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2547
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2548
                public String visitPrimitiveAsLong(PrimitiveType t, Object val) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2549
                    return val + "L";
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2550
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2551
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2552
                @Override
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2553
                protected String defaultAction(TypeMirror e, Object val) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2554
                    if (val == null)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2555
                        return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2556
                    else if (val instanceof Character)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2557
                        return sourceForm(((Character)val));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2558
                    else if (val instanceof Byte)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2559
                        return sourceForm(((Byte)val));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2560
                    else if (val instanceof String)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2561
                        return sourceForm((String)val);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2562
                    return val.toString(); // covers int, short
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2563
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2564
            }.visit(ve.asType(), workArounds.getConstValue(ve));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2565
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2566
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2567
        // where
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2568
        private String sourceForm(double v, char suffix) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2569
            if (Double.isNaN(v))
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2570
                return "0" + suffix + "/0" + suffix;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2571
            if (v == Double.POSITIVE_INFINITY)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2572
                return "1" + suffix + "/0" + suffix;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2573
            if (v == Double.NEGATIVE_INFINITY)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2574
                return "-1" + suffix + "/0" + suffix;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2575
            return v + (suffix == 'f' || suffix == 'F' ? "" + suffix : "");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2576
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2577
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2578
        private  String sourceForm(char c) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2579
            StringBuilder buf = new StringBuilder(8);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2580
            buf.append('\'');
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2581
            sourceChar(c, buf);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2582
            buf.append('\'');
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2583
            return buf.toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2584
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2585
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2586
        private String sourceForm(byte c) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2587
            return "0x" + Integer.toString(c & 0xff, 16);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2588
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2589
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2590
        private String sourceForm(String s) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2591
            StringBuilder buf = new StringBuilder(s.length() + 5);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2592
            buf.append('\"');
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2593
            for (int i=0; i<s.length(); i++) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2594
                char c = s.charAt(i);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2595
                sourceChar(c, buf);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2596
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2597
            buf.append('\"');
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2598
            return buf.toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2599
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2600
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2601
        private void sourceChar(char c, StringBuilder buf) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2602
            switch (c) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2603
            case '\b': buf.append("\\b"); return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2604
            case '\t': buf.append("\\t"); return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2605
            case '\n': buf.append("\\n"); return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2606
            case '\f': buf.append("\\f"); return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2607
            case '\r': buf.append("\\r"); return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2608
            case '\"': buf.append("\\\""); return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2609
            case '\'': buf.append("\\\'"); return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2610
            case '\\': buf.append("\\\\"); return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2611
            default:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2612
                if (isPrintableAscii(c)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2613
                    buf.append(c); return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2614
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2615
                unicodeEscape(c, buf);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2616
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2617
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2618
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2619
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2620
        private void unicodeEscape(char c, StringBuilder buf) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2621
            final String chars = "0123456789abcdef";
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2622
            buf.append("\\u");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2623
            buf.append(chars.charAt(15 & (c>>12)));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2624
            buf.append(chars.charAt(15 & (c>>8)));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2625
            buf.append(chars.charAt(15 & (c>>4)));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2626
            buf.append(chars.charAt(15 & (c>>0)));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2627
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2628
        private boolean isPrintableAscii(char c) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2629
            return c >= ' ' && c <= '~';
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2630
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2631
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2632
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2633
    public boolean isEnclosingPackageIncluded(TypeElement te) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2634
        return isIncluded(containingPackage(te));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2635
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2636
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2637
    public boolean isIncluded(Element e) {
39364
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 38617
diff changeset
  2638
        return configuration.docEnv.isIncluded(e);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2639
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2640
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2641
    private SimpleElementVisitor9<Boolean, Void> specifiedVisitor = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2642
    public boolean isSpecified(Element e) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2643
        if (specifiedVisitor == null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2644
            specifiedVisitor = new SimpleElementVisitor9<Boolean, Void>() {
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2645
                @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2646
                public Boolean visitModule(ModuleElement e, Void p) {
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2647
                    return configuration.getSpecifiedModuleElements().contains(e);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2648
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2649
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2650
                @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2651
                public Boolean visitPackage(PackageElement e, Void p) {
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2652
                    return configuration.getSpecifiedPackageElements().contains(e);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2653
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2654
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2655
                @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2656
                public Boolean visitType(TypeElement e, Void p) {
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42000
diff changeset
  2657
                    return configuration.getSpecifiedTypeElements().contains(e);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2658
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2659
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40605
diff changeset
  2660
                @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2661
                protected Boolean defaultAction(Element e, Void p) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2662
                    return false;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2663
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2664
            };
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2665
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2666
        return specifiedVisitor.visit(e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2667
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents: 40303
diff changeset
  2668
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2669
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2670
     * package name, an unnamed package is returned as &lt;Unnamed&gt;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2671
     * @param pkg
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2672
     * @return
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2673
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2674
    public String getPackageName(PackageElement pkg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2675
        if (pkg == null || pkg.isUnnamed()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2676
            return DocletConstants.DEFAULT_PACKAGE_NAME;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2677
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2678
        return pkg.getQualifiedName().toString();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2679
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2680
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2681
    public boolean isAttribute(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2682
        return isKind(doctree, ATTRIBUTE);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2683
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2684
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2685
    public boolean isAuthor(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2686
        return isKind(doctree, AUTHOR);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2687
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2688
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2689
    public boolean isComment(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2690
        return isKind(doctree, COMMENT);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2691
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2692
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2693
    public boolean isDeprecated(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2694
        return isKind(doctree, DEPRECATED);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2695
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2696
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2697
    public boolean isDocComment(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2698
        return isKind(doctree, DOC_COMMENT);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2699
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2700
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2701
    public boolean isDocRoot(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2702
        return isKind(doctree, DOC_ROOT);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2703
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2704
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2705
    public boolean isEndElement(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2706
        return isKind(doctree, END_ELEMENT);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2707
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2708
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2709
    public boolean isEntity(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2710
        return isKind(doctree, ENTITY);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2711
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2712
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2713
    public boolean isErroneous(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2714
        return isKind(doctree, ERRONEOUS);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2715
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2716
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2717
    public boolean isException(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2718
        return isKind(doctree, EXCEPTION);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2719
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2720
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2721
    public boolean isIdentifier(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2722
        return isKind(doctree, IDENTIFIER);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2723
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2724
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2725
    public boolean isInheritDoc(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2726
        return isKind(doctree, INHERIT_DOC);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2727
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2728
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2729
    public boolean isLink(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2730
        return isKind(doctree, LINK);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2731
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2732
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2733
    public boolean isLinkPlain(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2734
        return isKind(doctree, LINK_PLAIN);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2735
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2736
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2737
    public boolean isLiteral(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2738
        return isKind(doctree, LITERAL);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2739
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2740
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2741
    public boolean isOther(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2742
        return doctree.getKind() == DocTree.Kind.OTHER;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2743
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2744
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2745
    public boolean isParam(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2746
        return isKind(doctree, PARAM);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2747
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2748
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2749
    public boolean isReference(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2750
        return isKind(doctree, REFERENCE);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2751
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2752
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2753
    public boolean isReturn(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2754
        return isKind(doctree, RETURN);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2755
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2756
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2757
    public boolean isSee(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2758
        return isKind(doctree, SEE);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2759
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2760
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2761
    public boolean isSerial(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2762
        return isKind(doctree, SERIAL);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2763
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2764
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2765
    public boolean isSerialData(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2766
        return isKind(doctree, SERIAL_DATA);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2767
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2768
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2769
    public boolean isSerialField(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2770
        return isKind(doctree, SERIAL_FIELD);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2771
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2772
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2773
    public boolean isSince(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2774
        return isKind(doctree, SINCE);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2775
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2776
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2777
    public boolean isStartElement(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2778
        return isKind(doctree, START_ELEMENT);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2779
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2780
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2781
    public boolean isText(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2782
        return isKind(doctree, TEXT);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2783
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2784
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2785
    public boolean isThrows(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2786
        return isKind(doctree, THROWS);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2787
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2788
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2789
    public boolean isUnknownBlockTag(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2790
        return isKind(doctree, UNKNOWN_BLOCK_TAG);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2791
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2792
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2793
    public boolean isUnknownInlineTag(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2794
        return isKind(doctree, UNKNOWN_INLINE_TAG);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2795
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2796
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2797
    public boolean isValue(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2798
        return isKind(doctree, VALUE);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2799
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2800
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2801
    public boolean isVersion(DocTree doctree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2802
        return isKind(doctree, VERSION);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2803
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2804
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2805
    private boolean isKind(DocTree doctree, DocTree.Kind match) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2806
        return  doctree.getKind() == match;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2807
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2808
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2809
    private final WeakSoftHashMap wksMap = new WeakSoftHashMap(this);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2810
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2811
    public CommentHelper getCommentHelper(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2812
        return wksMap.computeIfAbsent(element);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2813
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2814
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2815
    public void removeCommentHelper(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2816
        wksMap.remove(element);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2817
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2818
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2819
    public List<? extends DocTree> filteredList(List<? extends DocTree> dlist, DocTree.Kind... select) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2820
        List<DocTree> list = new ArrayList<>(dlist.size());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2821
        if (select == null)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2822
            return dlist;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2823
        for (DocTree dt : dlist) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2824
            if (dt.getKind() != ERRONEOUS) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2825
                for (DocTree.Kind kind : select) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2826
                    if (dt.getKind() == kind) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2827
                        list.add(dt);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2828
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2829
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2830
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2831
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2832
        return list;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2833
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2834
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2835
    private List<? extends DocTree> getBlockTags0(Element element, DocTree.Kind... kinds) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2836
        DocCommentTree dcTree = getDocCommentTree(element);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2837
        if (dcTree == null)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2838
            return Collections.emptyList();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2839
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2840
        return filteredList(dcTree.getBlockTags(), kinds);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2841
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2842
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2843
    public List<? extends DocTree> getBlockTags(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2844
        return getBlockTags0(element, (Kind[]) null);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2845
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2846
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2847
    public List<? extends DocTree> getBlockTags(Element element, DocTree.Kind... kinds) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2848
        return getBlockTags0(element, kinds);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2849
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2850
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2851
    public List<? extends DocTree> getBlockTags(Element element, String tagName) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2852
        DocTree.Kind kind = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2853
        switch (tagName) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2854
            case "author":
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2855
            case "deprecated":
37009
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2856
            case "hidden":
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2857
            case "param":
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2858
            case "return":
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2859
            case "see":
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2860
            case "serial":
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2861
            case "since":
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2862
            case "throws":
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2863
            case "exception":
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2864
            case "version":
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2865
                kind = DocTree.Kind.valueOf(tagName.toUpperCase());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2866
                return getBlockTags(element, kind);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2867
            case "serialData":
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2868
                kind = SERIAL_DATA;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2869
                return getBlockTags(element, kind);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2870
            case "serialField":
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2871
                kind = SERIAL_FIELD;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2872
                return getBlockTags(element, kind);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2873
            default:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2874
                kind = DocTree.Kind.UNKNOWN_BLOCK_TAG;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2875
                break;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2876
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2877
        List<? extends DocTree> blockTags = getBlockTags(element, kind);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2878
        List<DocTree> out = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2879
        String tname = tagName.startsWith("@") ? tagName.substring(1) : tagName;
37009
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2880
        CommentHelper ch = getCommentHelper(element);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2881
        for (DocTree dt : blockTags) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2882
            if (ch.getTagName(dt).equals(tname)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2883
                out.add(dt);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2884
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2885
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2886
        return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2887
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2888
37009
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2889
    public boolean hasBlockTag(Element element, DocTree.Kind kind) {
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2890
        return hasBlockTag(element, kind, null);
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2891
    }
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2892
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2893
    public boolean hasBlockTag(Element element, DocTree.Kind kind, final String tagName) {
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2894
        CommentHelper ch = getCommentHelper(element);
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2895
        String tname = tagName != null && tagName.startsWith("@")
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2896
                ? tagName.substring(1)
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2897
                : tagName;
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2898
        for (DocTree dt : getBlockTags(element, kind)) {
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2899
            if (dt.getKind() == kind) {
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2900
                if (tname == null || ch.getTagName(dt).equals(tname)) {
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2901
                    return true;
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2902
                }
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2903
            }
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2904
        }
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2905
        return false;
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2906
    }
476d8d615222 8073100: [javadoc] Provide an ability to suppress document generation for specific elements.
ksrini
parents: 36526
diff changeset
  2907
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2908
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2909
     * Gets a TreePath for an Element. Note this method is called very
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2910
     * frequently, care must be taken to ensure this method is lithe
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2911
     * and efficient.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2912
     * @param e an Element
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2913
     * @return TreePath
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2914
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2915
    public TreePath getTreePath(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2916
        DocCommentDuo duo = dcTreeCache.get(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2917
        if (isValidDuo(duo) && duo.treePath != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2918
            return duo.treePath;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2919
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2920
        duo = configuration.cmtUtils.getSyntheticCommentDuo(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2921
        if (isValidDuo(duo) && duo.treePath != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2922
            return duo.treePath;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2923
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2924
        Map<Element, TreePath> elementToTreePath = configuration.workArounds.getElementToTreePath();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2925
        TreePath path = elementToTreePath.get(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2926
        if (path != null || elementToTreePath.containsKey(e)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2927
            // expedite the path and one that is a null
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2928
            return path;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2929
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2930
        return elementToTreePath.computeIfAbsent(e, docTrees::getPath);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2931
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2932
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2933
    private final Map<Element, DocCommentDuo> dcTreeCache = new LinkedHashMap<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2934
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2935
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2936
     * Retrieves the doc comments for a given element.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2937
     * @param element
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2938
     * @return DocCommentTree for the Element
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2939
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2940
    public DocCommentTree getDocCommentTree0(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2941
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2942
        DocCommentDuo duo = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2943
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2944
        ElementKind kind = element.getKind();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2945
        if (kind == ElementKind.PACKAGE || kind == ElementKind.OTHER) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2946
            duo = dcTreeCache.get(element); // local cache
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2947
            if (!isValidDuo(duo) && kind == ElementKind.PACKAGE) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2948
                // package-info.java
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2949
                duo = getDocCommentTuple(element);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2950
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2951
            if (!isValidDuo(duo)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2952
                // package.html or overview.html
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2953
                duo = configuration.cmtUtils.getHtmlCommentDuo(element); // html source
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2954
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2955
        } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2956
            duo = configuration.cmtUtils.getSyntheticCommentDuo(element);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2957
            if (!isValidDuo(duo)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2958
                duo = dcTreeCache.get(element); // local cache
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2959
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2960
            if (!isValidDuo(duo)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2961
                duo = getDocCommentTuple(element); // get the real mccoy
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2962
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2963
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2964
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2965
        DocCommentTree docCommentTree = isValidDuo(duo) ? duo.dcTree : null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2966
        TreePath path = isValidDuo(duo) ? duo.treePath : null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2967
        if (!dcTreeCache.containsKey(element)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2968
            if (docCommentTree != null && path != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2969
                configuration.workArounds.runDocLint(path);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2970
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2971
            dcTreeCache.put(element, duo);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2972
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2973
        return docCommentTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2974
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2975
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2976
    private DocCommentDuo getDocCommentTuple(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2977
        // prevent nasty things downstream with overview element
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2978
        if (element.getKind() != ElementKind.OTHER) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2979
            TreePath path = getTreePath(element);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2980
            if (path != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2981
                DocCommentTree docCommentTree = docTrees.getDocCommentTree(path);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2982
                return new DocCommentDuo(path, docCommentTree);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2983
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2984
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2985
        return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2986
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2987
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2988
    boolean isValidDuo(DocCommentDuo duo) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2989
        return duo != null && duo.dcTree != null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2990
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2991
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2992
    public DocCommentTree getDocCommentTree(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2993
        CommentHelper ch = wksMap.get(element);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2994
        if (ch != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2995
            return ch.dctree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2996
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2997
        DocCommentTree dcTree = getDocCommentTree0(element);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2998
        if (dcTree != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  2999
            wksMap.put(element, new CommentHelper(configuration, element, getTreePath(element), dcTree));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3000
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3001
        return dcTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3002
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3003
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 40606
diff changeset
  3004
    public List<? extends DocTree> getFullBody(Element element) {
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 40606
diff changeset
  3005
        DocCommentTree docCommentTree = getDocCommentTree(element);
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 40606
diff changeset
  3006
            return (docCommentTree == null)
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 40606
diff changeset
  3007
                    ? Collections.emptyList()
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 40606
diff changeset
  3008
                    : docCommentTree.getFullBody();
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 40606
diff changeset
  3009
    }
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 40606
diff changeset
  3010
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3011
    public List<? extends DocTree> getBody(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3012
        DocCommentTree docCommentTree = getDocCommentTree(element);
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 40606
diff changeset
  3013
        return (docCommentTree == null)
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 40606
diff changeset
  3014
                ? Collections.emptyList()
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 40606
diff changeset
  3015
                : docCommentTree.getFullBody();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3016
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3017
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3018
    public List<? extends DocTree> getDeprecatedTrees(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3019
        return getBlockTags(element, DEPRECATED);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3020
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3021
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3022
    public List<? extends DocTree> getSeeTrees(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3023
        return getBlockTags(element, SEE);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3024
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3025
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3026
    public List<? extends DocTree> getSerialTrees(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3027
        return getBlockTags(element, SERIAL);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3028
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3029
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3030
    public List<? extends DocTree> getSerialFieldTrees(VariableElement field) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3031
        return getBlockTags(field, DocTree.Kind.SERIAL_FIELD);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3032
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3033
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3034
    public List<? extends DocTree> getThrowsTrees(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3035
        return getBlockTags(element, DocTree.Kind.EXCEPTION, DocTree.Kind.THROWS);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3036
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3037
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3038
    public List<? extends DocTree> getTypeParamTrees(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3039
        return getParamTrees(element, true);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3040
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3041
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3042
    public List<? extends DocTree> getParamTrees(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3043
        return getParamTrees(element, false);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3044
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3045
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3046
    private  List<? extends DocTree> getParamTrees(Element element, boolean isTypeParameters) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3047
        List<DocTree> out = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3048
        for (DocTree dt : getBlockTags(element, PARAM)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3049
            ParamTree pt = (ParamTree) dt;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3050
            if (pt.isTypeParameter() == isTypeParameters) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3051
                out.add(dt);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3052
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3053
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3054
        return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3055
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3056
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3057
    public  List<? extends DocTree> getReturnTrees(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3058
        List<DocTree> out = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3059
        for (DocTree dt : getBlockTags(element, RETURN)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3060
            out.add(dt);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3061
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3062
        return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3063
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3064
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3065
    public List<? extends DocTree> getFirstSentenceTrees(Element element) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3066
        DocCommentTree dcTree = getDocCommentTree(element);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3067
        if (dcTree == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3068
            return Collections.emptyList();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3069
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3070
        List<DocTree> out = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3071
        for (DocTree dt : dcTree.getFirstSentence()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3072
            out.add(dt);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3073
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3074
        return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3075
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3076
40511
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  3077
    public ModuleElement containingModule(Element e) {
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  3078
        return elementUtils.getModuleOf(e);
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  3079
    }
1b3c502e0bdc 8155995: Update javadoc to include module search
bpatel
parents: 40508
diff changeset
  3080
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3081
    public PackageElement containingPackage(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3082
        return elementUtils.getPackageOf(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3083
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3084
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3085
    public TypeElement getTopMostContainingTypeElement(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3086
        if (isPackage(e)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3087
            return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3088
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3089
        TypeElement outer = getEnclosingTypeElement(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3090
        if (outer == null)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3091
            return (TypeElement)e;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3092
        while (outer != null && outer.getNestingKind().isNested()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3093
            outer = getEnclosingTypeElement(outer);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3094
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3095
        return outer;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3096
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3097
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3098
    static class WeakSoftHashMap implements Map<Element, CommentHelper> {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3099
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3100
        private final WeakHashMap<Element, SoftReference<CommentHelper>> wkMap;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3101
        private final Utils utils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3102
        public WeakSoftHashMap(Utils utils) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3103
            wkMap = new WeakHashMap<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3104
            this.utils = utils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3105
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3106
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3107
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3108
        public boolean containsKey(Object key) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3109
            return wkMap.containsKey(key);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3110
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3111
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3112
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3113
        public Collection<CommentHelper> values() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3114
            Set<CommentHelper> out = new LinkedHashSet<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3115
            for (SoftReference<CommentHelper> v : wkMap.values()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3116
                out.add(v.get());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3117
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3118
            return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3119
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3120
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3121
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3122
        public boolean containsValue(Object value) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3123
            return wkMap.containsValue(new SoftReference<>((CommentHelper)value));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3124
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3125
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3126
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3127
        public CommentHelper remove(Object key) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3128
            SoftReference<CommentHelper> value = wkMap.remove(key);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3129
            return value == null ? null : value.get();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3130
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3131
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3132
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3133
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3134
        public CommentHelper put(Element key, CommentHelper value) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3135
            SoftReference<CommentHelper> nvalue = wkMap.put(key, new SoftReference<>(value));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3136
            return nvalue == null ? null : nvalue.get();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3137
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3138
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3139
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3140
        public CommentHelper get(Object key) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3141
            SoftReference<CommentHelper> value = wkMap.get(key);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3142
            return value == null ? null : value.get();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3143
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3144
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3145
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3146
        public int size() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3147
            return wkMap.size();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3148
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3149
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3150
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3151
        public boolean isEmpty() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3152
            return wkMap.isEmpty();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3153
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3154
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3155
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3156
        public void clear() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3157
            wkMap.clear();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3158
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3159
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3160
        public CommentHelper computeIfAbsent(Element key) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3161
            if (wkMap.containsKey(key)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3162
                SoftReference<CommentHelper> value = wkMap.get(key);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3163
                if (value != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3164
                    CommentHelper cvalue = value.get();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3165
                    if (cvalue != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3166
                        return cvalue;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3167
                    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3168
                }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3169
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3170
            CommentHelper newValue = new CommentHelper(utils.configuration, key, utils.getTreePath(key),
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3171
                    utils.getDocCommentTree(key));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3172
            wkMap.put(key, new SoftReference<>(newValue));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3173
            return newValue;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3174
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3175
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3176
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3177
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3178
        public void putAll(Map<? extends Element, ? extends CommentHelper> map) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3179
            for (Map.Entry<? extends Element, ? extends CommentHelper> entry : map.entrySet()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3180
                put(entry.getKey(), entry.getValue());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3181
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3182
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3183
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3184
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3185
        public Set<Element> keySet() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3186
            return wkMap.keySet();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3187
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3188
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3189
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3190
        public Set<Entry<Element, CommentHelper>> entrySet() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3191
            Set<Entry<Element, CommentHelper>> out = new LinkedHashSet<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3192
            for (Element e : wkMap.keySet()) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3193
                SimpleEntry<Element, CommentHelper> n = new SimpleEntry<>(e, get(e));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3194
                out.add(n);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3195
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 26270
diff changeset
  3196
            return out;
24220
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  3197
        }
eb213562268d 8039410: [javadoc] fix class-use items to be deterministic and index ordering
ksrini
parents: 22165
diff changeset
  3198
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3199
}