From db3d6e13dd9215051dbd08c9b4b0c02dbe6c4c15 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Fri, 30 Nov 2018 10:22:57 -0600 Subject: [PATCH] Eclipse 4.10 (RC1) JDT Patch for Groovy-Eclipse: JDT commit 2ea4c6b #686 #741 --- .../feature.xml | 2 +- .../regression/AbstractRegressionTest.java | 27 ++- .../regression/AbstractRegressionTest9.java | 12 + .../compiler/regression/Deprecated9Test.java | 25 ++- .../regression/LocalVariableTest.java | 9 + .../regression/ModuleCompilationTests.java | 210 +++++++++++++++++- .../regression/ResourceLeakTests.java | 82 +++++++ .../core/tests/util/AbstractCompilerTest.java | 4 + jdt-patch/e410/org.eclipse.jdt.core/.options | 2 +- .../compiler/ast/ForeachStatement.java | 7 + .../compiler/lookup/CompilationUnitScope.java | 18 +- .../compiler/lookup/ModuleBinding.java | 4 +- .../jdt/internal/compiler/lookup/Scope.java | 2 +- .../e410/org.eclipse.jdt.core/readme.txt | 1 + 14 files changed, 372 insertions(+), 33 deletions(-) diff --git a/jdt-patch/e410/Feature-org.codehaus.groovy.jdt.patch/feature.xml b/jdt-patch/e410/Feature-org.codehaus.groovy.jdt.patch/feature.xml index 1aba80dd2d..431bfb2a64 100644 --- a/jdt-patch/e410/Feature-org.codehaus.groovy.jdt.patch/feature.xml +++ b/jdt-patch/e410/Feature-org.codehaus.groovy.jdt.patch/feature.xml @@ -18,7 +18,7 @@ - + javacCompilers = null; public static final String OUTPUT_DIR = Util.getOutputDirectory() + File.separator + "regression"; public static final String LIB_DIR = Util.getOutputDirectory() + File.separator + "lib"; @@ -1864,7 +1868,15 @@ protected void runConformTest( expectedSuccessOutputString, null, javacTestOptions); + } + + protected static void javacUsePathOption(String option) { + if (AbstractRegressionTest.javacCompilers != null) { + for (JavacCompiler compiler : AbstractRegressionTest.javacCompilers) { + compiler.usePathOption(option); + } } + } /* * Run Sun compilation using javac. @@ -2179,9 +2191,9 @@ protected void runJavac( } } String testName = testName(); - Iterator compilers = javacCompilers.iterator(); + Iterator compilers = javacCompilers.iterator(); while (compilers.hasNext()) { - JavacCompiler compiler = (JavacCompiler) compilers.next(); + JavacCompiler compiler = compilers.next(); if (!options.skip(compiler) && compiler.compliance == this.complianceLevel) { // WORK this may exclude some compilers under some conditions (when // complianceLevel is not set); consider accepting the compiler @@ -2203,6 +2215,7 @@ protected void runJavac( for (int i = 0, length = testFiles.length; i < length; ) { String fileName = testFiles[i++]; String contents = testFiles[i++]; + fileName = expandFileNameForJavac(fileName); File file = new File(javacOutputDirectory, fileName); if (fileName.lastIndexOf('/') >= 0) { File dir = file.getParentFile(); @@ -2216,7 +2229,7 @@ protected void runJavac( int testFilesLength = testFiles.length; sourceFileNames = new String[testFilesLength / 2]; for (int i = 0, j = 0; i < testFilesLength; i += 2, j++) { - sourceFileNames[j] = testFiles[i]; + sourceFileNames[j] = expandFileNameForJavac(testFiles[i]); } // compile @@ -2319,6 +2332,10 @@ protected void runJavac( } } } +/** Hook for AbstractRegressionTest9 */ +protected String expandFileNameForJavac(String fileName) { + return fileName; +} void handleMismatch(JavacCompiler compiler, String testName, String[] testFiles, String expectedCompilerLog, String expectedOutputString, String expectedErrorString, StringBuffer compilerLog, String output, String err, JavacTestOptions.Excuse excuse, int mismatch) { @@ -3568,7 +3585,7 @@ protected void setUp() throws Exception { System.out.println("* Sun Javac compiler output archived into file:"); System.out.println("* " + javacFullLogFileName); System.out.println("***************************************************************************"); - javacCompilers = new ArrayList(); + javacCompilers = new ArrayList<>(); String jdkRoots = System.getProperty("jdk.roots"); if (jdkRoots == null) { javacCompilers.add(new JavacCompiler(jdkRootDirPath.toString())); diff --git a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java index cc4962530f..57db3e4ac1 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java +++ b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java @@ -89,6 +89,18 @@ protected CompilationUnit[] getCompilationUnits(String[] testFiles) { return compilationUnits; } + /** + * javac cannot leverage our internal map {@code file2module}, so we better + * neatly place each file into a sub directory matching the module name. + */ + protected String expandFileNameForJavac(String fileName) { + String fileNameAsKey = fileName.replace(File.separator, "/"); + if (this.file2module != null && this.file2module.containsKey(fileNameAsKey)) { + fileName = new String(this.file2module.get(fileNameAsKey))+File.separator+fileName; + } + return fileName; + } + private IModule extractModuleDesc(String fileName, String fileContent, ICompilationUnit cu) { if (fileName.toLowerCase().endsWith(IModule.MODULE_INFO_JAVA)) { Parser parser = createParser(); diff --git a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated9Test.java b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated9Test.java index 9a7deef067..6f12b7dd0e 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated9Test.java +++ b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated9Test.java @@ -688,7 +688,8 @@ public void testDeprecatedModule() { runner.runNegativeTest(); } public void testDeprecatedProvidedServices() { - associateToModule("mod0", "p1/IServiceDep.java", "p1/IServiceDepSince.java", "p1/IServiceTermDep.java", "p1/IServiceTermDepSince.java"); + javacUsePathOption(" --module-source-path "); + associateToModule("mod0", "module-info.java", "p1/IServiceDep.java", "p1/IServiceDepSince.java", "p1/IServiceTermDep.java", "p1/IServiceTermDepSince.java"); associateToModule("mod1", "p1impl/ServiceDep.java", "p1impl/ServiceDepSince.java", "p1impl/ServiceTermDep.java", "p1impl/ServiceTermDepSince.java"); Runner runner = new Runner(); runner.customOptions = new HashMap<>(); @@ -732,7 +733,7 @@ public void testDeprecatedProvidedServices() { "package p1impl;\n" + "@Deprecated(since=\"3\",forRemoval=true)\n" + "public class ServiceTermDepSince implements p1.IServiceTermDepSince {}\n", - "folder2/module-info.java", + "mod1/module-info.java", "module mod1 {\n" + " requires mod0;\n" + " provides p1.IServiceDep with p1impl.ServiceDep;\n" + @@ -743,42 +744,42 @@ public void testDeprecatedProvidedServices() { }; runner.expectedCompilerLog = "----------\n" + - "1. INFO in folder2\\module-info.java (at line 3)\n" + + "1. INFO in mod1\\module-info.java (at line 3)\n" + " provides p1.IServiceDep with p1impl.ServiceDep;\n" + " ^^^^^^^^^^^\n" + "The type IServiceDep is deprecated\n" + "----------\n" + - "2. INFO in folder2\\module-info.java (at line 3)\n" + + "2. INFO in mod1\\module-info.java (at line 3)\n" + " provides p1.IServiceDep with p1impl.ServiceDep;\n" + " ^^^^^^^^^^\n" + "The type ServiceDep is deprecated\n" + "----------\n" + - "3. INFO in folder2\\module-info.java (at line 4)\n" + + "3. INFO in mod1\\module-info.java (at line 4)\n" + " provides p1.IServiceDepSince with p1impl.ServiceDepSince;\n" + " ^^^^^^^^^^^^^^^^\n" + "The type IServiceDepSince is deprecated since version 2\n" + "----------\n" + - "4. INFO in folder2\\module-info.java (at line 4)\n" + + "4. INFO in mod1\\module-info.java (at line 4)\n" + " provides p1.IServiceDepSince with p1impl.ServiceDepSince;\n" + " ^^^^^^^^^^^^^^^\n" + "The type ServiceDepSince is deprecated since version 2\n" + "----------\n" + - "5. WARNING in folder2\\module-info.java (at line 5)\n" + + "5. WARNING in mod1\\module-info.java (at line 5)\n" + " provides p1.IServiceTermDep with p1impl.ServiceTermDep;\n" + " ^^^^^^^^^^^^^^^\n" + "The type IServiceTermDep has been deprecated and marked for removal\n" + "----------\n" + - "6. WARNING in folder2\\module-info.java (at line 5)\n" + + "6. WARNING in mod1\\module-info.java (at line 5)\n" + " provides p1.IServiceTermDep with p1impl.ServiceTermDep;\n" + " ^^^^^^^^^^^^^^\n" + "The type ServiceTermDep has been deprecated and marked for removal\n" + "----------\n" + - "7. WARNING in folder2\\module-info.java (at line 6)\n" + + "7. WARNING in mod1\\module-info.java (at line 6)\n" + " provides p1.IServiceTermDepSince with p1impl.ServiceTermDepSince;\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + "The type IServiceTermDepSince has been deprecated since version 3 and marked for removal\n" + "----------\n" + - "8. WARNING in folder2\\module-info.java (at line 6)\n" + + "8. WARNING in mod1\\module-info.java (at line 6)\n" + " provides p1.IServiceTermDepSince with p1impl.ServiceTermDepSince;\n" + " ^^^^^^^^^^^^^^^^^^^\n" + "The type ServiceTermDepSince has been deprecated since version 3 and marked for removal\n" + @@ -786,6 +787,8 @@ public void testDeprecatedProvidedServices() { runner.runWarningTest(); } public void testDeprecatedUsedServices() { + javacUsePathOption(" --module-path "); + associateToModule("mod0", "p1/IServiceDep.java", "p1/IServiceDepSince.java", "p1/IServiceTermDep.java", "p1/IServiceTermDepSince.java"); Runner runner = new Runner(); runner.customOptions = new HashMap<>(); @@ -888,6 +891,8 @@ public void testBug533063_1() throws Exception { } } public void testBug533063_2() throws Exception { + javacUsePathOption(" --module-path "); + runConformTest(new String[] { "dont.use/module-info.java", "@Deprecated(forRemoval=true,since=\"9\") module dont.use {}\n" diff --git a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalVariableTest.java b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalVariableTest.java index cf2ad8afa8..5f7992e802 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalVariableTest.java +++ b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalVariableTest.java @@ -897,6 +897,8 @@ public void testBug537033() { " }\n" + "}\n" }, + this.complianceLevel < ClassFileConstants.JDK11 + ? "----------\n" + "1. WARNING in ShowBug.java (at line 9)\n" + " final X x = new X() {\n" + @@ -907,6 +909,13 @@ public void testBug537033() { " x.x(val - 1);\n" + " ^\n" + "The local variable x may not have been initialized\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in ShowBug.java (at line 13)\n" + + " x.x(val - 1);\n" + + " ^\n" + + "The local variable x may not have been initialized\n" + "----------\n"); } public static Class testClass() { diff --git a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java index e6746496fe..74b75a5444 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java +++ b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java @@ -40,7 +40,7 @@ public class ModuleCompilationTests extends AbstractBatchCompilerTest { static { -// TESTS_NAMES = new String[] { "test_npe_bug535107" }; +// TESTS_NAMES = new String[] { "testBug540067e" }; // TESTS_NUMBERS = new int[] { 1 }; // TESTS_RANGE = new int[] { 298, -1 }; } @@ -162,8 +162,7 @@ Set runConformModuleTest(String[] testFiles, String commandLine, if (javacCommandLine == null) { javacCommandLine = adjustForJavac(commandLine, null); } - for (Object comp : javacCompilers) { - JavacCompiler javacCompiler = (JavacCompiler) comp; + for (JavacCompiler javacCompiler : javacCompilers) { if (javacCompiler.compliance < ClassFileConstants.JDK9) continue; if (options.skip(javacCompiler)) { @@ -240,8 +239,7 @@ void runNegativeModuleTest(String[] testFiles, String commandLine, File outputDir = new File(OUTPUT_DIR); final Set outFiles = new HashSet<>(); walkOutFiles(output, outFiles, true); - for (Object comp : javacCompilers) { - JavacCompiler javacCompiler = (JavacCompiler) comp; + for (JavacCompiler javacCompiler : javacCompilers) { if (javacCompiler.compliance < ClassFileConstants.JDK9) continue; JavacTestOptions.Excuse excuse = options.excuseFor(javacCompiler); @@ -3632,11 +3630,7 @@ public void testBug521362_emptyFile() { " ^^\n" + "The package p1 does not exist or is empty\n" + "----------\n" + - "----------\n" + - "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p1/X.java\n" + - "Must declare a named package because this compilation unit is associated to the named module \'mod.one\'\n" + - "----------\n" + - "2 problems (2 errors)\n", + "1 problem (1 error)\n", false, "empty", OUTPUT_DIR + File.separator + out); @@ -5006,4 +5000,200 @@ public void test_npe_bug535107() { "", true); } + public void testBug540067a() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java", + "/*nothing in it */"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "X.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java"); + + runConformModuleTest( + new String[0], + buffer.toString(), + "", + "", + false); + } + public void testBug540067b() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java", + "package p.q;"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "X.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java"); + + runConformModuleTest( + new String[0], + buffer.toString(), + "", + "", + false); + } + public void testBug540067c() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java", + "package p.q;\n" + + "class Test {}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "X.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java"); + + runConformModuleTest( + new String[0], + buffer.toString(), + "", + "", + false); + } + public void testBug540067d() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java", + "class Test {}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "X.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java"); + + runNegativeModuleTest( + new String[0], + buffer.toString(), + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/q/Test.java (at line 1)\n" + + " class Test {}\n" + + " ^\n" + + "Must declare a named package because this compilation unit is associated to the named module \'mod.one\'\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "unnamed package is not allowed in named modules"); + } + public void testBug540067e() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java", + "import java.lang.*;"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-unused") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "X.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java"); + + runNegativeModuleTest( + new String[0], + buffer.toString(), + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/q/Test.java (at line 1)\n" + + " import java.lang.*;\n" + + " ^\n" + + "Must declare a named package because this compilation unit is associated to the named module \'mod.one\'\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "unnamed package is not allowed in named modules"); + } } diff --git a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java index 59f8347905..765e10dfac 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java +++ b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java @@ -5355,4 +5355,86 @@ public void testBug396575() { "----------\n", options); } +public void testBug473317() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // using diamond + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(JavaCore.COMPILER_PB_SYNTHETIC_ACCESS_EMULATION, JavaCore.IGNORE); + runLeakTest( + new String[] { + "AutoCloseableEnhancedForTest.java", + "import java.util.Iterator;\n" + + "\n" + + "public class AutoCloseableEnhancedForTest\n" + + "{\n" + + " private static class MyIterator implements Iterator\n" + + " {\n" + + " private T value;\n" + + " \n" + + " public MyIterator(T value)\n" + + " {\n" + + " this.value = value;\n" + + " }\n" + + " \n" + + " @Override\n" + + " public boolean hasNext()\n" + + " {\n" + + " return false;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public T next()\n" + + " {\n" + + " return value;\n" + + " }\n" + + " }\n" + + " \n" + + " private static class MyIterable implements Iterable, AutoCloseable\n" + + " {\n" + + " @Override\n" + + " public Iterator iterator()\n" + + " {\n" + + " return new MyIterator<>(null);\n" + + " }\n" + + " \n" + + " @Override\n" + + " public void close() throws Exception\n" + + " {\n" + + " }\n" + + " }\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " // Not flagged as \"never closed.\"\n" + + " for (Object value : new MyIterable<>())\n" + + " {\n" + + " System.out.println(String.valueOf(value));\n" + + " \n" + + " break;\n" + + " }\n" + + " \n" + + " // Flagged as \"never closed.\"\n" + + " MyIterable iterable = new MyIterable<>();\n" + + " \n" + + " for (Object value : iterable)\n" + + " {\n" + + " System.out.println(String.valueOf(value));\n" + + " \n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in AutoCloseableEnhancedForTest.java (at line 44)\n" + + " for (Object value : new MyIterable<>())\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n" + + "2. WARNING in AutoCloseableEnhancedForTest.java (at line 52)\n" + + " MyIterable iterable = new MyIterable<>();\n" + + " ^^^^^^^^\n" + + "Resource leak: \'iterable\' is never closed\n" + + "----------\n", + compilerOptions); +} } diff --git a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java index eec375388a..33aa81cb9a 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java +++ b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java @@ -383,6 +383,10 @@ static void initReflectionVersion() { if (version.startsWith("1.8.0_")) { int build = Integer.parseInt(version.substring("1.8.0_".length())); reflectNestedClassUseDollar = build >= 171; + } else if (version.startsWith("1.8.0-")) { + // Some versions start with 1.8.0- but don't have build qualifier. + // Just assume they are > 171 build. Nothing much can be done. + reflectNestedClassUseDollar = true; } else { throw new IllegalStateException("Unrecognized Java version: "+version); } diff --git a/jdt-patch/e410/org.eclipse.jdt.core/.options b/jdt-patch/e410/org.eclipse.jdt.core/.options index a90286e204..d558214448 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core/.options +++ b/jdt-patch/e410/org.eclipse.jdt.core/.options @@ -1,5 +1,5 @@ # Turn on debug tracing for org.eclipse.jdt.core plugin -org.eclipse.jdt.core/debug=true +org.eclipse.jdt.core/debug=false # Reports buffer manager activity org.eclipse.jdt.core/debug/buffermanager=false diff --git a/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java b/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java index edbc2216a5..26e30f772b 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java +++ b/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java @@ -131,6 +131,10 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl if (this.action.complainIfUnreachable(actionInfo, this.scope, initialComplaintLevel, true) < Statement.COMPLAINED_UNREACHABLE) { actionInfo = this.action.analyseCode(this.scope, loopingContext, actionInfo).unconditionalCopy(); + if (this.action instanceof Block) { + // action.analyseCode() missed the following check due to identical scopes of ForeachStatement and Block: + this.scope.checkUnclosedCloseables(actionInfo, loopingContext, null, null); + } } // code generation can be optimized when no need to continue in the loop @@ -147,6 +151,9 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl } } else { exitBranch = condInfo.initsWhenFalse(); + if (this.action instanceof Block && !this.action.isEmptyBlock()) { + this.scope.checkUnclosedCloseables(actionInfo, loopingContext, null, null); + } } // we need the variable to iterate the collection even if the diff --git a/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java b/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java index 918d41fb83..1f9f7f0cca 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java +++ b/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java @@ -1,6 +1,6 @@ // GROOVY PATCHED /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -144,8 +144,8 @@ void buildTypeBindings(AccessRestriction accessRestriction) { moduleDecl.createScope(this); moduleDecl.checkAndSetModifiers(); } - } else if (this.environment.module != this.environment.UnNamedModule) { - problemReporter().unnamedPackageInNamedModule(this.environment.module); + } else if (module() != this.environment.UnNamedModule) { + problemReporter().unnamedPackageInNamedModule(module()); } } else { if ((this.fPackage = this.environment.createPackage(this.currentPackageName)) == null) { @@ -762,6 +762,18 @@ public int nextCaptureID() { return this.captureID++; } +@Override +public ModuleBinding module() { + if (!this.referenceContext.isModuleInfo() && + this.referenceContext.types == null && + this.referenceContext.currentPackage == null && + this.referenceContext.imports == null) { + this.environment = this.environment.UnNamedModule.environment; + return this.environment.UnNamedModule; + } + return super.module(); +} + /* Answer the problem reporter to use for raising new problems. * * Note that as a side-effect, this updates the current reference context diff --git a/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java b/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java index ec3fdcdb23..d6117ed47a 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java +++ b/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java @@ -684,8 +684,8 @@ private PackageBinding combineWithPackagesFromOtherRelevantModules(PackageBindin for (ModuleBinding moduleBinding : otherRelevantModules(declaringModuleNames)) { if (!moduleBinding.isPackageLookupActive) { PackageBinding nextBinding = parent != null - ? moduleBinding.getVisiblePackage(parent, singleName, true) - : moduleBinding.getVisiblePackage(compoundName, true); + ? moduleBinding.getVisiblePackage(parent, singleName, false) + : moduleBinding.getVisiblePackage(compoundName, false); currentBinding = SplitPackageBinding.combine(nextBinding, currentBinding, this); } } diff --git a/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java b/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java index 62f4ba2bcf..969d08686c 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java +++ b/jdt-patch/e410/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java @@ -752,7 +752,7 @@ public final CompilationUnitScope compilationUnitScope() { } while (scope != null); return (CompilationUnitScope) lastScope; } - public final ModuleBinding module() { + public ModuleBinding module() { return environment().module; } public boolean isLambdaScope() { diff --git a/jdt-patch/e410/org.eclipse.jdt.core/readme.txt b/jdt-patch/e410/org.eclipse.jdt.core/readme.txt index 2ba879dc3f..207ec916d5 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core/readme.txt +++ b/jdt-patch/e410/org.eclipse.jdt.core/readme.txt @@ -1,2 +1,3 @@ 2018-10-16: e4fef6c (2018-12 M1) 2018-11-23: e806c1b (2018-12 M3) +2018-11-30: 2ea4c6b (2018-12 RC1)