# HG changeset patch # User jjg # Date 1320800818 28800 # Node ID 48713f779b1d22fc449566a6a9614108c0293948 # Parent 65b9fa7eaf55f49fadbec3efc5eba41742f90dd4 7108669: cleanup Log methods for direct printing to streams Reviewed-by: mcimadamore diff -r 65b9fa7eaf55 -r 48713f779b1d langtools/src/share/classes/com/sun/tools/apt/main/Main.java --- a/langtools/src/share/classes/com/sun/tools/apt/main/Main.java Tue Nov 08 17:06:08 2011 -0800 +++ b/langtools/src/share/classes/com/sun/tools/apt/main/Main.java Tue Nov 08 17:06:58 2011 -0800 @@ -205,7 +205,7 @@ String s = " " + helpSynopsis(); out.print(s); for (int j = s.length(); j < 29; j++) out.print(" "); - Bark.printLines(out, getLocalizedString(descrKey)); + Bark.printRawLines(out, getLocalizedString(descrKey)); } } @@ -227,7 +227,7 @@ String s = " " + helpSynopsis(); out.print(s); for (int j = s.length(); j < 29; j++) out.print(" "); - Bark.printLines(out, getLocalizedString(descrKey)); + Bark.printRawLines(out, getLocalizedString(descrKey)); } } @@ -259,7 +259,7 @@ String s = " " + helpSynopsis(); out.print(s); for (int j = s.length(); j < 29; j++) out.print(" "); - Log.printLines(out, getLocalizedString(descrKey)); + Log.printRawLines(out, getLocalizedString(descrKey)); } }; @@ -421,7 +421,7 @@ }, new AptOption("-version", "opt.version") { boolean process(String option) { - Bark.printLines(out, ownName + " " + AptJavaCompiler.version()); + Bark.printRawLines(out, ownName + " " + AptJavaCompiler.version()); return super.process(option); } }, @@ -660,11 +660,11 @@ /** Print a string that explains usage. */ 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++) { recognizedOptions[i].help(); } - Bark.printLines(out, getLocalizedString("msg.usage.footer")); + Bark.printRawLines(out, getLocalizedString("msg.usage.footer")); out.println(); } @@ -675,7 +675,7 @@ recognizedOptions[i].xhelp(); } out.println(); - Bark.printLines(out, getLocalizedString("msg.usage.nonstandard.footer")); + Bark.printRawLines(out, getLocalizedString("msg.usage.nonstandard.footer")); } /** Report a usage error. @@ -688,7 +688,7 @@ /** Report a warning. */ void warning(String key, Object... args) { - Bark.printLines(out, ownName + ": " + Bark.printRawLines(out, ownName + ": " + getLocalizedString(key, args)); } @@ -796,7 +796,7 @@ origFilenames = processArgs((args=CommandLine.parse(args))); if (options.get("suppress-tool-api-removal-message") == null) { - Bark.printLines(out, getLocalizedString("misc.Deprecation")); + Bark.printRawLines(out, getLocalizedString("misc.Deprecation")); } if (origFilenames == null) { @@ -808,7 +808,7 @@ return EXIT_OK; } } catch (java.io.FileNotFoundException e) { - Bark.printLines(out, ownName + ": " + + Bark.printRawLines(out, ownName + ": " + getLocalizedString("err.file.not.found", e.getMessage())); return EXIT_SYSERR; @@ -1183,7 +1183,7 @@ /** Print a message reporting an internal error. */ void bugMessage(Throwable ex) { - Bark.printLines(out, getLocalizedString("msg.bug", + Bark.printRawLines(out, getLocalizedString("msg.bug", AptJavaCompiler.version())); ex.printStackTrace(out); } @@ -1191,34 +1191,34 @@ /** Print a message reporting an fatal error. */ void apMessage(AnnotationProcessingError ex) { - Bark.printLines(out, getLocalizedString("misc.Problem")); + Bark.printRawLines(out, getLocalizedString("misc.Problem")); ex.getCause().printStackTrace(out); } /** Print a message about sun.misc.Service problem. */ void sceMessage(sun.misc.ServiceConfigurationError ex) { - Bark.printLines(out, getLocalizedString("misc.SunMiscService")); + Bark.printRawLines(out, getLocalizedString("misc.SunMiscService")); ex.printStackTrace(out); } /** Print a message reporting an fatal error. */ void feMessage(Throwable ex) { - Bark.printLines(out, ex.toString()); + Bark.printRawLines(out, ex.toString()); } /** Print a message reporting an input/output error. */ void ioMessage(Throwable ex) { - Bark.printLines(out, getLocalizedString("msg.io")); + Bark.printRawLines(out, getLocalizedString("msg.io")); ex.printStackTrace(out); } /** Print a message reporting an out-of-resources error. */ void resourceMessage(Throwable ex) { - Bark.printLines(out, getLocalizedString("msg.resource")); + Bark.printRawLines(out, getLocalizedString("msg.resource")); ex.printStackTrace(out); } diff -r 65b9fa7eaf55 -r 48713f779b1d langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java --- a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java Tue Nov 08 17:06:08 2011 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java Tue Nov 08 17:06:58 2011 -0800 @@ -52,6 +52,7 @@ import com.sun.tools.javac.util.ClientCodeException; import com.sun.tools.javac.util.Context; 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.Pair; @@ -156,15 +157,28 @@ return new JavacFileManager(context, true, charset); } + @Override public JavacTask getTask(Writer out, JavaFileManager fileManager, DiagnosticListener diagnosticListener, Iterable options, Iterable classes, - Iterable compilationUnits) + Iterable compilationUnits) { + Context context = new Context(); + return getTask(out, fileManager, diagnosticListener, + options, classes, compilationUnits, + context); + } + + public JavacTask getTask(Writer out, + JavaFileManager fileManager, + DiagnosticListener diagnosticListener, + Iterable options, + Iterable classes, + Iterable compilationUnits, + Context context) { try { - Context context = new Context(); ClientCodeWrapper ccw = ClientCodeWrapper.instance(context); final String kindMsg = "All compilation units must be of SOURCE kind"; @@ -212,9 +226,10 @@ return; Options optionTable = Options.instance(context); + Log log = Log.instance(context); JavacOption[] recognizedOptions = - RecognizedOptions.getJavacToolOptions(new GrumpyHelper()); + RecognizedOptions.getJavacToolOptions(new GrumpyHelper(log)); Iterator flags = options.iterator(); while (flags.hasNext()) { String flag = flags.next(); @@ -227,7 +242,7 @@ if (fileManager.handleOption(flag, flags)) { continue; } else { - String msg = Main.getLocalizedString("err.invalid.flag", flag); + String msg = log.localize(PrefixKind.JAVAC, "err.invalid.flag", flag); throw new IllegalArgumentException(msg); } } @@ -235,7 +250,7 @@ JavacOption option = recognizedOptions[j]; if (option.hasArg()) { 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); } String operand = flags.next(); @@ -269,7 +284,7 @@ public int isSupportedOption(String option) { JavacOption[] recognizedOptions = - RecognizedOptions.getJavacToolOptions(new GrumpyHelper()); + RecognizedOptions.getJavacToolOptions(new GrumpyHelper(null)); for (JavacOption o : recognizedOptions) { if (o.matches(option)) return o.hasArg() ? 1 : 0; diff -r 65b9fa7eaf55 -r 48713f779b1d langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Tue Nov 08 17:06:08 2011 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Tue Nov 08 17:06:58 2011 -0800 @@ -2539,7 +2539,7 @@ * @param arg An argument for substitution into the output string. */ private void printCCF(String key, Object arg) { - log.printNoteLines(key, arg); + log.printLines(key, arg); } diff -r 65b9fa7eaf55 -r 48713f779b1d langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java --- a/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Nov 08 17:06:08 2011 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Nov 08 17:06:58 2011 -0800 @@ -48,17 +48,18 @@ import com.sun.source.util.TaskEvent; 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.Lint.LintCategory; import com.sun.tools.javac.code.Symbol.*; +import com.sun.tools.javac.comp.*; +import com.sun.tools.javac.file.JavacFileManager; +import com.sun.tools.javac.jvm.*; +import com.sun.tools.javac.parser.*; +import com.sun.tools.javac.processing.*; 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.jvm.*; -import com.sun.tools.javac.processing.*; +import com.sun.tools.javac.util.*; +import com.sun.tools.javac.util.Log.WriterKind; import static javax.tools.StandardLocation.CLASS_OUTPUT; import static com.sun.tools.javac.main.OptionName.*; @@ -1602,7 +1603,7 @@ } protected void printNote(String lines) { - log.printLines(Log.WriterKind.NOTICE, lines); + log.printRawLines(Log.WriterKind.NOTICE, lines); } /** Print numbers of errors and warnings. @@ -1614,7 +1615,7 @@ key = "count." + kind; else key = "count." + kind + ".plural"; - log.printErrLines(key, String.valueOf(count)); + log.printLines(WriterKind.ERROR, key, String.valueOf(count)); log.flush(Log.WriterKind.ERROR); } } diff -r 65b9fa7eaf55 -r 48713f779b1d langtools/src/share/classes/com/sun/tools/javac/main/JavacOption.java --- a/langtools/src/share/classes/com/sun/tools/javac/main/JavacOption.java Tue Nov 08 17:06:08 2011 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/main/JavacOption.java Tue Nov 08 17:06:58 2011 -0800 @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -25,10 +25,11 @@ package com.sun.tools.javac.main; -import java.io.PrintWriter; import java.util.LinkedHashMap; import java.util.Map; 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; /** @@ -177,14 +178,14 @@ /** Print a line of documentation describing this option, if standard. * @param out the stream to which to write the documentation */ - void help(PrintWriter out) { - String s = " " + helpSynopsis(); - out.print(s); - for (int j = Math.min(s.length(), 28); j < 29; j++) out.print(" "); - Log.printLines(out, Main.getLocalizedString(descrKey)); + void help(Log log) { + log.printRawLines(WriterKind.NOTICE, + String.format(" %-26s %s", + helpSynopsis(log), + log.localize(PrefixKind.JAVAC, descrKey))); } - String helpSynopsis() { + String helpSynopsis(Log log) { StringBuilder sb = new StringBuilder(); sb.append(name); if (argsNameKey == null) { @@ -202,7 +203,7 @@ } else { if (!hasSuffix) sb.append(" "); - sb.append(Main.getLocalizedString(argsNameKey)); + sb.append(log.localize(PrefixKind.JAVAC, argsNameKey)); } return sb.toString(); @@ -211,7 +212,7 @@ /** Print a line of documentation describing this option, if non-standard. * @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. */ @@ -271,9 +272,9 @@ super(name, descrKey, kind, choices); } @Override - void help(PrintWriter out) {} + void help(Log log) {} @Override - void xhelp(PrintWriter out) { super.help(out); } + void xhelp(Log log) { super.help(log); } @Override public OptionKind getKind() { return OptionKind.EXTENDED; } }; @@ -288,9 +289,9 @@ super(name, argsNameKey, null); } @Override - void help(PrintWriter out) {} + void help(Log log) {} @Override - void xhelp(PrintWriter out) {} + void xhelp(Log log) {} @Override public OptionKind getKind() { return OptionKind.HIDDEN; } }; diff -r 65b9fa7eaf55 -r 48713f779b1d langtools/src/share/classes/com/sun/tools/javac/main/Main.java --- a/langtools/src/share/classes/com/sun/tools/javac/main/Main.java Tue Nov 08 17:06:08 2011 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/main/Main.java Tue Nov 08 17:06:58 2011 -0800 @@ -33,7 +33,6 @@ import java.security.MessageDigest; import java.util.Collection; import java.util.LinkedHashSet; -import java.util.MissingResourceException; import java.util.Set; import javax.tools.JavaFileManager; import javax.tools.JavaFileObject; @@ -46,6 +45,8 @@ import com.sun.tools.javac.main.JavacOption.Option; import com.sun.tools.javac.main.RecognizedOptions.OptionHelper; 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 static com.sun.tools.javac.main.OptionName.*; @@ -110,11 +111,11 @@ } public void printVersion() { - Log.printLines(out, getLocalizedString("version", ownName, JavaCompiler.version())); + log.printLines(PrefixKind.JAVAC, "version", ownName, JavaCompiler.version()); } public void printFullVersion() { - Log.printLines(out, getLocalizedString("fullVersion", ownName, JavaCompiler.fullVersion())); + log.printLines(PrefixKind.JAVAC, "fullversion", ownName, JavaCompiler.fullVersion()); } public void printHelp() { @@ -163,39 +164,38 @@ /** Print a string that explains usage. */ void help() { - Log.printLines(out, getLocalizedString("msg.usage.header", ownName)); + log.printLines(PrefixKind.JAVAC, "msg.usage.header", ownName); for (int i=0; i tlc = lastRound ? List.nil() : topLevelClasses; Set ap = lastRound ? Collections.emptySet() : annotationsPresent; - log.printNoteLines("x.print.rounds", + log.printLines("x.print.rounds", number, "{" + tlc.toString(", ") + "}", ap, diff -r 65b9fa7eaf55 -r 48713f779b1d langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties --- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Nov 08 17:06:08 2011 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Nov 08 17:06:58 2011 -0800 @@ -792,7 +792,7 @@ compiler.err.cant.apply.diamond=\ 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=\ cannot infer type arguments for {0};\n\ reason: {1} @@ -854,7 +854,7 @@ compiler.misc.varargs.trustme.on.virtual.varargs=\ Instance method {0} is not final. -# 0: type, 1: kind, 2: symbol +# 0: type, 1: symbol kind, 2: symbol compiler.misc.inaccessible.varargs.type=\ formal varargs element type {0} is not accessible from {1} {2} @@ -1631,6 +1631,7 @@ compiler.misc.diamond.non.generic=\ cannot use ''<>'' with non-generic class {0} +# 0: unused compiler.misc.diamond.and.explicit.params=\ cannot use ''<>'' with explicit type parameters for constructor @@ -1712,7 +1713,7 @@ ## The second argument {1} is the location 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=\ {0} {1} @@ -1847,6 +1848,7 @@ compiler.misc.varargs.clash.with=\ {0} in {1} overrides {2} in {3} +# 0: unused compiler.misc.diamond.and.anon.class=\ cannot use ''<>'' with anonymous inner classes diff -r 65b9fa7eaf55 -r 48713f779b1d langtools/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Tue Nov 08 17:06:08 2011 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Tue Nov 08 17:06:58 2011 -0800 @@ -166,7 +166,7 @@ // where private static JavacOption[] javacFileManagerOptions = RecognizedOptions.getJavacFileManagerOptions( - new RecognizedOptions.GrumpyHelper()); + new RecognizedOptions.GrumpyHelper(Log.instance(new Context()))); public int isSupportedOption(String option) { for (JavacOption o : javacFileManagerOptions) { diff -r 65b9fa7eaf55 -r 48713f779b1d langtools/src/share/classes/com/sun/tools/javac/util/Log.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Tue Nov 08 17:06:08 2011 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Tue Nov 08 17:06:58 2011 -0800 @@ -25,6 +25,7 @@ package com.sun.tools.javac.util; +import com.sun.tools.javac.main.Main; import java.io.*; import java.util.Arrays; import java.util.EnumSet; @@ -60,6 +61,19 @@ public static final Context.Key outKey = new Context.Key(); + /* 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 }; protected PrintWriter errWriter; @@ -136,6 +150,7 @@ this.diagListener = dl; messages = JavacMessages.instance(context); + messages.add(Main.javacBundleName); final Options options = Options.instance(context); initOptions(options); @@ -313,7 +328,6 @@ public void prompt() { if (promptOnError) { System.err.println(localize("resume.abort")); - char ch; try { while (true) { switch (System.in.read()) { @@ -340,7 +354,7 @@ return; int col = source.getColumnNumber(pos, false); - printLines(writer, line); + printRawLines(writer, line); for (int i = 0; i < col - 1; i++) { writer.print((line.charAt(i) == '\t') ? "\t" : " "); } @@ -348,17 +362,48 @@ writer.flush(); } - /** Print the text of a message, translating newlines appropriately - * for the platform. - */ - public void printLines(WriterKind kind, String msg) { - printLines(getWriter(kind), msg); + 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 static void printLines(PrintWriter writer, String msg) { + public void printRawLines(String msg) { + printRawLines(noticeWriter, msg); + } + + /** Print the text of a message, translating newlines appropriately + * for the platform. + */ + public void printRawLines(WriterKind kind, String msg) { + printRawLines(getWriter(kind), msg); + } + + /** Print the text of a message, translating newlines appropriately + * for the platform. + */ + public static void printRawLines(PrintWriter writer, String msg) { int nl; while ((nl = msg.indexOf('\n')) != -1) { writer.println(msg.substring(0, nl)); @@ -367,30 +412,16 @@ 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 * noticeWriter stream. */ 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) { - printErrLines(key, args); + printRawLines(errWriter, localize(key, args)); errWriter.flush(); } @@ -476,7 +507,7 @@ PrintWriter writer = getWriterForDiagnosticType(diag.getType()); - printLines(writer, diagFormatter.format(diag, messages.getCurrentLocale())); + printRawLines(writer, diagFormatter.format(diag, messages.getCurrentLocale())); if (promptOnError) { switch (diag.getType()) { @@ -519,7 +550,7 @@ * @param args Fields to substitute into the string. */ 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. @@ -527,9 +558,23 @@ * @param args Fields to substitute into the string. */ 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 * and quick prototyping @@ -539,12 +584,12 @@ */ private void printRawError(int pos, String msg) { if (source == null || pos == Position.NOPOS) { - printLines(errWriter, "error: " + msg); + printRawLines(errWriter, "error: " + msg); } else { int line = source.getLineNumber(pos); JavaFileObject file = source.getFile(); if (file != null) - printLines(errWriter, + printRawLines(errWriter, file.getName() + ":" + line + ": " + msg); printErrLine(pos, errWriter); diff -r 65b9fa7eaf55 -r 48713f779b1d langtools/test/tools/javac/6410653/T6410653.java --- a/langtools/test/tools/javac/6410653/T6410653.java Tue Nov 08 17:06:08 2011 -0800 +++ b/langtools/test/tools/javac/6410653/T6410653.java Tue Nov 08 17:06:58 2011 -0800 @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -28,7 +28,7 @@ * @author Peter von der Ah\u00e9 */ -import java.lang.reflect.Method; +import java.lang.reflect.Field; import java.io.File; import java.io.ByteArrayOutputStream; import javax.tools.*; @@ -39,12 +39,13 @@ String source = new File(testSrc, "T6410653.java").getPath(); ClassLoader cl = ToolProvider.getSystemToolClassLoader(); Tool compiler = ToolProvider.getSystemJavaCompiler(); - Class main = Class.forName("com.sun.tools.javac.main.Main", true, cl); - Method useRawMessages = main.getMethod("useRawMessages", boolean.class); - useRawMessages.invoke(null, true); + Class log = Class.forName("com.sun.tools.javac.util.Log", true, cl); + Field useRawMessages = log.getDeclaredField("useRawMessages"); + useRawMessages.setAccessible(true); + useRawMessages.setBoolean(null, true); ByteArrayOutputStream out = new ByteArrayOutputStream(); 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", "javac: javac.err.file.not.directory", "javac.msg.usage"))) { diff -r 65b9fa7eaf55 -r 48713f779b1d langtools/test/tools/javac/diags/ArgTypeCompilerFactory.java --- a/langtools/test/tools/javac/diags/ArgTypeCompilerFactory.java Tue Nov 08 17:06:08 2011 -0800 +++ b/langtools/test/tools/javac/diags/ArgTypeCompilerFactory.java Tue Nov 08 17:06:58 2011 -0800 @@ -105,13 +105,11 @@ Iterable fos = fm.getJavaFileObjectsFromFiles(files); - JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos); - Context c = t.getContext(); + Context c = new Context(); ArgTypeMessages.preRegister(c); ArgTypeJavaCompiler.preRegister(c); - Boolean ok = t.call(); - - return ok; + JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos, c); + return t.call(); } }