diff options
author | Roland Grunberg | 2020-09-23 17:50:04 +0000 |
---|---|---|
committer | Roland Grunberg | 2020-11-09 16:32:06 +0000 |
commit | 5a9f17e0594f387986b9c6f60d367deda690b056 (patch) | |
tree | c5cfd62b3b923468f3ff5754248f8069b3cbdf38 | |
parent | f07a7c0f048e8bb8af283b886c4733d390714b2f (diff) | |
download | eclipse.jdt.core-5a9f17e0594f387986b9c6f60d367deda690b056.tar.gz eclipse.jdt.core-5a9f17e0594f387986b9c6f60d367deda690b056.tar.xz eclipse.jdt.core-5a9f17e0594f387986b9c6f60d367deda690b056.zip |
Bug 537665 - Cannot parse module-info file standalone.I20201109-1800
- Binding resolution of module-info file fails with ASTParser
setEnvironment/createASTs API because ClasspathJar does not parse
module information, causing issues when resolution of the required
module is attempted using the environment
- Add testcase
Change-Id: I1b94e9b8f3113faa10fbe063707a5631909ef217
Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
8 files changed, 70 insertions, 8 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java index 9ac6d835f8..70c73637d2 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java @@ -893,17 +893,12 @@ public class ModuleCompilationTests extends AbstractBatchCompilerTest { buffer, "", "----------\n" + - "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/module-info.java (at line 2)\n" + - " requires mod.one;\n" + - " ^^^^^^^\n" + - "mod.one cannot be resolved to a module\n" + - "----------\n" + - "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/module-info.java (at line 3)\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/module-info.java (at line 3)\n" + " requires mod.two;\n" + " ^^^^^^^\n" + "mod.two cannot be resolved to a module\n" + "----------\n" + - "2 problems (2 errors)\n", + "1 problem (1 error)\n", false, "module"); } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java index dbde1223af..464719adbc 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java @@ -1881,4 +1881,31 @@ public class StandAloneASTParserTest extends AbstractRegressionTest { packDir.delete(); } } + public void testBug537665() throws IOException { + // resolve requires from a module-info.java file + String workDir = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Bug537665" + File.separator; + String mainModuleSource = workDir + "main/src"; + String utilModule = workDir + "util" + "/out/util.jar"; + String mainModuleInfo = mainModuleSource + "/module-info.java"; + + final class FileASTRequestorExtension extends FileASTRequestor { + @Override + public void acceptAST(String sourceFilePath, CompilationUnit unit) { + assertEquals(0, unit.getProblems().length); + } + } + + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setEnvironment(new String[] {utilModule}, new String[] {mainModuleSource, workDir}, null, true); + parser.setResolveBindings(true); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + Map<String, String> options = new HashMap<>(); + options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_10); + options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_10); + options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_10); + parser.setCompilerOptions(options); + + parser.createASTs(new String[] {mainModuleInfo}, null, new String[0], new FileASTRequestorExtension(), null); + } }
\ No newline at end of file diff --git a/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/main/src/main/Main.java b/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/main/src/main/Main.java new file mode 100644 index 0000000000..ee202f174c --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/main/src/main/Main.java @@ -0,0 +1,11 @@ +package main;
+
+import util.TimeUtil;
+
+public class Main {
+
+ public static void main(String[] args)
+ {
+ System.out.println(new TimeUtil().timeNow());
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/main/src/module-info.java b/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/main/src/module-info.java new file mode 100644 index 0000000000..d85e27208c --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/main/src/module-info.java @@ -0,0 +1,3 @@ +module main {
+ requires util;
+}
diff --git a/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/util/out/util.jar b/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/util/out/util.jar Binary files differnew file mode 100644 index 0000000000..25ec0820e5 --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/util/out/util.jar diff --git a/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/util/src/module-info.java b/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/util/src/module-info.java new file mode 100644 index 0000000000..2d980982ee --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/util/src/module-info.java @@ -0,0 +1,3 @@ +module util {
+ exports util;
+}
diff --git a/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/util/src/util/TimeUtil.java b/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/util/src/util/TimeUtil.java new file mode 100644 index 0000000000..08ebae8f17 --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/workspace/Bug537665/util/src/util/TimeUtil.java @@ -0,0 +1,11 @@ +package util;
+
+import java.util.Date;
+
+public class TimeUtil {
+
+ public String timeNow()
+ {
+ return new Date().toString();
+ }
+}
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java index 1fcce4beec..19cd3d3ef8 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -198,7 +198,19 @@ public void initialize() throws IOException { if (this.zipFile == null) { this.zipFile = new ZipFile(this.file); } + loadModules(); } +private void loadModules() { + try { + ClassFileReader reader = ClassFileReader.read(this.zipFile, IModule.MODULE_INFO_CLASS); + if (reader != null) { + this.module = reader.getModuleDeclaration(); + } + } catch (Exception e) { + // continue + } +} + void acceptModule(ClassFileReader reader) { if (reader != null) { acceptModule(reader.getModuleDeclaration()); |