langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ElementsTable.java
author ksrini
Thu, 24 Nov 2016 20:48:52 -0800
changeset 42277 2668b0bc7ad7
parent 42261 bb52b5514ad5
child 42408 d6f09ae68eab
permissions -rw-r--r--
8164316: Refine the Doclet APIs Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
     1
/*
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
     2
 * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
     4
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    10
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    15
 * accompanied this code).
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    16
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    20
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    23
 * questions.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    24
 */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    25
package jdk.javadoc.internal.tool;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    26
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    27
import java.io.IOException;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    28
import java.util.ArrayList;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    29
import java.util.Collection;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    30
import java.util.Collections;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    31
import java.util.EnumMap;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    32
import java.util.EnumSet;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    33
import java.util.HashSet;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    34
import java.util.LinkedHashMap;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    35
import java.util.LinkedHashSet;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    36
import java.util.List;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    37
import java.util.Map;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    38
import java.util.Set;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    39
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    40
import javax.lang.model.element.Element;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    41
import javax.lang.model.element.ElementKind;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    42
import javax.lang.model.element.ExecutableElement;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    43
import javax.lang.model.element.Modifier;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    44
import javax.lang.model.element.ModuleElement;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    45
import javax.lang.model.element.ModuleElement.ExportsDirective;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    46
import javax.lang.model.element.ModuleElement.RequiresDirective;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    47
import javax.lang.model.element.PackageElement;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    48
import javax.lang.model.element.TypeElement;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    49
import javax.lang.model.element.VariableElement;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    50
import javax.lang.model.util.ElementFilter;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    51
import javax.lang.model.util.SimpleElementVisitor9;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    52
import javax.tools.JavaFileManager;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    53
import javax.tools.JavaFileManager.Location;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    54
import javax.tools.JavaFileObject;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    55
import javax.tools.StandardLocation;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    56
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    57
import com.sun.tools.javac.code.Flags;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    58
import com.sun.tools.javac.code.Kinds.Kind;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    59
import com.sun.tools.javac.code.Symbol;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    60
import com.sun.tools.javac.code.Symbol.ClassSymbol;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    61
import com.sun.tools.javac.code.Symbol.CompletionFailure;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    62
import com.sun.tools.javac.code.Symbol.MethodSymbol;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    63
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    64
import com.sun.tools.javac.code.Symbol.PackageSymbol;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    65
import com.sun.tools.javac.code.Symbol.VarSymbol;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    66
import com.sun.tools.javac.code.Symtab;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    67
import com.sun.tools.javac.comp.Modules;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    68
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    69
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    70
import com.sun.tools.javac.util.Context;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    71
import com.sun.tools.javac.util.ListBuffer;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    72
import com.sun.tools.javac.util.Name;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    73
import com.sun.tools.javac.util.Names;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    74
import jdk.javadoc.doclet.DocletEnvironment;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    75
import jdk.javadoc.doclet.DocletEnvironment.ModuleMode;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    76
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    77
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
    78
import static jdk.javadoc.internal.tool.Main.Result.*;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    79
import static jdk.javadoc.internal.tool.JavadocTool.isValidClassName;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    80
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    81
/**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    82
 * This class manages elements specified on the command line, and
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    83
 * produces "specified" and "included" data sets, needed by the
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    84
 * doclet environment, as well as querying an elements' visibility
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    85
 * or inclusion.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    86
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    87
 * A. Initialization phase: the class is initialized with the
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    88
 *    options table by the caller. Some program elements may not
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    89
 *    be specified via specific options, such as packages, classes,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    90
 *    these are set with the use of setter methods, such setClassArgList
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    91
 *    and setClassDeclList.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    92
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    93
 * B. Scan and decode phase: this is performed by scanSpecifiedItems,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    94
 *    to identify the modules specified on the command line, modules
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    95
 *    specified with qualified packages and qualified subpackages, the
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    96
 *    modules so identified are used to initialize the module system.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    97
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    98
 * C. Intermediate phase: before the final analysis can be done,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    99
 *    intermediate methods can be used to get specified elements from
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   100
 *    the initialization phase, typically used to parse sources or packages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   101
 *    specified on the command line.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   102
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   103
 * D. Analysis phase: the final analysis is performed to determine
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   104
 *    the packages that ought to be included, as follows:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   105
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   106
 *    1. computes the specified modules, by considering the option
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   107
 *       "expand-requires", this must be done exhaustively, as the package
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   108
 *       computation phase expects a completed module graph, in order to
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   109
 *       check the target of a qualified export is in the included set.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   110
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   111
 *    2. computes the packages that must be documented, by considering
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   112
 *       the option "show-packages", also if only exported packages are
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   113
 *       to be considered, then also check for qualified packages, and
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   114
 *       include only those packages whose target is in the included set.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   115
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   116
 *    3. compute the specified packages, as part of this, first compute
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   117
 *       the subpackages and exclude any packages, if required.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   118
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   119
 *    4. Finally, compute the types found by previous parsing steps,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   120
 *       noting that, all enclosed types (nested types) must also be
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   121
 *       considered.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   122
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   123
 * E. Finally, this class provides methods to obtain the specified sets,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   124
 *    which are frozen and cached in the analysis phase, the included
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   125
 *    sets, are computed lazily and cached for future use. An element
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   126
 *    can be checked if it should be documented, in which case, the
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   127
 *    element is checked against the included set and the result is
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   128
 *    cached, for performance reasons.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   129
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   130
 * Definitions:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   131
 *    Fully included: an element is included and some or parts
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   132
 *    of it components are included implicitly, subject to a
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   133
 *    selection criteria of its enclosed children.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   134
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   135
 *    Included: if the item should be documented.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   136
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   137
 * Rules for processing:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   138
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   139
 * 1. A specified element, meaning an element given on the
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   140
 *    command-line, and exposed via specified elements collections.
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   141
 * 2. Expand-contents, an internal pseudo term, meaning
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   142
 *    it is part of the recursive expansion of specified
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   143
 *    elements, meaning, the modules are expanded first, then
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   144
 *    the packages contained in the expanded modules, and then
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   145
 *    the types contained within the packages, to produce the
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   146
 *    collections returned by the methods
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   147
 *    getInclude{Module|Package|Type}Elements(), this is a
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   148
 *    downward expansion.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   149
 * 3. An included element, meaning it should be documented, and
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   150
 *    exposed via isIncluded, this enclosing element (module, package)
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   151
 *    is recursively included.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   152
 */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   153
public class ElementsTable {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   154
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   155
    private final ToolEnvironment toolEnv;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   156
    private final Symtab syms;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   157
    private final Names names;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   158
    private final JavaFileManager fm;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   159
    private final Location location;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   160
    private final Modules modules;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   161
    private final Map<ToolOption, Object> opts;
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   162
    private final Messager messager;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   163
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   164
    private final Map<String, Entry> entries = new LinkedHashMap<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   165
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   166
    // specified elements
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   167
    private Set<ModuleElement> specifiedModuleElements = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   168
    private Set<PackageElement> specifiedPackageElements = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   169
    private Set<TypeElement> specifiedTypeElements =new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   170
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   171
    // included elements
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   172
    private Set<ModuleElement> includedModuleElements = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   173
    private Set<PackageElement> includedPackageElements = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   174
    private Set<TypeElement> includedTypeElements = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   175
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   176
    // cmdline specifiers
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   177
    private Set<ModulePackage> cmdLinePackages = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   178
    private Set<ModulePackage> excludePackages = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   179
    private Set<ModulePackage> subPackages = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   180
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   181
    private List<JCClassDecl> classDecList = Collections.emptyList();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   182
    private List<String> classArgList = Collections.emptyList();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   183
    private com.sun.tools.javac.util.List<JCCompilationUnit> classTreeList = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   184
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   185
    private final Set<JavaFileObject.Kind> sourceKinds = EnumSet.of(JavaFileObject.Kind.SOURCE);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   186
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   187
    private final ModifierFilter accessFilter;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   188
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   189
    private final AccessKind expandRequires;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   190
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   191
    final boolean xclasses;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   192
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   193
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   194
     * Creates the table to manage included and excluded elements.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   195
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   196
     * @param context the context to locate commonly used objects
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   197
     * @param location the location used to locate source files
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   198
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   199
    ElementsTable(Context context, Map<ToolOption, Object> opts) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   200
        this.toolEnv = ToolEnvironment.instance(context);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   201
        this.syms = Symtab.instance(context);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   202
        this.names = Names.instance(context);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   203
        this.fm = toolEnv.fileManager;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   204
        this.modules = Modules.instance(context);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   205
        this.opts = opts;
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   206
        this.messager = Messager.instance0(context);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   207
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   208
        this.location = modules.multiModuleMode
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   209
                ? StandardLocation.MODULE_SOURCE_PATH
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   210
                : toolEnv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   211
                    ? StandardLocation.SOURCE_PATH
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   212
                    : StandardLocation.CLASS_PATH;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   213
        getEntry("").excluded = false;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   214
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   215
        accessFilter = new ModifierFilter(opts);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   216
        xclasses = (boolean)opts.getOrDefault(ToolOption.XCLASSES, false);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   217
        expandRequires = (AccessKind)opts.get(ToolOption.EXPAND_REQUIRES);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   218
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   219
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   220
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   221
     * Returns the module documentation level mode.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   222
     * @return the module documentation level mode
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   223
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   224
    public ModuleMode getModuleMode() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   225
        switch(accessFilter.getAccessValue(ElementKind.MODULE)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   226
            case PACKAGE: case PRIVATE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   227
                return DocletEnvironment.ModuleMode.ALL;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   228
            default:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   229
                return DocletEnvironment.ModuleMode.API;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   230
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   231
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   232
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   233
    private Set<Element> specifiedElements = null;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   234
    /**
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   235
     * Returns a set of elements specified on the
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   236
     * command line, including any inner classes.
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   237
     *
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   238
     * @return the set of elements specified on the command line
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   239
     */
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   240
    public Set<? extends Element> getSpecifiedElements() {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   241
        if (specifiedElements == null) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   242
            Set<Element> result = new LinkedHashSet<>();
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   243
            result.addAll(specifiedModuleElements);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   244
            result.addAll(specifiedPackageElements);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   245
            result.addAll(specifiedTypeElements);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   246
            specifiedElements = Collections.unmodifiableSet(result);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   247
        }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   248
        return specifiedElements;
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   249
    }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   250
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   251
    private Set<Element> includedElements = null;
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   252
    /**
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   253
     * Returns a set of elements included elements. The inclusion is as
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   254
     * follows:
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   255
     * A module is fully included,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   256
     *   - is specified on the command line --module
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   257
     *   - is derived from the module graph, that is, by expanding the
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   258
     *     requires directive, based on --expand-requires
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   259
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   260
     * A module is included if an enclosed package or type is
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   261
     * specified on the command line.
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   262
     *
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   263
     * A package is fully included,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   264
     *  - is specified on the command line
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   265
     *  - is derived from expanding -subpackages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   266
     *  - can be documented in a fully included module based on --show-packages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   267
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   268
     * A package is included, if an enclosed package or a type is specified on
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   269
     * the command line.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   270
     *
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   271
     * Included type elements (including those within specified or included packages)
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   272
     * to be documented.
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   273
     *
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   274
     * A type is fully included if
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   275
     *  - is specified on the command line with -sourcepath
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   276
     *  - is visible with --show-types filter
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   277
     * A nested type is fully included if
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   278
     *  - is visible with --show-types filter
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   279
     *  - is enclosed in a fully included type
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   280
     * @return the set of elements specified on the command line
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   281
     */
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   282
    public Set<? extends Element> getIncludedElements() {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   283
        if (includedElements == null) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   284
            Set<Element> result = new LinkedHashSet<>();
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   285
            result.addAll(includedModuleElements);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   286
            result.addAll(includedPackageElements);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   287
            result.addAll(includedTypeElements);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   288
            includedElements = Collections.unmodifiableSet(result);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   289
        }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   290
        return includedElements;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   291
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   292
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   293
    private IncludedVisitor includedVisitor = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   294
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   295
    /**
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   296
     * Returns true if the given element is included for consideration.
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   297
     * This method accumulates elements in the cache as enclosed elements of
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   298
     * fully included elements are tested.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   299
     * A member (constructor, method, field) is included if
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   300
     *  - it is visible in a fully included type (--show-members)
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   301
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   302
     * @param e the element in question
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   303
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   304
     * @see getIncludedModuleElements
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   305
     * @see getIncludedPackageElements
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   306
     * @see getIncludedTypeElements
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   307
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   308
     * @return true if included
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   309
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   310
    public boolean isIncluded(Element e) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   311
        if (e == null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   312
            return false;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   313
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   314
        if (includedVisitor == null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   315
            includedVisitor = new IncludedVisitor();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   316
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   317
        return includedVisitor.visit(e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   318
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   319
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   320
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   321
     * Performs the final computation and freezes the collections.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   322
     * This is a terminal operation, thus no further modifications
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   323
     * are allowed to the specified data sets.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   324
     *
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   325
     * @throws ToolException if an error occurs
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   326
     */
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   327
    void analyze() throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   328
        // compute the specified element, by expanding module dependencies
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   329
        computeSpecifiedModules();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   330
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   331
        // compute all specified packages and subpackages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   332
        computeSpecifiedPackages();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   333
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   334
        // compute the specified types
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   335
        computeSpecifiedTypes();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   336
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   337
        // compute the packages belonging to all the specified modules
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   338
        Set<PackageElement> expandedModulePackages = computeModulePackages();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   339
        initializeIncludedSets(expandedModulePackages);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   340
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   341
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   342
    ElementsTable classTrees(com.sun.tools.javac.util.List<JCCompilationUnit> classTrees) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   343
        this.classTreeList = classTrees;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   344
        return this;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   345
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   346
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   347
    @SuppressWarnings("unchecked")
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   348
    ElementsTable scanSpecifiedItems() throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   349
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   350
        // scan modules specified on the command line
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   351
        List<String> moduleNames = (List<String>) opts.computeIfAbsent(ToolOption.MODULE,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   352
                s -> Collections.EMPTY_LIST);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   353
        List<String> mlist = new ArrayList<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   354
        for (String m : moduleNames) {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   355
            Location moduleLoc = getModuleLocation(location, m);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   356
            if (moduleLoc == null) {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   357
                String text = messager.getText("main.module_not_found", m);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   358
                throw new ToolException(CMDERR, text);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   359
            } else {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   360
                mlist.add(m);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   361
                ModuleSymbol msym = syms.enterModule(names.fromString(m));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   362
                specifiedModuleElements.add((ModuleElement) msym);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   363
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   364
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   365
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   366
        // scan for modules with qualified packages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   367
        cmdLinePackages.stream()
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   368
                .filter((mpkg) -> (mpkg.hasModule()))
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   369
                .forEachOrdered((mpkg) -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   370
                    mlist.add(mpkg.moduleName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   371
        });
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   372
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   373
        // scan for modules with qualified subpackages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   374
        ((List<String>)opts.computeIfAbsent(ToolOption.SUBPACKAGES, v -> Collections.EMPTY_LIST))
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   375
            .stream()
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   376
            .map((packageName) -> new ModulePackage(packageName))
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   377
            .forEachOrdered((mpkg) -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   378
                subPackages.add(mpkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   379
                if (mpkg.hasModule()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   380
                    mlist.add(mpkg.moduleName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   381
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   382
            });
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   383
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   384
        // all the modules specified on the command line have been scraped
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   385
        // init the module systems
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   386
        modules.addExtraAddModules(mlist.toArray(new String[mlist.size()]));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   387
        modules.initModules(this.classTreeList);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   388
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   389
        return this;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   390
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   391
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   392
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   393
     * Returns the includes table after setting a class names specified on the command line.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   394
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   395
     * @param classList
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   396
     * @return the include table
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   397
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   398
    ElementsTable setClassArgList(List<String> classList) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   399
        classArgList = classList;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   400
        return this;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   401
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   402
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   403
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   404
     * Returns the includes table after setting the parsed class names.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   405
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   406
     * @param classesDecList
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   407
     * @return the include table
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   408
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   409
    ElementsTable setClassDeclList(List<JCClassDecl> classesDecList) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   410
        this.classDecList = classesDecList;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   411
        return this;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   412
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   413
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   414
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   415
     * Returns an includes table after setting the specified package
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   416
     * names.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   417
     * @param packageNames packages on the command line
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   418
     * @return the includes table after setting the specified package
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   419
     * names
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   420
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   421
    ElementsTable packages(Collection<String> packageNames) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   422
        packageNames.stream()
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   423
            .map((packageName) -> new ModulePackage(packageName))
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   424
            .forEachOrdered((mpkg) -> cmdLinePackages.add(mpkg));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   425
        return this;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   426
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   427
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   428
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   429
     * Returns the aggregate set of included packages and specified
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   430
     * sub packages.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   431
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   432
     * @return the aggregate set of included packages and specified
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   433
     * sub packages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   434
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   435
    Iterable<ModulePackage> getPackagesToParse() throws IOException {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   436
        List<ModulePackage> result = new ArrayList<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   437
        result.addAll(cmdLinePackages);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   438
        result.addAll(subPackages);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   439
        return result;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   440
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   441
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   442
    @SuppressWarnings("unchecked")
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   443
    private void computeSubpackages() throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   444
        ((List<String>) opts.computeIfAbsent(ToolOption.EXCLUDE, v -> Collections.EMPTY_LIST))
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   445
                .stream()
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   446
                .map((packageName) -> new ModulePackage(packageName))
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   447
                .forEachOrdered((mpkg) -> excludePackages.add(mpkg));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   448
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   449
        excludePackages.forEach((p) -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   450
            getEntry(p).excluded = true;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   451
        });
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   452
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   453
        for (ModulePackage modpkg : subPackages) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   454
            Location packageLocn = getLocation(modpkg);
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   455
            Iterable<JavaFileObject> list = null;
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   456
            try {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   457
                list = fm.list(packageLocn, modpkg.packageName, sourceKinds, true);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   458
            } catch (IOException ioe) {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   459
                String text = messager.getText("main.file.manager.list", modpkg.packageName);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   460
                throw new ToolException(SYSERR, text, ioe);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   461
            }
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   462
            for (JavaFileObject fo : list) {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   463
                String binaryName = fm.inferBinaryName(packageLocn, fo);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   464
                String pn = getPackageName(binaryName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   465
                String simpleName = getSimpleName(binaryName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   466
                Entry e = getEntry(pn);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   467
                if (!e.isExcluded() && isValidClassName(simpleName)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   468
                    ModuleSymbol msym = (modpkg.hasModule())
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   469
                            ? syms.getModule(names.fromString(modpkg.moduleName))
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   470
                            : findModuleOfPackageName(modpkg.packageName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   471
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   472
                    if (msym != null && !msym.isUnnamed()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   473
                        syms.enterPackage(msym, names.fromString(pn));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   474
                        ModulePackage npkg = new ModulePackage(msym.toString(), pn);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   475
                        cmdLinePackages.add(npkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   476
                    } else {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   477
                        cmdLinePackages.add(e.modpkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   478
                    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   479
                    e.files = (e.files == null
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   480
                            ? com.sun.tools.javac.util.List.of(fo)
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   481
                            : e.files.prepend(fo));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   482
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   483
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   484
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   485
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   486
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   487
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   488
     * Returns the "requires" modules for the target module.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   489
     * @param mdle the target module element
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   490
     * @param isPublic true gets all the public requires, otherwise
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   491
     *                 gets all the non-public requires
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   492
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   493
     * @return a set of modules
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   494
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   495
    private Set<ModuleElement> getModuleRequires(ModuleElement mdle, boolean isPublic) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   496
        Set<ModuleElement> result = new HashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   497
        for (RequiresDirective rd : ElementFilter.requiresIn(mdle.getDirectives())) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   498
            if (isPublic && rd.isPublic()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   499
                result.add(rd.getDependency());
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   500
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   501
            if (!isPublic && !rd.isPublic()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   502
                result.add(rd.getDependency());
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   503
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   504
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   505
        return result;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   506
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   507
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   508
    private void computeSpecifiedModules() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   509
        if (expandRequires == null) { // no expansion requested
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   510
            specifiedModuleElements = Collections.unmodifiableSet(specifiedModuleElements);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   511
            return;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   512
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   513
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   514
        final boolean expandAll = expandRequires.equals(AccessKind.PRIVATE)
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   515
                || expandRequires.equals(AccessKind.PACKAGE);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   516
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   517
        Set<ModuleElement> result = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   518
        ListBuffer<ModuleElement> queue = new ListBuffer<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   519
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   520
        // expand each specified module
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   521
        for (ModuleElement mdle : specifiedModuleElements) {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   522
            result.add(mdle); // a specified module is included
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   523
            queue.append(mdle);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   524
            Set<ModuleElement> publicRequires = getModuleRequires(mdle, true);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   525
            result.addAll(publicRequires);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   526
            // add all requires public
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   527
            queue.addAll(publicRequires);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   528
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   529
            if (expandAll) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   530
                 // add non-public requires if needed
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   531
                result.addAll(getModuleRequires(mdle, !expandAll));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   532
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   533
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   534
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   535
        // compute the transitive closure of all the requires public
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   536
        for (ModuleElement m = queue.poll() ; m != null ; m = queue.poll()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   537
            for (ModuleElement mdle : getModuleRequires(m, true)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   538
                if (!result.contains(mdle)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   539
                    result.add(mdle);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   540
                    queue.append(mdle);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   541
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   542
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   543
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   544
        specifiedModuleElements = Collections.unmodifiableSet(result);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   545
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   546
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   547
    private Set<PackageElement> getAllModulePackages(ModuleElement mdle) throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   548
        Set<PackageElement> result = new HashSet<>();
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   549
        ModuleSymbol msym = (ModuleSymbol) mdle;
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   550
        Location msymloc = getModuleLocation(location, msym.name.toString());
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   551
        try {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   552
            for (JavaFileObject fo : fm.list(msymloc, "", sourceKinds, true)) {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   553
                if (fo.getName().endsWith("module-info.java"))
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   554
                    continue;
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   555
                String binaryName = fm.inferBinaryName(msymloc, fo);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   556
                String pn = getPackageName(binaryName);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   557
                PackageSymbol psym = syms.enterPackage(msym, names.fromString(pn));
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   558
                result.add((PackageElement) psym);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   559
            }
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   560
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   561
        } catch (IOException ioe) {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   562
            String text = messager.getText("main.file.manager.list", msymloc.getName());
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   563
            throw new ToolException(SYSERR, text, ioe);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   564
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   565
        return result;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   566
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   567
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   568
    private Set<PackageElement> computeModulePackages() throws ToolException {
41633
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   569
        AccessKind accessValue = accessFilter.getAccessValue(ElementKind.PACKAGE);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   570
        final boolean documentAllModulePackages = (accessValue == AccessKind.PACKAGE ||
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   571
                accessValue == AccessKind.PRIVATE);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   572
41633
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   573
        accessValue = accessFilter.getAccessValue(ElementKind.MODULE);
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   574
        final boolean moduleDetailedMode = (accessValue == AccessKind.PACKAGE ||
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   575
                accessValue == AccessKind.PRIVATE);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   576
        Set<PackageElement> expandedModulePackages = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   577
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   578
        for (ModuleElement mdle : specifiedModuleElements) {
41633
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   579
            if (documentAllModulePackages) { // include all packages
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   580
                List<PackageElement> packages = ElementFilter.packagesIn(mdle.getEnclosedElements());
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   581
                expandedModulePackages.addAll(packages);
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   582
                expandedModulePackages.addAll(getAllModulePackages(mdle));
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   583
            } else { // selectively include required packages
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   584
                List<ExportsDirective> exports = ElementFilter.exportsIn(mdle.getDirectives());
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   585
                for (ExportsDirective export : exports) {
41633
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   586
                    // add if fully exported or add qualified exports only if desired
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   587
                    if (export.getTargetModules() == null
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   588
                            || documentAllModulePackages || moduleDetailedMode) {
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   589
                        expandedModulePackages.add(export.getPackage());
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   590
                    }
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   591
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   592
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   593
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   594
            // add all packages specified on the command line
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   595
            // belonging to this module
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   596
            if (!cmdLinePackages.isEmpty()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   597
                for (ModulePackage modpkg : cmdLinePackages) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   598
                    PackageElement pkg = toolEnv.elements.getPackageElement(mdle,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   599
                            modpkg.packageName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   600
                    if (pkg != null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   601
                        expandedModulePackages.add(pkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   602
                    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   603
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   604
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   605
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   606
        return expandedModulePackages;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   607
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   608
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   609
    private void initializeIncludedSets(Set<PackageElement> expandedModulePackages) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   610
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   611
        // process modules
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   612
        Set<ModuleElement> imodules = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   613
        // add all the expanded modules
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   614
        imodules.addAll(specifiedModuleElements);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   615
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   616
        // process packages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   617
        Set<PackageElement> ipackages = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   618
        // add all packages belonging to expanded modules
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   619
        ipackages.addAll(expandedModulePackages);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   620
        // add all specified packages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   621
        specifiedPackageElements.forEach(pkg -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   622
            ModuleElement mdle = toolEnv.elements.getModuleOf(pkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   623
            imodules.add(mdle);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   624
            ipackages.add(pkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   625
        });
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   626
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   627
        // process types
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   628
        Set<TypeElement> iclasses = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   629
        // add all types enclosed in expanded modules and packages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   630
        ipackages.forEach((pkg) -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   631
            addAllClasses(iclasses, pkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   632
        });
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   633
        // add all types and its nested types
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   634
        specifiedTypeElements.forEach((klass) -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   635
            ModuleElement mdle = toolEnv.elements.getModuleOf(klass);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   636
            if (!mdle.isUnnamed())
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   637
                imodules.add(mdle);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   638
            PackageElement pkg = toolEnv.elements.getPackageOf(klass);
41633
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   639
            ipackages.add(pkg);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   640
            addAllClasses(iclasses, klass, true);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   641
        });
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   642
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   643
        // all done, freeze the collections
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   644
        includedModuleElements = Collections.unmodifiableSet(imodules);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   645
        includedPackageElements = Collections.unmodifiableSet(ipackages);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   646
        includedTypeElements = Collections.unmodifiableSet(iclasses);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   647
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   648
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   649
    /*
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   650
     * Computes the included packages and freezes the specified packages list.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   651
     */
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   652
    private void computeSpecifiedPackages() throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   653
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   654
        computeSubpackages();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   655
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   656
        Set<PackageElement> packlist = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   657
        cmdLinePackages.forEach((modpkg) -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   658
            ModuleElement mdle = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   659
            PackageElement pkg;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   660
            if (modpkg.hasModule()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   661
                mdle = toolEnv.elements.getModuleElement(modpkg.moduleName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   662
                pkg = toolEnv.elements.getPackageElement(mdle, modpkg.packageName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   663
            } else {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   664
                pkg = toolEnv.elements.getPackageElement(modpkg.toString());
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   665
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   666
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   667
            if (pkg != null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   668
                packlist.add(pkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   669
            } else {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   670
                messager.printWarningUsingKey("main.package_not_found", modpkg.toString());
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   671
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   672
        });
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   673
        specifiedPackageElements = Collections.unmodifiableSet(packlist);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   674
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   675
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   676
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   677
     * Adds all classes as well as inner classes, to the specified
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   678
     * list.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   679
     */
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   680
    private void computeSpecifiedTypes() throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   681
        Set<TypeElement> classes = new LinkedHashSet<>();
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   682
          classDecList.forEach((def) -> {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   683
            TypeElement te = (TypeElement) def.sym;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   684
            if (te != null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   685
                addAllClasses(classes, te, true);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   686
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   687
        });
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   688
        for (String className : classArgList) {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   689
            TypeElement te = toolEnv.loadClass(className);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   690
            if (te == null) {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   691
                String text = messager.getText("javadoc.class_not_found", className);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   692
                throw new ToolException(CMDERR, text);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   693
            } else {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   694
                addAllClasses(classes, te, true);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   695
            }
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   696
        }
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   697
        specifiedTypeElements = Collections.unmodifiableSet(classes);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   698
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   699
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   700
    private void addFilesForParser(Collection<JavaFileObject> result,
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   701
            Collection<ModulePackage> collection,
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   702
            boolean recurse) throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   703
        for (ModulePackage modpkg : collection) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   704
            toolEnv.notice("main.Loading_source_files_for_package", modpkg.toString());
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   705
            List<JavaFileObject> files = getFiles(modpkg, recurse);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   706
            if (files.isEmpty()) {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   707
                String text = messager.getText("main.no_source_files_for_package",
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   708
                        modpkg.toString());
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   709
                throw new ToolException(CMDERR, text);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   710
            } else {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   711
                result.addAll(files);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   712
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   713
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   714
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   715
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   716
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   717
     * Returns an aggregated list of java file objects from the items
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   718
     * specified on the command line. The packages specified should not
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   719
     * recurse, however sub-packages should recurse into the sub directories.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   720
     * @return a list of java file objects
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   721
     * @throws IOException if an error occurs
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   722
     */
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   723
    List<JavaFileObject> getFilesToParse() throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   724
        List<JavaFileObject> result = new ArrayList<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   725
        addFilesForParser(result, cmdLinePackages, false);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   726
        addFilesForParser(result, subPackages, true);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   727
        return result;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   728
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   729
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   730
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   731
     * Returns the set of source files for a package.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   732
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   733
     * @param packageName the specified package
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   734
     * @return the set of file objects for the specified package
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   735
     * @throws ToolException if an error occurs while accessing the files
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   736
     */
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   737
    private List<JavaFileObject> getFiles(ModulePackage modpkg,
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   738
            boolean recurse) throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   739
        Entry e = getEntry(modpkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   740
        // The files may have been found as a side effect of searching for subpackages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   741
        if (e.files != null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   742
            return e.files;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   743
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   744
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   745
        ListBuffer<JavaFileObject> lb = new ListBuffer<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   746
        Location packageLocn = getLocation(modpkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   747
        if (packageLocn == null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   748
            return Collections.emptyList();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   749
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   750
        String pname = modpkg.packageName;
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   751
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   752
        try {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   753
            for (JavaFileObject fo : fm.list(packageLocn, pname, sourceKinds, recurse)) {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   754
                String binaryName = fm.inferBinaryName(packageLocn, fo);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   755
                String simpleName = getSimpleName(binaryName);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   756
                if (isValidClassName(simpleName)) {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   757
                    lb.append(fo);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   758
                }
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   759
            }
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   760
        } catch (IOException ioe) {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   761
            String text = messager.getText("main.file.manager.list", pname);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   762
            throw new ToolException(SYSERR, text, ioe);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   763
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   764
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   765
        return lb.toList();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   766
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   767
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   768
    private ModuleSymbol findModuleOfPackageName(String packageName) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   769
            Name pack = names.fromString(packageName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   770
            for (ModuleSymbol msym : modules.allModules()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   771
                PackageSymbol p = syms.getPackage(msym, pack);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   772
                if (p != null && !p.members().isEmpty()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   773
                    return msym;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   774
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   775
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   776
            return null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   777
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   778
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   779
    private Location getLocation(ModulePackage modpkg) throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   780
        if (location != StandardLocation.MODULE_SOURCE_PATH) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   781
            return location;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   782
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   783
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   784
        if (modpkg.hasModule()) {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   785
            return getModuleLocation(location, modpkg.moduleName);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   786
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   787
        // TODO: handle invalid results better.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   788
        ModuleSymbol msym = findModuleOfPackageName(modpkg.packageName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   789
        if (msym == null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   790
            return null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   791
        }
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   792
        return getModuleLocation(location, msym.name.toString());
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   793
    }
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   794
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   795
    private Location getModuleLocation(Location location, String msymName)
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   796
            throws ToolException {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   797
        try {
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41633
diff changeset
   798
            return fm.getLocationForModule(location, msymName);
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   799
        } catch (IOException ioe) {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   800
            String text = messager.getText("main.doclet_could_not_get_location", msymName);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   801
            throw new ToolException(ERROR, text, ioe);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   802
        }
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   803
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   804
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   805
    private Entry getEntry(String name) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   806
        return getEntry(new ModulePackage(name));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   807
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   808
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   809
    private Entry getEntry(ModulePackage modpkg) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   810
        Entry e = entries.get(modpkg.packageName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   811
        if (e == null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   812
            entries.put(modpkg.packageName, e = new Entry(modpkg));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   813
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   814
        return e;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   815
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   816
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   817
    private String getPackageName(String name) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   818
        int lastDot = name.lastIndexOf(".");
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   819
        return (lastDot == -1 ? "" : name.substring(0, lastDot));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   820
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   821
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   822
    private String getSimpleName(String name) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   823
        int lastDot = name.lastIndexOf(".");
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   824
        return (lastDot == -1 ? name : name.substring(lastDot + 1));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   825
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   826
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   827
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   828
     * Adds all inner classes of this class, and their inner classes recursively, to the list
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   829
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   830
    private void addAllClasses(Collection<TypeElement> list, TypeElement typeElement, boolean filtered) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   831
        ClassSymbol klass = (ClassSymbol)typeElement;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   832
        try {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   833
            // eliminate needless checking, do this first.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   834
            if (list.contains(klass)) return;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   835
            // ignore classes with invalid Java class names
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   836
            if (!JavadocTool.isValidClassName(klass.name.toString())) return;
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   837
            if (filtered && !isTypeElementSelected(klass)) return;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   838
            list.add(klass);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   839
            for (Symbol sym : klass.members().getSymbols(NON_RECURSIVE)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   840
                if (sym != null && sym.kind == Kind.TYP) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   841
                    ClassSymbol s = (ClassSymbol)sym;
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   842
                    addAllClasses(list, s, filtered);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   843
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   844
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   845
        } catch (CompletionFailure e) {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   846
            if (e.getMessage() != null)
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   847
                messager.printWarning(e.getMessage());
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   848
            else
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   849
                messager.printWarningUsingKey("main.unexpected.exception", e);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   850
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   851
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   852
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   853
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   854
     * Returns a list of all classes contained in this package, including
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   855
     * member classes of those classes, and their member classes, etc.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   856
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   857
    private void addAllClasses(Collection<TypeElement> list, PackageElement pkg) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   858
        boolean filtered = true;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   859
        PackageSymbol sym = (PackageSymbol)pkg;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   860
        for (Symbol isym : sym.members().getSymbols(NON_RECURSIVE)) {
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   861
            addAllClasses(list, (TypeElement)isym, filtered);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   862
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   863
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   864
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   865
    private boolean isTypeElementSelected(TypeElement te) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   866
        return (xclasses || toolEnv.isFromSource(te)) && isSelected(te);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   867
    }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   868
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   869
    SimpleElementVisitor9<Boolean, Void> visibleElementVisitor = null;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   870
    /**
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   871
     * Returns true if the element is selected, by applying
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   872
     * the access filter checks. Special treatment is applied to
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   873
     * types, for a top level type the access filter applies completely,
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   874
     * however if is a nested type then it is allowed either  if
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   875
     * the enclosing is a static or the enclosing is also selected.
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   876
     *
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   877
     * @param e the element to be checked
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   878
     * @return true if the element is visible
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   879
     */
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   880
    public boolean isSelected(Element e) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   881
        if (toolEnv.isSynthetic((Symbol) e)) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   882
            return false;
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   883
        }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   884
        if (visibleElementVisitor == null) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   885
            visibleElementVisitor = new SimpleElementVisitor9<Boolean, Void>() {
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
   886
                @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   887
                public Boolean visitType(TypeElement e, Void p) {
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   888
                    if (!accessFilter.checkModifier(e)) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   889
                        return false; // it is not allowed
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   890
                    }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   891
                    Element encl = e.getEnclosingElement();
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   892
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   893
                    // check if nested
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   894
                    if (encl.getKind() == ElementKind.PACKAGE)
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   895
                        return true; // top-level class, allow it
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   896
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   897
                    // is enclosed static
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   898
                    if (encl.getModifiers().contains(Modifier.STATIC))
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   899
                        return true; // allowed
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   900
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   901
                    // check the enclosing
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   902
                    return visit(encl);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   903
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   904
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
   905
                @Override
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   906
                protected Boolean defaultAction(Element e, Void p) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   907
                    return accessFilter.checkModifier(e);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   908
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   909
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
   910
                @Override
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   911
                public Boolean visitUnknown(Element e, Void p) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   912
                    throw new AssertionError("unkown element: " + p);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   913
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   914
            };
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   915
        }
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   916
        return visibleElementVisitor.visit(e);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   917
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   918
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   919
    private class IncludedVisitor extends SimpleElementVisitor9<Boolean, Void> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   920
        final private Set<Element> includedCache;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   921
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   922
        public IncludedVisitor() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   923
            includedCache = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   924
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   925
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
   926
        @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   927
        public Boolean visitModule(ModuleElement e, Void p) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   928
            // deduced by specified and/or requires expansion
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   929
            return includedModuleElements.contains(e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   930
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   931
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
   932
        @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   933
        public Boolean visitPackage(PackageElement e, Void p) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   934
            // deduced by specified or downward expansions
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   935
            return includedPackageElements.contains(e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   936
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   937
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
   938
        @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   939
        public Boolean visitType(TypeElement e, Void p) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   940
            if (includedTypeElements.contains(e)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   941
                return true;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   942
            }
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   943
            if (isTypeElementSelected(e)) {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   944
                // Class is nameable from top-level and
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   945
                // the class and all enclosing classes
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   946
                // pass the modifier filter.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   947
                PackageElement pkg = toolEnv.elements.getPackageOf(e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   948
                if (specifiedPackageElements.contains(pkg)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   949
                    return true;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   950
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   951
                Element enclosing = e.getEnclosingElement();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   952
                if (enclosing != null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   953
                    switch(enclosing.getKind()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   954
                        case PACKAGE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   955
                            return specifiedPackageElements.contains((PackageElement)enclosing);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   956
                        case CLASS: case INTERFACE: case ENUM: case ANNOTATION_TYPE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   957
                            return visit((TypeElement) enclosing);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   958
                        default:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   959
                            throw new AssertionError("unknown element: " + enclosing);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   960
                    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   961
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   962
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   963
            return false;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   964
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   965
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   966
        // members
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
   967
        @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   968
        public Boolean defaultAction(Element e, Void p) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   969
            if (includedCache.contains(e))
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   970
                return true;
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   971
            if (visit(e.getEnclosingElement()) && isSelected(e)) {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   972
                switch(e.getKind()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   973
                    case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   974
                    case MODULE: case OTHER: case PACKAGE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   975
                        throw new AssertionError("invalid element for this operation: " + e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   976
                    default:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   977
                        // the only allowed kinds in the cache are "members"
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   978
                        includedCache.add(e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   979
                        return true;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   980
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   981
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   982
            return false;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   983
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   984
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
   985
        @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   986
        public Boolean visitUnknown(Element e, Void p) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   987
            throw new AssertionError("unknown element: " + e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   988
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   989
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   990
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   991
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   992
    class Entry {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   993
        final ModulePackage modpkg;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   994
        Boolean excluded = false;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   995
        com.sun.tools.javac.util.List<JavaFileObject> files;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   996
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   997
        Entry(ModulePackage modpkg) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   998
            this.modpkg = modpkg;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   999
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1000
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1001
        Entry(String name) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1002
            modpkg = new ModulePackage(name);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1003
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1004
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1005
        boolean isExcluded() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1006
            return excluded;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1007
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1008
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1009
        @Override
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1010
        public String toString() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1011
            return "Entry{" + "modpkg=" + modpkg + ", excluded=" + excluded + ", files=" + files + '}';
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1012
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1013
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1014
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1015
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1016
     * A container class to retrieve the module and package pair
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1017
     * from a parsed qualified package name.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1018
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1019
    static class ModulePackage {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1020
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1021
        public final String moduleName;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1022
        public final String packageName;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1023
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1024
        ModulePackage(String modulename, String packagename) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1025
            this.moduleName = modulename;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1026
            this.packageName = packagename;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1027
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1028
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1029
        ModulePackage(ModuleElement msym, String packagename) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1030
            this.moduleName = msym.toString();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1031
            this.packageName = packagename;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1032
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1033
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1034
        ModulePackage(String name) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1035
            String a[] = name.split("/");
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1036
            if (a.length == 2) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1037
                this.moduleName = a[0];
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1038
                this.packageName = a[1];
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1039
            } else {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1040
                moduleName = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1041
                packageName = name;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1042
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1043
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1044
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1045
        boolean hasModule() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1046
            return this.moduleName != null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1047
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1048
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1049
        @Override
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1050
        public boolean equals(Object obj) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1051
            if (obj instanceof ModulePackage) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1052
                ModulePackage that = (ModulePackage)obj;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1053
                return this.toString().equals(that.toString());
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1054
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1055
            return false;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1056
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1057
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1058
        @Override
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1059
        public int hashCode() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1060
             return toString().hashCode();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1061
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1062
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1063
        @Override
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1064
        public String toString() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1065
            return moduleName == null ? packageName : moduleName + "/" + packageName;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1066
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1067
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1068
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1069
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1070
     * A class which filters the access flags on classes, fields, methods, etc.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1071
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1072
     * @see javax.lang.model.element.Modifier
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1073
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1074
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1075
    static class ModifierFilter {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1076
        /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1077
         * The allowed ElementKind that can be stored.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1078
         */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1079
        static final EnumSet<ElementKind> ALLOWED_KINDS = EnumSet.of(ElementKind.METHOD,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1080
                                                    ElementKind.CLASS,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1081
                                                    ElementKind.PACKAGE,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1082
                                                    ElementKind.MODULE);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1083
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1084
        // all possible accesss levels allowed for each element
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1085
        private final EnumMap<ElementKind, EnumSet<AccessKind>> filterMap =
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1086
                new EnumMap<>(ElementKind.class);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1087
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1088
        // the specified access level for each element
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1089
        private final EnumMap<ElementKind, AccessKind> accessMap =
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1090
                new EnumMap<>(ElementKind.class);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1091
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1092
        /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1093
         * Constructor - Specify a filter.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1094
         *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1095
         * @param accessSet an Access filter.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1096
         */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1097
        ModifierFilter(Map<ToolOption, Object> opts) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1098
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1099
            AccessKind accessValue = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1100
            for (ElementKind kind : ALLOWED_KINDS) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1101
                switch (kind) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1102
                    case METHOD:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1103
                        accessValue  = (AccessKind)opts.get(ToolOption.SHOW_MEMBERS);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1104
                        break;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1105
                    case CLASS:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1106
                        accessValue  = (AccessKind)opts.get(ToolOption.SHOW_TYPES);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1107
                        break;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1108
                    case PACKAGE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1109
                        accessValue  = (AccessKind)opts.get(ToolOption.SHOW_PACKAGES);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1110
                        break;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1111
                    case MODULE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1112
                        accessValue  = (AccessKind)opts.get(ToolOption.SHOW_MODULE_CONTENTS);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1113
                        break;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1114
                    default:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1115
                        throw new AssertionError("unknown element: " + kind);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1116
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1117
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1118
                accessMap.put(kind, accessValue);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1119
                filterMap.put(kind, getFilterSet(accessValue));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1120
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1121
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1122
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1123
        static EnumSet<AccessKind> getFilterSet(AccessKind acccessValue) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1124
            switch (acccessValue) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1125
                case PUBLIC:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1126
                    return EnumSet.of(AccessKind.PUBLIC);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1127
                case PROTECTED:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1128
                default:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1129
                    return EnumSet.of(AccessKind.PUBLIC, AccessKind.PROTECTED);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1130
                case PACKAGE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1131
                    return EnumSet.of(AccessKind.PUBLIC, AccessKind.PROTECTED, AccessKind.PACKAGE);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1132
                case PRIVATE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1133
                    return EnumSet.allOf(AccessKind.class);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1134
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1135
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1136
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1137
        public AccessKind getAccessValue(ElementKind kind) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1138
            if (!ALLOWED_KINDS.contains(kind)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1139
                throw new IllegalArgumentException("not allowed: " + kind);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1140
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1141
            return accessMap.getOrDefault(kind, AccessKind.PROTECTED);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1142
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1143
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1144
        /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1145
         * Returns true if access is allowed.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1146
         *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1147
         * @param e the element in question
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1148
         * @return whether the modifiers pass this filter
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1149
         */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1150
        public boolean checkModifier(Element e) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1151
            Set<Modifier> modifiers = e.getModifiers();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1152
            AccessKind fflag = AccessKind.PACKAGE;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1153
            if (modifiers.contains(Modifier.PUBLIC)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1154
                fflag = AccessKind.PUBLIC;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1155
            } else if (modifiers.contains(Modifier.PROTECTED)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1156
                fflag = AccessKind.PROTECTED;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1157
            } else if (modifiers.contains(Modifier.PRIVATE)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1158
                fflag = AccessKind.PRIVATE;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1159
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1160
            EnumSet<AccessKind> filterSet = filterMap.get(getAllowedKind(e.getKind()));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1161
            return filterSet.contains(fflag);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1162
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1163
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1164
        // convert a requested element kind to an allowed access kind
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1165
        private ElementKind getAllowedKind(ElementKind kind) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1166
            switch (kind) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1167
                case CLASS: case METHOD: case MODULE: case PACKAGE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1168
                    return kind;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1169
                case ANNOTATION_TYPE: case ENUM: case INTERFACE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1170
                    return ElementKind.CLASS;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1171
                case CONSTRUCTOR: case ENUM_CONSTANT: case EXCEPTION_PARAMETER:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1172
                case FIELD: case INSTANCE_INIT: case LOCAL_VARIABLE: case PARAMETER:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1173
                case RESOURCE_VARIABLE: case STATIC_INIT: case TYPE_PARAMETER:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1174
                    return ElementKind.METHOD;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1175
                default:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1176
                    throw new AssertionError("unsupported kind: " + kind);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1177
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1178
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1179
    } // end ModifierFilter
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1180
}