Skip to content

Commit

Permalink
8268352: Rename javadoc Messager class to JavadocLog
Browse files Browse the repository at this point in the history
Reviewed-by: prappo
  • Loading branch information
jonathan-gibbons committed Jun 8, 2021
1 parent b568e87 commit fafc4d9
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public class ElementsTable {
private final List<Location> locations;
private final Modules modules;
private final ToolOptions options;
private final Messager messager;
private final JavadocLog log;
private final JavaCompiler compiler;

private final Map<String, Entry> entries = new LinkedHashMap<>();
Expand Down Expand Up @@ -210,7 +210,7 @@ public class ElementsTable {
this.fm = toolEnv.fileManager;
this.modules = Modules.instance(context);
this.options = options;
this.messager = Messager.instance0(context);
this.log = JavadocLog.instance0(context);
this.compiler = JavaCompiler.instance(context);
Source source = Source.instance(context);

Expand Down Expand Up @@ -370,19 +370,19 @@ void sanityCheckSourcePathModules(List<String> moduleNames) throws ToolException
return;

if (moduleNames.size() > 1) {
String text = messager.getText("main.cannot_use_sourcepath_for_modules",
String text = log.getText("main.cannot_use_sourcepath_for_modules",
String.join(", ", moduleNames));
throw new ToolException(CMDERR, text);
}

String foundModule = getModuleName(StandardLocation.SOURCE_PATH);
if (foundModule == null) {
String text = messager.getText("main.module_not_found_on_sourcepath", moduleNames.get(0));
String text = log.getText("main.module_not_found_on_sourcepath", moduleNames.get(0));
throw new ToolException(CMDERR, text);
}

if (!moduleNames.get(0).equals(foundModule)) {
String text = messager.getText("main.sourcepath_does_not_contain_module", moduleNames.get(0));
String text = log.getText("main.sourcepath_does_not_contain_module", moduleNames.get(0));
throw new ToolException(CMDERR, text);
}
}
Expand All @@ -399,7 +399,7 @@ private String getModuleName(Location location) throws ToolException {
}
}
} catch (IOException ioe) {
String text = messager.getText("main.file.manager.list", location);
String text = log.getText("main.file.manager.list", location);
throw new ToolException(SYSERR, text, ioe);
}
return null;
Expand All @@ -413,7 +413,7 @@ ElementsTable scanSpecifiedItems() throws ToolException {
for (String m : modules) {
List<Location> moduleLocations = getModuleLocation(locations, m);
if (moduleLocations.isEmpty()) {
String text = messager.getText("main.module_not_found", m);
String text = log.getText("main.module_not_found", m);
throw new ToolException(CMDERR, text);
}
if (moduleLocations.contains(StandardLocation.SOURCE_PATH)) {
Expand Down Expand Up @@ -520,7 +520,7 @@ private Iterable<JavaFileObject> fmList(Location location,
try {
return fm.list(location, packagename, kinds, recurse);
} catch (IOException ioe) {
String text = messager.getText("main.file.manager.list", packagename);
String text = log.getText("main.file.manager.list", packagename);
throw new ToolException(SYSERR, text, ioe);
}
}
Expand Down Expand Up @@ -567,7 +567,7 @@ private Set<ModuleElement> getModuleRequires(ModuleElement mdle, boolean onlyTra
if (!isMandated(mdle, rd) && onlyTransitive == rd.isTransitive()) {
if (!haveModuleSources(dep)) {
if (!warnedNoSources.contains(dep)) {
messager.printWarningUsingKey(dep, "main.module_source_not_found", dep.getQualifiedName());
log.printWarningUsingKey(dep, "main.module_source_not_found", dep.getQualifiedName());
warnedNoSources.add(dep);
}
}
Expand Down Expand Up @@ -759,7 +759,7 @@ private void computeSpecifiedPackages() throws ToolException {
if (pkg != null) {
packlist.add(pkg);
} else {
messager.printWarningUsingKey("main.package_not_found", modpkg.toString());
log.printWarningUsingKey("main.package_not_found", modpkg.toString());
}
});
specifiedPackageElements = Collections.unmodifiableSet(packlist);
Expand All @@ -780,7 +780,7 @@ private void computeSpecifiedTypes() throws ToolException {
for (String className : classArgList) {
TypeElement te = toolEnv.loadClass(className);
if (te == null) {
String text = messager.getText("javadoc.class_not_found", className);
String text = log.getText("javadoc.class_not_found", className);
throw new ToolException(CMDERR, text);
} else {
addAllClasses(classes, te, true);
Expand All @@ -796,7 +796,7 @@ private void addFilesForParser(Collection<JavaFileObject> result,
toolEnv.notice("main.Loading_source_files_for_package", modpkg.toString());
List<JavaFileObject> files = getFiles(modpkg, recurse);
if (files.isEmpty()) {
String text = messager.getText("main.no_source_files_for_package",
String text = log.getText("main.no_source_files_for_package",
modpkg.toString());
throw new ToolException(CMDERR, text);
} else {
Expand Down Expand Up @@ -909,7 +909,7 @@ private Location getModuleLocation(Location location, String msymName) throws To
try {
return fm.getLocationForModule(location, msymName);
} catch (IOException ioe) {
String text = messager.getText("main.doclet_could_not_get_location", msymName);
String text = log.getText("main.doclet_could_not_get_location", msymName);
throw new ToolException(ERROR, text, ioe);
}
}
Expand Down Expand Up @@ -956,9 +956,9 @@ private void addAllClasses(Collection<TypeElement> list, TypeElement typeElement
}
} catch (CompletionFailure e) {
if (e.getMessage() != null)
messager.printWarning(e.getMessage());
log.printWarning(e.getMessage());
else
messager.printWarningUsingKey("main.unexpected.exception", e);
log.printWarningUsingKey("main.unexpected.exception", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2021, 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
Expand Down Expand Up @@ -61,24 +61,24 @@ public static void preRegister(Context context) {

protected JavadocEnter(Context context) {
super(context);
messager = Messager.instance0(context);
log = JavadocLog.instance0(context);
toolEnv = ToolEnvironment.instance(context);
compiler = JavaCompiler.instance(context);
}

final Messager messager;
final JavadocLog log;
final ToolEnvironment toolEnv;
final JavaCompiler compiler;

@Override
public void main(List<JCCompilationUnit> trees) {
// cache the error count if we need to convert Enter errors as warnings.
int nerrors = messager.nerrors;
int nerrors = log.nerrors;
super.main(trees);
compiler.enterDone();
if (toolEnv.ignoreSourceErrors) {
messager.nwarnings += (messager.nerrors - nerrors);
messager.nerrors = nerrors;
log.nwarnings += (log.nerrors - nerrors);
log.nerrors = nerrors;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
* @see java.util.ResourceBundle
* @see java.text.MessageFormat
*/
public class Messager extends Log implements Reporter {
public class JavadocLog extends Log implements Reporter {
/** The overall context for the documentation run. */
private final Context context;

Expand All @@ -138,22 +138,22 @@ public class Messager extends Log implements Reporter {
*/
private final LinkedHashMap<JavaFileObject, SoftReference<DiagnosticSource>> diagSourceCache;

/** Get the current messager, which is also the compiler log. */
public static Messager instance0(Context context) {
/** Get the current javadoc log, which is also the compiler log. */
public static JavadocLog instance0(Context context) {
Log instance = context.get(logKey);
if (!(instance instanceof Messager m))
throw new InternalError("no messager instance!");
return m;
if (!(instance instanceof JavadocLog l))
throw new InternalError("no JavadocLog instance!");
return l;
}

public static void preRegister(Context context,
final String programName) {
context.put(logKey, (Factory<Log>)c -> new Messager(c, programName));
context.put(logKey, (Factory<Log>)c -> new JavadocLog(c, programName));
}

public static void preRegister(Context context, final String programName,
final PrintWriter outWriter, final PrintWriter errWriter) {
context.put(logKey, (Factory<Log>)c -> new Messager(c, programName, outWriter, errWriter));
context.put(logKey, (Factory<Log>)c -> new JavadocLog(c, programName, outWriter, errWriter));
}

final String programName;
Expand All @@ -176,7 +176,7 @@ public void close() {
* Constructor
* @param programName Name of the program (for error messages).
*/
public Messager(Context context, String programName) {
public JavadocLog(Context context, String programName) {
// use the current values of System.out, System.err, in case they have been redirected
this(context, programName,
createPrintWriter(System.out, false),
Expand All @@ -189,7 +189,7 @@ public Messager(Context context, String programName) {
* @param outWriter Stream for notices etc.
* @param errWriter Stream for errors and warnings
*/
public Messager(Context context, String programName, PrintWriter outWriter, PrintWriter errWriter) {
public JavadocLog(Context context, String programName, PrintWriter outWriter, PrintWriter errWriter) {
super(context, outWriter, errWriter);
messages = JavacMessages.instance(context);
messages.add(locale -> ResourceBundle.getBundle("jdk.javadoc.internal.tool.resources.javadoc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
ToolEnvironment toolEnv;

final Messager messager;
final JavadocLog log;
final ClassFinder javadocFinder;
final DeferredCompletionFailureHandler dcfh;
final Enter javadocEnter;
Expand All @@ -82,7 +82,7 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
*/
protected JavadocTool(Context context) {
super(context);
messager = Messager.instance0(context);
log = JavadocLog.instance0(context);
javadocFinder = JavadocClassFinder.instance(context);
dcfh = DeferredCompletionFailureHandler.instance(context);
javadocEnter = JavadocEnter.instance(context);
Expand All @@ -101,7 +101,7 @@ protected boolean keepComments() {
* Construct a new javadoc tool.
*/
public static JavadocTool make0(Context context) {
Messager messager = null;
JavadocLog log = null;
try {
// force the use of Javadoc's class finder
JavadocClassFinder.preRegister(context);
Expand All @@ -115,13 +115,13 @@ public static JavadocTool make0(Context context) {
// force the use of Javadoc's own todo phase
JavadocTodo.preRegister(context);

// force the use of Messager as a Log
messager = Messager.instance0(context);
// force the use of Javadoc's subtype of Log
log = JavadocLog.instance0(context);

return new JavadocTool(context);
} catch (CompletionFailure ex) {
assert messager != null;
messager.error(Position.NOPOS, ex.getMessage());
assert log != null;
log.error(Position.NOPOS, ex.getMessage());
return null;
}
}
Expand All @@ -142,11 +142,11 @@ public DocletEnvironment getEnvironment(ToolOptions toolOptions,
// If -Xclasses is set, the args should be a list of class names
for (String arg: javaNames) {
if (!isValidPackageName(arg)) { // checks
String text = messager.getText("main.illegal_class_name", arg);
String text = log.getText("main.illegal_class_name", arg);
throw new ToolException(CMDERR, text);
}
}
if (messager.hasErrors()) {
if (log.hasErrors()) {
return null;
}
etable.setClassArgList(javaNames);
Expand All @@ -171,14 +171,14 @@ public DocletEnvironment getEnvironment(ToolOptions toolOptions,
packageNames.add(arg);
} else if (arg.endsWith(".java")) {
if (fm == null) {
String text = messager.getText("main.assertion.error", "fm == null");
String text = log.getText("main.assertion.error", "fm == null");
throw new ToolException(ABNORMAL, text);
} else {
String text = messager.getText("main.file_not_found", arg);
String text = log.getText("main.file_not_found", arg);
throw new ToolException(ERROR, text);
}
} else {
String text = messager.getText("main.illegal_package_name", arg);
String text = log.getText("main.illegal_package_name", arg);
throw new ToolException(CMDERR, text);
}
}
Expand All @@ -191,7 +191,7 @@ public DocletEnvironment getEnvironment(ToolOptions toolOptions,
.scanSpecifiedItems();

// abort, if errors were encountered during modules initialization
if (messager.hasErrors()) {
if (log.hasErrors()) {
return null;
}

Expand All @@ -202,15 +202,15 @@ public DocletEnvironment getEnvironment(ToolOptions toolOptions,
modules.newRound();
modules.initModules(allTrees.toList());

if (messager.hasErrors()) {
if (log.hasErrors()) {
return null;
}

// Enter symbols for all files
toolEnv.notice("main.Building_tree");
javadocEnter.main(allTrees.toList());

if (messager.hasErrors()) {
if (log.hasErrors()) {
return null;
}

Expand All @@ -232,17 +232,17 @@ public DocletEnvironment getEnvironment(ToolOptions toolOptions,
} catch (CompletionFailure cf) {
throw new ToolException(ABNORMAL, cf.getMessage(), cf);
} catch (Abort abort) {
if (messager.hasErrors()) {
if (log.hasErrors()) {
// presumably a message has been emitted, keep silent
throw new ToolException(ABNORMAL, "", abort);
} else {
String text = messager.getText("main.internal.error");
String text = log.getText("main.internal.error");
Throwable t = abort.getCause() == null ? abort : abort.getCause();
throw new ToolException(ABNORMAL, text, t);
}
}

if (messager.hasErrors())
if (log.hasErrors())
return null;

toolEnv.docEnv = new DocEnvImpl(toolEnv, etable);
Expand Down
Loading

1 comment on commit fafc4d9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.