提交 24549cd5 编写于 作者: L lana

Merge

...@@ -25,23 +25,38 @@ ...@@ -25,23 +25,38 @@
# Properties for jprt # Properties for jprt
# The release to build # Locked down to jdk8
jprt.tools.default.release=jdk8 jprt.tools.default.release=jdk8
# The different build flavors we want, we override here so we just get these 2 # The different build flavors we want, we override here so we just get these 2
jprt.build.flavors=product,fastdebug jprt.build.flavors=product,fastdebug
# Standard list of jprt build targets for this source tree # Standard list of jprt build targets for this source tree
jprt.build.targets= \ jprt.build.targets= \
solaris_sparc_5.10-{product|fastdebug}, \ solaris_sparc_5.10-{product|fastdebug}, \
solaris_sparcv9_5.10-{product|fastdebug}, \ solaris_sparcv9_5.10-{product|fastdebug}, \
solaris_i586_5.10-{product|fastdebug}, \ solaris_i586_5.10-{product|fastdebug}, \
solaris_x64_5.10-{product|fastdebug}, \ solaris_x64_5.10-{product|fastdebug}, \
linux_i586_2.6-{product|fastdebug}, \ linux_i586_2.6-{product|fastdebug}, \
linux_x64_2.6-{product|fastdebug}, \ linux_x64_2.6-{product|fastdebug}, \
windows_i586_5.1-{product|fastdebug}, \ windows_i586_5.1-{product|fastdebug}, \
windows_x64_5.2-{product|fastdebug} windows_x64_5.2-{product|fastdebug}
# Test target list (no fastdebug & limited c2 testing)
jprt.my.test.target.set= \
solaris_sparc_5.10-product-c1-TESTNAME, \
solaris_sparcv9_5.10-product-c2-TESTNAME, \
solaris_i586_5.10-product-c1-TESTNAME, \
solaris_x64_5.10-product-c2-TESTNAME, \
linux_i586_2.6-product-{c1|c2}-TESTNAME, \
linux_x64_2.6-product-c2-TESTNAME, \
windows_i586_5.1-product-c1-TESTNAME, \
windows_x64_5.2-product-c2-TESTNAME
# Default test targets
jprt.make.rule.test.targets= \
${jprt.my.test.target.set:TESTNAME=jtreg}
# Directories to be excluded from the source bundles # Directories to be excluded from the source bundles
jprt.bundle.exclude.src.dirs=build dist webrev jprt.bundle.exclude.src.dirs=build dist webrev
...@@ -216,6 +216,7 @@ doclet.Groupname_already_used=In -group option, groupname already used: {0} ...@@ -216,6 +216,7 @@ doclet.Groupname_already_used=In -group option, groupname already used: {0}
doclet.Same_package_name_used=Package name format used twice: {0} doclet.Same_package_name_used=Package name format used twice: {0}
doclet.Serialization.Excluded_Class=Non-transient field {1} uses excluded class {0}. doclet.Serialization.Excluded_Class=Non-transient field {1} uses excluded class {0}.
doclet.Serialization.Nonexcluded_Class=Non-transient field {1} uses hidden, non-included class {0}. doclet.Serialization.Nonexcluded_Class=Non-transient field {1} uses hidden, non-included class {0}.
doclet.exception_encountered=Exception encountered while processing {1}\n{0}
doclet.usage=Provided by Standard doclet:\n\ doclet.usage=Provided by Standard doclet:\n\
-d <directory> Destination directory for output files\n\ -d <directory> Destination directory for output files\n\
-use Create class and package usage pages\n\ -use Create class and package usage pages\n\
......
...@@ -25,18 +25,15 @@ ...@@ -25,18 +25,15 @@
package com.sun.tools.javac.api; package com.sun.tools.javac.api;
import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import javax.lang.model.SourceVersion; import javax.lang.model.SourceVersion;
...@@ -44,17 +41,15 @@ import javax.tools.*; ...@@ -44,17 +41,15 @@ import javax.tools.*;
import com.sun.source.util.JavacTask; import com.sun.source.util.JavacTask;
import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.main.JavacOption.OptionKind;
import com.sun.tools.javac.main.JavacOption;
import com.sun.tools.javac.main.Main; import com.sun.tools.javac.main.Main;
import com.sun.tools.javac.main.RecognizedOptions.GrumpyHelper; import com.sun.tools.javac.main.Option;
import com.sun.tools.javac.main.RecognizedOptions; import com.sun.tools.javac.main.OptionHelper;
import com.sun.tools.javac.main.OptionHelper.GrumpyHelper;
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.Log.PrefixKind;
import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.Options;
import com.sun.tools.javac.util.Pair;
/** /**
* TODO: describe com.sun.tools.javac.api.Tool * TODO: describe com.sun.tools.javac.api.Tool
...@@ -67,23 +62,10 @@ import com.sun.tools.javac.util.Pair; ...@@ -67,23 +62,10 @@ import com.sun.tools.javac.util.Pair;
* @author Peter von der Ah\u00e9 * @author Peter von der Ah\u00e9
*/ */
public final class JavacTool implements JavaCompiler { public final class JavacTool implements JavaCompiler {
private final List<Pair<String,String>> options
= new ArrayList<Pair<String,String>>();
private final Context dummyContext = new Context();
private final PrintWriter silent = new PrintWriter(new OutputStream(){
public void write(int b) {}
});
private final Main sharedCompiler = new Main("javac", silent);
{
sharedCompiler.setOptions(Options.instance(dummyContext));
}
/** /**
* Constructor used by service provider mechanism. The correct way to * Constructor used by service provider mechanism. The recommended way to
* obtain an instance of this class is using create or the service provider * obtain an instance of this class is by using {@link #create} or the
* mechanism. * service provider mechanism.
* @see javax.tools.JavaCompilerTool * @see javax.tools.JavaCompilerTool
* @see javax.tools.ToolProvider * @see javax.tools.ToolProvider
* @see #create * @see #create
...@@ -99,49 +81,6 @@ public final class JavacTool implements JavaCompiler { ...@@ -99,49 +81,6 @@ public final class JavacTool implements JavaCompiler {
return new JavacTool(); return new JavacTool();
} }
private String argsToString(Object... args) {
String newArgs = null;
if (args.length > 0) {
StringBuilder sb = new StringBuilder();
String separator = "";
for (Object arg : args) {
sb.append(separator).append(arg.toString());
separator = File.pathSeparator;
}
newArgs = sb.toString();
}
return newArgs;
}
private void setOption1(String name, OptionKind kind, Object... args) {
String arg = argsToString(args);
JavacOption option = sharedCompiler.getOption(name);
if (option == null || !match(kind, option.getKind()))
throw new IllegalArgumentException(name);
if ((args.length != 0) != option.hasArg())
throw new IllegalArgumentException(name);
if (option.hasArg()) {
if (option.process(null, name, arg)) // FIXME
throw new IllegalArgumentException(name);
} else {
if (option.process(null, name)) // FIXME
throw new IllegalArgumentException(name);
}
options.add(new Pair<String,String>(name,arg));
}
public void setOption(String name, Object... args) {
setOption1(name, OptionKind.NORMAL, args);
}
public void setExtendedOption(String name, Object... args) {
setOption1(name, OptionKind.EXTENDED, args);
}
private static boolean match(OptionKind clientKind, OptionKind optionKind) {
return (clientKind == (optionKind == OptionKind.HIDDEN ? OptionKind.EXTENDED : optionKind));
}
public JavacFileManager getStandardFileManager( public JavacFileManager getStandardFileManager(
DiagnosticListener<? super JavaFileObject> diagnosticListener, DiagnosticListener<? super JavaFileObject> diagnosticListener,
Locale locale, Locale locale,
...@@ -209,7 +148,9 @@ public final class JavacTool implements JavaCompiler { ...@@ -209,7 +148,9 @@ public final class JavacTool implements JavaCompiler {
if (fileManager == null) if (fileManager == null)
fileManager = getStandardFileManager(diagnosticListener, null, null); fileManager = getStandardFileManager(diagnosticListener, null, null);
fileManager = ccw.wrap(fileManager); fileManager = ccw.wrap(fileManager);
context.put(JavaFileManager.class, fileManager); context.put(JavaFileManager.class, fileManager);
processOptions(context, fileManager, options); processOptions(context, fileManager, options);
Main compiler = new Main("javacTask", context.get(Log.outKey)); Main compiler = new Main("javacTask", context.get(Log.outKey));
return new JavacTaskImpl(compiler, options, context, classes, compilationUnits); return new JavacTaskImpl(compiler, options, context, classes, compilationUnits);
...@@ -225,11 +166,28 @@ public final class JavacTool implements JavaCompiler { ...@@ -225,11 +166,28 @@ public final class JavacTool implements JavaCompiler {
if (options == null) if (options == null)
return; return;
Options optionTable = Options.instance(context); final Options optionTable = Options.instance(context);
Log log = Log.instance(context); Log log = Log.instance(context);
JavacOption[] recognizedOptions = Option[] recognizedOptions =
RecognizedOptions.getJavacToolOptions(new GrumpyHelper(log)); Option.getJavacToolOptions().toArray(new Option[0]);
OptionHelper optionHelper = new GrumpyHelper(log) {
@Override
public String get(Option option) {
return optionTable.get(option.getText());
}
@Override
public void put(String name, String value) {
optionTable.put(name, value);
}
@Override
public void remove(String name) {
optionTable.remove(name);
}
};
Iterator<String> flags = options.iterator(); Iterator<String> flags = options.iterator();
while (flags.hasNext()) { while (flags.hasNext()) {
String flag = flags.next(); String flag = flags.next();
...@@ -247,19 +205,19 @@ public final class JavacTool implements JavaCompiler { ...@@ -247,19 +205,19 @@ public final class JavacTool implements JavaCompiler {
} }
} }
JavacOption option = recognizedOptions[j]; Option option = recognizedOptions[j];
if (option.hasArg()) { if (option.hasArg()) {
if (!flags.hasNext()) { if (!flags.hasNext()) {
String msg = log.localize(PrefixKind.JAVAC, "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();
if (option.process(optionTable, flag, operand)) if (option.process(optionHelper, flag, operand))
// should not happen as the GrumpyHelper will throw exceptions // should not happen as the GrumpyHelper will throw exceptions
// in case of errors // in case of errors
throw new IllegalArgumentException(flag + " " + operand); throw new IllegalArgumentException(flag + " " + operand);
} else { } else {
if (option.process(optionTable, flag)) if (option.process(optionHelper, flag))
// should not happen as the GrumpyHelper will throw exceptions // should not happen as the GrumpyHelper will throw exceptions
// in case of errors // in case of errors
throw new IllegalArgumentException(flag); throw new IllegalArgumentException(flag);
...@@ -283,9 +241,8 @@ public final class JavacTool implements JavaCompiler { ...@@ -283,9 +241,8 @@ public final class JavacTool implements JavaCompiler {
} }
public int isSupportedOption(String option) { public int isSupportedOption(String option) {
JavacOption[] recognizedOptions = Set<Option> recognizedOptions = Option.getJavacToolOptions();
RecognizedOptions.getJavacToolOptions(new GrumpyHelper(null)); for (Option o : recognizedOptions) {
for (JavacOption o : recognizedOptions) {
if (o.matches(option)) if (o.matches(option))
return o.hasArg() ? 1 : 0; return o.hasArg() ? 1 : 0;
} }
......
...@@ -32,7 +32,7 @@ import static javax.lang.model.SourceVersion.*; ...@@ -32,7 +32,7 @@ import static javax.lang.model.SourceVersion.*;
import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.*;
import com.sun.tools.javac.jvm.Target; import com.sun.tools.javac.jvm.Target;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.Option.*;
/** The source language version accepted. /** The source language version accepted.
* *
......
...@@ -48,7 +48,6 @@ import static com.sun.tools.javac.code.Kinds.*; ...@@ -48,7 +48,6 @@ import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.code.TypeTags.WILDCARD; import static com.sun.tools.javac.code.TypeTags.WILDCARD;
import static com.sun.tools.javac.main.OptionName.*;
import static com.sun.tools.javac.tree.JCTree.Tag.*; import static com.sun.tools.javac.tree.JCTree.Tag.*;
/** Type checking helper class for the attribution phase. /** Type checking helper class for the attribution phase.
...@@ -110,7 +109,7 @@ public class Check { ...@@ -110,7 +109,7 @@ public class Check {
allowAnnotations = source.allowAnnotations(); allowAnnotations = source.allowAnnotations();
allowCovariantReturns = source.allowCovariantReturns(); allowCovariantReturns = source.allowCovariantReturns();
allowSimplifiedVarargs = source.allowSimplifiedVarargs(); allowSimplifiedVarargs = source.allowSimplifiedVarargs();
complexInference = options.isSet(COMPLEXINFERENCE); complexInference = options.isSet("complexinference");
skipAnnotations = options.isSet("skipAnnotations"); skipAnnotations = options.isSet("skipAnnotations");
warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts"); warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts");
suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile"); suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile");
...@@ -2482,7 +2481,7 @@ public class Check { ...@@ -2482,7 +2481,7 @@ public class Check {
warnDeprecated(pos, s); warnDeprecated(pos, s);
} }
}); });
}; }
} }
void checkSunAPI(final DiagnosticPosition pos, final Symbol s) { void checkSunAPI(final DiagnosticPosition pos, final Symbol s) {
......
...@@ -34,7 +34,7 @@ import com.sun.tools.javac.code.Scope.*; ...@@ -34,7 +34,7 @@ import com.sun.tools.javac.code.Scope.*;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.code.Type.*;
import com.sun.tools.javac.jvm.*; import com.sun.tools.javac.jvm.*;
import com.sun.tools.javac.main.RecognizedOptions.PkgInfo; import com.sun.tools.javac.main.Option.PkgInfo;
import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.*;
......
...@@ -29,7 +29,7 @@ import java.util.*; ...@@ -29,7 +29,7 @@ import java.util.*;
import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.*;
import com.sun.tools.javac.jvm.*; import com.sun.tools.javac.jvm.*;
import com.sun.tools.javac.main.RecognizedOptions.PkgInfo; import com.sun.tools.javac.main.Option.PkgInfo;
import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
......
...@@ -47,14 +47,14 @@ import javax.tools.JavaFileManager.Location; ...@@ -47,14 +47,14 @@ import javax.tools.JavaFileManager.Location;
import javax.tools.StandardLocation; import javax.tools.StandardLocation;
import com.sun.tools.javac.code.Lint; import com.sun.tools.javac.code.Lint;
import com.sun.tools.javac.main.OptionName; import com.sun.tools.javac.main.Option;
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;
import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.Options;
import javax.tools.JavaFileManager; import javax.tools.JavaFileManager;
import static javax.tools.StandardLocation.*; import static javax.tools.StandardLocation.*;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.Option.*;
/** This class converts command line arguments, environment variables /** This class converts command line arguments, environment variables
* and system properties (in File.pathSeparator-separated String form) * and system properties (in File.pathSeparator-separated String form)
...@@ -318,23 +318,23 @@ public class Locations { ...@@ -318,23 +318,23 @@ public class Locations {
*/ */
protected abstract class LocationHandler { protected abstract class LocationHandler {
final Location location; final Location location;
final Set<OptionName> options; final Set<Option> options;
/** /**
* Create a handler. The location and options provide a way to map * Create a handler. The location and options provide a way to map
* from a location or an option to the corresponding handler. * from a location or an option to the corresponding handler.
* @see #initHandlers * @see #initHandlers
*/ */
protected LocationHandler(Location location, OptionName... options) { protected LocationHandler(Location location, Option... options) {
this.location = location; this.location = location;
this.options = options.length == 0 ? this.options = options.length == 0 ?
EnumSet.noneOf(OptionName.class): EnumSet.noneOf(Option.class):
EnumSet.copyOf(Arrays.asList(options)); EnumSet.copyOf(Arrays.asList(options));
} }
// TODO: TEMPORARY, while Options still used for command line options // TODO: TEMPORARY, while Options still used for command line options
void update(Options optionTable) { void update(Options optionTable) {
for (OptionName o: options) { for (Option o: options) {
String v = optionTable.get(o); String v = optionTable.get(o);
if (v != null) { if (v != null) {
handleOption(o, v); handleOption(o, v);
...@@ -343,7 +343,7 @@ public class Locations { ...@@ -343,7 +343,7 @@ public class Locations {
} }
/** @see JavaFileManager#handleOption. */ /** @see JavaFileManager#handleOption. */
abstract boolean handleOption(OptionName option, String value); abstract boolean handleOption(Option option, String value);
/** @see JavaFileManager#getLocation. */ /** @see JavaFileManager#getLocation. */
abstract Collection<File> getLocation(); abstract Collection<File> getLocation();
/** @see JavaFileManager#setLocation. */ /** @see JavaFileManager#setLocation. */
...@@ -359,12 +359,12 @@ public class Locations { ...@@ -359,12 +359,12 @@ public class Locations {
private class OutputLocationHandler extends LocationHandler { private class OutputLocationHandler extends LocationHandler {
private File outputDir; private File outputDir;
OutputLocationHandler(Location location, OptionName... options) { OutputLocationHandler(Location location, Option... options) {
super(location, options); super(location, options);
} }
@Override @Override
boolean handleOption(OptionName option, String value) { boolean handleOption(Option option, String value) {
if (!options.contains(option)) if (!options.contains(option))
return false; return false;
...@@ -410,12 +410,12 @@ public class Locations { ...@@ -410,12 +410,12 @@ public class Locations {
private class SimpleLocationHandler extends LocationHandler { private class SimpleLocationHandler extends LocationHandler {
protected Collection<File> searchPath; protected Collection<File> searchPath;
SimpleLocationHandler(Location location, OptionName... options) { SimpleLocationHandler(Location location, Option... options) {
super(location, options); super(location, options);
} }
@Override @Override
boolean handleOption(OptionName option, String value) { boolean handleOption(Option option, String value) {
if (!options.contains(option)) if (!options.contains(option))
return false; return false;
searchPath = value == null ? null : searchPath = value == null ? null :
...@@ -452,7 +452,7 @@ public class Locations { ...@@ -452,7 +452,7 @@ public class Locations {
private class ClassPathLocationHandler extends SimpleLocationHandler { private class ClassPathLocationHandler extends SimpleLocationHandler {
ClassPathLocationHandler() { ClassPathLocationHandler() {
super(StandardLocation.CLASS_PATH, super(StandardLocation.CLASS_PATH,
OptionName.CLASSPATH, OptionName.CP); Option.CLASSPATH, Option.CP);
} }
@Override @Override
...@@ -500,7 +500,7 @@ public class Locations { ...@@ -500,7 +500,7 @@ public class Locations {
*/ */
private class BootClassPathLocationHandler extends LocationHandler { private class BootClassPathLocationHandler extends LocationHandler {
private Collection<File> searchPath; private Collection<File> searchPath;
final Map<OptionName, String> optionValues = new EnumMap<OptionName,String>(OptionName.class); final Map<Option, String> optionValues = new EnumMap<Option,String>(Option.class);
/** /**
* rt.jar as found on the default bootclasspath. * rt.jar as found on the default bootclasspath.
...@@ -515,11 +515,11 @@ public class Locations { ...@@ -515,11 +515,11 @@ public class Locations {
BootClassPathLocationHandler() { BootClassPathLocationHandler() {
super(StandardLocation.PLATFORM_CLASS_PATH, super(StandardLocation.PLATFORM_CLASS_PATH,
OptionName.BOOTCLASSPATH, OptionName.XBOOTCLASSPATH, Option.BOOTCLASSPATH, Option.XBOOTCLASSPATH,
OptionName.XBOOTCLASSPATH_PREPEND, Option.XBOOTCLASSPATH_PREPEND,
OptionName.XBOOTCLASSPATH_APPEND, Option.XBOOTCLASSPATH_APPEND,
OptionName.ENDORSEDDIRS, OptionName.DJAVA_ENDORSED_DIRS, Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
OptionName.EXTDIRS, OptionName.DJAVA_EXT_DIRS); Option.EXTDIRS, Option.DJAVA_EXT_DIRS);
} }
boolean isDefault() { boolean isDefault() {
...@@ -533,7 +533,7 @@ public class Locations { ...@@ -533,7 +533,7 @@ public class Locations {
} }
@Override @Override
boolean handleOption(OptionName option, String value) { boolean handleOption(Option option, String value) {
if (!options.contains(option)) if (!options.contains(option))
return false; return false;
...@@ -549,14 +549,14 @@ public class Locations { ...@@ -549,14 +549,14 @@ public class Locations {
// where // where
// TODO: would be better if option aliasing was handled at a higher // TODO: would be better if option aliasing was handled at a higher
// level // level
private OptionName canonicalize(OptionName option) { private Option canonicalize(Option option) {
switch (option) { switch (option) {
case XBOOTCLASSPATH: case XBOOTCLASSPATH:
return OptionName.BOOTCLASSPATH; return Option.BOOTCLASSPATH;
case DJAVA_ENDORSED_DIRS: case DJAVA_ENDORSED_DIRS:
return OptionName.ENDORSEDDIRS; return Option.ENDORSEDDIRS;
case DJAVA_EXT_DIRS: case DJAVA_EXT_DIRS:
return OptionName.EXTDIRS; return Option.EXTDIRS;
default: default:
return option; return option;
} }
...@@ -636,29 +636,29 @@ public class Locations { ...@@ -636,29 +636,29 @@ public class Locations {
} }
Map<Location, LocationHandler> handlersForLocation; Map<Location, LocationHandler> handlersForLocation;
Map<OptionName, LocationHandler> handlersForOption; Map<Option, LocationHandler> handlersForOption;
void initHandlers() { void initHandlers() {
handlersForLocation = new HashMap<Location, LocationHandler>(); handlersForLocation = new HashMap<Location, LocationHandler>();
handlersForOption = new EnumMap<OptionName, LocationHandler>(OptionName.class); handlersForOption = new EnumMap<Option, LocationHandler>(Option.class);
LocationHandler[] handlers = { LocationHandler[] handlers = {
new BootClassPathLocationHandler(), new BootClassPathLocationHandler(),
new ClassPathLocationHandler(), new ClassPathLocationHandler(),
new SimpleLocationHandler(StandardLocation.SOURCE_PATH, OptionName.SOURCEPATH), new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCEPATH),
new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, OptionName.PROCESSORPATH), new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSORPATH),
new OutputLocationHandler((StandardLocation.CLASS_OUTPUT), OptionName.D), new OutputLocationHandler((StandardLocation.CLASS_OUTPUT), Option.D),
new OutputLocationHandler((StandardLocation.SOURCE_OUTPUT), OptionName.S) new OutputLocationHandler((StandardLocation.SOURCE_OUTPUT), Option.S)
}; };
for (LocationHandler h: handlers) { for (LocationHandler h: handlers) {
handlersForLocation.put(h.location, h); handlersForLocation.put(h.location, h);
for (OptionName o: h.options) for (Option o: h.options)
handlersForOption.put(o, h); handlersForOption.put(o, h);
} }
} }
boolean handleOption(OptionName option, String value) { boolean handleOption(Option option, String value) {
LocationHandler h = handlersForOption.get(option); LocationHandler h = handlersForOption.get(option);
return (h == null ? false : h.handleOption(option, value)); return (h == null ? false : h.handleOption(option, value));
} }
......
...@@ -59,7 +59,7 @@ import static com.sun.tools.javac.code.TypeTags.*; ...@@ -59,7 +59,7 @@ import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.jvm.ClassFile.*; import static com.sun.tools.javac.jvm.ClassFile.*;
import static com.sun.tools.javac.jvm.ClassFile.Version.*; import static com.sun.tools.javac.jvm.ClassFile.Version.*;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.Option.*;
/** This class provides operations to read a classfile into an internal /** This class provides operations to read a classfile into an internal
* representation. The internal representation is anchored in a * representation. The internal representation is anchored in a
......
...@@ -45,7 +45,7 @@ import static com.sun.tools.javac.code.Flags.*; ...@@ -45,7 +45,7 @@ import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.jvm.UninitializedType.*; import static com.sun.tools.javac.jvm.UninitializedType.*;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.Option.*;
import static javax.tools.StandardLocation.CLASS_OUTPUT; import static javax.tools.StandardLocation.CLASS_OUTPUT;
......
...@@ -45,7 +45,7 @@ import static com.sun.tools.javac.code.Kinds.*; ...@@ -45,7 +45,7 @@ import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.jvm.ByteCodes.*; import static com.sun.tools.javac.jvm.ByteCodes.*;
import static com.sun.tools.javac.jvm.CRTFlags.*; import static com.sun.tools.javac.jvm.CRTFlags.*;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.Option.*;
import static com.sun.tools.javac.tree.JCTree.Tag.*; import static com.sun.tools.javac.tree.JCTree.Tag.*;
import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK; import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK;
......
...@@ -31,7 +31,7 @@ import com.sun.tools.javac.code.Flags; ...@@ -31,7 +31,7 @@ import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.*;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.Option.*;
/** The classfile version target. /** The classfile version target.
* *
......
...@@ -62,7 +62,7 @@ import com.sun.tools.javac.util.*; ...@@ -62,7 +62,7 @@ import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.Log.WriterKind; 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.Option.*;
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
import static com.sun.tools.javac.util.ListBuffer.lb; import static com.sun.tools.javac.util.ListBuffer.lb;
...@@ -817,8 +817,8 @@ public class JavaCompiler implements ClassReader.SourceCompleter { ...@@ -817,8 +817,8 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
// forcibly set the equivalent of -Xlint:-options, so that no further // forcibly set the equivalent of -Xlint:-options, so that no further
// warnings about command line options are generated from this point on // warnings about command line options are generated from this point on
options.put(XLINT_CUSTOM + "-" + LintCategory.OPTIONS.option, "true"); options.put(XLINT_CUSTOM.text + "-" + LintCategory.OPTIONS.option, "true");
options.remove(XLINT_CUSTOM + LintCategory.OPTIONS.option); options.remove(XLINT_CUSTOM.text + LintCategory.OPTIONS.option);
start_msec = now(); start_msec = now();
......
/*
* 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.javac.main;
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;
/**
* TODO: describe com.sun.tools.javac.main.JavacOption
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own
* risk. This code and its internal interfaces are subject to change
* or deletion without notice.</b></p>
*/
public interface JavacOption {
OptionKind getKind();
/** Does this option take a (separate) operand?
* @return true if this option takes a separate operand
*/
boolean hasArg();
/** Does argument string match option pattern?
* @param arg the command line argument string
* @return true if {@code arg} matches this option
*/
boolean matches(String arg);
/** Process an option with an argument.
* @param options the accumulated set of analyzed options
* @param option the option to be processed
* @param arg the arg for the option to be processed
* @return true if an error was detected
*/
boolean process(Options options, String option, String arg);
/** Process the option with no argument.
* @param options the accumulated set of analyzed options
* @param option the option to be processed
* @return true if an error was detected
*/
boolean process(Options options, String option);
OptionName getName();
enum OptionKind {
NORMAL,
EXTENDED,
HIDDEN,
}
enum ChoiceKind {
ONEOF,
ANYOF
}
/** This class represents an option recognized by the main program
*/
static class Option implements JavacOption {
/** Option string.
*/
OptionName name;
/** Documentation key for arguments.
*/
String argsNameKey;
/** Documentation key for description.
*/
String descrKey;
/** Suffix option (-foo=bar or -foo:bar)
*/
boolean hasSuffix;
/** The kind of choices for this option, if any.
*/
ChoiceKind choiceKind;
/** The choices for this option, if any, and whether or not the choices
* are hidden
*/
Map<String,Boolean> choices;
Option(OptionName name, String argsNameKey, String descrKey) {
this.name = name;
this.argsNameKey = argsNameKey;
this.descrKey = descrKey;
char lastChar = name.optionName.charAt(name.optionName.length()-1);
hasSuffix = lastChar == ':' || lastChar == '=';
}
Option(OptionName name, String descrKey) {
this(name, null, descrKey);
}
Option(OptionName name, String descrKey, ChoiceKind choiceKind, String... choices) {
this(name, descrKey, choiceKind, createChoices(choices));
}
private static Map<String,Boolean> createChoices(String... choices) {
Map<String,Boolean> map = new LinkedHashMap<String,Boolean>();
for (String c: choices)
map.put(c, false);
return map;
}
Option(OptionName name, String descrKey, ChoiceKind choiceKind,
Map<String,Boolean> choices) {
this(name, null, descrKey);
if (choiceKind == null || choices == null)
throw new NullPointerException();
this.choiceKind = choiceKind;
this.choices = choices;
}
@Override
public String toString() {
return name.optionName;
}
public boolean hasArg() {
return argsNameKey != null && !hasSuffix;
}
public boolean matches(String option) {
if (!hasSuffix)
return option.equals(name.optionName);
if (!option.startsWith(name.optionName))
return false;
if (choices != null) {
String arg = option.substring(name.optionName.length());
if (choiceKind == ChoiceKind.ONEOF)
return choices.keySet().contains(arg);
else {
for (String a: arg.split(",+")) {
if (!choices.keySet().contains(a))
return false;
}
}
}
return true;
}
/** Print a line of documentation describing this option, if standard.
* @param out the stream to which to write the documentation
*/
void help(Log log) {
log.printRawLines(WriterKind.NOTICE,
String.format(" %-26s %s",
helpSynopsis(log),
log.localize(PrefixKind.JAVAC, descrKey)));
}
String helpSynopsis(Log log) {
StringBuilder sb = new StringBuilder();
sb.append(name);
if (argsNameKey == null) {
if (choices != null) {
String sep = "{";
for (Map.Entry<String,Boolean> e: choices.entrySet()) {
if (!e.getValue()) {
sb.append(sep);
sb.append(e.getKey());
sep = ",";
}
}
sb.append("}");
}
} else {
if (!hasSuffix)
sb.append(" ");
sb.append(log.localize(PrefixKind.JAVAC, argsNameKey));
}
return sb.toString();
}
/** Print a line of documentation describing this option, if non-standard.
* @param out the stream to which to write the documentation
*/
void xhelp(Log log) {}
/** Process the option (with arg). Return true if error detected.
*/
public boolean process(Options options, String option, String arg) {
if (options != null) {
if (choices != null) {
if (choiceKind == ChoiceKind.ONEOF) {
// some clients like to see just one of option+choice set
for (String s: choices.keySet())
options.remove(option + s);
String opt = option + arg;
options.put(opt, opt);
// some clients like to see option (without trailing ":")
// set to arg
String nm = option.substring(0, option.length() - 1);
options.put(nm, arg);
} else {
// set option+word for each word in arg
for (String a: arg.split(",+")) {
String opt = option + a;
options.put(opt, opt);
}
}
}
options.put(option, arg);
}
return false;
}
/** Process the option (without arg). Return true if error detected.
*/
public boolean process(Options options, String option) {
if (hasSuffix)
return process(options, name.optionName, option.substring(name.optionName.length()));
else
return process(options, option, option);
}
public OptionKind getKind() { return OptionKind.NORMAL; }
public OptionName getName() { return name; }
};
/** A nonstandard or extended (-X) option
*/
static class XOption extends Option {
XOption(OptionName name, String argsNameKey, String descrKey) {
super(name, argsNameKey, descrKey);
}
XOption(OptionName name, String descrKey) {
this(name, null, descrKey);
}
XOption(OptionName name, String descrKey, ChoiceKind kind, String... choices) {
super(name, descrKey, kind, choices);
}
XOption(OptionName name, String descrKey, ChoiceKind kind, Map<String,Boolean> choices) {
super(name, descrKey, kind, choices);
}
@Override
void help(Log log) {}
@Override
void xhelp(Log log) { super.help(log); }
@Override
public OptionKind getKind() { return OptionKind.EXTENDED; }
};
/** A hidden (implementor) option
*/
static class HiddenOption extends Option {
HiddenOption(OptionName name) {
super(name, null, null);
}
HiddenOption(OptionName name, String argsNameKey) {
super(name, argsNameKey, null);
}
@Override
void help(Log log) {}
@Override
void xhelp(Log log) {}
@Override
public OptionKind getKind() { return OptionKind.HIDDEN; }
};
}
...@@ -42,14 +42,12 @@ import com.sun.tools.javac.code.Source; ...@@ -42,14 +42,12 @@ import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.file.CacheFSInfo; import com.sun.tools.javac.file.CacheFSInfo;
import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.jvm.Target; import com.sun.tools.javac.jvm.Target;
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.*;
import com.sun.tools.javac.util.Log.WriterKind; import com.sun.tools.javac.util.Log.WriterKind;
import com.sun.tools.javac.util.Log.PrefixKind; 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.Option.*;
/** This class provides a commandline interface to the GJC compiler. /** This class provides a commandline interface to the GJC compiler.
* *
...@@ -99,42 +97,51 @@ public class Main { ...@@ -99,42 +97,51 @@ public class Main {
public final int exitCode; public final int exitCode;
} }
private Option[] recognizedOptions = RecognizedOptions.getJavaCompilerOptions(new OptionHelper() { private Option[] recognizedOptions =
Option.getJavaCompilerOptions().toArray(new Option[0]);
public void setOut(PrintWriter out) { private OptionHelper optionHelper = new OptionHelper() {
Main.this.out = out; @Override
Main.this.log.setWriters(out); public String get(Option option) {
return options.get(option);
} }
public void error(String key, Object... args) { @Override
Main.this.error(key, args); public void put(String name, String value) {
options.put(name, value);
} }
public void printVersion() { @Override
log.printLines(PrefixKind.JAVAC, "version", ownName, JavaCompiler.version()); public void remove(String name) {
options.remove(name);
} }
public void printFullVersion() { @Override
log.printLines(PrefixKind.JAVAC, "fullVersion", ownName, JavaCompiler.fullVersion()); public Log getLog() {
return log;
} }
public void printHelp() { @Override
help(); public String getOwnName() {
return ownName;
} }
public void printXhelp() { @Override
xhelp(); public void error(String key, Object... args) {
Main.this.error(key, args);
} }
@Override
public void addFile(File f) { public void addFile(File f) {
filenames.add(f); filenames.add(f);
} }
@Override
public void addClassName(String s) { public void addClassName(String s) {
classnames.append(s); classnames.append(s);
} }
}); };
/** /**
* Construct a compiler instance. * Construct a compiler instance.
...@@ -161,26 +168,6 @@ public class Main { ...@@ -161,26 +168,6 @@ public class Main {
*/ */
public ListBuffer<String> classnames = null; // XXX sb protected public ListBuffer<String> classnames = null; // XXX sb protected
/** Print a string that explains usage.
*/
void help() {
log.printLines(PrefixKind.JAVAC, "msg.usage.header", ownName);
for (int i=0; i<recognizedOptions.length; i++) {
recognizedOptions[i].help(log);
}
log.printNewline();
}
/** Print a string that explains usage for X options.
*/
void xhelp() {
for (int i=0; i<recognizedOptions.length; i++) {
recognizedOptions[i].xhelp(log);
}
log.printNewline();
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) {
...@@ -253,10 +240,10 @@ public class Main { ...@@ -253,10 +240,10 @@ public class Main {
} }
String operand = flags[ac]; String operand = flags[ac];
ac++; ac++;
if (option.process(options, flag, operand)) if (option.process(optionHelper, flag, operand))
return null; return null;
} else { } else {
if (option.process(options, flag)) if (option.process(optionHelper, flag))
return null; return null;
} }
} }
...@@ -317,8 +304,8 @@ public class Main { ...@@ -317,8 +304,8 @@ public class Main {
return filenames; return filenames;
} }
// where // where
private boolean checkDirectory(OptionName optName) { private boolean checkDirectory(Option option) {
String value = options.get(optName); String value = options.get(option);
if (value == null) if (value == null)
return true; return true;
File file = new File(value); File file = new File(value);
...@@ -375,7 +362,7 @@ public class Main { ...@@ -375,7 +362,7 @@ public class Main {
*/ */
try { try {
if (args.length == 0 && fileObjects.isEmpty()) { if (args.length == 0 && fileObjects.isEmpty()) {
help(); Option.HELP.process(optionHelper, "-help");
return Result.CMDERR; return Result.CMDERR;
} }
...@@ -407,8 +394,7 @@ public class Main { ...@@ -407,8 +394,7 @@ public class Main {
boolean forceStdOut = options.isSet("stdout"); boolean forceStdOut = options.isSet("stdout");
if (forceStdOut) { if (forceStdOut) {
log.flush(); log.flush();
out = new PrintWriter(System.out, true); log.setWriters(new PrintWriter(System.out, true));
log.setWriters(out);
} }
// allow System property in following line as a Mustang legacy // allow System property in following line as a Mustang legacy
......
此差异已折叠。
...@@ -25,81 +25,93 @@ ...@@ -25,81 +25,93 @@
package com.sun.tools.javac.main; package com.sun.tools.javac.main;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Log.PrefixKind;
import java.io.File;
/** /**
* TODO: describe com.sun.tools.javac.main.OptionName * Helper object to be used by {@link Option#process}, providing access to
* the compilation environment.
* *
* <p><b>This is NOT part of any supported API. * <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own * If you write code that depends on this, you do so at your own
* risk. This code and its internal interfaces are subject to change * risk. This code and its internal interfaces are subject to change
* or deletion without notice.</b></p> * or deletion without notice.</b></p>
*/ */
public enum OptionName {
G("-g"),
G_NONE("-g:none"),
G_CUSTOM("-g:"),
XLINT("-Xlint"),
XLINT_CUSTOM("-Xlint:"),
DIAGS("-XDdiags="),
NOWARN("-nowarn"),
VERBOSE("-verbose"),
DEPRECATION("-deprecation"),
CLASSPATH("-classpath"),
CP("-cp"),
SOURCEPATH("-sourcepath"),
BOOTCLASSPATH("-bootclasspath"),
XBOOTCLASSPATH_PREPEND("-Xbootclasspath/p:"),
XBOOTCLASSPATH_APPEND("-Xbootclasspath/a:"),
XBOOTCLASSPATH("-Xbootclasspath:"),
EXTDIRS("-extdirs"),
DJAVA_EXT_DIRS("-Djava.ext.dirs="),
ENDORSEDDIRS("-endorseddirs"),
DJAVA_ENDORSED_DIRS("-Djava.endorsed.dirs="),
PROC("-proc:"),
PROCESSOR("-processor"),
PROCESSORPATH("-processorpath"),
D("-d"),
S("-s"),
IMPLICIT("-implicit:"),
ENCODING("-encoding"),
SOURCE("-source"),
TARGET("-target"),
VERSION("-version"),
FULLVERSION("-fullversion"),
HELP("-help"),
A("-A"),
X("-X"),
J("-J"),
MOREINFO("-moreinfo"),
WERROR("-Werror"),
COMPLEXINFERENCE("-complexinference"),
PROMPT("-prompt"),
DOE("-doe"),
PRINTSOURCE("-printsource"),
WARNUNCHECKED("-warnunchecked"),
XMAXERRS("-Xmaxerrs"),
XMAXWARNS("-Xmaxwarns"),
XSTDOUT("-Xstdout"),
XPKGINFO("-Xpkginfo:"),
XPRINT("-Xprint"),
XPRINTROUNDS("-XprintRounds"),
XPRINTPROCESSORINFO("-XprintProcessorInfo"),
XPREFER("-Xprefer:"),
O("-O"),
XJCOV("-Xjcov"),
XD("-XD"),
AT("@"),
SOURCEFILE("sourcefile");
public final String optionName;
OptionName(String optionName) {
this.optionName = optionName;
}
@Override public abstract class OptionHelper {
public String toString() {
return optionName; /** Get the current value of an option. */
public abstract String get(Option option);
/** Set the value of an option. */
public abstract void put(String name, String value);
/** Remove any prior value for an option. */
public abstract void remove(String name);
/** Get access to the Log for the compilation. */
public abstract Log getLog();
/** Get the name of the tool, such as "javac", to be used in info like -help. */
public abstract String getOwnName();
/** Report an error. */
abstract void error(String key, Object... args);
/** Record a file to be compiled. */
abstract void addFile(File f);
/** Record the name of a class for annotation processing. */
abstract void addClassName(String s);
/** An implementation of OptionHelper that mostly throws exceptions. */
public static class GrumpyHelper extends OptionHelper {
private final Log log;
public GrumpyHelper(Log log) {
this.log = log;
}
@Override
public Log getLog() {
return log;
}
@Override
public String getOwnName() {
throw new IllegalStateException();
}
@Override
public String get(Option option) {
throw new IllegalArgumentException();
}
@Override
public void put(String name, String value) {
throw new IllegalArgumentException();
}
@Override
public void remove(String name) {
throw new IllegalArgumentException();
}
@Override
void error(String key, Object... args) {
throw new IllegalArgumentException(log.localize(PrefixKind.JAVAC, key, args));
}
@Override
public void addFile(File f) {
throw new IllegalArgumentException(f.getPath());
}
@Override
public void addClassName(String s) {
throw new IllegalArgumentException(s);
}
} }
} }
...@@ -63,7 +63,7 @@ import com.sun.tools.javac.util.Context; ...@@ -63,7 +63,7 @@ import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.ListBuffer;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.Option.*;
// NOTE the imports carefully for this compilation unit. // NOTE the imports carefully for this compilation unit.
......
...@@ -787,7 +787,7 @@ public class JavacParser implements Parser { ...@@ -787,7 +787,7 @@ public class JavacParser implements Parser {
top++; top++;
topOp = token; topOp = token;
nextToken(); nextToken();
odStack[top] = (topOp.kind == INSTANCEOF) ? parseType() : term3NoParams(); odStack[top] = (topOp.kind == INSTANCEOF) ? parseType() : term3();
while (top > 0 && prec(topOp.kind) >= prec(token.kind)) { while (top > 0 && prec(topOp.kind) >= prec(token.kind)) {
odStack[top-1] = makeOp(topOp.pos, topOp.kind, odStack[top-1], odStack[top-1] = makeOp(topOp.pos, topOp.kind, odStack[top-1],
odStack[top]); odStack[top]);
...@@ -931,7 +931,7 @@ public class JavacParser implements Parser { ...@@ -931,7 +931,7 @@ public class JavacParser implements Parser {
mode = EXPR; mode = EXPR;
t = literal(names.hyphen, pos); t = literal(names.hyphen, pos);
} else { } else {
t = term3NoParams(); t = term3();
return F.at(pos).Unary(unoptag(tk), t); return F.at(pos).Unary(unoptag(tk), t);
} }
} else return illegal(); } else return illegal();
...@@ -947,8 +947,8 @@ public class JavacParser implements Parser { ...@@ -947,8 +947,8 @@ public class JavacParser implements Parser {
break; break;
} else { } else {
nextToken(); nextToken();
mode = EXPR | TYPE; mode = EXPR | TYPE | NOPARAMS;
t = term3NoParams(); t = term3();
if ((mode & TYPE) != 0 && token.kind == LT) { if ((mode & TYPE) != 0 && token.kind == LT) {
// Could be a cast to a parameterized type // Could be a cast to a parameterized type
JCTree.Tag op = JCTree.Tag.LT; JCTree.Tag op = JCTree.Tag.LT;
...@@ -1011,7 +1011,7 @@ public class JavacParser implements Parser { ...@@ -1011,7 +1011,7 @@ public class JavacParser implements Parser {
lastmode = mode; lastmode = mode;
mode = EXPR; mode = EXPR;
if ((lastmode & EXPR) == 0) { if ((lastmode & EXPR) == 0) {
JCExpression t1 = term3NoParams(); JCExpression t1 = term3();
return F.at(pos).TypeCast(t, t1); return F.at(pos).TypeCast(t, t1);
} else if ((lastmode & TYPE) != 0) { } else if ((lastmode & TYPE) != 0) {
switch (token.kind) { switch (token.kind) {
...@@ -1024,7 +1024,7 @@ public class JavacParser implements Parser { ...@@ -1024,7 +1024,7 @@ public class JavacParser implements Parser {
case NEW: case IDENTIFIER: case ASSERT: case ENUM: case NEW: case IDENTIFIER: case ASSERT: case ENUM:
case BYTE: case SHORT: case CHAR: case INT: case BYTE: case SHORT: case CHAR: case INT:
case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case VOID: case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case VOID:
JCExpression t1 = term3NoParams(); JCExpression t1 = term3();
return F.at(pos).TypeCast(t, t1); return F.at(pos).TypeCast(t, t1);
} }
} }
...@@ -1143,49 +1143,35 @@ public class JavacParser implements Parser { ...@@ -1143,49 +1143,35 @@ public class JavacParser implements Parser {
// typeArgs saved for next loop iteration. // typeArgs saved for next loop iteration.
t = toP(F.at(pos).Select(t, ident())); t = toP(F.at(pos).Select(t, ident()));
break; break;
// case LT: case LT:
// if ((mode & (TYPE | NOPARAMS)) == 0) { if ((mode & TYPE) == 0 && isUnboundMemberRef()) {
// //could be an unbound method reference whose qualifier //this is an unbound method reference whose qualifier
// //is a generic type i.e. A<S>#m //is a generic type i.e. A<S>#m
// mode = EXPR | TYPE; int pos1 = token.pos;
// JCTree.Tag op = JCTree.Tag.LT; accept(LT);
// int pos1 = token.pos; ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
// nextToken(); args.append(typeArgument());
// mode |= EXPR | TYPE | TYPEARG; while (token.kind == COMMA) {
// JCExpression t1 = term3(); nextToken();
// if ((mode & TYPE) != 0 && args.append(typeArgument());
// (token.kind == COMMA || token.kind == GT)) { }
// mode = TYPE; accept(GT);
// ListBuffer<JCExpression> args = new ListBuffer<JCExpression>(); t = toP(F.at(pos1).TypeApply(t, args.toList()));
// args.append(t1); checkGenerics();
// while (token.kind == COMMA) { while (token.kind == DOT) {
// nextToken(); nextToken();
// args.append(typeArgument()); mode = TYPE;
// } t = toP(F.at(token.pos).Select(t, ident()));
// accept(GT); t = typeArgumentsOpt(t);
// t = toP(F.at(pos1).TypeApply(t, args.toList())); }
// checkGenerics(); if (token.kind != HASH) {
// while (token.kind == DOT) { //method reference expected here
// nextToken(); t = illegal();
// mode = TYPE; }
// t = toP(F.at(token.pos).Select(t, ident())); mode = EXPR;
// t = typeArgumentsOpt(t); return term3Rest(t, typeArgs);
// } }
// if (token.kind != HASH) { break loop;
// //method reference expected here
// t = illegal();
// }
// mode = EXPR;
// break;
// } else if ((mode & EXPR) != 0) {
// //rollback - it was a binary expression
// mode = EXPR;
// JCExpression e = term2Rest(t1, TreeInfo.shiftPrec);
// t = F.at(pos1).Binary(op, t, e);
// t = termRest(term1Rest(term2Rest(t, TreeInfo.orPrec)));
// }
// }
// break loop;
default: default:
break loop; break loop;
} }
...@@ -1225,15 +1211,6 @@ public class JavacParser implements Parser { ...@@ -1225,15 +1211,6 @@ public class JavacParser implements Parser {
return term3Rest(t, typeArgs); return term3Rest(t, typeArgs);
} }
JCExpression term3NoParams() {
try {
mode |= NOPARAMS;
return term3();
} finally {
mode &= ~NOPARAMS;
}
}
JCExpression term3Rest(JCExpression t, List<JCExpression> typeArgs) { JCExpression term3Rest(JCExpression t, List<JCExpression> typeArgs) {
if (typeArgs != null) illegal(); if (typeArgs != null) illegal();
while (true) { while (true) {
...@@ -1297,6 +1274,41 @@ public class JavacParser implements Parser { ...@@ -1297,6 +1274,41 @@ public class JavacParser implements Parser {
return toP(t); return toP(t);
} }
/**
* If we see an identifier followed by a '&lt;' it could be an unbound
* method reference or a binary expression. To disambiguate, look for a
* matching '&gt;' and see if the subsequent terminal is either '.' or '#'.
*/
@SuppressWarnings("fallthrough")
boolean isUnboundMemberRef() {
int pos = 0, depth = 0;
for (Token t = S.token(pos) ; ; t = S.token(++pos)) {
switch (t.kind) {
case IDENTIFIER: case QUES: case EXTENDS: case SUPER:
case DOT: case RBRACKET: case LBRACKET: case COMMA:
case BYTE: case SHORT: case INT: case LONG: case FLOAT:
case DOUBLE: case BOOLEAN: case CHAR:
break;
case LT:
depth++; break;
case GTGTGT:
depth--;
case GTGT:
depth--;
case GT:
depth--;
if (depth == 0) {
return
S.token(pos + 1).kind == TokenKind.DOT ||
S.token(pos + 1).kind == TokenKind.HASH;
}
break;
default:
return false;
}
}
}
JCExpression lambdaExpressionOrStatement(JCVariableDecl firstParam, int pos) { JCExpression lambdaExpressionOrStatement(JCVariableDecl firstParam, int pos) {
ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>(); ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>();
params.append(firstParam); params.append(firstParam);
......
...@@ -82,7 +82,7 @@ import com.sun.tools.javac.util.Options; ...@@ -82,7 +82,7 @@ import com.sun.tools.javac.util.Options;
import static javax.tools.StandardLocation.*; import static javax.tools.StandardLocation.*;
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.Option.*;
import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING; import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING;
/** /**
...@@ -1033,12 +1033,10 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -1033,12 +1033,10 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
Assert.checkNonNull(options); Assert.checkNonNull(options);
next.put(Options.optionsKey, options); next.put(Options.optionsKey, options);
PrintWriter out = context.get(Log.outKey);
Assert.checkNonNull(out);
next.put(Log.outKey, out);
Locale locale = context.get(Locale.class); Locale locale = context.get(Locale.class);
if (locale != null) if (locale != null)
next.put(Locale.class, locale); next.put(Locale.class, locale);
Assert.checkNonNull(messages); Assert.checkNonNull(messages);
next.put(JavacMessages.messagesKey, messages); next.put(JavacMessages.messagesKey, messages);
...@@ -1076,6 +1074,9 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -1076,6 +1074,9 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
Assert.checkNonNull(tokens); Assert.checkNonNull(tokens);
next.put(Tokens.tokensKey, tokens); next.put(Tokens.tokensKey, tokens);
// propogate the log's writers directly, instead of going through context
Log.instance(next).setWriters(log);
JavaCompiler oldCompiler = JavaCompiler.instance(context); JavaCompiler oldCompiler = JavaCompiler.instance(context);
JavaCompiler nextCompiler = JavaCompiler.instance(next); JavaCompiler nextCompiler = JavaCompiler.instance(next);
nextCompiler.initRound(oldCompiler); nextCompiler.initRound(oldCompiler);
...@@ -1472,14 +1473,6 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -1472,14 +1473,6 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
return context; return context;
} }
/**
* Internal use method to return the writer being used by the
* processing environment.
*/
public PrintWriter getWriter() {
return context.get(Log.outKey);
}
public String toString() { public String toString() {
return "javac ProcessingEnvironment"; return "javac ProcessingEnvironment";
} }
......
...@@ -46,6 +46,7 @@ import java.util.Collection; ...@@ -46,6 +46,7 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import javax.tools.JavaFileObject.Kind; import javax.tools.JavaFileObject.Kind;
...@@ -53,9 +54,9 @@ import com.sun.tools.javac.code.Lint; ...@@ -53,9 +54,9 @@ 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.file.FSInfo; import com.sun.tools.javac.file.FSInfo;
import com.sun.tools.javac.file.Locations; import com.sun.tools.javac.file.Locations;
import com.sun.tools.javac.main.JavacOption; import com.sun.tools.javac.main.Option;
import com.sun.tools.javac.main.OptionName; import com.sun.tools.javac.main.OptionHelper;
import com.sun.tools.javac.main.RecognizedOptions; import com.sun.tools.javac.main.OptionHelper.GrumpyHelper;
import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition;
/** /**
...@@ -101,7 +102,7 @@ public abstract class BaseFileManager { ...@@ -101,7 +102,7 @@ public abstract class BaseFileManager {
protected Locations locations; protected Locations locations;
protected Source getSource() { protected Source getSource() {
String sourceName = options.get(OptionName.SOURCE); String sourceName = options.get(Option.SOURCE);
Source source = null; Source source = null;
if (sourceName != null) if (sourceName != null)
source = Source.lookup(sourceName); source = Source.lookup(sourceName);
...@@ -145,15 +146,31 @@ public abstract class BaseFileManager { ...@@ -145,15 +146,31 @@ public abstract class BaseFileManager {
// <editor-fold defaultstate="collapsed" desc="Option handling"> // <editor-fold defaultstate="collapsed" desc="Option handling">
public boolean handleOption(String current, Iterator<String> remaining) { public boolean handleOption(String current, Iterator<String> remaining) {
for (JavacOption o: javacFileManagerOptions) { OptionHelper helper = new GrumpyHelper(log) {
@Override
public String get(Option option) {
return options.get(option.getText());
}
@Override
public void put(String name, String value) {
options.put(name, value);
}
@Override
public void remove(String name) {
options.remove(name);
}
};
for (Option o: javacFileManagerOptions) {
if (o.matches(current)) { if (o.matches(current)) {
if (o.hasArg()) { if (o.hasArg()) {
if (remaining.hasNext()) { if (remaining.hasNext()) {
if (!o.process(options, current, remaining.next())) if (!o.process(helper, current, remaining.next()))
return true; return true;
} }
} else { } else {
if (!o.process(options, current)) if (!o.process(helper, current))
return true; return true;
} }
// operand missing, or process returned false // operand missing, or process returned false
...@@ -164,12 +181,11 @@ public abstract class BaseFileManager { ...@@ -164,12 +181,11 @@ public abstract class BaseFileManager {
return false; return false;
} }
// where // where
private static JavacOption[] javacFileManagerOptions = private static Set<Option> javacFileManagerOptions =
RecognizedOptions.getJavacFileManagerOptions( Option.getJavacFileManagerOptions();
new RecognizedOptions.GrumpyHelper(Log.instance(new Context())));
public int isSupportedOption(String option) { public int isSupportedOption(String option) {
for (JavacOption o : javacFileManagerOptions) { for (Option o : javacFileManagerOptions) {
if (o.matches(option)) if (o.matches(option))
return o.hasArg() ? 1 : 0; return o.hasArg() ? 1 : 0;
} }
...@@ -191,7 +207,7 @@ public abstract class BaseFileManager { ...@@ -191,7 +207,7 @@ public abstract class BaseFileManager {
} }
public String getEncodingName() { public String getEncodingName() {
String encName = options.get(OptionName.ENCODING); String encName = options.get(Option.ENCODING);
if (encName == null) if (encName == null)
return getDefaultEncodingName(); return getDefaultEncodingName();
else else
......
...@@ -25,25 +25,23 @@ ...@@ -25,25 +25,23 @@
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;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.Set; import java.util.Set;
import javax.tools.DiagnosticListener; import javax.tools.DiagnosticListener;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import com.sun.tools.javac.api.DiagnosticFormatter; import com.sun.tools.javac.api.DiagnosticFormatter;
import com.sun.tools.javac.main.OptionName; import com.sun.tools.javac.main.Main;
import com.sun.tools.javac.main.Option;
import com.sun.tools.javac.parser.EndPosTable; import com.sun.tools.javac.parser.EndPosTable;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.Option.*;
/** A class for error logs. Reports errors and warnings, and /** A class for error logs. Reports errors and warnings, and
* keeps track of error numbers and positions. * keeps track of error numbers and positions.
...@@ -137,7 +135,6 @@ public class Log extends AbstractLog { ...@@ -137,7 +135,6 @@ public class Log extends AbstractLog {
/** Construct a log with given I/O redirections. /** Construct a log with given I/O redirections.
*/ */
@Deprecated
protected Log(Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) { protected Log(Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) {
super(JCDiagnostic.Factory.instance(context)); super(JCDiagnostic.Factory.instance(context));
context.put(logKey, this); context.put(logKey, this);
...@@ -179,8 +176,8 @@ public class Log extends AbstractLog { ...@@ -179,8 +176,8 @@ public class Log extends AbstractLog {
expectDiagKeys = new HashSet<String>(Arrays.asList(ek.split(", *"))); expectDiagKeys = new HashSet<String>(Arrays.asList(ek.split(", *")));
} }
private int getIntOption(Options options, OptionName optionName, int defaultValue) { private int getIntOption(Options options, Option option, int defaultValue) {
String s = options.get(optionName); String s = options.get(option);
try { try {
if (s != null) { if (s != null) {
int n = Integer.parseInt(s); int n = Integer.parseInt(s);
...@@ -298,6 +295,12 @@ public class Log extends AbstractLog { ...@@ -298,6 +295,12 @@ public class Log extends AbstractLog {
noticeWriter = warnWriter = errWriter = pw; noticeWriter = warnWriter = errWriter = pw;
} }
public void setWriters(Log other) {
this.noticeWriter = other.noticeWriter;
this.warnWriter = other.warnWriter;
this.errWriter = other.errWriter;
}
/** Flush the logs /** Flush the logs
*/ */
public void flush() { public void flush() {
......
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
package com.sun.tools.javac.util; package com.sun.tools.javac.util;
import java.util.*; import java.util.*;
import com.sun.tools.javac.main.OptionName; import com.sun.tools.javac.main.Option;
import static com.sun.tools.javac.main.OptionName.*; import static com.sun.tools.javac.main.Option.*;
/** A table of all command-line options. /** A table of all command-line options.
* If an option has an argument, the option name is mapped to the argument. * If an option has an argument, the option name is mapped to the argument.
...@@ -71,8 +71,8 @@ public class Options { ...@@ -71,8 +71,8 @@ public class Options {
/** /**
* Get the value for an option. * Get the value for an option.
*/ */
public String get(OptionName name) { public String get(Option option) {
return values.get(name.optionName); return values.get(option.text);
} }
/** /**
...@@ -101,15 +101,15 @@ public class Options { ...@@ -101,15 +101,15 @@ public class Options {
/** /**
* Check if the value for an option has been set. * Check if the value for an option has been set.
*/ */
public boolean isSet(OptionName name) { public boolean isSet(Option option) {
return (values.get(name.optionName) != null); return (values.get(option.text) != null);
} }
/** /**
* Check if the value for a choice option has been set to a specific value. * Check if the value for a choice option has been set to a specific value.
*/ */
public boolean isSet(OptionName name, String value) { public boolean isSet(Option option, String value) {
return (values.get(name.optionName + value) != null); return (values.get(option.text + value) != null);
} }
/** /**
...@@ -122,23 +122,23 @@ public class Options { ...@@ -122,23 +122,23 @@ public class Options {
/** /**
* Check if the value for an option has not been set. * Check if the value for an option has not been set.
*/ */
public boolean isUnset(OptionName name) { public boolean isUnset(Option option) {
return (values.get(name.optionName) == null); return (values.get(option.text) == null);
} }
/** /**
* Check if the value for a choice option has not been set to a specific value. * Check if the value for a choice option has not been set to a specific value.
*/ */
public boolean isUnset(OptionName name, String value) { public boolean isUnset(Option option, String value) {
return (values.get(name.optionName + value) == null); return (values.get(option.text + value) == null);
} }
public void put(String name, String value) { public void put(String name, String value) {
values.put(name, value); values.put(name, value);
} }
public void put(OptionName name, String value) { public void put(Option option, String value) {
values.put(name.optionName, value); values.put(option.text, value);
} }
public void putAll(Options options) { public void putAll(Options options) {
......
#!/bin/sh -f #!/bin/sh -f
# #
# Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2005, 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
...@@ -71,7 +71,7 @@ rm -f Test.java Test.out ...@@ -71,7 +71,7 @@ rm -f Test.java Test.out
diff ${DIFFOPTS} -c "${TESTSRC}${FS}Test.out" Test.out diff ${DIFFOPTS} -c "${TESTSRC}${FS}Test.out" Test.out
result=$? result=$?
if [ $result -eq o ] if [ $result -eq 0 ]
then then
echo "Passed" echo "Passed"
else else
......
...@@ -32,7 +32,6 @@ import java.util.*; ...@@ -32,7 +32,6 @@ import java.util.*;
import java.util.zip.*; import java.util.zip.*;
import javax.tools.*; import javax.tools.*;
import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.main.OptionName;
import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.Options;
......
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 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
...@@ -23,5 +23,6 @@ ...@@ -23,5 +23,6 @@
// key: compiler.err.unsupported.encoding // key: compiler.err.unsupported.encoding
// options: -encoding UNSUPPORTED -doe // options: -encoding UNSUPPORTED -doe
// run: simple
class UnsupportedEncoding { } class UnsupportedEncoding { }
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
/* /*
* @test * @test
* @bug 7115052 * @bug 7115052
* @ignore 7120266
* @summary Add parser support for method references * @summary Add parser support for method references
*/ */
...@@ -45,6 +44,7 @@ public class MethodReferenceParserTest { ...@@ -45,6 +44,7 @@ public class MethodReferenceParserTest {
enum ReferenceKind { enum ReferenceKind {
METHOD_REF("#Q##Gm"), METHOD_REF("#Q##Gm"),
CONSTRUCTOR_REF("#Q##Gnew"), CONSTRUCTOR_REF("#Q##Gnew"),
FALSE_REF("min < max"),
ERR_SUPER("#Q##Gsuper"), ERR_SUPER("#Q##Gsuper"),
ERR_METH0("#Q##Gm()"), ERR_METH0("#Q##Gm()"),
ERR_METH1("#Q##Gm(X)"), ERR_METH1("#Q##Gm(X)"),
...@@ -76,6 +76,21 @@ public class MethodReferenceParserTest { ...@@ -76,6 +76,21 @@ public class MethodReferenceParserTest {
} }
} }
enum ContextKind {
ASSIGN("SAM s = #E;"),
METHOD("m(#E, i);");
String contextTemplate;
ContextKind(String contextTemplate) {
this.contextTemplate = contextTemplate;
}
String contextString(ExprKind ek, ReferenceKind rk, QualifierKind qk, GenericKind gk, SubExprKind sk) {
return contextTemplate.replaceAll("#E", ek.expressionString(rk, qk, gk, sk));
}
}
enum GenericKind { enum GenericKind {
NONE(""), NONE(""),
ONE("<X>"), ONE("<X>"),
...@@ -97,7 +112,10 @@ public class MethodReferenceParserTest { ...@@ -97,7 +112,10 @@ public class MethodReferenceParserTest {
UBOUND_SIMPLE("A"), UBOUND_SIMPLE("A"),
UNBOUND_GENERIC1("A<X>"), UNBOUND_GENERIC1("A<X>"),
UNBOUND_GENERIC2("A<X, Y>"), UNBOUND_GENERIC2("A<X, Y>"),
UNBOUND_GENERIC3("A<? extends X, ? super Y>"); UNBOUND_GENERIC3("A<? extends X, ? super Y>"),
UNBOUND_GENERIC4("A<int[], short[][]>"),
NESTED_GENERIC1("A<A<X,Y>, A<X,Y>>"),
NESTED_GENERIC2("A<A<A<X,Y>,A<X,Y>>, A<A<X,Y>,A<X,Y>>>");
String qualifier; String qualifier;
...@@ -153,7 +171,9 @@ public class MethodReferenceParserTest { ...@@ -153,7 +171,9 @@ public class MethodReferenceParserTest {
for (GenericKind gk : GenericKind.values()) { for (GenericKind gk : GenericKind.values()) {
for (SubExprKind sk : SubExprKind.values()) { for (SubExprKind sk : SubExprKind.values()) {
for (ExprKind ek : ExprKind.values()) { for (ExprKind ek : ExprKind.values()) {
new MethodReferenceParserTest(rk, qk, gk, sk, ek).run(comp, fm); for (ContextKind ck : ContextKind.values()) {
new MethodReferenceParserTest(rk, qk, gk, sk, ek, ck).run(comp, fm);
}
} }
} }
} }
...@@ -167,15 +187,17 @@ public class MethodReferenceParserTest { ...@@ -167,15 +187,17 @@ public class MethodReferenceParserTest {
GenericKind gk; GenericKind gk;
SubExprKind sk; SubExprKind sk;
ExprKind ek; ExprKind ek;
ContextKind ck;
JavaSource source; JavaSource source;
DiagnosticChecker diagChecker; DiagnosticChecker diagChecker;
MethodReferenceParserTest(ReferenceKind rk, QualifierKind qk, GenericKind gk, SubExprKind sk, ExprKind ek) { MethodReferenceParserTest(ReferenceKind rk, QualifierKind qk, GenericKind gk, SubExprKind sk, ExprKind ek, ContextKind ck) {
this.rk = rk; this.rk = rk;
this.qk = qk; this.qk = qk;
this.gk = gk; this.gk = gk;
this.sk = sk; this.sk = sk;
this.ek = ek; this.ek = ek;
this.ck = ck;
this.source = new JavaSource(); this.source = new JavaSource();
this.diagChecker = new DiagnosticChecker(); this.diagChecker = new DiagnosticChecker();
} }
...@@ -183,14 +205,16 @@ public class MethodReferenceParserTest { ...@@ -183,14 +205,16 @@ public class MethodReferenceParserTest {
class JavaSource extends SimpleJavaFileObject { class JavaSource extends SimpleJavaFileObject {
String template = "class Test {\n" + String template = "class Test {\n" +
" SAM s = #E;\n" + " void test() {\n" +
" #C\n" +
" }" +
"}"; "}";
String source; String source;
public JavaSource() { public JavaSource() {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
source = template.replaceAll("#E", ek.expressionString(rk, qk, gk, sk)); source = template.replaceAll("#C", ck.contextString(ek, rk, qk, gk, sk));
} }
@Override @Override
......
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6987384
* @summary -XprintProcessorRoundsInfo message printed with different timing than previous
* @library ../../../lib
* @build JavacTestingAbstractProcessor Test TestWithXstdout
* @run main TestWithXstdout
*/
import java.io.*;
import java.nio.charset.*;
import java.nio.file.*;
import java.util.*;
public class TestWithXstdout {
public static void main(String... args) throws Exception {
File testSrc = new File(System.getProperty("test.src"));
File testClasses = new File(System.getProperty("test.classes"));
File stdout = new File("stdout.out");
run_javac("-XDrawDiagnostics",
"-XprintProcessorInfo",
"-Werror",
"-proc:only",
"-processor", "Test",
"-Xstdout", stdout.getPath(),
"-classpath", testClasses.getPath(),
new File(testSrc, "Test.java").getPath());
boolean ok = compare(stdout, new File(testSrc, "Test.out"));
if (!ok)
throw new Exception("differences found");
}
static void run_javac(String... args) throws IOException, InterruptedException {
File javaHome = new File(System.getProperty("java.home"));
if (javaHome.getName().equals("jre"))
javaHome = javaHome.getParentFile();
File javac = new File(new File(javaHome, "bin"), "javac");
List<String> opts = new ArrayList<>();
opts.add(javac.getPath());
String toolOpts = System.getProperty("test.tool.vm.opts");
if (toolOpts != null && !"".equals(toolOpts.trim())) {
opts.addAll(Arrays.asList(toolOpts.trim().split("[\\s]+")));
}
opts.addAll(Arrays.asList(args));
System.out.println("exec: " + opts);
ProcessBuilder pb = new ProcessBuilder(opts);
pb.redirectErrorStream();
Process p = pb.start();
try (BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
String line;
while ((line = r.readLine()) != null)
System.out.println();
}
int rc = p.waitFor();
if (rc != 0)
System.out.println("javac exited, rc=" + rc);
}
static boolean compare(File a, File b) throws IOException {
List<String> aLines = Files.readAllLines(a.toPath(), Charset.defaultCharset());
List<String> bLines = Files.readAllLines(b.toPath(), Charset.defaultCharset());
System.out.println(a + ": " + aLines.size() + " lines");
System.out.println(b + ": " + bLines.size() + " lines");
return aLines.equals(bLines);
}
}
...@@ -41,6 +41,7 @@ import javax.tools.Diagnostic; ...@@ -41,6 +41,7 @@ import javax.tools.Diagnostic;
import com.sun.tools.javac.processing.JavacProcessingEnvironment; import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.JavacMessages; import com.sun.tools.javac.util.JavacMessages;
import com.sun.tools.javac.util.Log;
@SupportedOptions("WriterString") @SupportedOptions("WriterString")
public class T6597678 extends JavacTestingAbstractProcessor { public class T6597678 extends JavacTestingAbstractProcessor {
...@@ -78,7 +79,10 @@ public class T6597678 extends JavacTestingAbstractProcessor { ...@@ -78,7 +79,10 @@ public class T6597678 extends JavacTestingAbstractProcessor {
@Override @Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
PrintWriter out = ((JavacProcessingEnvironment) processingEnv).getWriter(); Log log = Log.instance(context);
PrintWriter noteOut = log.getWriter(Log.WriterKind.NOTICE);
PrintWriter warnOut = log.getWriter(Log.WriterKind.WARNING);
PrintWriter errOut = log.getWriter(Log.WriterKind.ERROR);
Locale locale = context.get(Locale.class); Locale locale = context.get(Locale.class);
JavacMessages messages = context.get(JavacMessages.messagesKey); JavacMessages messages = context.get(JavacMessages.messagesKey);
...@@ -86,13 +90,20 @@ public class T6597678 extends JavacTestingAbstractProcessor { ...@@ -86,13 +90,20 @@ public class T6597678 extends JavacTestingAbstractProcessor {
if (round == 1) { if (round == 1) {
initialLocale = locale; initialLocale = locale;
initialMessages = messages; initialMessages = messages;
initialWriter = out; initialNoteWriter = noteOut;
initialWarnWriter = warnOut;
checkEqual("writerString", out.toString().intern(), options.get("WriterString").intern()); initialErrWriter = errOut;
String writerStringOpt = options.get("WriterString").intern();
checkEqual("noteWriterString", noteOut.toString().intern(), writerStringOpt);
checkEqual("warnWriterString", warnOut.toString().intern(), writerStringOpt);
checkEqual("errWriterString", errOut.toString().intern(), writerStringOpt);
} else { } else {
checkEqual("locale", locale, initialLocale); checkEqual("locale", locale, initialLocale);
checkEqual("messages", messages, initialMessages); checkEqual("messages", messages, initialMessages);
checkEqual("writer", out, initialWriter); checkEqual("noteWriter", noteOut, initialNoteWriter);
checkEqual("warnWriter", warnOut, initialWarnWriter);
checkEqual("errWriter", errOut, initialErrWriter);
} }
return true; return true;
...@@ -109,5 +120,7 @@ public class T6597678 extends JavacTestingAbstractProcessor { ...@@ -109,5 +120,7 @@ public class T6597678 extends JavacTestingAbstractProcessor {
int round = 0; int round = 0;
Locale initialLocale; Locale initialLocale;
JavacMessages initialMessages; JavacMessages initialMessages;
PrintWriter initialWriter; PrintWriter initialNoteWriter;
PrintWriter initialWarnWriter;
PrintWriter initialErrWriter;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册