src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ElementsTable.java
author jlahoda
Fri, 09 Mar 2018 09:42:10 +0100
changeset 49197 cc2673fa8c20
parent 48054 702043a4cdeb
permissions -rw-r--r--
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure. Summary: Catching CompletionFailures that would be thrown to API clients, and re-completing the symbols again when javac itself needs it. Reviewed-by: cushon, 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
/*
43265
4ec472ee5135 8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents: 42827
diff changeset
     2
 * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
40508
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;
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
    33
import java.util.HashMap;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    34
import java.util.HashSet;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    35
import java.util.LinkedHashMap;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    36
import java.util.LinkedHashSet;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    37
import java.util.List;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    38
import java.util.Map;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    39
import java.util.Set;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    40
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    41
import javax.lang.model.element.Element;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    42
import javax.lang.model.element.ElementKind;
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.util.ElementFilter;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    50
import javax.lang.model.util.SimpleElementVisitor9;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    51
import javax.tools.JavaFileManager;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    52
import javax.tools.JavaFileManager.Location;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    53
import javax.tools.JavaFileObject;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    54
import javax.tools.StandardLocation;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    55
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    56
import com.sun.tools.javac.code.Kinds.Kind;
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
    57
import com.sun.tools.javac.code.Source;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47216
diff changeset
    58
import com.sun.tools.javac.code.Source.Feature;
40508
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.ModuleSymbol;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    63
import com.sun.tools.javac.code.Symbol.PackageSymbol;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    64
import com.sun.tools.javac.code.Symtab;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    65
import com.sun.tools.javac.comp.Modules;
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
    66
import com.sun.tools.javac.main.JavaCompiler;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    67
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    68
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
    69
import com.sun.tools.javac.tree.JCTree.JCModuleDecl;
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
    70
import com.sun.tools.javac.tree.TreeInfo;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    71
import com.sun.tools.javac.util.Context;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    72
import com.sun.tools.javac.util.ListBuffer;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    73
import com.sun.tools.javac.util.Name;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    74
import com.sun.tools.javac.util.Names;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    75
import jdk.javadoc.doclet.DocletEnvironment;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    76
import jdk.javadoc.doclet.DocletEnvironment.ModuleMode;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    77
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    78
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
    79
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
    80
import static javax.lang.model.util.Elements.Origin.*;
43265
4ec472ee5135 8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents: 42827
diff changeset
    81
import static javax.tools.JavaFileObject.Kind.*;
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
    82
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
    83
import static jdk.javadoc.internal.tool.Main.Result.*;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    84
import static jdk.javadoc.internal.tool.JavadocTool.isValidClassName;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    85
43265
4ec472ee5135 8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents: 42827
diff changeset
    86
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    87
/**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    88
 * 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
    89
 * produces "specified" and "included" data sets, needed by the
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    90
 * doclet environment, as well as querying an elements' visibility
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    91
 * or inclusion.
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
 * A. Initialization phase: the class is initialized with the
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    94
 *    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
    95
 *    be specified via specific options, such as packages, classes,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    96
 *    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
    97
 *    and setClassDeclList.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    98
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
    99
 * 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
   100
 *    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
   101
 *    specified with qualified packages and qualified subpackages, the
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   102
 *    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
   103
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   104
 * 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
   105
 *    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
   106
 *    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
   107
 *    specified on the command line.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   108
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   109
 * 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
   110
 *    the packages that ought to be included, as follows:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   111
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   112
 *    1. computes the specified modules, by considering the option
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   113
 *       "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
   114
 *       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
   115
 *       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
   116
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   117
 *    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
   118
 *       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
   119
 *       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
   120
 *       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
   121
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   122
 *    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
   123
 *       the subpackages and exclude any packages, if required.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   124
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   125
 *    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
   126
 *       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
   127
 *       considered.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   128
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   129
 * 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
   130
 *    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
   131
 *    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
   132
 *    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
   133
 *    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
   134
 *    cached, for performance reasons.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   135
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   136
 * Definitions:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   137
 *    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
   138
 *    of it components are included implicitly, subject to a
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   139
 *    selection criteria of its enclosed children.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   140
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   141
 *    Included: if the item should be documented.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   142
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   143
 * Rules for processing:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   144
 *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   145
 * 1. A specified element, meaning an element given on the
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   146
 *    command-line, and exposed via specified elements collections.
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   147
 * 2. Expand-contents, an internal pseudo term, meaning
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   148
 *    it is part of the recursive expansion of specified
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   149
 *    elements, meaning, the modules are expanded first, then
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   150
 *    the packages contained in the expanded modules, and then
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   151
 *    the types contained within the packages, to produce the
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   152
 *    collections returned by the methods
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   153
 *    getInclude{Module|Package|Type}Elements(), this is a
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   154
 *    downward expansion.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   155
 * 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
   156
 *    exposed via isIncluded, this enclosing element (module, package)
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   157
 *    is recursively included.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   158
 */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   159
public class ElementsTable {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   160
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   161
    private final ToolEnvironment toolEnv;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   162
    private final Symtab syms;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   163
    private final Names names;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   164
    private final JavaFileManager fm;
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   165
    private final List<Location> locations;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   166
    private final Modules modules;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   167
    private final Map<ToolOption, Object> opts;
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   168
    private final Messager messager;
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   169
    private final JavaCompiler compiler;
40508
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
    private final Map<String, Entry> entries = new LinkedHashMap<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   172
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   173
    // specified elements
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   174
    private Set<ModuleElement> specifiedModuleElements = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   175
    private Set<PackageElement> specifiedPackageElements = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   176
    private Set<TypeElement> specifiedTypeElements =new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   177
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   178
    // included elements
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   179
    private Set<ModuleElement> includedModuleElements = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   180
    private Set<PackageElement> includedPackageElements = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   181
    private Set<TypeElement> includedTypeElements = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   182
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   183
    // cmdline specifiers
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   184
    private Set<ModulePackage> cmdLinePackages = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   185
    private Set<ModulePackage> excludePackages = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   186
    private Set<ModulePackage> subPackages = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   187
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   188
    private List<JCClassDecl> classDecList = Collections.emptyList();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   189
    private List<String> classArgList = Collections.emptyList();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   190
    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
   191
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   192
    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
   193
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   194
    private final ModifierFilter accessFilter;
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
    private final AccessKind expandRequires;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   197
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   198
    final boolean xclasses;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   199
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   200
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   201
     * Creates the table to manage included and excluded elements.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   202
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   203
     * @param context the context to locate commonly used objects
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   204
     * @param location the location used to locate source files
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   205
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   206
    ElementsTable(Context context, Map<ToolOption, Object> opts) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   207
        this.toolEnv = ToolEnvironment.instance(context);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   208
        this.syms = Symtab.instance(context);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   209
        this.names = Names.instance(context);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   210
        this.fm = toolEnv.fileManager;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   211
        this.modules = Modules.instance(context);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   212
        this.opts = opts;
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   213
        this.messager = Messager.instance0(context);
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   214
        this.compiler = JavaCompiler.instance(context);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   215
        Source source = Source.instance(context);
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   216
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   217
        List<Location> locs = new ArrayList<>();
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   218
        if (modules.multiModuleMode) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   219
            locs.add(StandardLocation.MODULE_SOURCE_PATH);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   220
        } else {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   221
            if (toolEnv.fileManager.hasLocation(StandardLocation.SOURCE_PATH))
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   222
                locs.add(StandardLocation.SOURCE_PATH);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   223
            else
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   224
                locs.add(StandardLocation.CLASS_PATH);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   225
        }
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47216
diff changeset
   226
        if (Feature.MODULES.allowedInSource(source) && toolEnv.fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH))
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   227
            locs.add(StandardLocation.PATCH_MODULE_PATH);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   228
        this.locations = Collections.unmodifiableList(locs);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   229
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   230
        getEntry("").excluded = false;
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
        accessFilter = new ModifierFilter(opts);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   233
        xclasses = (boolean)opts.getOrDefault(ToolOption.XCLASSES, false);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   234
        expandRequires = (AccessKind)opts.get(ToolOption.EXPAND_REQUIRES);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   235
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   236
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   237
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   238
     * Returns the module documentation level mode.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   239
     * @return the module documentation level mode
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   240
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   241
    public ModuleMode getModuleMode() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   242
        switch(accessFilter.getAccessValue(ElementKind.MODULE)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   243
            case PACKAGE: case PRIVATE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   244
                return DocletEnvironment.ModuleMode.ALL;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   245
            default:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   246
                return DocletEnvironment.ModuleMode.API;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   247
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   248
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   249
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   250
    private Set<Element> specifiedElements = null;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   251
    /**
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   252
     * Returns a set of elements specified on the
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   253
     * command line, including any inner classes.
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   254
     *
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   255
     * @return the set of elements specified on the command line
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   256
     */
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   257
    public Set<? extends Element> getSpecifiedElements() {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   258
        if (specifiedElements == null) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   259
            Set<Element> result = new LinkedHashSet<>();
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   260
            result.addAll(specifiedModuleElements);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   261
            result.addAll(specifiedPackageElements);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   262
            result.addAll(specifiedTypeElements);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   263
            specifiedElements = Collections.unmodifiableSet(result);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   264
        }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   265
        return specifiedElements;
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   266
    }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   267
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   268
    private Set<Element> includedElements = null;
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   269
    /**
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   270
     * Returns a set of elements included elements. The inclusion is as
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   271
     * follows:
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   272
     * A module is fully included,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   273
     *   - is specified on the command line --module
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   274
     *   - 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
   275
     *     requires directive, based on --expand-requires
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   276
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   277
     * 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
   278
     * specified on the command line.
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   279
     *
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   280
     * A package is fully included,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   281
     *  - is specified on the command line
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   282
     *  - is derived from expanding -subpackages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   283
     *  - 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
   284
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   285
     * 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
   286
     * the command line.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   287
     *
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   288
     * Included type elements (including those within specified or included packages)
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   289
     * to be documented.
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   290
     *
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   291
     * A type is fully included if
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   292
     *  - is specified on the command line with -sourcepath
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   293
     *  - is visible with --show-types filter
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   294
     * A nested type is fully included if
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   295
     *  - is visible with --show-types filter
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   296
     *  - is enclosed in a fully included type
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   297
     * @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
   298
     */
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   299
    public Set<? extends Element> getIncludedElements() {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   300
        if (includedElements == null) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   301
            Set<Element> result = new LinkedHashSet<>();
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   302
            result.addAll(includedModuleElements);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   303
            result.addAll(includedPackageElements);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   304
            result.addAll(includedTypeElements);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   305
            includedElements = Collections.unmodifiableSet(result);
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   306
        }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   307
        return includedElements;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   308
    }
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
    private IncludedVisitor includedVisitor = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   311
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   312
    /**
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   313
     * 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
   314
     * 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
   315
     * fully included elements are tested.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   316
     * A member (constructor, method, field) is included if
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   317
     *  - 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
   318
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   319
     * @param e the element in question
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
     * @see getIncludedModuleElements
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   322
     * @see getIncludedPackageElements
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   323
     * @see getIncludedTypeElements
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   324
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   325
     * @return true if included
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   326
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   327
    public boolean isIncluded(Element e) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   328
        if (e == null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   329
            return false;
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
        if (includedVisitor == null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   332
            includedVisitor = new IncludedVisitor();
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
        return includedVisitor.visit(e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   335
    }
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
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   338
     * Performs the final computation and freezes the collections.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   339
     * This is a terminal operation, thus no further modifications
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   340
     * are allowed to the specified data sets.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   341
     *
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   342
     * @throws ToolException if an error occurs
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   343
     */
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   344
    void analyze() throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   345
        // compute the specified element, by expanding module dependencies
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   346
        computeSpecifiedModules();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   347
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   348
        // compute all specified packages and subpackages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   349
        computeSpecifiedPackages();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   350
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   351
        // compute the specified types
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   352
        computeSpecifiedTypes();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   353
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   354
        // compute the packages belonging to all the specified modules
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   355
        Set<PackageElement> expandedModulePackages = computeModulePackages();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   356
        initializeIncludedSets(expandedModulePackages);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   357
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   358
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   359
    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
   360
        this.classTreeList = classTrees;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   361
        return this;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   362
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   363
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   364
    /*
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   365
     * This method sanity checks the following cases:
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   366
     * a. a source-path containing a single module and many modules specified with --module
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   367
     * b. no modules on source-path
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   368
     * c. mismatched source-path and many modules specified with --module
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   369
     */
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   370
    void sanityCheckSourcePathModules(List<String> moduleNames) throws ToolException {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   371
        if (!haveSourceLocationWithModule)
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   372
            return;
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   373
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   374
        if (moduleNames.size() > 1) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   375
            String text = messager.getText("main.cannot_use_sourcepath_for_modules",
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   376
                    String.join(", ", moduleNames));
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   377
            throw new ToolException(CMDERR, text);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   378
        }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   379
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   380
        String foundModule = getModuleName(StandardLocation.SOURCE_PATH);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   381
        if (foundModule == null) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   382
            String text = messager.getText("main.module_not_found_on_sourcepath", moduleNames.get(0));
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   383
            throw new ToolException(CMDERR, text);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   384
        }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   385
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   386
        if (!moduleNames.get(0).equals(foundModule)) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   387
            String text = messager.getText("main.sourcepath_does_not_contain_module", moduleNames.get(0));
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   388
            throw new ToolException(CMDERR, text);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   389
        }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   390
    }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   391
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   392
    private String getModuleName(Location location) throws ToolException {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   393
        try {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   394
            JavaFileObject jfo = fm.getJavaFileForInput(location,
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   395
                    "module-info", JavaFileObject.Kind.SOURCE);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   396
            if (jfo != null) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   397
                JCCompilationUnit jcu = compiler.parse(jfo);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   398
                JCModuleDecl module = TreeInfo.getModule(jcu);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   399
                if (module != null) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   400
                    return module.getName().toString();
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   401
                }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   402
            }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   403
        } catch (IOException ioe) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   404
            String text = messager.getText("main.file.manager.list", location);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   405
            throw new ToolException(SYSERR, text, ioe);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   406
        }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   407
        return null;
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   408
    }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   409
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   410
    @SuppressWarnings("unchecked")
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   411
    ElementsTable scanSpecifiedItems() throws ToolException {
40508
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
        // scan modules specified on the command line
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   414
        List<String> moduleNames = (List<String>) opts.computeIfAbsent(ToolOption.MODULE,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   415
                s -> Collections.EMPTY_LIST);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   416
        List<String> mlist = new ArrayList<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   417
        for (String m : moduleNames) {
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   418
            List<Location> moduleLocations = getModuleLocation(locations, m);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   419
            if (moduleLocations.isEmpty()) {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   420
                String text = messager.getText("main.module_not_found", m);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   421
                throw new ToolException(CMDERR, text);
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   422
            }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   423
            if (moduleLocations.contains(StandardLocation.SOURCE_PATH)) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   424
                sanityCheckSourcePathModules(moduleNames);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   425
            }
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   426
            mlist.add(m);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   427
            ModuleSymbol msym = syms.enterModule(names.fromString(m));
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   428
            specifiedModuleElements.add((ModuleElement) msym);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   429
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   430
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   431
        // scan for modules with qualified packages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   432
        cmdLinePackages.stream()
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   433
                .filter((mpkg) -> (mpkg.hasModule()))
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   434
                .forEachOrdered((mpkg) -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   435
                    mlist.add(mpkg.moduleName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   436
        });
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   437
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   438
        // scan for modules with qualified subpackages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   439
        ((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
   440
            .stream()
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42824
diff changeset
   441
            .map(ModulePackage::new)
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   442
            .forEachOrdered((mpkg) -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   443
                subPackages.add(mpkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   444
                if (mpkg.hasModule()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   445
                    mlist.add(mpkg.moduleName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   446
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   447
            });
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
        // 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
   450
        // init the module systems
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   451
        modules.addExtraAddModules(mlist.toArray(new String[mlist.size()]));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   452
        modules.initModules(this.classTreeList);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   453
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   454
        return this;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   455
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   456
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   457
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   458
     * 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
   459
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   460
     * @param classList
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   461
     * @return the include table
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   462
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   463
    ElementsTable setClassArgList(List<String> classList) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   464
        classArgList = classList;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   465
        return this;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   466
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   467
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   468
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   469
     * 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
   470
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   471
     * @param classesDecList
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   472
     * @return the include table
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   473
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   474
    ElementsTable setClassDeclList(List<JCClassDecl> classesDecList) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   475
        this.classDecList = classesDecList;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   476
        return this;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   477
    }
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
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   480
     * Returns an includes table after setting the specified package
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   481
     * names.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   482
     * @param packageNames packages on the command line
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   483
     * @return the includes table after setting the specified package
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   484
     * names
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
    ElementsTable packages(Collection<String> packageNames) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   487
        packageNames.stream()
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42824
diff changeset
   488
            .map(ModulePackage::new)
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   489
            .forEachOrdered((mpkg) -> cmdLinePackages.add(mpkg));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   490
        return this;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   491
    }
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
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   494
     * Returns the aggregate set of included packages and specified
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   495
     * sub packages.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   496
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   497
     * @return the aggregate set of included packages and specified
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   498
     * sub packages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   499
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   500
    Iterable<ModulePackage> getPackagesToParse() throws IOException {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   501
        List<ModulePackage> result = new ArrayList<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   502
        result.addAll(cmdLinePackages);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   503
        result.addAll(subPackages);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   504
        return result;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   505
    }
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
    @SuppressWarnings("unchecked")
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   508
    private void computeSubpackages() throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   509
        ((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
   510
                .stream()
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42824
diff changeset
   511
                .map(ModulePackage::new)
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   512
                .forEachOrdered((mpkg) -> excludePackages.add(mpkg));
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
        excludePackages.forEach((p) -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   515
            getEntry(p).excluded = true;
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
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   518
        for (ModulePackage modpkg : subPackages) {
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   519
            List<Location> locs = getLocation(modpkg);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   520
            for (Location loc : locs) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   521
                addPackagesFromLocations(loc, modpkg);
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   522
            }
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   523
        }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   524
    }
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   525
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   526
    /* Call fm.list and wrap any IOException that occurs in a ToolException */
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   527
    private Iterable<JavaFileObject> fmList(Location location,
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   528
                                            String packagename,
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   529
                                            Set<JavaFileObject.Kind> kinds,
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   530
                                            boolean recurse) throws ToolException {
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   531
        try {
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   532
            return fm.list(location, packagename, kinds, recurse);
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   533
        } catch (IOException ioe) {
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   534
            String text = messager.getText("main.file.manager.list", packagename);
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   535
            throw new ToolException(SYSERR, text, ioe);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   536
        }
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   537
    }
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   538
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   539
    private void addPackagesFromLocations(Location packageLocn, ModulePackage modpkg) throws ToolException {
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   540
        for (JavaFileObject fo : fmList(packageLocn, modpkg.packageName, sourceKinds, true)) {
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   541
            String binaryName = fm.inferBinaryName(packageLocn, fo);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   542
            String pn = getPackageName(binaryName);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   543
            String simpleName = getSimpleName(binaryName);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   544
            Entry e = getEntry(pn);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   545
            if (!e.isExcluded() && isValidClassName(simpleName)) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   546
                ModuleSymbol msym = (modpkg.hasModule())
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   547
                        ? syms.getModule(names.fromString(modpkg.moduleName))
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   548
                        : findModuleOfPackageName(modpkg.packageName);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   549
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   550
                if (msym != null && !msym.isUnnamed()) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   551
                    syms.enterPackage(msym, names.fromString(pn));
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   552
                    ModulePackage npkg = new ModulePackage(msym.toString(), pn);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   553
                    cmdLinePackages.add(npkg);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   554
                } else {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   555
                    cmdLinePackages.add(e.modpkg);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   556
                }
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   557
                e.files = (e.files == null
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   558
                        ? com.sun.tools.javac.util.List.of(fo)
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   559
                        : e.files.prepend(fo));
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   560
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   561
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   562
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   563
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
     * Returns the "requires" modules for the target module.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   566
     * @param mdle the target module element
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   567
     * @param onlyTransitive true gets all the requires transitive, otherwise
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   568
     *                 gets all the non-transitive requires
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   569
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   570
     * @return a set of modules
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   571
     */
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   572
    private Set<ModuleElement> getModuleRequires(ModuleElement mdle, boolean onlyTransitive) throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   573
        Set<ModuleElement> result = new HashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   574
        for (RequiresDirective rd : ElementFilter.requiresIn(mdle.getDirectives())) {
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   575
            ModuleElement dep = rd.getDependency();
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   576
            if (result.contains(dep))
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   577
                continue;
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   578
            if (!isMandated(mdle, rd) && onlyTransitive == rd.isTransitive()) {
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   579
                if (!haveModuleSources(dep)) {
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   580
                    messager.printWarning(dep, "main.module_not_found", dep.getSimpleName());
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   581
                }
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   582
                result.add(dep);
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   583
            } else if (isMandated(mdle, rd) && haveModuleSources(dep)) {
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   584
                result.add(dep);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   585
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   586
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   587
        return result;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   588
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   589
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   590
    private boolean isMandated(ModuleElement mdle, RequiresDirective rd) {
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   591
        return toolEnv.elements.getOrigin(mdle, rd) == MANDATED;
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   592
    }
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   593
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   594
    Map<ModuleSymbol, Boolean> haveModuleSourcesCache = new HashMap<>();
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   595
    private boolean haveModuleSources(ModuleElement mdle) throws ToolException {
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   596
        ModuleSymbol msym =  (ModuleSymbol)mdle;
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   597
        if (msym.sourceLocation != null) {
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   598
            return true;
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   599
        }
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   600
        if (msym.patchLocation != null) {
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   601
            Boolean value = haveModuleSourcesCache.get(msym);
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   602
            if (value == null) {
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   603
                value = fmList(msym.patchLocation, "", sourceKinds, true).iterator().hasNext();
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   604
                haveModuleSourcesCache.put(msym, value);
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   605
            }
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   606
            return value;
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   607
        }
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   608
        return false;
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   609
    }
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   610
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   611
    private void computeSpecifiedModules() throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   612
        if (expandRequires == null) { // no expansion requested
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   613
            specifiedModuleElements = Collections.unmodifiableSet(specifiedModuleElements);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   614
            return;
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
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   617
        final boolean expandAll = expandRequires.equals(AccessKind.PRIVATE)
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   618
                || expandRequires.equals(AccessKind.PACKAGE);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   619
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   620
        Set<ModuleElement> result = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   621
        ListBuffer<ModuleElement> queue = new ListBuffer<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   622
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   623
        // expand each specified module
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   624
        for (ModuleElement mdle : specifiedModuleElements) {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   625
            result.add(mdle); // a specified module is included
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   626
            queue.append(mdle);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   627
            Set<ModuleElement> publicRequires = getModuleRequires(mdle, true);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   628
            result.addAll(publicRequires);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   629
            // add all requires public
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   630
            queue.addAll(publicRequires);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   631
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   632
            if (expandAll) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   633
                 // add non-public requires if needed
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   634
                result.addAll(getModuleRequires(mdle, !expandAll));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   635
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   636
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   637
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   638
        // compute the transitive closure of all the requires public
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   639
        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
   640
            for (ModuleElement mdle : getModuleRequires(m, true)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   641
                if (!result.contains(mdle)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   642
                    result.add(mdle);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   643
                    queue.append(mdle);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   644
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   645
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   646
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   647
        specifiedModuleElements = Collections.unmodifiableSet(result);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   648
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   649
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   650
    private Set<PackageElement> getAllModulePackages(ModuleElement mdle) throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   651
        Set<PackageElement> result = new HashSet<>();
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   652
        ModuleSymbol msym = (ModuleSymbol) mdle;
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   653
        List<Location> msymlocs = getModuleLocation(locations, msym.name.toString());
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   654
        for (Location msymloc : msymlocs) {
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   655
            for (JavaFileObject fo : fmList(msymloc, "", sourceKinds, true)) {
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   656
                if (fo.getName().endsWith("module-info.java")) {
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   657
                    continue;
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   658
                }
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   659
                String binaryName = fm.inferBinaryName(msymloc, fo);
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   660
                String pn = getPackageName(binaryName);
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   661
                PackageSymbol psym = syms.enterPackage(msym, names.fromString(pn));
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   662
                result.add((PackageElement) psym);
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   663
            }
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   664
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   665
        return result;
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
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   668
    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
   669
        AccessKind accessValue = accessFilter.getAccessValue(ElementKind.PACKAGE);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   670
        final boolean documentAllModulePackages = (accessValue == AccessKind.PACKAGE ||
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   671
                accessValue == AccessKind.PRIVATE);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   672
41633
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   673
        accessValue = accessFilter.getAccessValue(ElementKind.MODULE);
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   674
        final boolean moduleDetailedMode = (accessValue == AccessKind.PACKAGE ||
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   675
                accessValue == AccessKind.PRIVATE);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   676
        Set<PackageElement> expandedModulePackages = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   677
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   678
        for (ModuleElement mdle : specifiedModuleElements) {
41633
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   679
            if (documentAllModulePackages) { // include all packages
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   680
                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
   681
                expandedModulePackages.addAll(packages);
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   682
                expandedModulePackages.addAll(getAllModulePackages(mdle));
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   683
            } else { // selectively include required packages
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   684
                List<ExportsDirective> exports = ElementFilter.exportsIn(mdle.getDirectives());
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   685
                for (ExportsDirective export : exports) {
41633
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   686
                    // 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
   687
                    if (export.getTargetModules() == null
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   688
                            || documentAllModulePackages || moduleDetailedMode) {
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   689
                        expandedModulePackages.add(export.getPackage());
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 41451
diff changeset
   690
                    }
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   691
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   692
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   693
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   694
            // add all packages specified on the command line
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   695
            // belonging to this module
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   696
            if (!cmdLinePackages.isEmpty()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   697
                for (ModulePackage modpkg : cmdLinePackages) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   698
                    PackageElement pkg = toolEnv.elements.getPackageElement(mdle,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   699
                            modpkg.packageName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   700
                    if (pkg != null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   701
                        expandedModulePackages.add(pkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   702
                    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   703
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   704
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   705
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   706
        return expandedModulePackages;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   707
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   708
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   709
    private void initializeIncludedSets(Set<PackageElement> expandedModulePackages) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   710
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   711
        // process modules
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   712
        Set<ModuleElement> imodules = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   713
        // add all the expanded modules
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   714
        imodules.addAll(specifiedModuleElements);
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
        // process packages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   717
        Set<PackageElement> ipackages = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   718
        // add all packages belonging to expanded modules
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   719
        ipackages.addAll(expandedModulePackages);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   720
        // add all specified packages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   721
        specifiedPackageElements.forEach(pkg -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   722
            ModuleElement mdle = toolEnv.elements.getModuleOf(pkg);
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42408
diff changeset
   723
            if (mdle != null)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42408
diff changeset
   724
                imodules.add(mdle);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   725
            ipackages.add(pkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   726
        });
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   727
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   728
        // process types
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   729
        Set<TypeElement> iclasses = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   730
        // add all types enclosed in expanded modules and packages
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   731
        ipackages.forEach((pkg) -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   732
            addAllClasses(iclasses, pkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   733
        });
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   734
        // add all types and its nested types
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   735
        specifiedTypeElements.forEach((klass) -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   736
            ModuleElement mdle = toolEnv.elements.getModuleOf(klass);
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42408
diff changeset
   737
            if (mdle != null && !mdle.isUnnamed())
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   738
                imodules.add(mdle);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   739
            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
   740
            ipackages.add(pkg);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   741
            addAllClasses(iclasses, klass, true);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   742
        });
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
        // all done, freeze the collections
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   745
        includedModuleElements = Collections.unmodifiableSet(imodules);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   746
        includedPackageElements = Collections.unmodifiableSet(ipackages);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   747
        includedTypeElements = Collections.unmodifiableSet(iclasses);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   748
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   749
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   750
    /*
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   751
     * 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
   752
     */
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   753
    private void computeSpecifiedPackages() throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   754
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   755
        computeSubpackages();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   756
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   757
        Set<PackageElement> packlist = new LinkedHashSet<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   758
        cmdLinePackages.forEach((modpkg) -> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   759
            PackageElement pkg;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   760
            if (modpkg.hasModule()) {
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   761
                ModuleElement mdle = toolEnv.elements.getModuleElement(modpkg.moduleName);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   762
                pkg = toolEnv.elements.getPackageElement(mdle, modpkg.packageName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   763
            } else {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   764
                pkg = toolEnv.elements.getPackageElement(modpkg.toString());
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   765
            }
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
            if (pkg != null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   768
                packlist.add(pkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   769
            } else {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   770
                messager.printWarningUsingKey("main.package_not_found", modpkg.toString());
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   771
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   772
        });
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   773
        specifiedPackageElements = Collections.unmodifiableSet(packlist);
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
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   777
     * 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
   778
     * list.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   779
     */
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   780
    private void computeSpecifiedTypes() throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   781
        Set<TypeElement> classes = new LinkedHashSet<>();
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   782
          classDecList.forEach((def) -> {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   783
            TypeElement te = (TypeElement) def.sym;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   784
            if (te != null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   785
                addAllClasses(classes, te, true);
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
        });
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   788
        for (String className : classArgList) {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   789
            TypeElement te = toolEnv.loadClass(className);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   790
            if (te == null) {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   791
                String text = messager.getText("javadoc.class_not_found", className);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   792
                throw new ToolException(CMDERR, text);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   793
            } else {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   794
                addAllClasses(classes, te, true);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   795
            }
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   796
        }
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   797
        specifiedTypeElements = Collections.unmodifiableSet(classes);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   798
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   799
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   800
    private void addFilesForParser(Collection<JavaFileObject> result,
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   801
            Collection<ModulePackage> collection,
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   802
            boolean recurse) throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   803
        for (ModulePackage modpkg : collection) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   804
            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
   805
            List<JavaFileObject> files = getFiles(modpkg, recurse);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   806
            if (files.isEmpty()) {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   807
                String text = messager.getText("main.no_source_files_for_package",
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   808
                        modpkg.toString());
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   809
                throw new ToolException(CMDERR, text);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   810
            } else {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   811
                result.addAll(files);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   812
            }
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
    }
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
     * 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
   818
     * 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
   819
     * 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
   820
     * @return a list of java file objects
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   821
     * @throws IOException if an error occurs
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   822
     */
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   823
    List<JavaFileObject> getFilesToParse() throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   824
        List<JavaFileObject> result = new ArrayList<>();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   825
        addFilesForParser(result, cmdLinePackages, false);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   826
        addFilesForParser(result, subPackages, true);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   827
        return result;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   828
    }
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
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   831
     * Returns the set of source files for a package.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   832
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   833
     * @param packageName the specified package
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   834
     * @return the set of file objects for the specified package
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   835
     * @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
   836
     */
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   837
    private List<JavaFileObject> getFiles(ModulePackage modpkg,
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   838
            boolean recurse) throws ToolException {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   839
        Entry e = getEntry(modpkg);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   840
        // 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
   841
        if (e.files != null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   842
            return e.files;
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
        ListBuffer<JavaFileObject> lb = new ListBuffer<>();
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   846
        List<Location> locs = getLocation(modpkg);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   847
        if (locs.isEmpty()) {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   848
            return Collections.emptyList();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   849
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   850
        String pname = modpkg.packageName;
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   851
        for (Location packageLocn : locs) {
44389
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   852
            for (JavaFileObject fo : fmList(packageLocn, pname, sourceKinds, recurse)) {
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   853
                String binaryName = fm.inferBinaryName(packageLocn, fo);
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   854
                String simpleName = getSimpleName(binaryName);
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   855
                if (isValidClassName(simpleName)) {
a745e6ff79a5 8176481: javadoc does not consider mandated modules
ksrini
parents: 44301
diff changeset
   856
                    lb.append(fo);
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   857
                }
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   858
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   859
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   860
        return lb.toList();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   861
    }
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
    private ModuleSymbol findModuleOfPackageName(String packageName) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   864
            Name pack = names.fromString(packageName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   865
            for (ModuleSymbol msym : modules.allModules()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   866
                PackageSymbol p = syms.getPackage(msym, pack);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   867
                if (p != null && !p.members().isEmpty()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   868
                    return msym;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   869
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   870
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   871
            return null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   872
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   873
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   874
    private List<Location> getLocation(ModulePackage modpkg) throws ToolException {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   875
        if (locations.size() == 1 && !locations.contains(StandardLocation.MODULE_SOURCE_PATH)) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   876
            return Collections.singletonList(locations.get(0));
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   877
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   878
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   879
        if (modpkg.hasModule()) {
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   880
            return getModuleLocation(locations, modpkg.moduleName);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   881
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   882
        // TODO: handle invalid results better.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   883
        ModuleSymbol msym = findModuleOfPackageName(modpkg.packageName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   884
        if (msym == null) {
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   885
            return Collections.emptyList();
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   886
        }
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   887
        return getModuleLocation(locations, msym.name.toString());
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   888
    }
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   889
44301
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   890
    boolean haveSourceLocationWithModule = false;
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   891
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   892
    private List<Location> getModuleLocation(List<Location> locations, String msymName) throws ToolException {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   893
        List<Location> out = new ArrayList<>();
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   894
        // search in the patch module first, this overrides others
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   895
        if (locations.contains(StandardLocation.PATCH_MODULE_PATH)) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   896
            Location loc = getModuleLocation(StandardLocation.PATCH_MODULE_PATH, msymName);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   897
            if (loc != null)
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   898
                out.add(loc);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   899
        }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   900
        for (Location location : locations) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   901
            // skip patch module, already done
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   902
            if (location == StandardLocation.PATCH_MODULE_PATH) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   903
                continue;
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   904
            } else if (location == StandardLocation.MODULE_SOURCE_PATH) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   905
                Location loc = getModuleLocation(location, msymName);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   906
                if (loc != null)
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   907
                    out.add(loc);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   908
            } else if (location == StandardLocation.SOURCE_PATH) {
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   909
                haveSourceLocationWithModule = true;
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   910
                out.add(StandardLocation.SOURCE_PATH);
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   911
            }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   912
        }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   913
        return out;
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   914
    }
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   915
2f97c71f06f4 8175346: javadoc does not handle Locations correctly with --patch-module
ksrini
parents: 43265
diff changeset
   916
    private Location getModuleLocation(Location location, String msymName) throws ToolException {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   917
        try {
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41633
diff changeset
   918
            return fm.getLocationForModule(location, msymName);
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   919
        } catch (IOException ioe) {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   920
            String text = messager.getText("main.doclet_could_not_get_location", msymName);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   921
            throw new ToolException(ERROR, text, ioe);
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   922
        }
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   923
    }
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
    private Entry getEntry(String name) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   926
        return getEntry(new ModulePackage(name));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   927
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   928
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   929
    private Entry getEntry(ModulePackage modpkg) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   930
        Entry e = entries.get(modpkg.packageName);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   931
        if (e == null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   932
            entries.put(modpkg.packageName, e = new Entry(modpkg));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   933
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   934
        return e;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   935
    }
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
    private String getPackageName(String name) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   938
        int lastDot = name.lastIndexOf(".");
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   939
        return (lastDot == -1 ? "" : name.substring(0, lastDot));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   940
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   941
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   942
    private String getSimpleName(String name) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   943
        int lastDot = name.lastIndexOf(".");
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   944
        return (lastDot == -1 ? name : name.substring(lastDot + 1));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   945
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   946
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   947
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   948
     * 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
   949
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   950
    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
   951
        ClassSymbol klass = (ClassSymbol)typeElement;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   952
        try {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   953
            // eliminate needless checking, do this first.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   954
            if (list.contains(klass)) return;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   955
            // ignore classes with invalid Java class names
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   956
            if (!JavadocTool.isValidClassName(klass.name.toString())) return;
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   957
            if (filtered && !isTypeElementSelected(klass)) return;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   958
            list.add(klass);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   959
            for (Symbol sym : klass.members().getSymbols(NON_RECURSIVE)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   960
                if (sym != null && sym.kind == Kind.TYP) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   961
                    ClassSymbol s = (ClassSymbol)sym;
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   962
                    addAllClasses(list, s, filtered);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   963
                }
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
        } catch (CompletionFailure e) {
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   966
            if (e.getMessage() != null)
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   967
                messager.printWarning(e.getMessage());
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   968
            else
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 40606
diff changeset
   969
                messager.printWarningUsingKey("main.unexpected.exception", e);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   970
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   971
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   972
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   973
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   974
     * 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
   975
     * 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
   976
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   977
    private void addAllClasses(Collection<TypeElement> list, PackageElement pkg) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   978
        boolean filtered = true;
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48054
diff changeset
   979
        for (Element isym : pkg.getEnclosedElements()) {
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   980
            addAllClasses(list, (TypeElement)isym, filtered);
40508
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
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   983
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   984
    private boolean isTypeElementSelected(TypeElement te) {
43265
4ec472ee5135 8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents: 42827
diff changeset
   985
        return (xclasses || toolEnv.getFileKind(te) == SOURCE) && isSelected(te);
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   986
    }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   987
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   988
    SimpleElementVisitor9<Boolean, Void> visibleElementVisitor = null;
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   989
    /**
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   990
     * Returns true if the element is selected, by applying
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   991
     * the access filter checks. Special treatment is applied to
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   992
     * types, for a top level type the access filter applies completely,
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   993
     * however if is a nested type then it is allowed either  if
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   994
     * the enclosing is a static or the enclosing is also selected.
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   995
     *
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   996
     * @param e the element to be checked
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   997
     * @return true if the element is visible
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
   998
     */
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
   999
    public boolean isSelected(Element e) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1000
        if (toolEnv.isSynthetic((Symbol) e)) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1001
            return false;
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1002
        }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1003
        if (visibleElementVisitor == null) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1004
            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
  1005
                @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1006
                public Boolean visitType(TypeElement e, Void p) {
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1007
                    if (!accessFilter.checkModifier(e)) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1008
                        return false; // it is not allowed
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1009
                    }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1010
                    Element encl = e.getEnclosingElement();
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1011
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1012
                    // check if nested
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1013
                    if (encl.getKind() == ElementKind.PACKAGE)
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1014
                        return true; // top-level class, allow it
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1015
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1016
                    // is enclosed static
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1017
                    if (encl.getModifiers().contains(Modifier.STATIC))
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1018
                        return true; // allowed
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1019
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1020
                    // check the enclosing
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1021
                    return visit(encl);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1022
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1023
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
  1024
                @Override
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1025
                protected Boolean defaultAction(Element e, Void p) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1026
                    return accessFilter.checkModifier(e);
40508
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
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
  1029
                @Override
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1030
                public Boolean visitUnknown(Element e, Void p) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1031
                    throw new AssertionError("unkown element: " + p);
40508
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
        }
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1035
        return visibleElementVisitor.visit(e);
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1036
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1037
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1038
    private class IncludedVisitor extends SimpleElementVisitor9<Boolean, Void> {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1039
        final private Set<Element> includedCache;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1040
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1041
        public IncludedVisitor() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1042
            includedCache = new LinkedHashSet<>();
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
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
  1045
        @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1046
        public Boolean visitModule(ModuleElement e, Void p) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1047
            // deduced by specified and/or requires expansion
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1048
            return includedModuleElements.contains(e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1049
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1050
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
  1051
        @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1052
        public Boolean visitPackage(PackageElement e, Void p) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1053
            // deduced by specified or downward expansions
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1054
            return includedPackageElements.contains(e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1055
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1056
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
  1057
        @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1058
        public Boolean visitType(TypeElement e, Void p) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1059
            if (includedTypeElements.contains(e)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1060
                return true;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1061
            }
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1062
            if (isTypeElementSelected(e)) {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1063
                // Class is nameable from top-level and
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1064
                // the class and all enclosing classes
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1065
                // pass the modifier filter.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1066
                PackageElement pkg = toolEnv.elements.getPackageOf(e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1067
                if (specifiedPackageElements.contains(pkg)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1068
                    return true;
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
                Element enclosing = e.getEnclosingElement();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1071
                if (enclosing != null) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1072
                    switch(enclosing.getKind()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1073
                        case PACKAGE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1074
                            return specifiedPackageElements.contains((PackageElement)enclosing);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1075
                        case CLASS: case INTERFACE: case ENUM: case ANNOTATION_TYPE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1076
                            return visit((TypeElement) enclosing);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1077
                        default:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1078
                            throw new AssertionError("unknown element: " + enclosing);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1079
                    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1080
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1081
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1082
            return false;
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
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1085
        // members
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
  1086
        @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1087
        public Boolean defaultAction(Element e, Void p) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1088
            if (includedCache.contains(e))
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1089
                return true;
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 42261
diff changeset
  1090
            if (visit(e.getEnclosingElement()) && isSelected(e)) {
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1091
                switch(e.getKind()) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1092
                    case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1093
                    case MODULE: case OTHER: case PACKAGE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1094
                        throw new AssertionError("invalid element for this operation: " + e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1095
                    default:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1096
                        // the only allowed kinds in the cache are "members"
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1097
                        includedCache.add(e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1098
                        return true;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1099
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1100
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1101
            return false;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1102
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1103
40606
eb2c81860c86 8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents: 40508
diff changeset
  1104
        @Override
40508
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1105
        public Boolean visitUnknown(Element e, Void p) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1106
            throw new AssertionError("unknown element: " + e);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1107
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1108
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1109
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1110
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1111
    class Entry {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1112
        final ModulePackage modpkg;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1113
        Boolean excluded = false;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1114
        com.sun.tools.javac.util.List<JavaFileObject> files;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1115
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1116
        Entry(ModulePackage modpkg) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1117
            this.modpkg = modpkg;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1118
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1119
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1120
        Entry(String name) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1121
            modpkg = new ModulePackage(name);
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
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1124
        boolean isExcluded() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1125
            return excluded;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1126
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1127
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1128
        @Override
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1129
        public String toString() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1130
            return "Entry{" + "modpkg=" + modpkg + ", excluded=" + excluded + ", files=" + files + '}';
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1131
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1132
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1133
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
     * 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
  1136
     * from a parsed qualified package name.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1137
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1138
    static class ModulePackage {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1139
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1140
        public final String moduleName;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1141
        public final String packageName;
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
        ModulePackage(String modulename, String packagename) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1144
            this.moduleName = modulename;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1145
            this.packageName = packagename;
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
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1148
        ModulePackage(ModuleElement msym, String packagename) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1149
            this.moduleName = msym.toString();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1150
            this.packageName = packagename;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1151
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1152
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1153
        ModulePackage(String name) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1154
            String a[] = name.split("/");
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1155
            if (a.length == 2) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1156
                this.moduleName = a[0];
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1157
                this.packageName = a[1];
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1158
            } else {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1159
                moduleName = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1160
                packageName = name;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1161
            }
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
        boolean hasModule() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1165
            return this.moduleName != null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1166
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1167
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1168
        @Override
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1169
        public boolean equals(Object obj) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1170
            if (obj instanceof ModulePackage) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1171
                ModulePackage that = (ModulePackage)obj;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1172
                return this.toString().equals(that.toString());
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1173
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1174
            return false;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1175
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1176
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1177
        @Override
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1178
        public int hashCode() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1179
             return toString().hashCode();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1180
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1181
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1182
        @Override
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1183
        public String toString() {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1184
            return moduleName == null ? packageName : moduleName + "/" + packageName;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1185
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1186
    }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1187
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1188
    /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1189
     * 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
  1190
     *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1191
     * @see javax.lang.model.element.Modifier
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1192
     */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1193
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1194
    static class ModifierFilter {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1195
        /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1196
         * The allowed ElementKind that can be stored.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1197
         */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1198
        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
  1199
                                                    ElementKind.CLASS,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1200
                                                    ElementKind.PACKAGE,
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1201
                                                    ElementKind.MODULE);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1202
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1203
        // all possible accesss levels allowed for each element
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1204
        private final EnumMap<ElementKind, EnumSet<AccessKind>> filterMap =
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1205
                new EnumMap<>(ElementKind.class);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1206
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1207
        // the specified access level for each element
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1208
        private final EnumMap<ElementKind, AccessKind> accessMap =
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1209
                new EnumMap<>(ElementKind.class);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1210
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1211
        /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1212
         * Constructor - Specify a filter.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1213
         *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1214
         * @param accessSet an Access filter.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1215
         */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1216
        ModifierFilter(Map<ToolOption, Object> opts) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1217
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1218
            AccessKind accessValue = null;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1219
            for (ElementKind kind : ALLOWED_KINDS) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1220
                switch (kind) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1221
                    case METHOD:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1222
                        accessValue  = (AccessKind)opts.get(ToolOption.SHOW_MEMBERS);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1223
                        break;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1224
                    case CLASS:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1225
                        accessValue  = (AccessKind)opts.get(ToolOption.SHOW_TYPES);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1226
                        break;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1227
                    case PACKAGE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1228
                        accessValue  = (AccessKind)opts.get(ToolOption.SHOW_PACKAGES);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1229
                        break;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1230
                    case MODULE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1231
                        accessValue  = (AccessKind)opts.get(ToolOption.SHOW_MODULE_CONTENTS);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1232
                        break;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1233
                    default:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1234
                        throw new AssertionError("unknown element: " + kind);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1235
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1236
                }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1237
                accessMap.put(kind, accessValue);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1238
                filterMap.put(kind, getFilterSet(accessValue));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1239
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1240
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1241
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1242
        static EnumSet<AccessKind> getFilterSet(AccessKind acccessValue) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1243
            switch (acccessValue) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1244
                case PUBLIC:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1245
                    return EnumSet.of(AccessKind.PUBLIC);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1246
                case PROTECTED:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1247
                default:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1248
                    return EnumSet.of(AccessKind.PUBLIC, AccessKind.PROTECTED);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1249
                case PACKAGE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1250
                    return EnumSet.of(AccessKind.PUBLIC, AccessKind.PROTECTED, AccessKind.PACKAGE);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1251
                case PRIVATE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1252
                    return EnumSet.allOf(AccessKind.class);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1253
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1254
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1255
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1256
        public AccessKind getAccessValue(ElementKind kind) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1257
            if (!ALLOWED_KINDS.contains(kind)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1258
                throw new IllegalArgumentException("not allowed: " + kind);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1259
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1260
            return accessMap.getOrDefault(kind, AccessKind.PROTECTED);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1261
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1262
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1263
        /**
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1264
         * Returns true if access is allowed.
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1265
         *
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1266
         * @param e the element in question
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1267
         * @return whether the modifiers pass this filter
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1268
         */
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1269
        public boolean checkModifier(Element e) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1270
            Set<Modifier> modifiers = e.getModifiers();
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1271
            AccessKind fflag = AccessKind.PACKAGE;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1272
            if (modifiers.contains(Modifier.PUBLIC)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1273
                fflag = AccessKind.PUBLIC;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1274
            } else if (modifiers.contains(Modifier.PROTECTED)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1275
                fflag = AccessKind.PROTECTED;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1276
            } else if (modifiers.contains(Modifier.PRIVATE)) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1277
                fflag = AccessKind.PRIVATE;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1278
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1279
            EnumSet<AccessKind> filterSet = filterMap.get(getAllowedKind(e.getKind()));
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1280
            return filterSet.contains(fflag);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1281
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1282
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1283
        // 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
  1284
        private ElementKind getAllowedKind(ElementKind kind) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1285
            switch (kind) {
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1286
                case CLASS: case METHOD: case MODULE: case PACKAGE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1287
                    return kind;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1288
                case ANNOTATION_TYPE: case ENUM: case INTERFACE:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1289
                    return ElementKind.CLASS;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1290
                case CONSTRUCTOR: case ENUM_CONSTANT: case EXCEPTION_PARAMETER:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1291
                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
  1292
                case RESOURCE_VARIABLE: case STATIC_INIT: case TYPE_PARAMETER:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1293
                    return ElementKind.METHOD;
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1294
                default:
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1295
                    throw new AssertionError("unsupported kind: " + kind);
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1296
            }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1297
        }
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1298
    } // end ModifierFilter
74ef30d16fb9 8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
diff changeset
  1299
}