提交 bf0d054e 编写于 作者: J jjg

7108669: cleanup Log methods for direct printing to streams

Reviewed-by: mcimadamore
上级 ecb72958
...@@ -205,7 +205,7 @@ public class Main { ...@@ -205,7 +205,7 @@ public class Main {
String s = " " + helpSynopsis(); String s = " " + helpSynopsis();
out.print(s); out.print(s);
for (int j = s.length(); j < 29; j++) out.print(" "); for (int j = s.length(); j < 29; j++) out.print(" ");
Bark.printLines(out, getLocalizedString(descrKey)); Bark.printRawLines(out, getLocalizedString(descrKey));
} }
} }
...@@ -227,7 +227,7 @@ public class Main { ...@@ -227,7 +227,7 @@ public class Main {
String s = " " + helpSynopsis(); String s = " " + helpSynopsis();
out.print(s); out.print(s);
for (int j = s.length(); j < 29; j++) out.print(" "); for (int j = s.length(); j < 29; j++) out.print(" ");
Bark.printLines(out, getLocalizedString(descrKey)); Bark.printRawLines(out, getLocalizedString(descrKey));
} }
} }
...@@ -259,7 +259,7 @@ public class Main { ...@@ -259,7 +259,7 @@ public class Main {
String s = " " + helpSynopsis(); String s = " " + helpSynopsis();
out.print(s); out.print(s);
for (int j = s.length(); j < 29; j++) out.print(" "); for (int j = s.length(); j < 29; j++) out.print(" ");
Log.printLines(out, getLocalizedString(descrKey)); Log.printRawLines(out, getLocalizedString(descrKey));
} }
}; };
...@@ -421,7 +421,7 @@ public class Main { ...@@ -421,7 +421,7 @@ public class Main {
}, },
new AptOption("-version", "opt.version") { new AptOption("-version", "opt.version") {
boolean process(String option) { boolean process(String option) {
Bark.printLines(out, ownName + " " + AptJavaCompiler.version()); Bark.printRawLines(out, ownName + " " + AptJavaCompiler.version());
return super.process(option); return super.process(option);
} }
}, },
...@@ -660,11 +660,11 @@ public class Main { ...@@ -660,11 +660,11 @@ public class Main {
/** Print a string that explains usage. /** Print a string that explains usage.
*/ */
void help() { void help() {
Bark.printLines(out, getLocalizedString("msg.usage.header", ownName)); Bark.printRawLines(out, getLocalizedString("msg.usage.header", ownName));
for (int i=0; i < recognizedOptions.length; i++) { for (int i=0; i < recognizedOptions.length; i++) {
recognizedOptions[i].help(); recognizedOptions[i].help();
} }
Bark.printLines(out, getLocalizedString("msg.usage.footer")); Bark.printRawLines(out, getLocalizedString("msg.usage.footer"));
out.println(); out.println();
} }
...@@ -675,7 +675,7 @@ public class Main { ...@@ -675,7 +675,7 @@ public class Main {
recognizedOptions[i].xhelp(); recognizedOptions[i].xhelp();
} }
out.println(); out.println();
Bark.printLines(out, getLocalizedString("msg.usage.nonstandard.footer")); Bark.printRawLines(out, getLocalizedString("msg.usage.nonstandard.footer"));
} }
/** Report a usage error. /** Report a usage error.
...@@ -688,7 +688,7 @@ public class Main { ...@@ -688,7 +688,7 @@ public class Main {
/** Report a warning. /** Report a warning.
*/ */
void warning(String key, Object... args) { void warning(String key, Object... args) {
Bark.printLines(out, ownName + ": " Bark.printRawLines(out, ownName + ": "
+ getLocalizedString(key, args)); + getLocalizedString(key, args));
} }
...@@ -796,7 +796,7 @@ public class Main { ...@@ -796,7 +796,7 @@ public class Main {
origFilenames = processArgs((args=CommandLine.parse(args))); origFilenames = processArgs((args=CommandLine.parse(args)));
if (options.get("suppress-tool-api-removal-message") == null) { if (options.get("suppress-tool-api-removal-message") == null) {
Bark.printLines(out, getLocalizedString("misc.Deprecation")); Bark.printRawLines(out, getLocalizedString("misc.Deprecation"));
} }
if (origFilenames == null) { if (origFilenames == null) {
...@@ -808,7 +808,7 @@ public class Main { ...@@ -808,7 +808,7 @@ public class Main {
return EXIT_OK; return EXIT_OK;
} }
} catch (java.io.FileNotFoundException e) { } catch (java.io.FileNotFoundException e) {
Bark.printLines(out, ownName + ": " + Bark.printRawLines(out, ownName + ": " +
getLocalizedString("err.file.not.found", getLocalizedString("err.file.not.found",
e.getMessage())); e.getMessage()));
return EXIT_SYSERR; return EXIT_SYSERR;
...@@ -1183,7 +1183,7 @@ public class Main { ...@@ -1183,7 +1183,7 @@ public class Main {
/** Print a message reporting an internal error. /** Print a message reporting an internal error.
*/ */
void bugMessage(Throwable ex) { void bugMessage(Throwable ex) {
Bark.printLines(out, getLocalizedString("msg.bug", Bark.printRawLines(out, getLocalizedString("msg.bug",
AptJavaCompiler.version())); AptJavaCompiler.version()));
ex.printStackTrace(out); ex.printStackTrace(out);
} }
...@@ -1191,34 +1191,34 @@ public class Main { ...@@ -1191,34 +1191,34 @@ public class Main {
/** Print a message reporting an fatal error. /** Print a message reporting an fatal error.
*/ */
void apMessage(AnnotationProcessingError ex) { void apMessage(AnnotationProcessingError ex) {
Bark.printLines(out, getLocalizedString("misc.Problem")); Bark.printRawLines(out, getLocalizedString("misc.Problem"));
ex.getCause().printStackTrace(out); ex.getCause().printStackTrace(out);
} }
/** Print a message about sun.misc.Service problem. /** Print a message about sun.misc.Service problem.
*/ */
void sceMessage(sun.misc.ServiceConfigurationError ex) { void sceMessage(sun.misc.ServiceConfigurationError ex) {
Bark.printLines(out, getLocalizedString("misc.SunMiscService")); Bark.printRawLines(out, getLocalizedString("misc.SunMiscService"));
ex.printStackTrace(out); ex.printStackTrace(out);
} }
/** Print a message reporting an fatal error. /** Print a message reporting an fatal error.
*/ */
void feMessage(Throwable ex) { void feMessage(Throwable ex) {
Bark.printLines(out, ex.toString()); Bark.printRawLines(out, ex.toString());
} }
/** Print a message reporting an input/output error. /** Print a message reporting an input/output error.
*/ */
void ioMessage(Throwable ex) { void ioMessage(Throwable ex) {
Bark.printLines(out, getLocalizedString("msg.io")); Bark.printRawLines(out, getLocalizedString("msg.io"));
ex.printStackTrace(out); ex.printStackTrace(out);
} }
/** Print a message reporting an out-of-resources error. /** Print a message reporting an out-of-resources error.
*/ */
void resourceMessage(Throwable ex) { void resourceMessage(Throwable ex) {
Bark.printLines(out, getLocalizedString("msg.resource")); Bark.printRawLines(out, getLocalizedString("msg.resource"));
ex.printStackTrace(out); ex.printStackTrace(out);
} }
......
...@@ -52,6 +52,7 @@ import com.sun.tools.javac.main.RecognizedOptions; ...@@ -52,6 +52,7 @@ import com.sun.tools.javac.main.RecognizedOptions;
import com.sun.tools.javac.util.ClientCodeException; import com.sun.tools.javac.util.ClientCodeException;
import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Log.PrefixKind;
import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.Options;
import com.sun.tools.javac.util.Pair; import com.sun.tools.javac.util.Pair;
...@@ -156,15 +157,28 @@ public final class JavacTool implements JavaCompiler { ...@@ -156,15 +157,28 @@ public final class JavacTool implements JavaCompiler {
return new JavacFileManager(context, true, charset); return new JavacFileManager(context, true, charset);
} }
@Override
public JavacTask getTask(Writer out, public JavacTask getTask(Writer out,
JavaFileManager fileManager, JavaFileManager fileManager,
DiagnosticListener<? super JavaFileObject> diagnosticListener, DiagnosticListener<? super JavaFileObject> diagnosticListener,
Iterable<String> options, Iterable<String> options,
Iterable<String> classes, Iterable<String> classes,
Iterable<? extends JavaFileObject> compilationUnits) Iterable<? extends JavaFileObject> compilationUnits) {
Context context = new Context();
return getTask(out, fileManager, diagnosticListener,
options, classes, compilationUnits,
context);
}
public JavacTask getTask(Writer out,
JavaFileManager fileManager,
DiagnosticListener<? super JavaFileObject> diagnosticListener,
Iterable<String> options,
Iterable<String> classes,
Iterable<? extends JavaFileObject> compilationUnits,
Context context)
{ {
try { try {
Context context = new Context();
ClientCodeWrapper ccw = ClientCodeWrapper.instance(context); ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);
final String kindMsg = "All compilation units must be of SOURCE kind"; final String kindMsg = "All compilation units must be of SOURCE kind";
...@@ -212,9 +226,10 @@ public final class JavacTool implements JavaCompiler { ...@@ -212,9 +226,10 @@ public final class JavacTool implements JavaCompiler {
return; return;
Options optionTable = Options.instance(context); Options optionTable = Options.instance(context);
Log log = Log.instance(context);
JavacOption[] recognizedOptions = JavacOption[] recognizedOptions =
RecognizedOptions.getJavacToolOptions(new GrumpyHelper()); RecognizedOptions.getJavacToolOptions(new GrumpyHelper(log));
Iterator<String> flags = options.iterator(); Iterator<String> flags = options.iterator();
while (flags.hasNext()) { while (flags.hasNext()) {
String flag = flags.next(); String flag = flags.next();
...@@ -227,7 +242,7 @@ public final class JavacTool implements JavaCompiler { ...@@ -227,7 +242,7 @@ public final class JavacTool implements JavaCompiler {
if (fileManager.handleOption(flag, flags)) { if (fileManager.handleOption(flag, flags)) {
continue; continue;
} else { } else {
String msg = Main.getLocalizedString("err.invalid.flag", flag); String msg = log.localize(PrefixKind.JAVAC, "err.invalid.flag", flag);
throw new IllegalArgumentException(msg); throw new IllegalArgumentException(msg);
} }
} }
...@@ -235,7 +250,7 @@ public final class JavacTool implements JavaCompiler { ...@@ -235,7 +250,7 @@ public final class JavacTool implements JavaCompiler {
JavacOption option = recognizedOptions[j]; JavacOption option = recognizedOptions[j];
if (option.hasArg()) { if (option.hasArg()) {
if (!flags.hasNext()) { if (!flags.hasNext()) {
String msg = Main.getLocalizedString("err.req.arg", flag); String msg = log.localize(PrefixKind.JAVAC, "err.req.arg", flag);
throw new IllegalArgumentException(msg); throw new IllegalArgumentException(msg);
} }
String operand = flags.next(); String operand = flags.next();
...@@ -269,7 +284,7 @@ public final class JavacTool implements JavaCompiler { ...@@ -269,7 +284,7 @@ public final class JavacTool implements JavaCompiler {
public int isSupportedOption(String option) { public int isSupportedOption(String option) {
JavacOption[] recognizedOptions = JavacOption[] recognizedOptions =
RecognizedOptions.getJavacToolOptions(new GrumpyHelper()); RecognizedOptions.getJavacToolOptions(new GrumpyHelper(null));
for (JavacOption o : recognizedOptions) { for (JavacOption o : recognizedOptions) {
if (o.matches(option)) if (o.matches(option))
return o.hasArg() ? 1 : 0; return o.hasArg() ? 1 : 0;
......
...@@ -2539,7 +2539,7 @@ public class ClassReader implements Completer { ...@@ -2539,7 +2539,7 @@ public class ClassReader implements Completer {
* @param arg An argument for substitution into the output string. * @param arg An argument for substitution into the output string.
*/ */
private void printCCF(String key, Object arg) { private void printCCF(String key, Object arg) {
log.printNoteLines(key, arg); log.printLines(key, arg);
} }
......
...@@ -48,17 +48,18 @@ import javax.tools.DiagnosticListener; ...@@ -48,17 +48,18 @@ import javax.tools.DiagnosticListener;
import com.sun.source.util.TaskEvent; import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskListener; import com.sun.source.util.TaskListener;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.code.Lint.LintCategory;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.parser.*;
import com.sun.tools.javac.comp.*; import com.sun.tools.javac.comp.*;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.jvm.*; import com.sun.tools.javac.jvm.*;
import com.sun.tools.javac.parser.*;
import com.sun.tools.javac.processing.*; import com.sun.tools.javac.processing.*;
import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.Log.WriterKind;
import static javax.tools.StandardLocation.CLASS_OUTPUT; import static javax.tools.StandardLocation.CLASS_OUTPUT;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.OptionName.*;
...@@ -1602,7 +1603,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter { ...@@ -1602,7 +1603,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
} }
protected void printNote(String lines) { protected void printNote(String lines) {
log.printLines(Log.WriterKind.NOTICE, lines); log.printRawLines(Log.WriterKind.NOTICE, lines);
} }
/** Print numbers of errors and warnings. /** Print numbers of errors and warnings.
...@@ -1614,7 +1615,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter { ...@@ -1614,7 +1615,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
key = "count." + kind; key = "count." + kind;
else else
key = "count." + kind + ".plural"; key = "count." + kind + ".plural";
log.printErrLines(key, String.valueOf(count)); log.printLines(WriterKind.ERROR, key, String.valueOf(count));
log.flush(Log.WriterKind.ERROR); log.flush(Log.WriterKind.ERROR);
} }
} }
......
/* /*
* Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,10 +25,11 @@ ...@@ -25,10 +25,11 @@
package com.sun.tools.javac.main; package com.sun.tools.javac.main;
import java.io.PrintWriter;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Log.PrefixKind;
import com.sun.tools.javac.util.Log.WriterKind;
import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.Options;
/** /**
...@@ -177,14 +178,14 @@ public interface JavacOption { ...@@ -177,14 +178,14 @@ public interface JavacOption {
/** Print a line of documentation describing this option, if standard. /** Print a line of documentation describing this option, if standard.
* @param out the stream to which to write the documentation * @param out the stream to which to write the documentation
*/ */
void help(PrintWriter out) { void help(Log log) {
String s = " " + helpSynopsis(); log.printRawLines(WriterKind.NOTICE,
out.print(s); String.format(" %-26s %s",
for (int j = Math.min(s.length(), 28); j < 29; j++) out.print(" "); helpSynopsis(log),
Log.printLines(out, Main.getLocalizedString(descrKey)); log.localize(PrefixKind.JAVAC, descrKey)));
} }
String helpSynopsis() { String helpSynopsis(Log log) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(name); sb.append(name);
if (argsNameKey == null) { if (argsNameKey == null) {
...@@ -202,7 +203,7 @@ public interface JavacOption { ...@@ -202,7 +203,7 @@ public interface JavacOption {
} else { } else {
if (!hasSuffix) if (!hasSuffix)
sb.append(" "); sb.append(" ");
sb.append(Main.getLocalizedString(argsNameKey)); sb.append(log.localize(PrefixKind.JAVAC, argsNameKey));
} }
return sb.toString(); return sb.toString();
...@@ -211,7 +212,7 @@ public interface JavacOption { ...@@ -211,7 +212,7 @@ public interface JavacOption {
/** Print a line of documentation describing this option, if non-standard. /** Print a line of documentation describing this option, if non-standard.
* @param out the stream to which to write the documentation * @param out the stream to which to write the documentation
*/ */
void xhelp(PrintWriter out) {} void xhelp(Log log) {}
/** Process the option (with arg). Return true if error detected. /** Process the option (with arg). Return true if error detected.
*/ */
...@@ -271,9 +272,9 @@ public interface JavacOption { ...@@ -271,9 +272,9 @@ public interface JavacOption {
super(name, descrKey, kind, choices); super(name, descrKey, kind, choices);
} }
@Override @Override
void help(PrintWriter out) {} void help(Log log) {}
@Override @Override
void xhelp(PrintWriter out) { super.help(out); } void xhelp(Log log) { super.help(log); }
@Override @Override
public OptionKind getKind() { return OptionKind.EXTENDED; } public OptionKind getKind() { return OptionKind.EXTENDED; }
}; };
...@@ -288,9 +289,9 @@ public interface JavacOption { ...@@ -288,9 +289,9 @@ public interface JavacOption {
super(name, argsNameKey, null); super(name, argsNameKey, null);
} }
@Override @Override
void help(PrintWriter out) {} void help(Log log) {}
@Override @Override
void xhelp(PrintWriter out) {} void xhelp(Log log) {}
@Override @Override
public OptionKind getKind() { return OptionKind.HIDDEN; } public OptionKind getKind() { return OptionKind.HIDDEN; }
}; };
......
...@@ -33,7 +33,6 @@ import java.security.DigestInputStream; ...@@ -33,7 +33,6 @@ import java.security.DigestInputStream;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.MissingResourceException;
import java.util.Set; import java.util.Set;
import javax.tools.JavaFileManager; import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
...@@ -46,6 +45,8 @@ import com.sun.tools.javac.jvm.Target; ...@@ -46,6 +45,8 @@ import com.sun.tools.javac.jvm.Target;
import com.sun.tools.javac.main.JavacOption.Option; import com.sun.tools.javac.main.JavacOption.Option;
import com.sun.tools.javac.main.RecognizedOptions.OptionHelper; import com.sun.tools.javac.main.RecognizedOptions.OptionHelper;
import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.Log.WriterKind;
import com.sun.tools.javac.util.Log.PrefixKind;
import com.sun.tools.javac.processing.AnnotationProcessingError; import com.sun.tools.javac.processing.AnnotationProcessingError;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.OptionName.*;
...@@ -110,11 +111,11 @@ public class Main { ...@@ -110,11 +111,11 @@ public class Main {
} }
public void printVersion() { public void printVersion() {
Log.printLines(out, getLocalizedString("version", ownName, JavaCompiler.version())); log.printLines(PrefixKind.JAVAC, "version", ownName, JavaCompiler.version());
} }
public void printFullVersion() { public void printFullVersion() {
Log.printLines(out, getLocalizedString("fullVersion", ownName, JavaCompiler.fullVersion())); log.printLines(PrefixKind.JAVAC, "fullversion", ownName, JavaCompiler.fullVersion());
} }
public void printHelp() { public void printHelp() {
...@@ -163,39 +164,38 @@ public class Main { ...@@ -163,39 +164,38 @@ public class Main {
/** Print a string that explains usage. /** Print a string that explains usage.
*/ */
void help() { void help() {
Log.printLines(out, getLocalizedString("msg.usage.header", ownName)); log.printLines(PrefixKind.JAVAC, "msg.usage.header", ownName);
for (int i=0; i<recognizedOptions.length; i++) { for (int i=0; i<recognizedOptions.length; i++) {
recognizedOptions[i].help(out); recognizedOptions[i].help(log);
} }
out.println(); log.printNewline();
} }
/** Print a string that explains usage for X options. /** Print a string that explains usage for X options.
*/ */
void xhelp() { void xhelp() {
for (int i=0; i<recognizedOptions.length; i++) { for (int i=0; i<recognizedOptions.length; i++) {
recognizedOptions[i].xhelp(out); recognizedOptions[i].xhelp(log);
} }
out.println(); log.printNewline();
Log.printLines(out, getLocalizedString("msg.usage.nonstandard.footer")); log.printLines(PrefixKind.JAVAC, "msg.usage.nonstandard.footer");
} }
/** Report a usage error. /** Report a usage error.
*/ */
void error(String key, Object... args) { void error(String key, Object... args) {
if (apiMode) { if (apiMode) {
String msg = getLocalizedString(key, args); String msg = log.localize(PrefixKind.JAVAC, key, args);
throw new PropagatedException(new IllegalStateException(msg)); throw new PropagatedException(new IllegalStateException(msg));
} }
warning(key, args); warning(key, args);
Log.printLines(out, getLocalizedString("msg.usage", ownName)); log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
} }
/** Report a warning. /** Report a warning.
*/ */
void warning(String key, Object... args) { void warning(String key, Object... args) {
Log.printLines(out, ownName + ": " log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args));
+ getLocalizedString(key, args));
} }
public Option getOption(String flag) { public Option getOption(String flag) {
...@@ -400,9 +400,7 @@ public class Main { ...@@ -400,9 +400,7 @@ public class Main {
return Result.CMDERR; return Result.CMDERR;
} }
} catch (java.io.FileNotFoundException e) { } catch (java.io.FileNotFoundException e) {
Log.printLines(out, ownName + ": " + warning("err.file.not.found", e.getMessage());
getLocalizedString("err.file.not.found",
e.getMessage()));
return Result.SYSERR; return Result.SYSERR;
} }
...@@ -440,10 +438,10 @@ public class Main { ...@@ -440,10 +438,10 @@ public class Main {
if (log.expectDiagKeys != null) { if (log.expectDiagKeys != null) {
if (log.expectDiagKeys.isEmpty()) { if (log.expectDiagKeys.isEmpty()) {
log.printLines(Log.WriterKind.NOTICE, "all expected diagnostics found"); log.printRawLines("all expected diagnostics found");
return Result.OK; return Result.OK;
} else { } else {
log.printLines(Log.WriterKind.NOTICE, "expected diagnostic keys not found: " + log.expectDiagKeys); log.printRawLines("expected diagnostic keys not found: " + log.expectDiagKeys);
return Result.ERROR; return Result.ERROR;
} }
} }
...@@ -498,52 +496,50 @@ public class Main { ...@@ -498,52 +496,50 @@ public class Main {
/** Print a message reporting an internal error. /** Print a message reporting an internal error.
*/ */
void bugMessage(Throwable ex) { void bugMessage(Throwable ex) {
Log.printLines(out, getLocalizedString("msg.bug", log.printLines(PrefixKind.JAVAC, "msg.bug", JavaCompiler.version());
JavaCompiler.version())); ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
ex.printStackTrace(out);
} }
/** Print a message reporting a fatal error. /** Print a message reporting a fatal error.
*/ */
void feMessage(Throwable ex) { void feMessage(Throwable ex) {
Log.printLines(out, ex.getMessage()); log.printRawLines(ex.getMessage());
if (ex.getCause() != null && options.isSet("dev")) { if (ex.getCause() != null && options.isSet("dev")) {
ex.getCause().printStackTrace(out); ex.getCause().printStackTrace(log.getWriter(WriterKind.NOTICE));
} }
} }
/** Print a message reporting an input/output error. /** Print a message reporting an input/output error.
*/ */
void ioMessage(Throwable ex) { void ioMessage(Throwable ex) {
Log.printLines(out, getLocalizedString("msg.io")); log.printLines(PrefixKind.JAVAC, "msg.io");
ex.printStackTrace(out); ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
} }
/** Print a message reporting an out-of-resources error. /** Print a message reporting an out-of-resources error.
*/ */
void resourceMessage(Throwable ex) { void resourceMessage(Throwable ex) {
Log.printLines(out, getLocalizedString("msg.resource")); log.printLines(PrefixKind.JAVAC, "msg.resource");
// System.out.println("(name buffer len = " + Name.names.length + " " + Name.nc);//DEBUG ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
ex.printStackTrace(out);
} }
/** Print a message reporting an uncaught exception from an /** Print a message reporting an uncaught exception from an
* annotation processor. * annotation processor.
*/ */
void apMessage(AnnotationProcessingError ex) { void apMessage(AnnotationProcessingError ex) {
Log.printLines(out, log.printLines("msg.proc.annotation.uncaught.exception");
getLocalizedString("msg.proc.annotation.uncaught.exception")); ex.getCause().printStackTrace(log.getWriter(WriterKind.NOTICE));
ex.getCause().printStackTrace(out);
} }
/** Display the location and checksum of a class. */ /** Display the location and checksum of a class. */
void showClass(String className) { void showClass(String className) {
out.println("javac: show class: " + className); PrintWriter pw = log.getWriter(WriterKind.NOTICE);
pw.println("javac: show class: " + className);
URL url = getClass().getResource('/' + className.replace('.', '/') + ".class"); URL url = getClass().getResource('/' + className.replace('.', '/') + ".class");
if (url == null) if (url == null)
out.println(" class not found"); pw.println(" class not found");
else { else {
out.println(" " + url); pw.println(" " + url);
try { try {
final String algorithm = "MD5"; final String algorithm = "MD5";
byte[] digest; byte[] digest;
...@@ -560,9 +556,9 @@ public class Main { ...@@ -560,9 +556,9 @@ public class Main {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (byte b: digest) for (byte b: digest)
sb.append(String.format("%02x", b)); sb.append(String.format("%02x", b));
out.println(" " + algorithm + " checksum: " + sb); pw.println(" " + algorithm + " checksum: " + sb);
} catch (Exception e) { } catch (Exception e) {
out.println(" cannot compute digest: " + e); pw.println(" cannot compute digest: " + e);
} }
} }
} }
...@@ -573,35 +569,35 @@ public class Main { ...@@ -573,35 +569,35 @@ public class Main {
* Internationalization * Internationalization
*************************************************************************/ *************************************************************************/
/** Find a localized string in the resource bundle. // /** Find a localized string in the resource bundle.
* @param key The key for the localized string. // * @param key The key for the localized string.
*/ // */
public static String getLocalizedString(String key, Object... args) { // FIXME sb private // public static String getLocalizedString(String key, Object... args) { // FIXME sb private
try { // try {
if (messages == null) // if (messages == null)
messages = new JavacMessages(javacBundleName); // messages = new JavacMessages(javacBundleName);
return messages.getLocalizedString("javac." + key, args); // return messages.getLocalizedString("javac." + key, args);
} // }
catch (MissingResourceException e) { // catch (MissingResourceException e) {
throw new Error("Fatal Error: Resource for javac is missing", e); // throw new Error("Fatal Error: Resource for javac is missing", e);
} // }
} // }
//
public static void useRawMessages(boolean enable) { // public static void useRawMessages(boolean enable) {
if (enable) { // if (enable) {
messages = new JavacMessages(javacBundleName) { // messages = new JavacMessages(javacBundleName) {
@Override // @Override
public String getLocalizedString(String key, Object... args) { // public String getLocalizedString(String key, Object... args) {
return key; // return key;
} // }
}; // };
} else { // } else {
messages = new JavacMessages(javacBundleName); // messages = new JavacMessages(javacBundleName);
} // }
} // }
private static final String javacBundleName = public static final String javacBundleName =
"com.sun.tools.javac.resources.javac"; "com.sun.tools.javac.resources.javac";
//
private static JavacMessages messages; // private static JavacMessages messages;
} }
...@@ -25,6 +25,15 @@ ...@@ -25,6 +25,15 @@
package com.sun.tools.javac.main; package com.sun.tools.javac.main;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import javax.lang.model.SourceVersion;
import com.sun.tools.javac.code.Lint; import com.sun.tools.javac.code.Lint;
import com.sun.tools.javac.code.Source; import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type;
...@@ -32,17 +41,11 @@ import com.sun.tools.javac.jvm.Target; ...@@ -32,17 +41,11 @@ import com.sun.tools.javac.jvm.Target;
import com.sun.tools.javac.main.JavacOption.HiddenOption; import com.sun.tools.javac.main.JavacOption.HiddenOption;
import com.sun.tools.javac.main.JavacOption.Option; import com.sun.tools.javac.main.JavacOption.Option;
import com.sun.tools.javac.main.JavacOption.XOption; import com.sun.tools.javac.main.JavacOption.XOption;
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Log.PrefixKind;
import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.Options;
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import javax.lang.model.SourceVersion;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.OptionName.*;
...@@ -79,13 +82,18 @@ public class RecognizedOptions { ...@@ -79,13 +82,18 @@ public class RecognizedOptions {
} }
public static class GrumpyHelper implements OptionHelper { public static class GrumpyHelper implements OptionHelper {
private Log log;
public GrumpyHelper(Log log) {
this.log = log;
}
public void setOut(PrintWriter out) { public void setOut(PrintWriter out) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
public void error(String key, Object... args) { public void error(String key, Object... args) {
throw new IllegalArgumentException(Main.getLocalizedString(key, args)); throw new IllegalArgumentException(log.localize(PrefixKind.JAVAC, key, args));
} }
public void printVersion() { public void printVersion() {
...@@ -400,9 +408,9 @@ public class RecognizedOptions { ...@@ -400,9 +408,9 @@ public class RecognizedOptions {
}, },
new Option(A, "opt.arg.key.equals.value","opt.A") { new Option(A, "opt.arg.key.equals.value","opt.A") {
@Override @Override
String helpSynopsis() { String helpSynopsis(Log log) {
hasSuffix = true; hasSuffix = true;
return super.helpSynopsis(); return super.helpSynopsis(log);
} }
@Override @Override
...@@ -444,9 +452,9 @@ public class RecognizedOptions { ...@@ -444,9 +452,9 @@ public class RecognizedOptions {
// It's actually implemented by the launcher. // It's actually implemented by the launcher.
new Option(J, "opt.arg.flag", "opt.J") { new Option(J, "opt.arg.flag", "opt.J") {
@Override @Override
String helpSynopsis() { String helpSynopsis(Log log) {
hasSuffix = true; hasSuffix = true;
return super.helpSynopsis(); return super.helpSynopsis(log);
} }
@Override @Override
public boolean process(Options options, String option) { public boolean process(Options options, String option) {
...@@ -570,9 +578,9 @@ public class RecognizedOptions { ...@@ -570,9 +578,9 @@ public class RecognizedOptions {
// It's actually implemented by the CommandLine class. // It's actually implemented by the CommandLine class.
new Option(AT, "opt.arg.file", "opt.AT") { new Option(AT, "opt.arg.file", "opt.AT") {
@Override @Override
String helpSynopsis() { String helpSynopsis(Log log) {
hasSuffix = true; hasSuffix = true;
return super.helpSynopsis(); return super.helpSynopsis(log);
} }
@Override @Override
public boolean process(Options options, String option) { public boolean process(Options options, String option) {
......
...@@ -688,7 +688,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -688,7 +688,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
ps.removeSupportedOptions(unmatchedProcessorOptions); ps.removeSupportedOptions(unmatchedProcessorOptions);
if (printProcessorInfo || verbose) { if (printProcessorInfo || verbose) {
log.printNoteLines("x.print.processor.info", log.printLines("x.print.processor.info",
ps.processor.getClass().getName(), ps.processor.getClass().getName(),
matchedNames.toString(), matchedNames.toString(),
processingResult); processingResult);
...@@ -1014,7 +1014,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -1014,7 +1014,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
if (printRounds || verbose) { if (printRounds || verbose) {
List<ClassSymbol> tlc = lastRound ? List.<ClassSymbol>nil() : topLevelClasses; List<ClassSymbol> tlc = lastRound ? List.<ClassSymbol>nil() : topLevelClasses;
Set<TypeElement> ap = lastRound ? Collections.<TypeElement>emptySet() : annotationsPresent; Set<TypeElement> ap = lastRound ? Collections.<TypeElement>emptySet() : annotationsPresent;
log.printNoteLines("x.print.rounds", log.printLines("x.print.rounds",
number, number,
"{" + tlc.toString(", ") + "}", "{" + tlc.toString(", ") + "}",
ap, ap,
......
...@@ -792,7 +792,7 @@ compiler.err.invalid.inferred.types=\ ...@@ -792,7 +792,7 @@ compiler.err.invalid.inferred.types=\
compiler.err.cant.apply.diamond=\ compiler.err.cant.apply.diamond=\
cannot infer type arguments for {0} cannot infer type arguments for {0}
# 0: message segment, 1: message segment # 0: message segment or type, 1: message segment
compiler.err.cant.apply.diamond.1=\ compiler.err.cant.apply.diamond.1=\
cannot infer type arguments for {0};\n\ cannot infer type arguments for {0};\n\
reason: {1} reason: {1}
...@@ -854,7 +854,7 @@ compiler.misc.varargs.trustme.on.non.varargs.meth=\ ...@@ -854,7 +854,7 @@ compiler.misc.varargs.trustme.on.non.varargs.meth=\
compiler.misc.varargs.trustme.on.virtual.varargs=\ compiler.misc.varargs.trustme.on.virtual.varargs=\
Instance method {0} is not final. Instance method {0} is not final.
# 0: type, 1: kind, 2: symbol # 0: type, 1: symbol kind, 2: symbol
compiler.misc.inaccessible.varargs.type=\ compiler.misc.inaccessible.varargs.type=\
formal varargs element type {0} is not accessible from {1} {2} formal varargs element type {0} is not accessible from {1} {2}
...@@ -1631,6 +1631,7 @@ compiler.misc.diamond=\ ...@@ -1631,6 +1631,7 @@ compiler.misc.diamond=\
compiler.misc.diamond.non.generic=\ compiler.misc.diamond.non.generic=\
cannot use ''<>'' with non-generic class {0} cannot use ''<>'' with non-generic class {0}
# 0: unused
compiler.misc.diamond.and.explicit.params=\ compiler.misc.diamond.and.explicit.params=\
cannot use ''<>'' with explicit type parameters for constructor cannot use ''<>'' with explicit type parameters for constructor
...@@ -1712,7 +1713,7 @@ compiler.err.cant.resolve.location.args.params=\ ...@@ -1712,7 +1713,7 @@ compiler.err.cant.resolve.location.args.params=\
## The second argument {1} is the location name ## The second argument {1} is the location name
## The third argument {2} is the location type (only when {1} is a variable name) ## The third argument {2} is the location type (only when {1} is a variable name)
# 0: symbol kind, 1: symbol, 2: unused # 0: symbol kind, 1: type or symbol, 2: unused
compiler.misc.location=\ compiler.misc.location=\
{0} {1} {0} {1}
...@@ -1847,6 +1848,7 @@ compiler.misc.varargs.implement=\ ...@@ -1847,6 +1848,7 @@ compiler.misc.varargs.implement=\
compiler.misc.varargs.clash.with=\ compiler.misc.varargs.clash.with=\
{0} in {1} overrides {2} in {3} {0} in {1} overrides {2} in {3}
# 0: unused
compiler.misc.diamond.and.anon.class=\ compiler.misc.diamond.and.anon.class=\
cannot use ''<>'' with anonymous inner classes cannot use ''<>'' with anonymous inner classes
......
...@@ -166,7 +166,7 @@ public abstract class BaseFileManager { ...@@ -166,7 +166,7 @@ public abstract class BaseFileManager {
// where // where
private static JavacOption[] javacFileManagerOptions = private static JavacOption[] javacFileManagerOptions =
RecognizedOptions.getJavacFileManagerOptions( RecognizedOptions.getJavacFileManagerOptions(
new RecognizedOptions.GrumpyHelper()); new RecognizedOptions.GrumpyHelper(Log.instance(new Context())));
public int isSupportedOption(String option) { public int isSupportedOption(String option) {
for (JavacOption o : javacFileManagerOptions) { for (JavacOption o : javacFileManagerOptions) {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
package com.sun.tools.javac.util; package com.sun.tools.javac.util;
import com.sun.tools.javac.main.Main;
import java.io.*; import java.io.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.EnumSet; import java.util.EnumSet;
...@@ -60,6 +61,19 @@ public class Log extends AbstractLog { ...@@ -60,6 +61,19 @@ public class Log extends AbstractLog {
public static final Context.Key<PrintWriter> outKey = public static final Context.Key<PrintWriter> outKey =
new Context.Key<PrintWriter>(); new Context.Key<PrintWriter>();
/* TODO: Should unify this with prefix handling in JCDiagnostic.Factory. */
public enum PrefixKind {
JAVAC("javac."),
COMPILER_MISC("compiler.misc.");
PrefixKind(String v) {
value = v;
}
public String key(String k) {
return value + k;
}
final String value;
}
public enum WriterKind { NOTICE, WARNING, ERROR }; public enum WriterKind { NOTICE, WARNING, ERROR };
protected PrintWriter errWriter; protected PrintWriter errWriter;
...@@ -136,6 +150,7 @@ public class Log extends AbstractLog { ...@@ -136,6 +150,7 @@ public class Log extends AbstractLog {
this.diagListener = dl; this.diagListener = dl;
messages = JavacMessages.instance(context); messages = JavacMessages.instance(context);
messages.add(Main.javacBundleName);
final Options options = Options.instance(context); final Options options = Options.instance(context);
initOptions(options); initOptions(options);
...@@ -313,7 +328,6 @@ public class Log extends AbstractLog { ...@@ -313,7 +328,6 @@ public class Log extends AbstractLog {
public void prompt() { public void prompt() {
if (promptOnError) { if (promptOnError) {
System.err.println(localize("resume.abort")); System.err.println(localize("resume.abort"));
char ch;
try { try {
while (true) { while (true) {
switch (System.in.read()) { switch (System.in.read()) {
...@@ -340,7 +354,7 @@ public class Log extends AbstractLog { ...@@ -340,7 +354,7 @@ public class Log extends AbstractLog {
return; return;
int col = source.getColumnNumber(pos, false); int col = source.getColumnNumber(pos, false);
printLines(writer, line); printRawLines(writer, line);
for (int i = 0; i < col - 1; i++) { for (int i = 0; i < col - 1; i++) {
writer.print((line.charAt(i) == '\t') ? "\t" : " "); writer.print((line.charAt(i) == '\t') ? "\t" : " ");
} }
...@@ -348,17 +362,48 @@ public class Log extends AbstractLog { ...@@ -348,17 +362,48 @@ public class Log extends AbstractLog {
writer.flush(); writer.flush();
} }
public void printNewline() {
noticeWriter.println();
}
public void printNewline(WriterKind wk) {
getWriter(wk).println();
}
public void printLines(String key, Object... args) {
printRawLines(noticeWriter, localize(key, args));
}
public void printLines(PrefixKind pk, String key, Object... args) {
printRawLines(noticeWriter, localize(pk, key, args));
}
public void printLines(WriterKind wk, String key, Object... args) {
printRawLines(getWriter(wk), localize(key, args));
}
public void printLines(WriterKind wk, PrefixKind pk, String key, Object... args) {
printRawLines(getWriter(wk), localize(pk, key, args));
}
/** Print the text of a message, translating newlines appropriately
* for the platform.
*/
public void printRawLines(String msg) {
printRawLines(noticeWriter, msg);
}
/** Print the text of a message, translating newlines appropriately /** Print the text of a message, translating newlines appropriately
* for the platform. * for the platform.
*/ */
public void printLines(WriterKind kind, String msg) { public void printRawLines(WriterKind kind, String msg) {
printLines(getWriter(kind), msg); printRawLines(getWriter(kind), msg);
} }
/** Print the text of a message, translating newlines appropriately /** Print the text of a message, translating newlines appropriately
* for the platform. * for the platform.
*/ */
public static void printLines(PrintWriter writer, String msg) { public static void printRawLines(PrintWriter writer, String msg) {
int nl; int nl;
while ((nl = msg.indexOf('\n')) != -1) { while ((nl = msg.indexOf('\n')) != -1) {
writer.println(msg.substring(0, nl)); writer.println(msg.substring(0, nl));
...@@ -367,30 +412,16 @@ public class Log extends AbstractLog { ...@@ -367,30 +412,16 @@ public class Log extends AbstractLog {
if (msg.length() != 0) writer.println(msg); if (msg.length() != 0) writer.println(msg);
} }
/** Print the text of a message to the errWriter stream,
* translating newlines appropriately for the platform.
*/
public void printErrLines(String key, Object... args) {
printLines(errWriter, localize(key, args));
}
/** Print the text of a message to the noticeWriter stream,
* translating newlines appropriately for the platform.
*/
public void printNoteLines(String key, Object... args) {
printLines(noticeWriter, localize(key, args));
}
/** /**
* Print the localized text of a "verbose" message to the * Print the localized text of a "verbose" message to the
* noticeWriter stream. * noticeWriter stream.
*/ */
public void printVerbose(String key, Object... args) { public void printVerbose(String key, Object... args) {
printLines(noticeWriter, localize("verbose." + key, args)); printRawLines(noticeWriter, localize("verbose." + key, args));
} }
protected void directError(String key, Object... args) { protected void directError(String key, Object... args) {
printErrLines(key, args); printRawLines(errWriter, localize(key, args));
errWriter.flush(); errWriter.flush();
} }
...@@ -476,7 +507,7 @@ public class Log extends AbstractLog { ...@@ -476,7 +507,7 @@ public class Log extends AbstractLog {
PrintWriter writer = getWriterForDiagnosticType(diag.getType()); PrintWriter writer = getWriterForDiagnosticType(diag.getType());
printLines(writer, diagFormatter.format(diag, messages.getCurrentLocale())); printRawLines(writer, diagFormatter.format(diag, messages.getCurrentLocale()));
if (promptOnError) { if (promptOnError) {
switch (diag.getType()) { switch (diag.getType()) {
...@@ -519,7 +550,7 @@ public class Log extends AbstractLog { ...@@ -519,7 +550,7 @@ public class Log extends AbstractLog {
* @param args Fields to substitute into the string. * @param args Fields to substitute into the string.
*/ */
public static String getLocalizedString(String key, Object ... args) { public static String getLocalizedString(String key, Object ... args) {
return JavacMessages.getDefaultLocalizedString("compiler.misc." + key, args); return JavacMessages.getDefaultLocalizedString(PrefixKind.COMPILER_MISC.key(key), args);
} }
/** Find a localized string in the resource bundle. /** Find a localized string in the resource bundle.
...@@ -527,8 +558,22 @@ public class Log extends AbstractLog { ...@@ -527,8 +558,22 @@ public class Log extends AbstractLog {
* @param args Fields to substitute into the string. * @param args Fields to substitute into the string.
*/ */
public String localize(String key, Object... args) { public String localize(String key, Object... args) {
return messages.getLocalizedString("compiler.misc." + key, args); return localize(PrefixKind.COMPILER_MISC, key, args);
}
/** Find a localized string in the resource bundle.
* @param key The key for the localized string.
* @param args Fields to substitute into the string.
*/
public String localize(PrefixKind pk, String key, Object... args) {
if (useRawMessages)
return pk.key(key);
else
return messages.getLocalizedString(pk.key(key), args);
} }
// where
// backdoor hook for testing, should transition to use -XDrawDiagnostics
private static boolean useRawMessages = false;
/*************************************************************************** /***************************************************************************
* raw error messages without internationalization; used for experimentation * raw error messages without internationalization; used for experimentation
...@@ -539,12 +584,12 @@ public class Log extends AbstractLog { ...@@ -539,12 +584,12 @@ public class Log extends AbstractLog {
*/ */
private void printRawError(int pos, String msg) { private void printRawError(int pos, String msg) {
if (source == null || pos == Position.NOPOS) { if (source == null || pos == Position.NOPOS) {
printLines(errWriter, "error: " + msg); printRawLines(errWriter, "error: " + msg);
} else { } else {
int line = source.getLineNumber(pos); int line = source.getLineNumber(pos);
JavaFileObject file = source.getFile(); JavaFileObject file = source.getFile();
if (file != null) if (file != null)
printLines(errWriter, printRawLines(errWriter,
file.getName() + ":" + file.getName() + ":" +
line + ": " + msg); line + ": " + msg);
printErrLine(pos, errWriter); printErrLine(pos, errWriter);
......
/* /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
* @author Peter von der Ah\u00e9 * @author Peter von der Ah\u00e9
*/ */
import java.lang.reflect.Method; import java.lang.reflect.Field;
import java.io.File; import java.io.File;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import javax.tools.*; import javax.tools.*;
...@@ -39,12 +39,13 @@ public class T6410653 { ...@@ -39,12 +39,13 @@ public class T6410653 {
String source = new File(testSrc, "T6410653.java").getPath(); String source = new File(testSrc, "T6410653.java").getPath();
ClassLoader cl = ToolProvider.getSystemToolClassLoader(); ClassLoader cl = ToolProvider.getSystemToolClassLoader();
Tool compiler = ToolProvider.getSystemJavaCompiler(); Tool compiler = ToolProvider.getSystemJavaCompiler();
Class<?> main = Class.forName("com.sun.tools.javac.main.Main", true, cl); Class<?> log = Class.forName("com.sun.tools.javac.util.Log", true, cl);
Method useRawMessages = main.getMethod("useRawMessages", boolean.class); Field useRawMessages = log.getDeclaredField("useRawMessages");
useRawMessages.invoke(null, true); useRawMessages.setAccessible(true);
useRawMessages.setBoolean(null, true);
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
compiler.run(null, null, out, "-d", source, source); compiler.run(null, null, out, "-d", source, source);
useRawMessages.invoke(null, false); useRawMessages.setBoolean(null, false);
if (!out.toString().equals(String.format("%s%n%s%n", if (!out.toString().equals(String.format("%s%n%s%n",
"javac: javac.err.file.not.directory", "javac: javac.err.file.not.directory",
"javac.msg.usage"))) { "javac.msg.usage"))) {
......
...@@ -105,13 +105,11 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory { ...@@ -105,13 +105,11 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory {
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files); Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos); Context c = new Context();
Context c = t.getContext();
ArgTypeMessages.preRegister(c); ArgTypeMessages.preRegister(c);
ArgTypeJavaCompiler.preRegister(c); ArgTypeJavaCompiler.preRegister(c);
Boolean ok = t.call(); JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos, c);
return t.call();
return ok;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册