### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java,v
retrieving revision 1.115
diff -u -r1.115 CompilationUnitResolver.java
--- dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java 20 Jan 2006 12:10:34 -0000 1.115
+++ dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java 23 Jan 2006 12:56:38 -0000
@@ -169,7 +169,7 @@
new CompilationResult(sourceUnit, index++, maxUnits, this.options.maxProblemsPerUnit);
try {
if (options.verbose) {
- System.out.println(
+ this.out.println(
Messages.bind(Messages.compilation_request,
new String[] {
String.valueOf(index++ + 1),
Index: batch/org/eclipse/jdt/internal/compiler/batch/Main.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java,v
retrieving revision 1.226
diff -u -r1.226 Main.java
--- batch/org/eclipse/jdt/internal/compiler/batch/Main.java 23 Jan 2006 10:34:45 -0000 1.226
+++ batch/org/eclipse/jdt/internal/compiler/batch/Main.java 23 Jan 2006 12:56:37 -0000
@@ -966,6 +966,10 @@
public String destinationPath;
public String[] encodings;
public Logger logger;
+ PrintWriter out;
+ // need to pass the compiler messages output to the delegate compiler
+ // do not user directly (use logger)
+ // TODO (maxime) this is used in one instance - check reason with olivier
public int exportedClassFilesCounter;
public String[] filenames;
public boolean generatePackagesStructure;
@@ -1000,6 +1004,7 @@
public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished, Map customDefaultOptions) {
this.logger = new Logger(outWriter, errWriter);
+ this.out = outWriter;
this.systemExitWhenFinished = systemExitWhenFinished;
this.options = new CompilerOptions().getMap();
if (customDefaultOptions != null) {
@@ -2770,7 +2775,7 @@
String relativeStringName = new String(relativeName);
try {
if (this.compilerOptions.verbose)
- System.out.println(
+ this.out.println(
Messages.bind(
Messages.compilation_write,
new String[] {
@@ -2810,7 +2815,8 @@
getHandlingPolicy(),
this.options,
getBatchRequestor(),
- getProblemFactory());
+ getProblemFactory(),
+ this.out);
this.compilerOptions = batchCompiler.options;
// set the non-externally configurable options.
Index: compiler/org/eclipse/jdt/internal/compiler/Compiler.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java,v
retrieving revision 1.72
diff -u -r1.72 Compiler.java
--- compiler/org/eclipse/jdt/internal/compiler/Compiler.java 20 Jan 2006 12:10:35 -0000 1.72
+++ compiler/org/eclipse/jdt/internal/compiler/Compiler.java 23 Jan 2006 12:56:38 -0000
@@ -27,6 +27,7 @@
public ICompilerRequestor requestor;
public CompilerOptions options;
public ProblemReporter problemReporter;
+ protected PrintWriter out; // output for messages that are not sent to problemReporter
// management of unit to be processed
//public CompilationUnitResult currentCompilationUnitResult;
@@ -83,33 +84,62 @@
* them back as part of the compilation unit result.
*/
public Compiler(
- INameEnvironment environment,
- IErrorHandlingPolicy policy,
- Map settings,
- final ICompilerRequestor requestor,
- IProblemFactory problemFactory) {
-
- // create a problem handler given a handling policy
- this.options = new CompilerOptions(settings);
-
- // wrap requestor in DebugRequestor if one is specified
- if(DebugRequestor == null) {
- this.requestor = requestor;
- } else {
- this.requestor = new ICompilerRequestor(){
- public void acceptResult(CompilationResult result){
- if (DebugRequestor.isActive()){
- DebugRequestor.acceptDebugResult(result);
- }
- requestor.acceptResult(result);
- }
- };
- }
- this.problemReporter =
- new ProblemReporter(policy, this.options, problemFactory);
- this.lookupEnvironment =
- new LookupEnvironment(this, this.options, this.problemReporter, environment);
- initializeParser();
+ INameEnvironment environment,
+ IErrorHandlingPolicy policy,
+ Map settings,
+ final ICompilerRequestor requestor,
+ IProblemFactory problemFactory) {
+ this(environment, policy, settings, requestor, problemFactory,
+ null, false, false, false, false); // all defaults
+ }
+
+ /**
+ * Answer a new compiler using the given name environment and compiler options.
+ * The environment and options will be in effect for the lifetime of the compiler.
+ * When the compiler is run, compilation results are sent to the given requestor.
+ *
+ * @param environment org.eclipse.jdt.internal.compiler.api.env.INameEnvironment
+ * Environment used by the compiler in order to resolve type and package
+ * names. The name environment implements the actual connection of the compiler
+ * to the outside world (e.g. in batch mode the name environment is performing
+ * pure file accesses, reuse previous build state or connection to repositories).
+ * Note: the name environment is responsible for implementing the actual classpath
+ * rules.
+ *
+ * @param policy org.eclipse.jdt.internal.compiler.api.problem.IErrorHandlingPolicy
+ * Configurable part for problem handling, allowing the compiler client to
+ * specify the rules for handling problems (stop on first error or accumulate
+ * them all) and at the same time perform some actions such as opening a dialog
+ * in UI when compiling interactively.
+ * @see org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies
+ *
+ * @param requestor org.eclipse.jdt.internal.compiler.api.ICompilerRequestor
+ * Component which will receive and persist all compilation results and is intended
+ * to consume them as they are produced. Typically, in a batch compiler, it is
+ * responsible for writing out the actual .class files to the file system.
+ * @see org.eclipse.jdt.internal.compiler.CompilationResult
+ *
+ * @param problemFactory org.eclipse.jdt.internal.compiler.api.problem.IProblemFactory
+ * Factory used inside the compiler to create problem descriptors. It allows the
+ * compiler client to supply its own representation of compilation problems in
+ * order to avoid object conversions. Note that the factory is not supposed
+ * to accumulate the created problems, the compiler will gather them all and hand
+ * them back as part of the compilation unit result.
+ *
+ * @param out java.io.PrintWriter
+ * Used by the compiler to output messages which are not related to problems,
+ * e.g. the information issued in verbose mode. If null, defaults to System.out
+ * with automatic flushing.
+ */
+ public Compiler(
+ INameEnvironment environment,
+ IErrorHandlingPolicy policy,
+ Map settings,
+ final ICompilerRequestor requestor,
+ IProblemFactory problemFactory,
+ PrintWriter out) {
+ this(environment, policy, settings, requestor, problemFactory, out,
+ false, false, false, false); // all defaults
}
/**
@@ -144,27 +174,107 @@
* order to avoid object conversions. Note that the factory is not supposed
* to accumulate the created problems, the compiler will gather them all and hand
* them back as part of the compilation unit result.
+ *
* @param parseLiteralExpressionsAsConstants boolean
* This parameter is used to optimize the literals or leave them as they are in the source.
* If you put true, "Hello" + " world" will be converted to "Hello world".
+ *
+ * @param storeAnnotations boolean
+ * This parameter is used to tell the compiler to store annotations on
+ * type bindings, or not.
+ *
+ * @param statementsRecovery boolean
+ * This parameter is used to tell the compiler to perform syntax error
+ * recovery on statements, or not.
*/
public Compiler(
- INameEnvironment environment,
- IErrorHandlingPolicy policy,
- Map settings,
- final ICompilerRequestor requestor,
- IProblemFactory problemFactory,
- boolean parseLiteralExpressionsAsConstants,
- boolean storeAnnotations,
- boolean statementsRecovery) {
+ INameEnvironment environment,
+ IErrorHandlingPolicy policy,
+ Map settings,
+ final ICompilerRequestor requestor,
+ IProblemFactory problemFactory,
+ boolean parseLiteralExpressionsAsConstants,
+ boolean storeAnnotations,
+ boolean statementsRecovery) {
+ this(environment, policy, settings, requestor, problemFactory,
+ null, // default
+ parseLiteralExpressionsAsConstants, storeAnnotations, statementsRecovery, true);
+ }
+
+ /**
+ * Answer a new compiler using the given name environment and compiler options.
+ * The environment and options will be in effect for the lifetime of the compiler.
+ * When the compiler is run, compilation results are sent to the given requestor.
+ *
+ * @param environment org.eclipse.jdt.internal.compiler.api.env.INameEnvironment
+ * Environment used by the compiler in order to resolve type and package
+ * names. The name environment implements the actual connection of the compiler
+ * to the outside world (e.g. in batch mode the name environment is performing
+ * pure file accesses, reuse previous build state or connection to repositories).
+ * Note: the name environment is responsible for implementing the actual classpath
+ * rules.
+ *
+ * @param policy org.eclipse.jdt.internal.compiler.api.problem.IErrorHandlingPolicy
+ * Configurable part for problem handling, allowing the compiler client to
+ * specify the rules for handling problems (stop on first error or accumulate
+ * them all) and at the same time perform some actions such as opening a dialog
+ * in UI when compiling interactively.
+ * @see org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies
+ *
+ * @param requestor org.eclipse.jdt.internal.compiler.api.ICompilerRequestor
+ * Component which will receive and persist all compilation results and is intended
+ * to consume them as they are produced. Typically, in a batch compiler, it is
+ * responsible for writing out the actual .class files to the file system.
+ * @see org.eclipse.jdt.internal.compiler.CompilationResult
+ *
+ * @param problemFactory org.eclipse.jdt.internal.compiler.api.problem.IProblemFactory
+ * Factory used inside the compiler to create problem descriptors. It allows the
+ * compiler client to supply its own representation of compilation problems in
+ * order to avoid object conversions. Note that the factory is not supposed
+ * to accumulate the created problems, the compiler will gather them all and hand
+ * them back as part of the compilation unit result.
+ *
+ * @param out java.io.PrintWriter
+ * Used by the compiler to output messages which are not related to problems,
+ * e.g. the information issued in verbose mode. If null, defaults to System.out
+ * with automatic flushing.
+ *
+ * @param parseLiteralExpressionsAsConstants boolean
+ * This parameter is used to optimize the literals or leave them as they are in the source.
+ * If you put true, "Hello" + " world" will be converted to "Hello world".
+ *
+ * @param storeAnnotations boolean
+ * This parameter is used to tell the compiler to store annotations on
+ * type bindings, or not.
+ *
+ * @param statementsRecovery boolean
+ * This parameter is used to tell the compiler to perform syntax error
+ * recovery on statements, or not.
+ *
+ * @param flag boolean
+ * Set to true if and only if the other boolean parameters are significant.
+ */
+ private Compiler(
+ INameEnvironment environment,
+ IErrorHandlingPolicy policy,
+ Map settings,
+ final ICompilerRequestor requestor,
+ IProblemFactory problemFactory,
+ PrintWriter out,
+ boolean parseLiteralExpressionsAsConstants,
+ boolean storeAnnotations,
+ boolean statementsRecovery,
+ boolean flag) {
// create a problem handler given a handling policy
this.options = new CompilerOptions(settings);
- this.options.parseLiteralExpressionsAsConstants = parseLiteralExpressionsAsConstants;
- this.options.storeAnnotations = storeAnnotations;
- this.options.performStatementsRecovery =
- statementsRecovery &&
- this.options.performStatementsRecovery;// TODO temporary code to take into account the temporary JavaCore options
+ if (flag) { // boolean parameters are significant, pass them down
+ this.options.parseLiteralExpressionsAsConstants = parseLiteralExpressionsAsConstants;
+ this.options.storeAnnotations = storeAnnotations;
+ this.options.performStatementsRecovery =
+ statementsRecovery &&
+ this.options.performStatementsRecovery;// TODO temporary code to take into account the temporary JavaCore options
+ }
// wrap requestor in DebugRequestor if one is specified
if(DebugRequestor == null) {
@@ -181,6 +291,7 @@
}
this.problemReporter = new ProblemReporter(policy, this.options, problemFactory);
this.lookupEnvironment = new LookupEnvironment(this, this.options, problemReporter, environment);
+ this.out = out == null ? new PrintWriter(System.out, true) : out;
initializeParser();
}
@@ -189,7 +300,7 @@
*/
public void accept(IBinaryType binaryType, PackageBinding packageBinding, AccessRestriction accessRestriction) {
if (this.options.verbose) {
- System.out.println(
+ this.out.println(
Messages.bind(Messages.compilation_loadBinary, new String(binaryType.getName())));
// new Exception("TRACE BINARY").printStackTrace(System.out);
// System.out.println();
@@ -208,7 +319,7 @@
try {
if (options.verbose) {
String count = String.valueOf(totalUnits + 1);
- System.out.println(
+ this.out.println(
Messages.bind(Messages.compilation_request,
new String[] {
count,
@@ -281,7 +392,7 @@
new CompilationResult(sourceUnits[i], i, maxUnits, this.options.maxProblemsPerUnit);
try {
if (options.verbose) {
- System.out.println(
+ this.out.println(
Messages.bind(Messages.compilation_request,
new String[] {
String.valueOf(i + 1),
@@ -326,7 +437,7 @@
unit = unitsToProcess[i];
try {
if (options.verbose)
- System.out.println(
+ this.out.println(
Messages.bind(Messages.compilation_process,
new String[] {
String.valueOf(i + 1),
@@ -341,7 +452,7 @@
unitsToProcess[i] = null; // release reference to processed unit declaration
requestor.acceptResult(unit.compilationResult.tagAsAccepted());
if (options.verbose)
- System.out.println(
+ this.out.println(
Messages.bind(Messages.compilation_done,
new String[] {
String.valueOf(i + 1),
@@ -362,10 +473,10 @@
}
if (options.verbose) {
if (this.totalUnits > 1) {
- System.out.println(
+ this.out.println(
Messages.bind(Messages.compilation_units, String.valueOf(this.totalUnits)));
} else {
- System.out.println(
+ this.out.println(
Messages.bind(Messages.compilation_unit, String.valueOf(this.totalUnits)));
}
}
#P org.eclipse.jdt.core.tests.compiler
Index: src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java,v
retrieving revision 1.34
diff -u -r1.34 BatchCompilerTest.java
--- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 23 Jan 2006 10:34:27 -0000 1.34
+++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 23 Jan 2006 12:56:42 -0000
@@ -618,7 +618,7 @@
result);
}
// test the tester - runConformTest
-public void _test007(){
+public void test007(){
this.runConformTest(
new String[] {
"X.java",
@@ -640,20 +640,24 @@
+ " -1.5 -g -preserveAllLocals"
+ " -bootclasspath " + JRE_HOME_DIR + "/lib/rt.jar"
+ " -cp " + JRE_HOME_DIR + "/lib/jce.jar"
- + " -verbose -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal"
- + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"",
- "[1 .class file generated]\n",
- "----------\n" +
- "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---" + File.separator + "X.java\n" +
- " (at line 1)\n" +
- " import java.util.List;\n" +
- " ^^^^^^^^^^^^^^\n" +
- "The import java.util.List is never used\n" +
- "----------\n" +
- "1 problem (1 warning)", true);
+ + " -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal"
+ + " -verbose -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"",
+ "[parsing ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" +
+ "[reading java/lang/Object.class]\n" +
+ "[analyzing ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" +
+ "[reading java/util/List.class]\n" +
+ "[reading java/lang/SuppressWarnings.class]\n" +
+ "[reading java/lang/String.class]\n" +
+ "[writing X.class - #1]\n" +
+ "[completed ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" +
+ "[1 unit compiled]\n" +
+ "[1 .class file generated]\n",
+ "", // changed with bug 123522: now the SuppressWarning upon the first type
+ // influences warnings on unused imports
+ true);
}
// test the tester - runNegativeTest
-public void _test008(){
+public void test008(){
this.runNegativeTest(
new String[] {
"X.java",
@@ -675,9 +679,9 @@
+ " -1.5 -g -preserveAllLocals"
+ " -bootclasspath " + JRE_HOME_DIR + "/lib/rt.jar"
+ " -cp " + JRE_HOME_DIR + "/lib/jce.jar"
- + " -verbose -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal"
+ + " -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal"
+ " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"",
- "[1 .class file generated]\n",
+ "",
"----------\n" +
"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---" + File.separator + "X.java\n" +
" (at line 11)\n" +
@@ -689,7 +693,7 @@
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=92398 -- a case that works, another that does not
// revisit this test case depending on https://bugs.eclipse.org/bugs/show_bug.cgi?id=95349
-public void _test009(){
+public void test009(){
this.runNegativeTest(
new String[] {
"X.java",
@@ -726,35 +730,33 @@
+ " -1.5 -g -preserveAllLocals"
+ " -cp \"" + OUTPUT_DIR + "[+OK2" + File.pathSeparator + "~Warn"
+ File.pathSeparator + "-KO]\""
- + " -verbose -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal"
+ + " -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal"
+ " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"",
- "[5 .class files generated]\n",
- "----------\n" +
- "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---" + File.separator + "X.java\n" +
- " (at line 5)\n" +
- " Warn warn;\n" +
- " ^^^^\n" +
- "Discouraged access: Warn\n" +
- "----------\n" +
- "----------\n" +
- "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---" + File.separator + "X.java\n" +
- " (at line 6)\n" +
- " KO ko;\n" +
- " ^^\n" +
- "Access restriction: KO\n" +
- "----------\n" +
- "----------\n" +
- "3. ERROR in ---OUTPUT_DIR_PLACEHOLDER---" + File.separator + "X.java\n" +
- " (at line 7)\n" +
- " Zork z;\n" +
- " ^^^^\n" +
- "Zork cannot be resolved to a type\n" +
- "----------\n" +
- "3 problems (1 error, 2 warnings)",
+ "",
+ "----------\n" +
+ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java\n" +
+ " (at line 5)\n" +
+ " Warn warn;\n" +
+ " ^^^^\n" +
+ "Discouraged access: The type Warn is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---\n" +
+ "----------\n" +
+ "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java\n" +
+ " (at line 6)\n" +
+ " KO ko;\n" +
+ " ^^\n" +
+ "Access restriction: The type KO is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---\n" +
+ "----------\n" +
+ "3. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java\n" +
+ " (at line 7)\n" +
+ " Zork z;\n" +
+ " ^^^^\n" +
+ "Zork cannot be resolved to a type\n" +
+ "----------\n" +
+ "3 problems (1 error, 2 warnings)",
true);
}
// command line - no user classpath nor bootclasspath
-public void _test010(){
+public void test010(){
this.runConformTest(
new String[] {
"X.java",
@@ -776,15 +778,18 @@
+ " -1.5 -g -preserveAllLocals"
+ " -verbose -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal"
+ " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"",
- "[1 .class file generated]\n",
- "----------\n" +
- "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---" + File.separator + "X.java\n" +
- " (at line 1)\n" +
- " import java.util.List;\n" +
- " ^^^^^^^^^^^^^^\n" +
- "The import java.util.List is never used\n" +
- "----------\n" +
- "1 problem (1 warning)", true);
+ "[parsing ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" +
+ "[reading java/lang/Object.class]\n" +
+ "[analyzing ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" +
+ "[reading java/util/List.class]\n" +
+ "[reading java/lang/SuppressWarnings.class]\n" +
+ "[reading java/lang/String.class]\n" +
+ "[writing X.class - #1]\n" +
+ "[completed ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" +
+ "[1 unit compiled]\n" +
+ "[1 .class file generated]\n",
+ "",
+ true);
}
// command line - unusual classpath (ends with ';', still OK)
public void test011(){
@@ -805,141 +810,155 @@
true);
}
// command line - help
-public void _test012(){
+public void test012(){
final String expectedOutput =
"{0}\n" +
- " \n" +
- " Usage: