< prev index next >

src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ElementsTable.java

Print this page




 147  * 2. Expand-contents, an internal pseudo term, meaning
 148  *    it is part of the recursive expansion of specified
 149  *    elements, meaning, the modules are expanded first, then
 150  *    the packages contained in the expanded modules, and then
 151  *    the types contained within the packages, to produce the
 152  *    collections returned by the methods
 153  *    getInclude{Module|Package|Type}Elements(), this is a
 154  *    downward expansion.
 155  * 3. An included element, meaning it should be documented, and
 156  *    exposed via isIncluded, this enclosing element (module, package)
 157  *    is recursively included.
 158  */
 159 public class ElementsTable {
 160 
 161     private final ToolEnvironment toolEnv;
 162     private final Symtab syms;
 163     private final Names names;
 164     private final JavaFileManager fm;
 165     private final List<Location> locations;
 166     private final Modules modules;
 167     private final Map<ToolOption, Object> opts;
 168     private final Messager messager;
 169     private final JavaCompiler compiler;
 170 
 171     private final Map<String, Entry> entries = new LinkedHashMap<>();
 172 
 173     // specified elements
 174     private Set<ModuleElement> specifiedModuleElements = new LinkedHashSet<>();
 175     private Set<PackageElement> specifiedPackageElements = new LinkedHashSet<>();
 176     private Set<TypeElement> specifiedTypeElements =new LinkedHashSet<>();
 177 
 178     // included elements
 179     private Set<ModuleElement> includedModuleElements = null;
 180     private Set<PackageElement> includedPackageElements = null;
 181     private Set<TypeElement> includedTypeElements = null;
 182 
 183     // cmdline specifiers
 184     private Set<ModulePackage> cmdLinePackages = new LinkedHashSet<>();
 185     private Set<ModulePackage> excludePackages = new LinkedHashSet<>();
 186     private Set<ModulePackage> subPackages = new LinkedHashSet<>();
 187 
 188     private List<JCClassDecl> classDecList = Collections.emptyList();
 189     private List<String> classArgList = Collections.emptyList();
 190     private com.sun.tools.javac.util.List<JCCompilationUnit> classTreeList = null;
 191 
 192     private final Set<JavaFileObject.Kind> sourceKinds = EnumSet.of(JavaFileObject.Kind.SOURCE);
 193 
 194     private final ModifierFilter accessFilter;
 195 
 196     private final AccessKind expandRequires;
 197 
 198     final boolean xclasses;
 199 
 200     /**
 201      * Creates the table to manage included and excluded elements.
 202      *
 203      * @param context the context to locate commonly used objects
 204      * @param location the location used to locate source files
 205      */
 206     ElementsTable(Context context, Map<ToolOption, Object> opts) {
 207         this.toolEnv = ToolEnvironment.instance(context);
 208         this.syms = Symtab.instance(context);
 209         this.names = Names.instance(context);
 210         this.fm = toolEnv.fileManager;
 211         this.modules = Modules.instance(context);
 212         this.opts = opts;
 213         this.messager = Messager.instance0(context);
 214         this.compiler = JavaCompiler.instance(context);
 215         Source source = Source.instance(context);
 216 
 217         List<Location> locs = new ArrayList<>();
 218         if (modules.multiModuleMode) {
 219             locs.add(StandardLocation.MODULE_SOURCE_PATH);
 220         } else {
 221             if (toolEnv.fileManager.hasLocation(StandardLocation.SOURCE_PATH))
 222                 locs.add(StandardLocation.SOURCE_PATH);
 223             else
 224                 locs.add(StandardLocation.CLASS_PATH);
 225         }
 226         if (Feature.MODULES.allowedInSource(source) && toolEnv.fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH))
 227             locs.add(StandardLocation.PATCH_MODULE_PATH);
 228         this.locations = Collections.unmodifiableList(locs);
 229 
 230         getEntry("").excluded = false;
 231 
 232         accessFilter = new ModifierFilter(opts);
 233         xclasses = (boolean)opts.getOrDefault(ToolOption.XCLASSES, false);
 234         expandRequires = (AccessKind)opts.get(ToolOption.EXPAND_REQUIRES);
 235     }
 236 
 237     /**
 238      * Returns the module documentation level mode.
 239      * @return the module documentation level mode
 240      */
 241     public ModuleMode getModuleMode() {
 242         switch(accessFilter.getAccessValue(ElementKind.MODULE)) {
 243             case PACKAGE: case PRIVATE:
 244                 return DocletEnvironment.ModuleMode.ALL;
 245             default:
 246                 return DocletEnvironment.ModuleMode.API;
 247         }
 248     }
 249 
 250     private Set<Element> specifiedElements = null;
 251     /**
 252      * Returns a set of elements specified on the
 253      * command line, including any inner classes.
 254      *


 301             Set<Element> result = new LinkedHashSet<>();
 302             result.addAll(includedModuleElements);
 303             result.addAll(includedPackageElements);
 304             result.addAll(includedTypeElements);
 305             includedElements = Collections.unmodifiableSet(result);
 306         }
 307         return includedElements;
 308     }
 309 
 310     private IncludedVisitor includedVisitor = null;
 311 
 312     /**
 313      * Returns true if the given element is included for consideration.
 314      * This method accumulates elements in the cache as enclosed elements of
 315      * fully included elements are tested.
 316      * A member (constructor, method, field) is included if
 317      *  - it is visible in a fully included type (--show-members)
 318      *
 319      * @param e the element in question
 320      *
 321      * @see getIncludedModuleElements
 322      * @see getIncludedPackageElements
 323      * @see getIncludedTypeElements
 324      *
 325      * @return true if included
 326      */
 327     public boolean isIncluded(Element e) {
 328         if (e == null) {
 329             return false;
 330         }
 331         if (includedVisitor == null) {
 332             includedVisitor = new IncludedVisitor();
 333         }
 334         return includedVisitor.visit(e);
 335     }
 336 
 337     /**
 338      * Performs the final computation and freezes the collections.
 339      * This is a terminal operation, thus no further modifications
 340      * are allowed to the specified data sets.
 341      *
 342      * @throws ToolException if an error occurs
 343      */


 394             JavaFileObject jfo = fm.getJavaFileForInput(location,
 395                     "module-info", JavaFileObject.Kind.SOURCE);
 396             if (jfo != null) {
 397                 JCCompilationUnit jcu = compiler.parse(jfo);
 398                 JCModuleDecl module = TreeInfo.getModule(jcu);
 399                 if (module != null) {
 400                     return module.getName().toString();
 401                 }
 402             }
 403         } catch (IOException ioe) {
 404             String text = messager.getText("main.file.manager.list", location);
 405             throw new ToolException(SYSERR, text, ioe);
 406         }
 407         return null;
 408     }
 409 
 410     @SuppressWarnings("unchecked")
 411     ElementsTable scanSpecifiedItems() throws ToolException {
 412 
 413         // scan modules specified on the command line
 414         List<String> moduleNames = (List<String>) opts.computeIfAbsent(ToolOption.MODULE,
 415                 s -> Collections.EMPTY_LIST);
 416         List<String> mlist = new ArrayList<>();
 417         for (String m : moduleNames) {
 418             List<Location> moduleLocations = getModuleLocation(locations, m);
 419             if (moduleLocations.isEmpty()) {
 420                 String text = messager.getText("main.module_not_found", m);
 421                 throw new ToolException(CMDERR, text);
 422             }
 423             if (moduleLocations.contains(StandardLocation.SOURCE_PATH)) {
 424                 sanityCheckSourcePathModules(moduleNames);
 425             }
 426             mlist.add(m);
 427             ModuleSymbol msym = syms.enterModule(names.fromString(m));
 428             specifiedModuleElements.add((ModuleElement) msym);
 429         }
 430 
 431         // scan for modules with qualified packages
 432         cmdLinePackages.stream()
 433                 .filter((mpkg) -> (mpkg.hasModule()))
 434                 .forEachOrdered((mpkg) -> {
 435                     mlist.add(mpkg.moduleName);
 436         });
 437 
 438         // scan for modules with qualified subpackages
 439         ((List<String>)opts.computeIfAbsent(ToolOption.SUBPACKAGES, v -> Collections.EMPTY_LIST))
 440             .stream()
 441             .map(ModulePackage::new)
 442             .forEachOrdered((mpkg) -> {
 443                 subPackages.add(mpkg);
 444                 if (mpkg.hasModule()) {
 445                     mlist.add(mpkg.moduleName);
 446                 }
 447             });
 448 
 449         // all the modules specified on the command line have been scraped
 450         // init the module systems
 451         modules.addExtraAddModules(mlist.toArray(new String[mlist.size()]));
 452         modules.initModules(this.classTreeList);
 453 
 454         return this;
 455     }
 456 
 457     /**
 458      * Returns the includes table after setting a class names specified on the command line.
 459      *
 460      * @param classList
 461      * @return the include table
 462      */
 463     ElementsTable setClassArgList(List<String> classList) {
 464         classArgList = classList;
 465         return this;
 466     }
 467 
 468     /**
 469      * Returns the includes table after setting the parsed class names.
 470      *
 471      * @param classesDecList
 472      * @return the include table


 489             .forEachOrdered((mpkg) -> cmdLinePackages.add(mpkg));
 490         return this;
 491     }
 492 
 493     /**
 494      * Returns the aggregate set of included packages and specified
 495      * sub packages.
 496      *
 497      * @return the aggregate set of included packages and specified
 498      * sub packages
 499      */
 500     Iterable<ModulePackage> getPackagesToParse() throws IOException {
 501         List<ModulePackage> result = new ArrayList<>();
 502         result.addAll(cmdLinePackages);
 503         result.addAll(subPackages);
 504         return result;
 505     }
 506 
 507     @SuppressWarnings("unchecked")
 508     private void computeSubpackages() throws ToolException {
 509         ((List<String>) opts.computeIfAbsent(ToolOption.EXCLUDE, v -> Collections.EMPTY_LIST))
 510                 .stream()
 511                 .map(ModulePackage::new)
 512                 .forEachOrdered((mpkg) -> excludePackages.add(mpkg));
 513 
 514         excludePackages.forEach((p) -> {
 515             getEntry(p).excluded = true;
 516         });
 517 
 518         for (ModulePackage modpkg : subPackages) {
 519             List<Location> locs = getLocation(modpkg);
 520             for (Location loc : locs) {
 521                 addPackagesFromLocations(loc, modpkg);
 522             }
 523         }
 524     }
 525 
 526     /* Call fm.list and wrap any IOException that occurs in a ToolException */
 527     private Iterable<JavaFileObject> fmList(Location location,
 528                                             String packagename,
 529                                             Set<JavaFileObject.Kind> kinds,
 530                                             boolean recurse) throws ToolException {


 813         }
 814     }
 815 
 816     /**
 817      * Returns an aggregated list of java file objects from the items
 818      * specified on the command line. The packages specified should not
 819      * recurse, however sub-packages should recurse into the sub directories.
 820      * @return a list of java file objects
 821      * @throws IOException if an error occurs
 822      */
 823     List<JavaFileObject> getFilesToParse() throws ToolException {
 824         List<JavaFileObject> result = new ArrayList<>();
 825         addFilesForParser(result, cmdLinePackages, false);
 826         addFilesForParser(result, subPackages, true);
 827         return result;
 828     }
 829 
 830     /**
 831      * Returns the set of source files for a package.
 832      *
 833      * @param packageName the specified package
 834      * @return the set of file objects for the specified package
 835      * @throws ToolException if an error occurs while accessing the files
 836      */
 837     private List<JavaFileObject> getFiles(ModulePackage modpkg,
 838             boolean recurse) throws ToolException {
 839         Entry e = getEntry(modpkg);
 840         // The files may have been found as a side effect of searching for subpackages
 841         if (e.files != null) {
 842             return e.files;
 843         }
 844 
 845         ListBuffer<JavaFileObject> lb = new ListBuffer<>();
 846         List<Location> locs = getLocation(modpkg);
 847         if (locs.isEmpty()) {
 848             return Collections.emptyList();
 849         }
 850         String pname = modpkg.packageName;
 851         for (Location packageLocn : locs) {
 852             for (JavaFileObject fo : fmList(packageLocn, pname, sourceKinds, recurse)) {
 853                 String binaryName = fm.inferBinaryName(packageLocn, fo);


1197     static class ModifierFilter {
1198         /**
1199          * The allowed ElementKind that can be stored.
1200          */
1201         static final EnumSet<ElementKind> ALLOWED_KINDS = EnumSet.of(ElementKind.METHOD,
1202                                                     ElementKind.CLASS,
1203                                                     ElementKind.PACKAGE,
1204                                                     ElementKind.MODULE);
1205 
1206         // all possible access levels allowed for each element
1207         private final EnumMap<ElementKind, EnumSet<AccessKind>> filterMap =
1208                 new EnumMap<>(ElementKind.class);
1209 
1210         // the specified access level for each element
1211         private final EnumMap<ElementKind, AccessKind> accessMap =
1212                 new EnumMap<>(ElementKind.class);
1213 
1214         /**
1215          * Constructor - Specify a filter.
1216          *
1217          * @param accessSet an Access filter.
1218          */
1219         ModifierFilter(Map<ToolOption, Object> opts) {
1220 
1221             AccessKind accessValue = null;
1222             for (ElementKind kind : ALLOWED_KINDS) {
1223                 switch (kind) {
1224                     case METHOD:
1225                         accessValue  = (AccessKind)opts.get(ToolOption.SHOW_MEMBERS);
1226                         break;
1227                     case CLASS:
1228                         accessValue  = (AccessKind)opts.get(ToolOption.SHOW_TYPES);
1229                         break;
1230                     case PACKAGE:
1231                         accessValue  = (AccessKind)opts.get(ToolOption.SHOW_PACKAGES);
1232                         break;
1233                     case MODULE:
1234                         accessValue  = (AccessKind)opts.get(ToolOption.SHOW_MODULE_CONTENTS);
1235                         break;
1236                     default:
1237                         throw new AssertionError("unknown element: " + kind);
1238 
1239                 }
1240                 accessMap.put(kind, accessValue);
1241                 filterMap.put(kind, getFilterSet(accessValue));
1242             }
1243         }
1244 
1245         static EnumSet<AccessKind> getFilterSet(AccessKind accessValue) {
1246             switch (accessValue) {
1247                 case PUBLIC:
1248                     return EnumSet.of(AccessKind.PUBLIC);
1249                 case PROTECTED:
1250                 default:
1251                     return EnumSet.of(AccessKind.PUBLIC, AccessKind.PROTECTED);
1252                 case PACKAGE:
1253                     return EnumSet.of(AccessKind.PUBLIC, AccessKind.PROTECTED, AccessKind.PACKAGE);
1254                 case PRIVATE:




 147  * 2. Expand-contents, an internal pseudo term, meaning
 148  *    it is part of the recursive expansion of specified
 149  *    elements, meaning, the modules are expanded first, then
 150  *    the packages contained in the expanded modules, and then
 151  *    the types contained within the packages, to produce the
 152  *    collections returned by the methods
 153  *    getInclude{Module|Package|Type}Elements(), this is a
 154  *    downward expansion.
 155  * 3. An included element, meaning it should be documented, and
 156  *    exposed via isIncluded, this enclosing element (module, package)
 157  *    is recursively included.
 158  */
 159 public class ElementsTable {
 160 
 161     private final ToolEnvironment toolEnv;
 162     private final Symtab syms;
 163     private final Names names;
 164     private final JavaFileManager fm;
 165     private final List<Location> locations;
 166     private final Modules modules;
 167     private final ToolOptions options;
 168     private final Messager messager;
 169     private final JavaCompiler compiler;
 170 
 171     private final Map<String, Entry> entries = new LinkedHashMap<>();
 172 
 173     // specified elements
 174     private Set<ModuleElement> specifiedModuleElements = new LinkedHashSet<>();
 175     private Set<PackageElement> specifiedPackageElements = new LinkedHashSet<>();
 176     private Set<TypeElement> specifiedTypeElements =new LinkedHashSet<>();
 177 
 178     // included elements
 179     private Set<ModuleElement> includedModuleElements = null;
 180     private Set<PackageElement> includedPackageElements = null;
 181     private Set<TypeElement> includedTypeElements = null;
 182 
 183     // cmdline specifiers
 184     private Set<ModulePackage> cmdLinePackages = new LinkedHashSet<>();
 185     private Set<ModulePackage> excludePackages = new LinkedHashSet<>();
 186     private Set<ModulePackage> subPackages = new LinkedHashSet<>();
 187 
 188     private List<JCClassDecl> classDecList = Collections.emptyList();
 189     private List<String> classArgList = Collections.emptyList();
 190     private com.sun.tools.javac.util.List<JCCompilationUnit> classTreeList = null;
 191 
 192     private final Set<JavaFileObject.Kind> sourceKinds = EnumSet.of(JavaFileObject.Kind.SOURCE);
 193 
 194     private final ModifierFilter accessFilter;
 195 
 196     private final AccessKind expandRequires;
 197 
 198     final boolean xclasses;
 199 
 200     /**
 201      * Creates the table to manage included and excluded elements.
 202      *
 203      * @param context the context to locate commonly used objects
 204      * @param options the tool options
 205      */
 206     ElementsTable(Context context, ToolOptions options) {
 207         this.toolEnv = ToolEnvironment.instance(context);
 208         this.syms = Symtab.instance(context);
 209         this.names = Names.instance(context);
 210         this.fm = toolEnv.fileManager;
 211         this.modules = Modules.instance(context);
 212         this.options = options;
 213         this.messager = Messager.instance0(context);
 214         this.compiler = JavaCompiler.instance(context);
 215         Source source = Source.instance(context);
 216 
 217         List<Location> locs = new ArrayList<>();
 218         if (modules.multiModuleMode) {
 219             locs.add(StandardLocation.MODULE_SOURCE_PATH);
 220         } else {
 221             if (toolEnv.fileManager.hasLocation(StandardLocation.SOURCE_PATH))
 222                 locs.add(StandardLocation.SOURCE_PATH);
 223             else
 224                 locs.add(StandardLocation.CLASS_PATH);
 225         }
 226         if (Feature.MODULES.allowedInSource(source) && toolEnv.fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH))
 227             locs.add(StandardLocation.PATCH_MODULE_PATH);
 228         this.locations = Collections.unmodifiableList(locs);
 229 
 230         getEntry("").excluded = false;
 231 
 232         accessFilter = new ModifierFilter(options);
 233         xclasses = options.xclasses();
 234         expandRequires = options.expandRequires();
 235     }
 236 
 237     /**
 238      * Returns the module documentation level mode.
 239      * @return the module documentation level mode
 240      */
 241     public ModuleMode getModuleMode() {
 242         switch(accessFilter.getAccessValue(ElementKind.MODULE)) {
 243             case PACKAGE: case PRIVATE:
 244                 return DocletEnvironment.ModuleMode.ALL;
 245             default:
 246                 return DocletEnvironment.ModuleMode.API;
 247         }
 248     }
 249 
 250     private Set<Element> specifiedElements = null;
 251     /**
 252      * Returns a set of elements specified on the
 253      * command line, including any inner classes.
 254      *


 301             Set<Element> result = new LinkedHashSet<>();
 302             result.addAll(includedModuleElements);
 303             result.addAll(includedPackageElements);
 304             result.addAll(includedTypeElements);
 305             includedElements = Collections.unmodifiableSet(result);
 306         }
 307         return includedElements;
 308     }
 309 
 310     private IncludedVisitor includedVisitor = null;
 311 
 312     /**
 313      * Returns true if the given element is included for consideration.
 314      * This method accumulates elements in the cache as enclosed elements of
 315      * fully included elements are tested.
 316      * A member (constructor, method, field) is included if
 317      *  - it is visible in a fully included type (--show-members)
 318      *
 319      * @param e the element in question
 320      *
 321      * @see #getIncludedElements()


 322      *
 323      * @return true if included
 324      */
 325     public boolean isIncluded(Element e) {
 326         if (e == null) {
 327             return false;
 328         }
 329         if (includedVisitor == null) {
 330             includedVisitor = new IncludedVisitor();
 331         }
 332         return includedVisitor.visit(e);
 333     }
 334 
 335     /**
 336      * Performs the final computation and freezes the collections.
 337      * This is a terminal operation, thus no further modifications
 338      * are allowed to the specified data sets.
 339      *
 340      * @throws ToolException if an error occurs
 341      */


 392             JavaFileObject jfo = fm.getJavaFileForInput(location,
 393                     "module-info", JavaFileObject.Kind.SOURCE);
 394             if (jfo != null) {
 395                 JCCompilationUnit jcu = compiler.parse(jfo);
 396                 JCModuleDecl module = TreeInfo.getModule(jcu);
 397                 if (module != null) {
 398                     return module.getName().toString();
 399                 }
 400             }
 401         } catch (IOException ioe) {
 402             String text = messager.getText("main.file.manager.list", location);
 403             throw new ToolException(SYSERR, text, ioe);
 404         }
 405         return null;
 406     }
 407 
 408     @SuppressWarnings("unchecked")
 409     ElementsTable scanSpecifiedItems() throws ToolException {
 410 
 411         // scan modules specified on the command line
 412         List<String> modules = options.modules();

 413         List<String> mlist = new ArrayList<>();
 414         for (String m : modules) {
 415             List<Location> moduleLocations = getModuleLocation(locations, m);
 416             if (moduleLocations.isEmpty()) {
 417                 String text = messager.getText("main.module_not_found", m);
 418                 throw new ToolException(CMDERR, text);
 419             }
 420             if (moduleLocations.contains(StandardLocation.SOURCE_PATH)) {
 421                 sanityCheckSourcePathModules(modules);
 422             }
 423             mlist.add(m);
 424             ModuleSymbol msym = syms.enterModule(names.fromString(m));
 425             specifiedModuleElements.add((ModuleElement) msym);
 426         }
 427 
 428         // scan for modules with qualified packages
 429         cmdLinePackages.stream()
 430                 .filter((mpkg) -> (mpkg.hasModule()))
 431                 .forEachOrdered((mpkg) -> {
 432                     mlist.add(mpkg.moduleName);
 433         });
 434 
 435         // scan for modules with qualified subpackages
 436         options.subpackages().stream()

 437             .map(ModulePackage::new)
 438             .forEachOrdered((mpkg) -> {
 439                 subPackages.add(mpkg);
 440                 if (mpkg.hasModule()) {
 441                     mlist.add(mpkg.moduleName);
 442                 }
 443             });
 444 
 445         // all the modules specified on the command line have been scraped
 446         // init the module systems
 447         this.modules.addExtraAddModules(mlist.toArray(new String[mlist.size()]));
 448         this.modules.initModules(this.classTreeList);
 449 
 450         return this;
 451     }
 452 
 453     /**
 454      * Returns the includes table after setting a class names specified on the command line.
 455      *
 456      * @param classList
 457      * @return the include table
 458      */
 459     ElementsTable setClassArgList(List<String> classList) {
 460         classArgList = classList;
 461         return this;
 462     }
 463 
 464     /**
 465      * Returns the includes table after setting the parsed class names.
 466      *
 467      * @param classesDecList
 468      * @return the include table


 485             .forEachOrdered((mpkg) -> cmdLinePackages.add(mpkg));
 486         return this;
 487     }
 488 
 489     /**
 490      * Returns the aggregate set of included packages and specified
 491      * sub packages.
 492      *
 493      * @return the aggregate set of included packages and specified
 494      * sub packages
 495      */
 496     Iterable<ModulePackage> getPackagesToParse() throws IOException {
 497         List<ModulePackage> result = new ArrayList<>();
 498         result.addAll(cmdLinePackages);
 499         result.addAll(subPackages);
 500         return result;
 501     }
 502 
 503     @SuppressWarnings("unchecked")
 504     private void computeSubpackages() throws ToolException {
 505         options.excludes().stream()

 506                 .map(ModulePackage::new)
 507                 .forEachOrdered((mpkg) -> excludePackages.add(mpkg));
 508 
 509         excludePackages.forEach((p) -> {
 510             getEntry(p).excluded = true;
 511         });
 512 
 513         for (ModulePackage modpkg : subPackages) {
 514             List<Location> locs = getLocation(modpkg);
 515             for (Location loc : locs) {
 516                 addPackagesFromLocations(loc, modpkg);
 517             }
 518         }
 519     }
 520 
 521     /* Call fm.list and wrap any IOException that occurs in a ToolException */
 522     private Iterable<JavaFileObject> fmList(Location location,
 523                                             String packagename,
 524                                             Set<JavaFileObject.Kind> kinds,
 525                                             boolean recurse) throws ToolException {


 808         }
 809     }
 810 
 811     /**
 812      * Returns an aggregated list of java file objects from the items
 813      * specified on the command line. The packages specified should not
 814      * recurse, however sub-packages should recurse into the sub directories.
 815      * @return a list of java file objects
 816      * @throws IOException if an error occurs
 817      */
 818     List<JavaFileObject> getFilesToParse() throws ToolException {
 819         List<JavaFileObject> result = new ArrayList<>();
 820         addFilesForParser(result, cmdLinePackages, false);
 821         addFilesForParser(result, subPackages, true);
 822         return result;
 823     }
 824 
 825     /**
 826      * Returns the set of source files for a package.
 827      *
 828      * @param modpkg the specified package
 829      * @return the set of file objects for the specified package
 830      * @throws ToolException if an error occurs while accessing the files
 831      */
 832     private List<JavaFileObject> getFiles(ModulePackage modpkg,
 833             boolean recurse) throws ToolException {
 834         Entry e = getEntry(modpkg);
 835         // The files may have been found as a side effect of searching for subpackages
 836         if (e.files != null) {
 837             return e.files;
 838         }
 839 
 840         ListBuffer<JavaFileObject> lb = new ListBuffer<>();
 841         List<Location> locs = getLocation(modpkg);
 842         if (locs.isEmpty()) {
 843             return Collections.emptyList();
 844         }
 845         String pname = modpkg.packageName;
 846         for (Location packageLocn : locs) {
 847             for (JavaFileObject fo : fmList(packageLocn, pname, sourceKinds, recurse)) {
 848                 String binaryName = fm.inferBinaryName(packageLocn, fo);


1192     static class ModifierFilter {
1193         /**
1194          * The allowed ElementKind that can be stored.
1195          */
1196         static final EnumSet<ElementKind> ALLOWED_KINDS = EnumSet.of(ElementKind.METHOD,
1197                                                     ElementKind.CLASS,
1198                                                     ElementKind.PACKAGE,
1199                                                     ElementKind.MODULE);
1200 
1201         // all possible access levels allowed for each element
1202         private final EnumMap<ElementKind, EnumSet<AccessKind>> filterMap =
1203                 new EnumMap<>(ElementKind.class);
1204 
1205         // the specified access level for each element
1206         private final EnumMap<ElementKind, AccessKind> accessMap =
1207                 new EnumMap<>(ElementKind.class);
1208 
1209         /**
1210          * Constructor - Specify a filter.
1211          *
1212          * @param options the tool options
1213          */
1214         ModifierFilter(ToolOptions options) {
1215 
1216             AccessKind accessValue = null;
1217             for (ElementKind kind : ALLOWED_KINDS) {
1218                 switch (kind) {
1219                     case METHOD:
1220                         accessValue  = options.showMembersAccess();
1221                         break;
1222                     case CLASS:
1223                         accessValue  = options.showTypesAccess();
1224                         break;
1225                     case PACKAGE:
1226                         accessValue  = options.showPackagesAccess();
1227                         break;
1228                     case MODULE:
1229                         accessValue  = options.showModuleContents();
1230                         break;
1231                     default:
1232                         throw new AssertionError("unknown element: " + kind);
1233 
1234                 }
1235                 accessMap.put(kind, accessValue);
1236                 filterMap.put(kind, getFilterSet(accessValue));
1237             }
1238         }
1239 
1240         static EnumSet<AccessKind> getFilterSet(AccessKind accessValue) {
1241             switch (accessValue) {
1242                 case PUBLIC:
1243                     return EnumSet.of(AccessKind.PUBLIC);
1244                 case PROTECTED:
1245                 default:
1246                     return EnumSet.of(AccessKind.PUBLIC, AccessKind.PROTECTED);
1247                 case PACKAGE:
1248                     return EnumSet.of(AccessKind.PUBLIC, AccessKind.PROTECTED, AccessKind.PACKAGE);
1249                 case PRIVATE:


< prev index next >