diff options
29 files changed, 444 insertions, 103 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index cf591399d..1db0b9c2a 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1407,7 +1407,13 @@ protected static class JavacTestOptions { for (int i = 0; i < testFiles.length; i += 2) { System.out.print(testFiles[i]); System.out.println(" ["); //$NON-NLS-1$ - System.out.println(testFiles[i + 1]); + String content = testFiles[i + 1]; + if (content.length() > 10000) { + System.out.println(content.substring(0, 10000)); + System.out.println("...(truncated)"); //$NON-NLS-1$ + } else { + System.out.println(content); + } System.out.println("]"); //$NON-NLS-1$ } } @@ -1422,7 +1428,13 @@ protected static class JavacTestOptions { protected void printFiles(String[] testFiles) { for (int i=0, length=testFiles.length; i<length; i++) { System.out.println(testFiles[i++]); - System.out.println(testFiles[i]); + String content = testFiles[i]; + if (content.length() > 10000) { + System.out.println(content.substring(0, 10000)); + System.out.println("...(truncated)"); //$NON-NLS-1$ + } else { + System.out.println(content); + } } System.out.println(""); } @@ -2964,12 +2976,7 @@ protected void runNegativeTest(boolean skipJavac, JavacTestOptions javacTestOpti if (execOutputString != null && execOutputString.length() > 0) { System.out.println("[OUT]:"+execOutputString); //$NON-NLS-1$ } - for (int i = 0; i < testFiles.length; i += 2) { - System.out.print(testFiles[i]); - System.out.println(" ["); //$NON-NLS-1$ - System.out.println(testFiles[i + 1]); - System.out.println("]"); //$NON-NLS-1$ - } + logTestFiles(false, testFiles); assertEquals(this.verifier.failureReason, expectedErrorString == null ? "" : expectedErrorString, execErrorString); assertEquals(this.verifier.failureReason, expectedOutputString == null ? "" : expectedOutputString, execOutputString); } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java index efc12a85f..f60348090 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java @@ -1175,6 +1175,7 @@ public void test012b(){ " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedWarningToken\" value=\"warning\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast\" value=\"warning\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.processAnnotations\" value=\"disabled\"/>\n" + + " <option key=\"org.eclipse.jdt.core.compiler.release\" value=\"disabled\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.source\" value=\"1.5\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.storeAnnotations\" value=\"disabled\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.taskCaseSensitive\" value=\"enabled\"/>\n" + diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java index daacae43d..06c32a404 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1476,6 +1476,7 @@ public void testBug199265c1() throws JavaModelException { ); } public void testBug199265c2() throws JavaModelException { + setFormatLineCommentOnFirstColumn(); this.formatterPrefs.comment_format_header = true; String source = "import java.util.List;\n" + @@ -4447,6 +4448,7 @@ public void testBug293300_wksp2_10() { ); } public void testBug293300_wksp2_11() { + setFormatLineCommentOnFirstColumn(); String source = "package wksp2;\n" + "\n" + @@ -4582,6 +4584,7 @@ public void testBug293300_wksp2_12b() { } public void testBug293300_wksp2_13() { useOldCommentWidthCounting(); + setFormatLineCommentOnFirstColumn(); String source = "package wksp2;\n" + "\n" + @@ -4613,6 +4616,7 @@ public void testBug293300_wksp2_13() { ); } public void testBug293300_wksp2_14() { + setFormatLineCommentOnFirstColumn(); String source = "package wksp2;\n" + "\n" + @@ -4697,6 +4701,7 @@ public void testBug293300_wksp2_15b() { ); } public void testBug293300_wksp3_01() { + setFormatLineCommentOnFirstColumn(); String source = "package wksp3;\n" + "\n" + @@ -5714,6 +5719,7 @@ public void testBug298243() { * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=298844" */ public void testBug298844a() { + setFormatLineCommentOnFirstColumn(); this.formatterPrefs.insert_new_line_in_empty_method_body = false; String source = "public class X01 {\n" + @@ -6154,6 +6160,7 @@ public void testBug311578a() throws JavaModelException { ); } public void testBug311578b() throws JavaModelException { + setFormatLineCommentOnFirstColumn(); this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "/* J- */".toCharArray(); this.formatterPrefs.enabling_tag = "/* J+ */".toCharArray(); @@ -6289,6 +6296,8 @@ public void testBug311578c() throws JavaModelException { ); } public void testBug311578d() throws JavaModelException { + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT_STARTING_ON_FIRST_COLUMN, + DefaultCodeFormatterConstants.TRUE); this.formatterPrefs = null; this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_USE_ON_OFF_TAGS, DefaultCodeFormatterConstants.TRUE); this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "/*F--*/"); @@ -9370,6 +9379,7 @@ public void testBug330313_wksp1_40_njl() { ); } public void testBug330313_wksp1_41_njl() { + setFormatLineCommentOnFirstColumn(); this.formatterPrefs.join_wrapped_lines = false; String source = "package wksp1;\n" + @@ -10959,6 +10969,7 @@ public void testBug465669() throws Exception { ); } public void testBug471090() throws JavaModelException { + setFormatLineCommentOnFirstColumn(); this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; this.formatterPrefs.indentation_size = 2; String source = diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java index 25b984d74..658571ccd 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -2117,6 +2117,7 @@ public void testBug236230() throws JavaModelException { ); } public void testBug236230b() throws JavaModelException { + setFormatLineCommentOnFirstColumn(); String source = "/**\n" + " * Need a javadoc comment before to get the exception.\n" + @@ -2309,6 +2310,7 @@ public void testBug236406_CDB1() { ); } public void testBug236406_CDB2() { + setFormatLineCommentOnFirstColumn(); String source = "/** Javadoc comment */void foo1() {System.out.println();}\n" + "// Line comment \n" + @@ -2351,6 +2353,7 @@ public void testBug236406_EX1() { ); } public void testBug236406_EX2() { + setFormatLineCommentOnFirstColumn(); String source = "// Line comment \n" + "i = \n" + @@ -2388,6 +2391,7 @@ public void testBug236406_ST1() { ); } public void testBug236406_ST2() { + setFormatLineCommentOnFirstColumn(); String source = "/** Javadoc comment */foo1();\n" + "// Line comment \n" + @@ -3650,6 +3654,7 @@ public void testBug241687() throws JavaModelException { * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=251133" */ public void testBug251133() throws JavaModelException { + setFormatLineCommentOnFirstColumn(); String source = "public class X01 {\n" + "// int a = 1;\n" + @@ -6291,6 +6296,7 @@ public void testBug300379b() { * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304705" */ public void testBug304705() { + setFormatLineCommentOnFirstColumn(); this.formatterPrefs.never_indent_line_comments_on_first_column = true; String source = "public interface Example {\n" + @@ -6976,6 +6982,7 @@ public void testBug313651_01b() { formatSource(source); } public void testBug313651_01c() { + setFormatLineCommentOnFirstColumn(); String source = "public class X01 {\n" + " public void testMethod() {\n" + @@ -7032,6 +7039,7 @@ public void testBug313651_02b() { formatSource(source); } public void testBug313651_02c() { + setFormatLineCommentOnFirstColumn(); String source = "public class X02 {\n" + " public void testMethod() {\n" + @@ -7088,6 +7096,7 @@ public void testBug313651_03b() { formatSource(source); } public void testBug313651_03c() { + setFormatLineCommentOnFirstColumn(); String source = "public class X03 {\n" + " public void testMethod() {\n" + @@ -7111,6 +7120,7 @@ public void testBug313651_03c() { ); } public void testBug313651_wksp3_01() { + setFormatLineCommentOnFirstColumn(); String source = "package wksp3;\n" + "public class X01 implements\n" + @@ -7131,6 +7141,7 @@ public void testBug313651_wksp3_01() { ); } public void testBug313651_wksp3_02() { + setFormatLineCommentOnFirstColumn(); String source = "package wksp3;\n" + "public class X02 implements MyOtherInterface, \n" + diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java index 192044bb8..afa74b11f 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -802,6 +802,7 @@ public void testLineComments05() throws JavaModelException { formatUnit("comments.line", "X05.java"); } public void testLineComments06() throws JavaModelException { + setFormatLineCommentOnFirstColumn(); formatUnit("comments.line", "X06.java"); } public void testLineComments07() throws JavaModelException { diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java index f6521a9af..dacaf3a40 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java @@ -125,19 +125,14 @@ public class FormatterRegressionTests extends AbstractJavaModelTests { protected void useOldCommentWidthCounting() { this.formatterPrefs.comment_count_line_length_from_starting_position = false; } + /** - * Returns the OS path to the directory that contains this plugin. - * - protected String getPluginDirectoryPath() { - try { - URL platformURL = Platform.getBundle("org.eclipse.jdt.core.tests.model").getEntry("/"); - return new File(FileLocator.toFileURL(platformURL).getFile()).getAbsolutePath(); - } catch (IOException e) { - e.printStackTrace(); - } - return null; + * Helper function for old tests that are expect comment line comments + * on first column to be formatted. + */ + protected void setFormatLineCommentOnFirstColumn() { + this.formatterPrefs.comment_format_line_comment_starting_on_first_column = true; } - */ private String getResource(String packageName, String resourceName) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); @@ -7987,6 +7982,7 @@ public class FormatterRegressionTests extends AbstractJavaModelTests { public void test553() { Map options = DefaultCodeFormatterConstants.getJavaConventionsSettings(); DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); + preferences.comment_format_line_comment_starting_on_first_column = true; preferences.tab_char = DefaultCodeFormatterOptions.SPACE; preferences.tab_size = 4; DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences); @@ -8001,6 +7997,7 @@ public class FormatterRegressionTests extends AbstractJavaModelTests { public void test554() { Map options = DefaultCodeFormatterConstants.getJavaConventionsSettings(); DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options); + preferences.comment_format_line_comment_starting_on_first_column = true; preferences.tab_char = DefaultCodeFormatterOptions.SPACE; preferences.tab_size = 4; DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences); @@ -13301,6 +13298,7 @@ public void testBug479109c() { * https://bugs.eclipse.org/479109 - [formatter] Add option to group aligned fields with blank lines */ public void testBug479109d() { + setFormatLineCommentOnFirstColumn(); this.formatterPrefs.align_type_members_on_columns = true; this.formatterPrefs.align_fields_grouping_blank_lines = 2; String source = @@ -13942,6 +13940,7 @@ public void testBug493296() throws JavaModelException { */ public void testBug362260a() throws JavaModelException { setPageWidth80(); + setFormatLineCommentOnFirstColumn(); this.formatterPrefs.comment_line_length = 40; this.formatterPrefs.comment_format_header = true; this.formatterPrefs.comment_count_line_length_from_starting_position = true; diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java index fc1801e0b..51e4add38 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java @@ -1322,7 +1322,10 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases { } protected IJavaProject createJava9Project(String name) throws CoreException { - return createJava9Project(name, new String[]{"src"}); + return createJava9ProjectWithJREAttributes(name, new String[]{"src"}, null, "9"); + } + protected IJavaProject createJava9Project(String name, String compliance) throws CoreException { + return createJava9ProjectWithJREAttributes(name, new String[]{"src"}, null, compliance); } protected IJavaProject createJava9Project(String name, String[] srcFolders) throws CoreException { return createJava9ProjectWithJREAttributes(name, srcFolders, null); @@ -1341,6 +1344,20 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases { project.setRawClasspath(newPath, null); return project; } + protected IJavaProject createJava9ProjectWithJREAttributes(String name, String[] srcFolders, IClasspathAttribute[] attributes, String compliance) throws CoreException { + String javaHome = System.getProperty("java.home") + File.separator; + Path bootModPath = new Path(javaHome +"/lib/jrt-fs.jar"); + Path sourceAttachment = new Path(javaHome +"/lib/src.zip"); + IClasspathEntry jrtEntry = JavaCore.newLibraryEntry(bootModPath, sourceAttachment, null, null, attributes, false); + IJavaProject project = this.createJavaProject(name, srcFolders, new String[0], + new String[0], "bin", compliance); + IClasspathEntry[] old = project.getRawClasspath(); + IClasspathEntry[] newPath = new IClasspathEntry[old.length +1]; + System.arraycopy(old, 0, newPath, 0, old.length); + newPath[old.length] = jrtEntry; + project.setRawClasspath(newPath, null); + return project; + } /* } * Creates a Java project where prj=src=bin and with JCL_LIB on its classpath. diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs9Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs9Tests.java index 568b7bda7..036edd29a 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs9Tests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs9Tests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2017 IBM Corporation and others. + * Copyright (c) 2016, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -4462,5 +4462,62 @@ public void testBug530016_007() throws Exception { deleteProject("third"); } } + +public void testBug529367() throws Exception { + try { + IJavaProject project1 = createJavaProject("Library", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + project1.open(null); + createFolder("/Library/src/javax/xml/bind"); + createFile("/Library/src/javax/xml/bind/JAXBContext.java", + "package javax.xml.bind;\n" + + "public abstract class JAXBContext {\n" + + " public static JAXBContext newInstance( String contextPath )\n" + + " throws JAXBException {\n" + + " return null;\n" + + " }\n" + + "}\n"); + createFile("/Library/src/javax/xml/bind/JAXBException.java", + "package javax.xml.bind;\n" + + "public class JAXBException extends Exception {}\n"); + + IJavaProject project2 = createJava9Project("second", new String[] {"src"}); + project2.open(null); + addClasspathEntry(project2, JavaCore.newProjectEntry(project1.getPath())); + createFolder("/second/src/p1"); + createFile("/second/src/p1/ImportJAXBType.java", + "package p1;\n" + + "\n" + + "import javax.xml.bind.JAXBContext;\n" + + "\n" + + "public class ImportJAXBType {\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " JAXBContext context = JAXBContext.newInstance(\"\");\n" + + " }\n" + + "\n" + + "}\n"); + + project1.close(); // sync + project2.close(); + project2.open(null); + project1.open(null); + waitUntilIndexesReady(); + + SearchPattern pattern = SearchPattern.createPattern("JAXBContext", IJavaSearchConstants.TYPE, REFERENCES, SearchPattern.R_EXACT_MATCH); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] + {project2}); + search(pattern, scope, this.resultCollector); + assertSearchResults( + "src/javax/xml/bind/JAXBContext.java JAXBContext javax.xml.bind.JAXBContext.newInstance(String) [JAXBContext] EXACT_MATCH\n" + + "src/p1/ImportJAXBType.java [JAXBContext] EXACT_MATCH\n" + + "src/p1/ImportJAXBType.java void p1.ImportJAXBType.main(String[]) [JAXBContext] EXACT_MATCH\n" + + "src/p1/ImportJAXBType.java void p1.ImportJAXBType.main(String[]) [JAXBContext] EXACT_MATCH", + this.resultCollector); + } + finally { + deleteProject("Library"); + deleteProject("second"); + } +} // Add more tests here }
\ No newline at end of file diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java index aaced5ec9..e7cc28ef7 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java @@ -57,7 +57,7 @@ public class ModuleBuilderTests extends ModifyingResourceTests { } static { - // TESTS_NAMES = new String[] { "testBug528467" }; +// TESTS_NAMES = new String[] { "testBug527569c" }; } private String sourceWorkspacePath = null; protected ProblemRequestor problemRequestor; @@ -6814,7 +6814,130 @@ public class ModuleBuilderTests extends ModifyingResourceTests { new File(jarPath).delete(); } } + public void testBug527569a() throws CoreException { + if (!isJRE9) return; + IJavaProject p1 = createJava9Project("Bug527569", "9"); + try { + createFolder("/Bug527569/src/p1"); + createFile("/Bug527569/src/p1/X.java", + "package p1;\n" + + "public class X {\n" + + " public java.util.stream.Stream<String> emptyStream() {\n" + + " return null;\n" + + " }\n" + + "}"); + + waitForManualRefresh(); + waitForAutoBuild(); + p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); + IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + assertMarkers("Unexpected markers", "", markers); + } finally { + deleteProject(p1); + } + } + public void testBug527569b() throws CoreException { + if (!isJRE9) return; + IJavaProject p1 = createJava9Project("Bug527569", "1.7"); + try { + createFolder("/Bug527569/src/p1"); + createFile("/Bug527569/src/p1/X.java", + "package p1;\n" + + "public class X {\n" + + " public java.util.stream.Stream<String> emptyStream() {\n" + + " return null;\n" + + " }\n" + + "}"); + + waitForManualRefresh(); + waitForAutoBuild(); + p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); + IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + assertMarkers("Unexpected markers", "", markers); + } finally { + deleteProject(p1); + } + } + public void testBug527569c() throws CoreException { + if (!isJRE9) return; + IJavaProject p1 = createJava9Project("Bug527569", "1.7"); + Map<String, String> options = new HashMap<>(); + // Make sure the new options map doesn't reset. + options.put(CompilerOptions.OPTION_Compliance, "1.7"); + options.put(CompilerOptions.OPTION_Source, "1.7"); + options.put(CompilerOptions.OPTION_TargetPlatform, "1.7"); + options.put(CompilerOptions.OPTION_Release, "enabled"); + p1.setOptions(options); + try { + createFolder("/Bug527569/src/p1"); + createFile("/Bug527569/src/p1/X.java", + "package p1;\n" + + "public class X {\n" + + " public java.util.stream.Stream<String> emptyStream() {\n" + + " return null;\n" + + " }\n" + + "}"); + + waitForManualRefresh(); + waitForAutoBuild(); + p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); + IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + assertMarkers("Unexpected markers", "java.util.stream.Stream cannot be resolved to a type", markers); + } finally { + deleteProject(p1); + } + } + public void testBug527569d() throws CoreException { + if (!isJRE9) return; + IJavaProject p1 = createJava9Project("Bug527569", "9"); + try { + createFolder("/Bug527569/src/p1"); + createFile("/Bug527569/src/p1/X.java", + "package p1;\n" + + "public class X {\n" + + " public java.lang.Compiler getCompiler() {\n" + + " return null;\n" + + " }\n" + + "}"); + + waitForManualRefresh(); + waitForAutoBuild(); + p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); + IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + assertMarkers("Unexpected markers", "The type Compiler has been deprecated since version 9 and marked for removal", markers); + } finally { + deleteProject(p1); + } + } + public void testBug527569e() throws CoreException { + if (!isJRE9) return; + IJavaProject p1 = createJava9Project("Bug527569", "1.8"); + Map<String, String> options = new HashMap<>(); + // Make sure the new options map doesn't reset. + options.put(CompilerOptions.OPTION_Compliance, "1.7"); + options.put(CompilerOptions.OPTION_Source, "1.7"); + options.put(CompilerOptions.OPTION_TargetPlatform, "1.7"); + options.put(CompilerOptions.OPTION_Release, "enabled"); + p1.setOptions(options); + try { + createFolder("/Bug527569/src/p1"); + createFile("/Bug527569/src/p1/X.java", + "package p1;\n" + + "public class X {\n" + + " public java.lang.Compiler getCompiler() {\n" + + " return null;\n" + + " }\n" + + "}"); + waitForManualRefresh(); + waitForAutoBuild(); + p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); + IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + assertMarkers("Unexpected markers", "", markers); + } finally { + deleteProject(p1); + } + } protected void assertNoErrors() throws CoreException { for (IProject p : getWorkspace().getRoot().getProjects()) { int maxSeverity = p.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE); diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java index bb11cfcbb..0e7d971bc 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java @@ -34,7 +34,7 @@ public class ClasspathJep247 extends ClasspathLocation { private Path releasePath = null; private File file = null; private Set<String> packageCache; - + public ClasspathJep247(File jdkHome, String release, AccessRuleSet accessRuleSet) { super(accessRuleSet, null); this.release = release; @@ -63,7 +63,7 @@ public class ClasspathJep247 extends ClasspathLocation { Path p = this.fs.getPath(rel, qualifiedBinaryFileName); if (Files.exists(p)) { content = Files.readAllBytes(p); - if (content != null) + if (content != null) break; } } @@ -101,7 +101,7 @@ public class ClasspathJep247 extends ClasspathLocation { if (!Files.exists(filePath)) { return; } - URI uri = URI.create("jar:file:" + t.getPath()); //$NON-NLS-1$ + URI uri = URI.create("jar:file:" + t.getRawPath()); //$NON-NLS-1$ try { this.fs = FileSystems.getFileSystem(uri); } catch(FileSystemNotFoundException fne) { diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java index 17daac2ff..d7de9a9b4 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2017 IBM Corporation. + * Copyright (c) 2016, 2018 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -19,8 +19,10 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.function.Function; import java.util.zip.ZipFile; @@ -44,7 +46,7 @@ public class ClasspathJrt extends ClasspathLocation implements IMultiModuleEntry protected ZipFile annotationZipFile; protected boolean closeZipFileAtEnd; private static HashMap<String, Map<String,IModule>> ModulesCache = new HashMap<>(); - public HashMap<String, Path> modulePathMap; + public final Set<String> moduleNamesCache; //private Set<String> packageCache; protected List<String> annotationPaths; @@ -53,7 +55,7 @@ public class ClasspathJrt extends ClasspathLocation implements IMultiModuleEntry super(accessRuleSet, destinationPath); this.file = file; this.closeZipFileAtEnd = closeZipFileAtEnd; - this.modulePathMap = new HashMap<>(); + this.moduleNamesCache = new HashSet<>(); } @Override @@ -79,7 +81,7 @@ public class ClasspathJrt extends ClasspathLocation implements IMultiModuleEntry return null; // most common case try { - IBinaryType reader = ClassFileReader.readFromModule(this.file, moduleName, qualifiedBinaryFileName); + IBinaryType reader = ClassFileReader.readFromModule(this.file, moduleName, qualifiedBinaryFileName, this.moduleNamesCache::contains); if (reader != null) { searchPaths: @@ -217,7 +219,7 @@ public class ClasspathJrt extends ClasspathLocation implements IMultiModuleEntry public FileVisitResult visitModule(Path mod) throws IOException { try { ClasspathJrt.this.acceptModule(JRTUtil.getClassfileContent(ClasspathJrt.this.file, IModule.MODULE_INFO_CLASS, mod.toString())); - ClasspathJrt.this.modulePathMap.put(mod.getFileName().toString(), mod); + ClasspathJrt.this.moduleNamesCache.add(mod.getFileName().toString()); } catch (ClassFormatException e) { e.printStackTrace(); } @@ -227,6 +229,8 @@ public class ClasspathJrt extends ClasspathLocation implements IMultiModuleEntry } catch (IOException e) { // TODO: Java 9 Should report better } + } else { + this.moduleNamesCache.addAll(cache.keySet()); } } void acceptModule(ClassFileReader reader) { @@ -353,7 +357,6 @@ public class ClasspathJrt extends ClasspathLocation implements IMultiModuleEntry //this.packageCache = null; this.annotationPaths = null; } - this.modulePathMap.clear(); } @Override public String toString() { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java index 00ee887ce..37d85cc50 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java @@ -25,6 +25,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; +import java.util.function.Predicate; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.codegen.AnnotationTargetTypeConstants; @@ -149,13 +150,6 @@ public static ClassFileReader read( return read(zip, filename, false); } -public static ClassFileReader readFromJimage( - File jrt, - String filename) - throws ClassFormatException, java.io.IOException { - - return readFromModule(jrt, null, filename); - } public static ClassFileReader readFromJrt( File jrt, IModule module, @@ -167,10 +161,11 @@ public static ClassFileReader readFromJrt( public static ClassFileReader readFromModule( File jrt, String moduleName, - String filename) + String filename, + Predicate<String> moduleNameFilter) throws ClassFormatException, java.io.IOException { - return JRTUtil.getClassfile(jrt, filename, moduleName); + return JRTUtil.getClassfile(jrt, filename, moduleName, moduleNameFilter); } public static ClassFileReader read( java.util.zip.ZipFile zip, diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModulePathEntry.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModulePathEntry.java index 09d6a52bf..a488a457a 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModulePathEntry.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/IModulePathEntry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2017 IBM Corporation and others. + * Copyright (c) 2016, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.env; -import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.compiler.CharOperation; /** @@ -80,9 +79,4 @@ public interface IModulePathEntry { public default boolean isAutomaticModule() { return false; } - - /** Tests whether the current entry represents the given java project. */ - public default boolean equalsProject(IJavaProject project) { - return false; - } }
\ No newline at end of file diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java index 6a4545701..739acba3b 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java @@ -122,6 +122,7 @@ public class CompilerOptions { public static final String OPTION_Source = "org.eclipse.jdt.core.compiler.source"; //$NON-NLS-1$ public static final String OPTION_TargetPlatform = "org.eclipse.jdt.core.compiler.codegen.targetPlatform"; //$NON-NLS-1$ public static final String OPTION_Compliance = "org.eclipse.jdt.core.compiler.compliance"; //$NON-NLS-1$ + public static final String OPTION_Release = "org.eclipse.jdt.core.compiler.release"; //$NON-NLS-1$ public static final String OPTION_Encoding = "org.eclipse.jdt.core.encoding"; //$NON-NLS-1$ public static final String OPTION_MaxProblemPerUnit = "org.eclipse.jdt.core.compiler.maxProblemPerUnit"; //$NON-NLS-1$ public static final String OPTION_TaskTags = "org.eclipse.jdt.core.compiler.taskTags"; //$NON-NLS-1$ @@ -1554,6 +1555,7 @@ public class CompilerOptions { optionsMap.put(OPTION_ReportUnusedLabel, getSeverityString(UnusedLabel)); optionsMap.put(OPTION_ReportUnusedTypeArgumentsForMethodInvocation, getSeverityString(UnusedTypeArguments)); optionsMap.put(OPTION_Compliance, versionFromJdkLevel(this.complianceLevel)); + optionsMap.put(OPTION_Release, DISABLED); optionsMap.put(OPTION_Source, versionFromJdkLevel(this.sourceLevel)); optionsMap.put(OPTION_TargetPlatform, versionFromJdkLevel(this.targetJDK)); optionsMap.put(OPTION_FatalOptionalError, this.treatOptionalErrorAsFatal ? ENABLED : DISABLED); diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/JRTUtil.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/JRTUtil.java index 8633fede5..446496fe9 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/JRTUtil.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/JRTUtil.java @@ -31,6 +31,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Predicate; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; @@ -155,8 +156,8 @@ public class JRTUtil { public static ClassFileReader getClassfile(File jrt, String fileName, IModule module) throws IOException, ClassFormatException { return getJrtSystem(jrt).getClassfile(fileName, module); } - public static ClassFileReader getClassfile(File jrt, String fileName, String module) throws IOException, ClassFormatException { - return getJrtSystem(jrt).getClassfile(fileName, module); + public static ClassFileReader getClassfile(File jrt, String fileName, String module, Predicate<String> moduleNameFilter) throws IOException, ClassFormatException { + return getJrtSystem(jrt).getClassfile(fileName, module, moduleNameFilter); } public static List<String> getModulesDeclaringPackage(File jrt, String qName, String moduleName) { return getJrtSystem(jrt).getModulesDeclaringPackage(qName, moduleName); @@ -282,11 +283,13 @@ class JrtFileSystem { } return null; } - private ClassFileReader getClassfile(String fileName) throws IOException, ClassFormatException { + private ClassFileReader getClassfile(String fileName, Predicate<String> moduleNameFilter) throws IOException, ClassFormatException { String[] modules = getModules(fileName); byte[] content = null; String module = null; for (String mod : modules) { + if (moduleNameFilter != null && !moduleNameFilter.test(mod)) + continue; try { content = Files.readAllBytes(this.jrtSystem.getPath(JRTUtil.MODULES_SUBDIR, mod, fileName)); if (content != null) { @@ -333,10 +336,10 @@ class JrtFileSystem { } return content; } - public ClassFileReader getClassfile(String fileName, String module) throws IOException, ClassFormatException { + public ClassFileReader getClassfile(String fileName, String module, Predicate<String> moduleNameFilter) throws IOException, ClassFormatException { ClassFileReader reader = null; if (module == null) { - reader = getClassfile(fileName); + reader = getClassfile(fileName, moduleNameFilter); } else { byte[] content = getClassfileBytes(fileName, module); if (content != null) { @@ -349,7 +352,7 @@ class JrtFileSystem { public ClassFileReader getClassfile(String fileName, IModule module) throws IOException, ClassFormatException { ClassFileReader reader = null; if (module == null) { - reader = getClassfile(fileName); + reader = getClassfile(fileName, (Predicate<String>)null); } else { byte[] content = getClassfileBytes(fileName, new String(module.name())); if (content != null) { diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java index 463c0ac78..b561fe037 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java @@ -2778,7 +2778,7 @@ public class DefaultCodeFormatterOptions { this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT; this.alignment_for_compact_if = Alignment.M_COMPACT_SPLIT; this.alignment_for_conditional_expression = Alignment.M_NEXT_PER_LINE_SPLIT; - this.alignment_for_enum_constants = Alignment.M_NO_ALIGNMENT; + this.alignment_for_enum_constants = Alignment.M_COMPACT_SPLIT; this.alignment_for_expressions_in_array_initializer = Alignment.M_COMPACT_SPLIT; this.alignment_for_expressions_in_for_loop_header = Alignment.M_NO_ALIGNMENT; this.alignment_for_method_declaration = Alignment.M_NO_ALIGNMENT; @@ -2826,7 +2826,7 @@ public class DefaultCodeFormatterOptions { this.comment_format_block_comment = true; this.comment_format_javadoc_comment = true; this.comment_format_line_comment = true; - this.comment_format_line_comment_starting_on_first_column = true; + this.comment_format_line_comment_starting_on_first_column = false; this.comment_format_header = false; this.comment_format_html = true; this.comment_format_source = true; diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java index 2fa093a33..55ee23670 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java @@ -112,13 +112,21 @@ package org.eclipse.jdt.core; +import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.zip.ZipFile; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; @@ -157,6 +165,11 @@ import org.eclipse.jdt.core.search.SearchPattern; import org.eclipse.jdt.core.search.TypeNameRequestor; import org.eclipse.jdt.core.util.IAttributeNamesConstants; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.env.AutomaticModuleNaming; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.IModule.IModuleReference; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; import org.eclipse.jdt.internal.core.BatchOperation; @@ -2096,6 +2109,22 @@ public final class JavaCore extends Plugin { */ public static final String COMPILER_COMPLIANCE = PLUGIN_ID + ".compiler.compliance"; //$NON-NLS-1$ /** + * Compiler option ID: Use system libraries from release. + * <p>When enabled, the compiler will compile against the system libraries from release + * of the specified compliance level</p> + * <p>Setting this option sets the {@link #COMPILER_CODEGEN_TARGET_PLATFORM}) and {@link #COMPILER_SOURCE} to + * the same level as the compiler compliance. This option is available to a project only when a supporting + * JDK is found in the project's build path</p> + * <dl> + * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.release"</code></dd> + * <dt>Possible values:</dt><dd><code>{ "enabled", "disabled" }</code></dd> + * <dt>Default:</dt><dd><code>"disabled"</code></dd> + * </dl> + * @since 3.14 + * @category CompilerOptionID + */ + public static final String COMPILER_RELEASE = PLUGIN_ID + ".compiler.release"; //$NON-NLS-1$ + /** * Compiler option ID: Defining the Automatic Task Priorities. * <p>In parallel with the Automatic Task Tags, this list defines the priorities (high, normal or low) * of the task markers issued by the compiler. @@ -6125,6 +6154,71 @@ public final class JavaCore extends Plugin { return new ModuleInfoBuilder().compileWithAttributes(module, classFileAttributes); } + /** + * Returns the module name computed for a jar. If the file is a jar and contains a module-info.class, the name + * specified in it is used, otherwise, the algorithm for automatic module naming is used, which first looks for a + * module name in the Manifest.MF and as last resort computes it from the file name. + * + * @param file the jar to examine + * @return null if file is not a file, otherwise the module name. + * @since 3.14 + */ + public static String getModuleNameFromJar(File file) { + if (!file.isFile()) { + return null; + } + + char[] moduleName = null; + try (ZipFile zipFile = new ZipFile(file)) { + IModule module = null; + ClassFileReader reader = ClassFileReader.read(zipFile, IModule.MODULE_INFO_CLASS); + if (reader != null) { + module = reader.getModuleDeclaration(); + if (module != null) { + moduleName = module.name(); + } + } + } catch (ClassFormatException | IOException ex) { + Util.log(ex); + } + if (moduleName == null) { + moduleName = AutomaticModuleNaming.determineAutomaticModuleName(file.getAbsolutePath()); + } + return new String(moduleName); + } + + /** + * Returns the names of the modules required by the module-info.class in the jar. If the file is not jar or a jar + * that has no module-info.class is present, the empty set is returned. + * + * @param file the jar to examine + * @return set of module names. + * @since 3.14 + */ + public static Set<String> getRequiredModulesFromJar(File file) { + if (!file.isFile()) { + return Collections.emptySet(); + } + try (ZipFile zipFile = new ZipFile(file)) { + IModule module = null; + ClassFileReader reader = ClassFileReader.read(zipFile, IModule.MODULE_INFO_CLASS); + if (reader != null) { + module = reader.getModuleDeclaration(); + if (module != null) { + IModuleReference[] moduleRefs = module.requires(); + if (moduleRefs != null) { + return Stream.of(moduleRefs).map(m -> new String(m.name())) + .collect(Collectors.toCollection(LinkedHashSet::new)); + } + } + } + } catch (ClassFormatException | IOException ex) { + Util.log(ex); + } + return Collections.emptySet(); + } + + /* (non-Javadoc) * Shutdown the JavaCore plug-in. * <p> diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java index f1fe42eb4..a449eb160 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java @@ -850,7 +850,7 @@ public class JavaProject JrtPackageFragmentRoot root = this.modNames2Roots.get(moduleName); if (root != null) { try { - ClassFileReader classFile = JRTUtil.getClassfile(this.jrtFile, TypeConstants.MODULE_INFO_CLASS_NAME_STRING, root.moduleName); + ClassFileReader classFile = JRTUtil.getClassfile(this.jrtFile, TypeConstants.MODULE_INFO_CLASS_NAME_STRING, root.moduleName, null); result = classFile.getModuleDeclaration(); this.modules.put(moduleName, result); } catch (IOException | ClassFormatException e) { diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleSourcePathManager.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleSourcePathManager.java index 458a401c7..e70aaa742 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleSourcePathManager.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ModuleSourcePathManager.java @@ -53,7 +53,7 @@ public class ModuleSourcePathManager { public void removeEntry(JavaProject javaProject) { Entry<String, IModulePathEntry> entry = this.knownModules.entrySet().stream() - .filter(e -> e.getValue().equalsProject(javaProject)) + .filter(e -> ProjectEntry.representsProject(e.getValue(), javaProject)) .findFirst() .orElse(null); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ProjectEntry.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ProjectEntry.java index a4cf6cb60..7e17ac66d 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ProjectEntry.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ProjectEntry.java @@ -27,6 +27,13 @@ import org.eclipse.jdt.internal.compiler.env.IModulePathEntry; */ public class ProjectEntry implements IModulePathEntry { + static boolean representsProject(IModulePathEntry entry, IJavaProject otherProject) { + if (entry instanceof ProjectEntry) { + return ((ProjectEntry) entry).project.equals(otherProject); + } + return false; + } + JavaProject project; public ProjectEntry(JavaProject project) { @@ -47,11 +54,6 @@ public class ProjectEntry implements IModulePathEntry { } @Override - public boolean equalsProject(IJavaProject otherProject) { - return this.project.equals(otherProject); - } - - @Override public boolean isAutomaticModule() { return false; } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java index fe57e9af0..56b4f5880 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java @@ -11,6 +11,7 @@ package org.eclipse.jdt.internal.core.builder; import java.io.IOException; +import java.util.function.Predicate; import java.util.zip.ZipFile; import org.eclipse.core.resources.IContainer; @@ -144,7 +145,7 @@ public boolean equals(Object o) { return this.binaryFolder.equals(dir.binaryFolder) && areAllModuleOptionsEqual(dir); } @Override -public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { +public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly, Predicate<String> moduleNameFilter) { if (!doesFileExist(binaryFileName, qualifiedPackageName, qualifiedBinaryFileName)) return null; // most common case IBinaryType reader = null; @@ -247,7 +248,7 @@ public String debugPathString() { @Override public NameEnvironmentAnswer findClass(String typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName) { // - return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false); + return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false, null); } } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJMod.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJMod.java index 812a4e2d9..1675f424d 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJMod.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJMod.java @@ -12,6 +12,7 @@ package org.eclipse.jdt.internal.core.builder; import java.io.IOException; import java.util.Enumeration; +import java.util.function.Predicate; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -61,8 +62,11 @@ public class ClasspathJMod extends ClasspathJar { } @Override - public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { + public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, + boolean asBinaryOnly, Predicate<String> moduleNameFilter) { if (!isPackage(qualifiedPackageName, moduleName)) return null; // most common case + if (moduleNameFilter != null && this.module != null && !moduleNameFilter.test(String.valueOf(this.module.name()))) + return null; try { qualifiedBinaryFileName = new String(CharOperation.append(CLASSES_FOLDER, qualifiedBinaryFileName.toCharArray())); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java index edafe379e..89d310cbf 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.IOException; import java.util.Date; import java.util.Enumeration; +import java.util.function.Predicate; import java.util.jar.Manifest; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -234,7 +235,7 @@ public boolean equals(Object o) { } @Override -public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { +public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly, Predicate<String> moduleNameFilter) { if (!isPackage(qualifiedPackageName, moduleName)) return null; // most common case try { @@ -359,7 +360,7 @@ public IModule getModule() { @Override public NameEnvironmentAnswer findClass(String typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName) { // - return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false); + return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false, null); } public Manifest getManifest() { scanContent(); // ensure zipFile is initialized diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java index e83dbaec9..80d378a70 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.function.Predicate; import java.util.zip.ZipFile; import org.eclipse.core.runtime.IPath; @@ -69,9 +70,9 @@ public ClasspathJrt(String zipFilename, AccessRuleSet accessRuleSet, IPath exter this.accessRuleSet = accessRuleSet; if (externalAnnotationPath != null) this.externalAnnotationPath = externalAnnotationPath.toString(); - if (compliance.length() == 0) { + if (compliance != null && compliance.length() == 0) { this.compliance = null; - } else { + } else { this.compliance = compliance; } initialize(); @@ -92,7 +93,7 @@ static HashMap<String, SimpleSet> findPackagesInModules(final ClasspathJrt jrt) PackageCache.put(zipFileName, packagesInModule); try { final File imageFile = new File(zipFileName); - org.eclipse.jdt.internal.compiler.util.JRTUtil.walkModuleImage(imageFile, + org.eclipse.jdt.internal.compiler.util.JRTUtil.walkModuleImage(imageFile, new org.eclipse.jdt.internal.compiler.util.JRTUtil.JrtFileVisitor<Path>() { SimpleSet packageSet = null; @Override @@ -180,7 +181,7 @@ public void initialize() { if (!Files.exists(filePath)) { return; } - URI uri = URI.create("jar:file:" + t.getPath()); //$NON-NLS-1$ + URI uri = URI.create("jar:file:" + t.getRawPath()); //$NON-NLS-1$ try { this.fs = FileSystems.getFileSystem(uri); } catch(FileSystemNotFoundException fne) { @@ -195,7 +196,7 @@ public void initialize() { return; } } - this.releasePath = this.fs.getPath(""); //$NON-NLS-1$ + this.releasePath = this.fs.getPath("/"); //$NON-NLS-1$ if (!Files.exists(this.fs.getPath(this.compliance)) || Files.exists(this.fs.getPath(this.compliance, "system-modules"))) { //$NON-NLS-1$ this.compliance = null; @@ -231,7 +232,7 @@ private String getReleaseOptionFromCompliance(String comp) { } } void acceptModule(byte[] content) { - if (content == null) + if (content == null) return; ClassFileReader reader = null; try { @@ -276,13 +277,14 @@ public boolean equals(Object o) { } @Override -public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { +public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, + boolean asBinaryOnly, Predicate<String> moduleNameFilter) { if (!isPackage(qualifiedPackageName, moduleName)) return null; // most common case try { IBinaryType reader = null; byte[] content = null; - String fileNameWithoutExtension = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - SuffixConstants.SUFFIX_CLASS.length); + String fileNameWithoutExtension = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - SuffixConstants.SUFFIX_CLASS.length); if (this.subReleases != null && this.subReleases.length > 0) { qualifiedBinaryFileName = qualifiedBinaryFileName.replace(".class", ".sig"); //$NON-NLS-1$ //$NON-NLS-2$ for (String rel : this.subReleases) { @@ -296,7 +298,7 @@ public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPa } } } else { - reader = ClassFileReader.readFromModule(new File(this.zipFilename), moduleName, qualifiedBinaryFileName); + reader = ClassFileReader.readFromModule(new File(this.zipFilename), moduleName, qualifiedBinaryFileName, moduleNameFilter); } if (reader != null) { if (this.externalAnnotationPath != null) { @@ -311,8 +313,8 @@ public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPa } if (this.accessRuleSet == null) return new NameEnvironmentAnswer(reader, null, reader.getModule()); - return new NameEnvironmentAnswer(reader, - this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray()), + return new NameEnvironmentAnswer(reader, + this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray()), reader.getModule()); } } catch (ClassFormatException e) { // treat as if class file is missing @@ -333,7 +335,7 @@ public int hashCode() { @Override public char[][] getModulesDeclaringPackage(String qualifiedPackageName, String moduleName) { List<String> moduleNames = JRTUtil.getModulesDeclaringPackage(new File(this.zipFilename), qualifiedPackageName, moduleName); - return CharOperation.toCharArrays(moduleNames); + return CharOperation.toCharArrays(moduleNames); } @Override public boolean hasCompilationUnit(String qualifiedPackageName, String moduleName) { @@ -355,9 +357,10 @@ public String debugPathString() { return this.zipFilename; } @Override -public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { +public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, + boolean asBinaryOnly, Predicate<String> moduleNameFilter) { String fileName = new String(typeName); - return findClass(fileName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, asBinaryOnly); + return findClass(fileName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, asBinaryOnly, moduleNameFilter); } @Override public boolean hasModule() { @@ -412,8 +415,8 @@ private void addRequired(String mod, Set<String> allModules) { } @Override public NameEnvironmentAnswer findClass(String typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName) { - // - return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false); + // + return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false, null); } /** TEST ONLY */ public static void resetCaches() { diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathLocation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathLocation.java index 042798145..f524946a9 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathLocation.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathLocation.java @@ -15,6 +15,7 @@ package org.eclipse.jdt.internal.core.builder; import java.util.List; import java.util.Set; import java.util.function.Consumer; +import java.util.function.Predicate; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; @@ -36,7 +37,8 @@ public abstract class ClasspathLocation { protected String patchModuleName = null; // In the following signatures, passing a null moduleName signals "don't care": abstract public NameEnvironmentAnswer findClass(String typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName); - abstract public NameEnvironmentAnswer findClass(String typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly); + abstract public NameEnvironmentAnswer findClass(String typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, + boolean asBinaryOnly, Predicate<String> moduleNameFilter); abstract public boolean isPackage(String qualifiedPackageName, String moduleName); public char[][] getModulesDeclaringPackage(String qualifiedPackageName, String moduleName) { return singletonModuleNameIf(isPackage(qualifiedPackageName, moduleName)); @@ -44,9 +46,10 @@ public abstract class ClasspathLocation { public boolean hasModule() { return getModule() != null; } abstract public boolean hasCompilationUnit(String pkgName, String moduleName); - public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { + public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, + boolean asBinaryOnly, Predicate<String> moduleNameFilter) { String fileName = new String(typeName); - return findClass(fileName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, asBinaryOnly); + return findClass(fileName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, asBinaryOnly, moduleNameFilter); } public void setModule (IModule mod) { this.module = mod; diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java index 5ad36c985..8498de94f 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java @@ -302,6 +302,9 @@ private void computeClasspathLocations( && JavaCore.IGNORE.equals(javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true))) ? null : entry.getAccessRuleSet(); + if (JavaCore.DISABLED.equals(javaProject.getOption(JavaCore.COMPILER_RELEASE, true))) { + compliance = null; + } ClasspathLocation bLocation = ClasspathLocation.forLibrary(path.toOSString(), accessRuleSet, externalAnnotationPath, isOnModulePath, compliance); bLocations.add(bLocation); if (moduleEntries != null) { @@ -498,7 +501,8 @@ private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeNam if (modulePathEntry instanceof ModulePathEntry) { relevantLocations = ((ModulePathEntry) modulePathEntry).getClasspathLocations(); } else if (modulePathEntry instanceof ClasspathLocation) { - return ((ClasspathLocation) modulePathEntry).findClass(typeName, qPackageName, moduleName, qBinaryFileName, false); + return ((ClasspathLocation) modulePathEntry).findClass(typeName, qPackageName, moduleName, qBinaryFileName, false, + null/*module already checked*/); } else { return null; } @@ -510,13 +514,9 @@ private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeNam if (!strategy.matches(classpathLocation, ClasspathLocation::hasModule)) { continue; } - NameEnvironmentAnswer answer = classpathLocation.findClass(binaryFileName, qPackageName, moduleName, qBinaryFileName, false); + NameEnvironmentAnswer answer = classpathLocation.findClass(binaryFileName, qPackageName, moduleName, qBinaryFileName, false, + this.modulePathEntries != null ? this.modulePathEntries::containsKey : null); if (answer != null) { - char[] answerMod = answer.moduleName(); - if (answerMod != null && this.modulePathEntries != null) { - if (!this.modulePathEntries.containsKey(String.valueOf(answerMod))) - continue; // assumed to be filtered out by --limit-modules - } if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) return answer; diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java index c7358290d..4a2682bcf 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ package org.eclipse.jdt.internal.core.search.matching; import java.util.Iterator; import java.util.Map; +import java.util.function.Predicate; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; @@ -110,7 +111,7 @@ public boolean equals(Object o) { } @Override -public NameEnvironmentAnswer findClass(String typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { +public NameEnvironmentAnswer findClass(String typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly, Predicate<String> moduleNameFilter) { return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName); } @Override diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/IndexBasedJavaSearchEnvironment.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/IndexBasedJavaSearchEnvironment.java index 7f9b1d15b..f0cb2a57d 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/IndexBasedJavaSearchEnvironment.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/IndexBasedJavaSearchEnvironment.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2017 Google, Inc and others. + * Copyright (c) 2015, 2018 Google, Inc and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -196,7 +196,9 @@ public class IndexBasedJavaSearchEnvironment implements INameEnvironment, Suffix sourceFileName, // doesn't include the file extension qPackageName, null, // TODO(SHMOD): don't have a module name, but while looking in unindexed classpath locations, this is probably OK - qSourceFileName); // doesn't include the file extension + qSourceFileName, // doesn't include the file extension + false, + null /*no module filtering on source dir*/); } } else { if (binaryFileName == null) { @@ -214,7 +216,9 @@ public class IndexBasedJavaSearchEnvironment implements INameEnvironment, Suffix binaryFileName, qPackageName, null, // TODO(SHMOD): don't have a module name, but while looking in unindexed classpath locations, this is probably OK - qBinaryFileName); + qBinaryFileName, + false, + null /*no module filtering, this env is not module aware*/); } if (answer != null) { if (!answer.ignoreIfBetter()) { diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchNameEnvironment.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchNameEnvironment.java index 05f5ebf85..480bb6e64 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchNameEnvironment.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchNameEnvironment.java @@ -250,7 +250,9 @@ private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeNam sourceFileName, // doesn't include the file extension qPackageName, moduleName, - qSourceFileName); // doesn't include the file extension + qSourceFileName, // doesn't include the file extension + false, + null /*no module filtering on source dir*/); } } else { if (binaryFileName == null) { @@ -268,7 +270,9 @@ private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeNam binaryFileName, qPackageName, moduleName, - qBinaryFileName); + qBinaryFileName, + false, + this.moduleLocations != null ? this.moduleLocations::containsKey : null); } if (answer != null) { if (!answer.ignoreIfBetter()) { |