Skip to content
Permalink
Browse files

8237803: Reorganize impl of tool options

Reviewed-by: prappo
  • Loading branch information
jonathan-gibbons committed Jan 27, 2020
1 parent 99b9939 commit 6b4223eec2012838dd6d11aa0c07a7cfaceebc73
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
@@ -50,7 +50,7 @@
import com.sun.tools.javac.util.ClientCodeException;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Log;
import jdk.javadoc.internal.tool.ToolOption;
import jdk.javadoc.internal.tool.ToolOptions;

/**
* Provides access to functionality specific to the JDK documentation tool,
@@ -170,13 +170,7 @@ public int run(InputStream in, OutputStream out, OutputStream err, String... arg
public int isSupportedOption(String option) {
if (option == null)
throw new NullPointerException();
for (ToolOption o : ToolOption.values()) {
for (String name : o.names) {
if (name.equals(option))
return o.hasArg ? 1 : 0;
}
}
return -1;
return ToolOptions.isSupportedOption(option);
}

}
@@ -2023,10 +2023,8 @@ public int compare(Element e1, Element e2) {
return result;
}
if (hasParameters(e1) && hasParameters(e2)) {
@SuppressWarnings("unchecked")
List<VariableElement> parameters1 = (List<VariableElement>)((ExecutableElement)e1).getParameters();
@SuppressWarnings("unchecked")
List<VariableElement> parameters2 = (List<VariableElement>)((ExecutableElement)e2).getParameters();
List<? extends VariableElement> parameters1 = ((ExecutableElement)e1).getParameters();
List<? extends VariableElement> parameters2 = ((ExecutableElement)e2).getParameters();
result = compareParameters(false, parameters1, parameters2);
if (result != 0) {
return result;
@@ -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);
@@ -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
@@ -32,7 +32,6 @@
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.lang.model.element.Element;
@@ -121,18 +120,18 @@ public static JavadocTool make0(Context context) {

return new JavadocTool(context);
} catch (CompletionFailure ex) {
assert messager != null;
messager.error(Position.NOPOS, ex.getMessage());
return null;
}
}

public DocletEnvironment getEnvironment(Map<ToolOption,
Object> jdtoolOpts,
public DocletEnvironment getEnvironment(ToolOptions toolOptions,
List<String> javaNames,
Iterable<? extends JavaFileObject> fileObjects) throws ToolException {
toolEnv = ToolEnvironment.instance(context);
toolEnv.initialize(jdtoolOpts);
ElementsTable etable = new ElementsTable(context, jdtoolOpts);
toolEnv.initialize(toolOptions);
ElementsTable etable = new ElementsTable(context, toolOptions);
javadocFinder.sourceCompleter = etable.xclasses
? Completer.NULL_COMPLETER
: sourceCompleter;

0 comments on commit 6b4223e

Please sign in to comment.