< 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      */


 390     }
 391 
 392     private String getModuleName(Location location) throws ToolException {
 393         try {
 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


 487         packageNames.stream()
 488             .map(ModulePackage::new)
 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      */


 388     }
 389 
 390     private String getModuleName(Location location) throws ToolException {
 391         try {
 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     ElementsTable scanSpecifiedItems() throws ToolException {
 409 
 410         // scan modules specified on the command line
 411         List<String> modules = options.modules();

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

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


 482         packageNames.stream()
 483             .map(ModulePackage::new)
 484             .forEachOrdered((mpkg) -> cmdLinePackages.add(mpkg));
 485         return this;
 486     }
 487 
 488     /**
 489      * Returns the aggregate set of included packages and specified
 490      * sub packages.
 491      *
 492      * @return the aggregate set of included packages and specified
 493      * sub packages
 494      */
 495     Iterable<ModulePackage> getPackagesToParse() throws IOException {
 496         List<ModulePackage> result = new ArrayList<>();
 497         result.addAll(cmdLinePackages);
 498         result.addAll(subPackages);
 499         return result;
 500     }
 501 

 502     private void computeSubpackages() throws ToolException {
 503         options.excludes().stream()

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


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


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


< prev index next >