|
|
@@ -1,5 +1,5 @@ |
|
|
/* |
|
|
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
|
|
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved. |
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
|
* |
|
|
* This code is free software; you can redistribute it and/or modify it |
|
@@ -164,7 +164,7 @@ |
|
|
private final JavaFileManager fm; |
|
|
private final List<Location> locations; |
|
|
private final Modules modules; |
|
|
private final Map<ToolOption, Object> opts; |
|
|
private final ToolOptions options; |
|
|
private final Messager messager; |
|
|
private final JavaCompiler compiler; |
|
|
|
|
@@ -201,15 +201,15 @@ |
|
|
* Creates the table to manage included and excluded elements. |
|
|
* |
|
|
* @param context the context to locate commonly used objects |
|
|
* @param location the location used to locate source files |
|
|
* @param options the tool options |
|
|
*/ |
|
|
ElementsTable(Context context, Map<ToolOption, Object> opts) { |
|
|
ElementsTable(Context context, ToolOptions options) { |
|
|
this.toolEnv = ToolEnvironment.instance(context); |
|
|
this.syms = Symtab.instance(context); |
|
|
this.names = Names.instance(context); |
|
|
this.fm = toolEnv.fileManager; |
|
|
this.modules = Modules.instance(context); |
|
|
this.opts = opts; |
|
|
this.options = options; |
|
|
this.messager = Messager.instance0(context); |
|
|
this.compiler = JavaCompiler.instance(context); |
|
|
Source source = Source.instance(context); |
|
@@ -229,9 +229,9 @@ |
|
|
|
|
|
getEntry("").excluded = false; |
|
|
|
|
|
accessFilter = new ModifierFilter(opts); |
|
|
xclasses = (boolean)opts.getOrDefault(ToolOption.XCLASSES, false); |
|
|
expandRequires = (AccessKind)opts.get(ToolOption.EXPAND_REQUIRES); |
|
|
accessFilter = new ModifierFilter(options); |
|
|
xclasses = options.xclasses(); |
|
|
expandRequires = options.expandRequires(); |
|
|
} |
|
|
|
|
|
/** |
|
@@ -318,9 +318,7 @@ public ModuleMode getModuleMode() { |
|
|
* |
|
|
* @param e the element in question |
|
|
* |
|
|
* @see getIncludedModuleElements |
|
|
* @see getIncludedPackageElements |
|
|
* @see getIncludedTypeElements |
|
|
* @see #getIncludedElements() |
|
|
* |
|
|
* @return true if included |
|
|
*/ |
|
@@ -407,21 +405,19 @@ private String getModuleName(Location location) throws ToolException { |
|
|
return null; |
|
|
} |
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
ElementsTable scanSpecifiedItems() throws ToolException { |
|
|
|
|
|
// scan modules specified on the command line |
|
|
List<String> moduleNames = (List<String>) opts.computeIfAbsent(ToolOption.MODULE, |
|
|
s -> Collections.EMPTY_LIST); |
|
|
List<String> modules = options.modules(); |
|
|
List<String> mlist = new ArrayList<>(); |
|
|
for (String m : moduleNames) { |
|
|
for (String m : modules) { |
|
|
List<Location> moduleLocations = getModuleLocation(locations, m); |
|
|
if (moduleLocations.isEmpty()) { |
|
|
String text = messager.getText("main.module_not_found", m); |
|
|
throw new ToolException(CMDERR, text); |
|
|
} |
|
|
if (moduleLocations.contains(StandardLocation.SOURCE_PATH)) { |
|
|
sanityCheckSourcePathModules(moduleNames); |
|
|
sanityCheckSourcePathModules(modules); |
|
|
} |
|
|
mlist.add(m); |
|
|
ModuleSymbol msym = syms.enterModule(names.fromString(m)); |
|
@@ -436,8 +432,7 @@ ElementsTable scanSpecifiedItems() throws ToolException { |
|
|
}); |
|
|
|
|
|
// scan for modules with qualified subpackages |
|
|
((List<String>)opts.computeIfAbsent(ToolOption.SUBPACKAGES, v -> Collections.EMPTY_LIST)) |
|
|
.stream() |
|
|
options.subpackages().stream() |
|
|
.map(ModulePackage::new) |
|
|
.forEachOrdered((mpkg) -> { |
|
|
subPackages.add(mpkg); |
|
@@ -448,8 +443,8 @@ ElementsTable scanSpecifiedItems() throws ToolException { |
|
|
|
|
|
// all the modules specified on the command line have been scraped |
|
|
// init the module systems |
|
|
modules.addExtraAddModules(mlist.toArray(new String[mlist.size()])); |
|
|
modules.initModules(this.classTreeList); |
|
|
this.modules.addExtraAddModules(mlist.toArray(new String[mlist.size()])); |
|
|
this.modules.initModules(this.classTreeList); |
|
|
|
|
|
return this; |
|
|
} |
|
@@ -504,10 +499,8 @@ ElementsTable packages(Collection<String> packageNames) { |
|
|
return result; |
|
|
} |
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
private void computeSubpackages() throws ToolException { |
|
|
((List<String>) opts.computeIfAbsent(ToolOption.EXCLUDE, v -> Collections.EMPTY_LIST)) |
|
|
.stream() |
|
|
options.excludes().stream() |
|
|
.map(ModulePackage::new) |
|
|
.forEachOrdered((mpkg) -> excludePackages.add(mpkg)); |
|
|
|
|
@@ -830,7 +823,7 @@ private void addFilesForParser(Collection<JavaFileObject> result, |
|
|
/** |
|
|
* Returns the set of source files for a package. |
|
|
* |
|
|
* @param packageName the specified package |
|
|
* @param modpkg the specified package |
|
|
* @return the set of file objects for the specified package |
|
|
* @throws ToolException if an error occurs while accessing the files |
|
|
*/ |
|
@@ -1214,24 +1207,24 @@ public String toString() { |
|
|
/** |
|
|
* Constructor - Specify a filter. |
|
|
* |
|
|
* @param accessSet an Access filter. |
|
|
* @param options the tool options |
|
|
*/ |
|
|
ModifierFilter(Map<ToolOption, Object> opts) { |
|
|
ModifierFilter(ToolOptions options) { |
|
|
|
|
|
AccessKind accessValue = null; |
|
|
for (ElementKind kind : ALLOWED_KINDS) { |
|
|
switch (kind) { |
|
|
case METHOD: |
|
|
accessValue = (AccessKind)opts.get(ToolOption.SHOW_MEMBERS); |
|
|
accessValue = options.showMembersAccess(); |
|
|
break; |
|
|
case CLASS: |
|
|
accessValue = (AccessKind)opts.get(ToolOption.SHOW_TYPES); |
|
|
accessValue = options.showTypesAccess(); |
|
|
break; |
|
|
case PACKAGE: |
|
|
accessValue = (AccessKind)opts.get(ToolOption.SHOW_PACKAGES); |
|
|
accessValue = options.showPackagesAccess(); |
|
|
break; |
|
|
case MODULE: |
|
|
accessValue = (AccessKind)opts.get(ToolOption.SHOW_MODULE_CONTENTS); |
|
|
accessValue = options.showModuleContents(); |
|
|
break; |
|
|
default: |
|
|
throw new AssertionError("unknown element: " + kind); |
|
|