diff options
author | Stephan Herrmann | 2021-11-02 15:02:07 +0000 |
---|---|---|
committer | Stephan Herrmann | 2021-11-02 15:02:07 +0000 |
commit | 57a500147822de7614b27477f163b6f47dba9137 (patch) | |
tree | f5383a5d359be837fb12e54a060f5ff56e9d4556 /org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt | |
parent | 92bbdc7002f4cbca40feebdf3e03543cfc1a92e5 (diff) | |
download | org.eclipse.objectteams-57a500147822de7614b27477f163b6f47dba9137.tar.gz org.eclipse.objectteams-57a500147822de7614b27477f163b6f47dba9137.tar.xz org.eclipse.objectteams-57a500147822de7614b27477f163b6f47dba9137.zip |
update jdt.core to I20211025-1800
Diffstat (limited to 'org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt')
13 files changed, 634 insertions, 14 deletions
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 076d52315..40b921720 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 @@ -876,6 +876,17 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases { ); } + protected void assertResourceOnClasspathEntry(IJavaProject project, IResource resource, String path) { + IClasspathEntry cp = project.findContainingClasspathEntry(resource); + assertNotNull("IClasspathEntry exists for the resource", cp); + assertEquals("In the expected classpath entry", path, cp.getPath().toPortableString()); + } + + protected void assertResourceNotOnClasspathEntry(IJavaProject project, IResource resource) { + IClasspathEntry cp = project.findContainingClasspathEntry(resource); + assertNull("IClasspathEntry does not exists for the resource", cp); + } + protected void assertResourceTreeEquals(String message, String expected, Object[] resources) throws CoreException { sortResources(resources); StringBuffer buffer = new StringBuffer(); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java index 8590fb38b..1d514561a 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java @@ -18,6 +18,7 @@ package org.eclipse.jdt.core.tests.model; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import org.eclipse.jdt.core.tests.compiler.CharDeduplicationTest; import org.eclipse.jdt.core.tests.compiler.map.CharArrayMapperTest; import org.eclipse.jdt.core.tests.junit.extension.TestCase; @@ -229,6 +230,8 @@ private static Class[] getAllTestClasses() { JavaModelManagerTests.class, CharArrayMapperTest.class, + + CharDeduplicationTest.class, }; Class[] deprecatedClasses = getDeprecatedJDOMTestClasses(); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java index 18fda7acd..0a9a3e920 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java @@ -2489,8 +2489,8 @@ public void test0090() throws JavaModelException { "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" + "completion token=\"\"\n" + "completion token kind=TOKEN_KIND_NAME\n" + - "expectedTypesSignatures=null\n" + - "expectedTypesKeys=null\n"+ + "expectedTypesSignatures={I}\n" + + "expectedTypesKeys={I}\n"+ "completion token location=UNKNOWN", result.context); } @@ -2545,8 +2545,8 @@ public void test0092() throws JavaModelException { "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" + "completion token=\"\"\n" + "completion token kind=TOKEN_KIND_NAME\n" + - "expectedTypesSignatures=null\n" + - "expectedTypesKeys=null\n"+ + "expectedTypesSignatures={I}\n" + + "expectedTypesKeys={I}\n"+ "completion token location=UNKNOWN", result.context); } @@ -2601,8 +2601,8 @@ public void test0094() throws JavaModelException { "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" + "completion token=\"\"\n" + "completion token kind=TOKEN_KIND_NAME\n" + - "expectedTypesSignatures=null\n" + - "expectedTypesKeys=null\n"+ + "expectedTypesSignatures={I}\n" + + "expectedTypesKeys={I}\n"+ "completion token location=UNKNOWN", result.context); } @@ -2657,8 +2657,8 @@ public void test0096() throws JavaModelException { "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" + "completion token=\"\"\n" + "completion token kind=TOKEN_KIND_NAME\n" + - "expectedTypesSignatures=null\n" + - "expectedTypesKeys=null\n"+ + "expectedTypesSignatures={I}\n" + + "expectedTypesKeys={I}\n"+ "completion token location=UNKNOWN", result.context); } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java index cd84004ab..b0e1172b8 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java @@ -13324,6 +13324,7 @@ public void testCompletionPrefixMethodName3() throws JavaModelException { int tEnd = tStart; assertResults( + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, replace["+tStart+", "+tEnd+"], token["+tStart+", "+tEnd+"], 52}\n" + "xBar[METHOD_REF]{CompletionPrefixMethodName3.this.xBar(1,, LCompletionPrefixMethodName3;, (II)I, xBar, (a, b), replace["+rStart1+", "+rEnd1+"], token["+tStart+", "+tEnd+"], "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME+ R_NON_RESTRICTED)+"}\n"+ "xBar[METHOD_REF]{, LCompletionPrefixMethodName3$classFoo;, (II)I, xBar, (a, b), replace["+rStart2+", "+rEnd2+"], token["+tStart+", "+tEnd+"], "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_UNQUALIFIED + R_NON_RESTRICTED)+"}", requestor.getResults()); @@ -19294,9 +19295,7 @@ public void testStaticMembers1() throws JavaModelException { "StaticMembers.StaticClazz[TYPE_REF]{StaticClazz, test, Ltest.StaticMembers$StaticClazz;, null, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_INHERITED + R_NON_RESTRICTED) + "}\n" + "class[FIELD_REF]{class, null, Ljava.lang.Class;, class, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_INHERITED + R_NON_RESTRICTED) + "}\n" + "staticField[FIELD_REF]{staticField, Ltest.StaticMembers;, I, staticField, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_INHERITED + R_NON_RESTRICTED) + "}\n" + - "staticMethod[METHOD_REF]{staticMethod(), Ltest.StaticMembers;, ()I, staticMethod, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_INHERITED + R_NON_RESTRICTED) + "}\n" + - "super[KEYWORD]{super, null, null, super, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_INHERITED + R_NON_RESTRICTED) + "}\n" + - "this[KEYWORD]{this, null, null, this, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_INHERITED + R_NON_RESTRICTED) + "}", + "staticMethod[METHOD_REF]{staticMethod(), Ltest.StaticMembers;, ()I, staticMethod, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_INHERITED + R_NON_RESTRICTED) + "}", requestor.getResults()); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99631 diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java index 90aad655c..a3c593dbc 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java @@ -26,6 +26,7 @@ import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.eval.IEvaluationContext; import org.eclipse.jdt.internal.codeassist.RelevanceConstants; @@ -242,7 +243,8 @@ public void test006b() throws JavaModelException { int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); assertResults( - "argument[LOCAL_VARIABLE_REF]{argument, null, Ljava.lang.Object;, argument, null, " + (R_DEFAULT + 21) + "}", // FIXME should be "I" and 22 like test006 + "argument[LOCAL_VARIABLE_REF]{argument, null, Ljava.lang.Object;, argument, null, 51}\n" // FIXME should be "I" and 22 like test006 + + "[LAMBDA_EXPRESSION]{->, LI;, (I)I, foo, (x), 89}", requestor.getResults()); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=405126, [1.8][code assist] Lambda parameters incorrectly recovered as fields. @@ -5948,8 +5950,8 @@ public void testBug574912_comment6() throws JavaModelException { int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); String result = requestor.getResults(); - assertResults("getMinimum[METHOD_REF]{, Ljava.util.Calendar;, (I)I, getMinimum, (arg0), 86}", - result); + assertResults("num[FIELD_REF]{num, LLambdaFreeze2;, I, num, null, 52}\n" + + "getMinimum[METHOD_REF]{, Ljava.util.Calendar;, (I)I, getMinimum, (arg0), 86}", result); } public void testBug574912_comment6b() throws JavaModelException { this.workingCopies = new ICompilationUnit[1]; @@ -6024,4 +6026,163 @@ public void testBug574882() throws Exception { "completion token location={STATEMENT_START}", // this is required for sysout template proposal requestor.getContext()); } +public void testBug575149_expectOverloadedMethodsAndVariablesRankedWithExpectedType() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "Completion/src/Bug443091.java", + "import java.util.function.Consumer;\n" + + "import java.util.function.Function;\n" + + "\n" + + "public class Bug443091 {\n" + + " private void foo() {\n" + + " Consumer<Integer> capture = null;\n" + + " forEach()" + + " }\n" + + " private void forEach(Consumer<Integer> in) {}\n" + + " private void forEach(Function<Integer, String> in) {}\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "forEach("; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + String result = requestor.getResults(); + assertResults( + "capture[LOCAL_VARIABLE_REF]{capture, null, Ljava.util.function.Consumer<Ljava.lang.Integer;>;, capture, null, 52}\n" + + "forEach[METHOD_REF]{, LBug443091;, (Ljava.util.function.Consumer<Ljava.lang.Integer;>;)V, forEach, (in), 56}\n" + + "forEach[METHOD_REF]{, LBug443091;, (Ljava.util.function.Function<Ljava.lang.Integer;Ljava.lang.String;>;)V, forEach, (in), 56}\n" + + "[LAMBDA_EXPRESSION]{->, Ljava.util.function.Function<Ljava.lang.Integer;Ljava.lang.String;>;, (Ljava.lang.Integer;)Ljava.lang.String;, apply, (arg0), 89}\n" + + "[LAMBDA_EXPRESSION]{->, Ljava.util.function.Consumer<Ljava.lang.Integer;>;, (Ljava.lang.Integer;)V, accept, (t), 89}", + result); + assertTrue("expected type signatures don't match", CharOperation.equals(requestor.getExpectedTypesSignatures(), + new char[][] {"Ljava.util.function.Function<Ljava.lang.Integer;Ljava.lang.String;>;".toCharArray(), + "Ljava.util.function.Consumer<Ljava.lang.Integer;>;".toCharArray()}, true)); +} +public void testBug575149_expectRemainingOverloadedMethodsMatchingFilledArguments() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "Completion/src/Bug443091.java", + "import java.util.function.Consumer;\n" + + "import java.util.function.Function;\n" + + "\n" + + "public class Bug443091 {\n" + + " private void foo() {\n" + + " Consumer<Integer> capture = null;\n" + + " forEach(capture, )" + + " }\n" + + " private void forEach(Consumer<Integer> in) {}\n" + + " private void forEach(Consumer<Integer> in, Integer limit) {}\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "forEach(capture,"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + String result = requestor.getResults(); + assertResults("hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, 52}\n" + + "forEach[METHOD_REF]{, LBug443091;, (Ljava.util.function.Consumer<Ljava.lang.Integer;>;)V, forEach, (in), 56}\n" + + "forEach[METHOD_REF]{, LBug443091;, (Ljava.util.function.Consumer<Ljava.lang.Integer;>;Ljava.lang.Integer;)V, forEach, (in, limit), 56}", + result); + assertTrue("expected type signatures don't match", CharOperation.equals(requestor.getExpectedTypesSignatures(), new char[][] {"Ljava.lang.Integer;".toCharArray()}, true)); +} +public void testBug575149_expectOverloadsOverEnumLiterals() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "Completion/src/Bug443091.java", + "import java.util.function.Consumer;\n" + + "import java.util.function.Function;\n" + + "\n" + + "public class Bug443091 {\n" + + " private void foo() {\n" + + " Consumer<Integer> capture = null;\n" + + " forEach(capture, )" + + " }\n" + + " private Thread.State defaultState() { return null;} \n" + + " private void forEach(Consumer<Integer> in, Thread.State state) {}\n" + + " private void forEach(Consumer<Integer> in, Thread.State state, Integer limit) {}\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "forEach(capture,"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + String result = requestor.getResults(); + assertResults("BLOCKED[FIELD_REF]{State.BLOCKED, Ljava.lang.Thread$State;, Ljava.lang.Thread$State;, BLOCKED, null, 49}\n" + + "NEW[FIELD_REF]{State.NEW, Ljava.lang.Thread$State;, Ljava.lang.Thread$State;, NEW, null, 49}\n" + + "RUNNABLE[FIELD_REF]{State.RUNNABLE, Ljava.lang.Thread$State;, Ljava.lang.Thread$State;, RUNNABLE, null, 49}\n" + + "TERMINATED[FIELD_REF]{State.TERMINATED, Ljava.lang.Thread$State;, Ljava.lang.Thread$State;, TERMINATED, null, 49}\n" + + "TIMED_WAITING[FIELD_REF]{State.TIMED_WAITING, Ljava.lang.Thread$State;, Ljava.lang.Thread$State;, TIMED_WAITING, null, 49}\n" + + "WAITING[FIELD_REF]{State.WAITING, Ljava.lang.Thread$State;, Ljava.lang.Thread$State;, WAITING, null, 49}\n" + + "defaultState[METHOD_REF]{defaultState(), LBug443091;, ()Ljava.lang.Thread$State;, defaultState, null, 52}\n" + + "forEach[METHOD_REF]{, LBug443091;, (Ljava.util.function.Consumer<Ljava.lang.Integer;>;Ljava.lang.Thread$State;)V, forEach, (in, state), 56}\n" + + "forEach[METHOD_REF]{, LBug443091;, (Ljava.util.function.Consumer<Ljava.lang.Integer;>;Ljava.lang.Thread$State;Ljava.lang.Integer;)V, forEach, (in, state, limit), 56}", + result); + assertTrue("expected type signatures don't match", CharOperation.equals(requestor.getExpectedTypesSignatures(), new char[][] {"Ljava.lang.Thread$State;".toCharArray()}, true)); +} +public void testBug443091_expectLambdaCompletions_forFunctionalInterfaceArgumentAssignment() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "Completion/src/Bug443091.java", + "import java.util.function.Consumer;\n" + + "\n" + + "public class Bug443091 {\n" + + " private void foo() {\n" + + " forEach(capture)" + + " }\n" + + " private void forEach(Consumer<Integer> in) {}\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "forEach("; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + String result = requestor.getResults(); + assertResults("forEach[METHOD_REF]{, LBug443091;, (Ljava.util.function.Consumer<Ljava.lang.Integer;>;)V, forEach, (in), 56}\n" + + "[LAMBDA_EXPRESSION]{->, Ljava.util.function.Consumer<Ljava.lang.Integer;>;, (Ljava.lang.Integer;)V, accept, (t), 89}", + result); +} +public void testBug443091_expectLambdaCompletions_forFunctionalInterfaceVariableAssigments() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "Completion/src/Bug443091.java", + "import java.util.function.Consumer;\n" + + "\n" + + "public class Bug443091 {\n" + + " private void foo() {\n" + + " Consumer<Integer> in = \n" + + " }\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "in ="; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + String result = requestor.getResults(); + assertResults("finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, finalize, null, 47}\n" + + "foo[METHOD_REF]{foo(), LBug443091;, ()V, foo, null, 47}\n" + + "notify[METHOD_REF]{notify(), Ljava.lang.Object;, ()V, notify, null, 47}\n" + + "notifyAll[METHOD_REF]{notifyAll(), Ljava.lang.Object;, ()V, notifyAll, null, 47}\n" + + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, ()V, wait, null, 47}\n" + + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (J)V, wait, (millis), 47}\n" + + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (JI)V, wait, (millis, nanos), 47}\n" + + "Bug443091[TYPE_REF]{Bug443091, , LBug443091;, null, null, 52}\n" + + "clone[METHOD_REF]{clone(), Ljava.lang.Object;, ()Ljava.lang.Object;, clone, null, 52}\n" + + "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), 52}\n" + + "getClass[METHOD_REF]{getClass(), Ljava.lang.Object;, ()Ljava.lang.Class<*>;, getClass, null, 52}\n" + + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, 52}\n" + + "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, 52}\n" + + "Consumer<java.lang.Integer>[TYPE_REF]{Consumer, java.util.function, Ljava.util.function.Consumer<Ljava.lang.Integer;>;, null, null, 82}\n" + + "[LAMBDA_EXPRESSION]{->, Ljava.util.function.Consumer<Ljava.lang.Integer;>;, (Ljava.lang.Integer;)V, accept, (t), 89}", + result); +} } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests2.java index 9ac305f2b..ae1ae0677 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests2.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests2.java @@ -6489,4 +6489,110 @@ public void test479656() throws Exception { deleteProject("P"); } } +public void testBug575562_AccessRestrictionCheck_ENABLED() throws Exception { + Hashtable oldOptions = JavaCore.getOptions(); + try { + Hashtable options = new Hashtable(oldOptions); + options.put(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, JavaCore.ERROR); + options.put(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, JavaCore.ENABLED); + options.put(JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK, JavaCore.DISABLED); + JavaCore.setOptions(options); + setUpJavaProject("AccessRestrictions", "1.4", false); + createJavaProject( + "P1", + new String[] {"src"}, + new String[] {"JCL_LIB", "/AccessRestrictions/lib.jar"}, + new String[][]{{}, {}}, + new String[][]{{}, {"**/*"}}, + null/*no project*/, + null/*no inclusion pattern*/, + null/*no exclusion pattern*/, + null/*no exported project*/, + "bin", + null/*no source outputs*/, + null/*no inclusion pattern*/, + null/*no exclusion pattern*/, + "1.4"); + this.createFolder("/P1/src/p11"); + this.createFile( + "/P1/src/p11/Y11.java", + "package p11;\n"+ + "public class YY11 {\n"+ + " void foo() {\n"+ + " X\n"+ + " }\n"+ + "}"); + waitUntilIndexesReady(); + + // do completion + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(); + ICompilationUnit cu= getCompilationUnit("P1", "src", "p11", "Y11.java"); + + String str = cu.getSource(); + String completeBehind = "X"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + cu.codeComplete(cursorLocation, requestor); + + assertResults( + "", + requestor.getResults()); + } finally { + this.deleteProject("AccessRestrictions"); + this.deleteProject("P1"); + JavaCore.setOptions(oldOptions); + } +} +public void testBug575562_AccessRestrictionCheck_DISABLED() throws Exception { + Hashtable oldOptions = JavaCore.getOptions(); + try { + Hashtable options = new Hashtable(oldOptions); + options.put(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, JavaCore.ERROR); + options.put(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, JavaCore.DISABLED); + options.put(JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK, JavaCore.DISABLED); + JavaCore.setOptions(options); + setUpJavaProject("AccessRestrictions", "1.4", false); + createJavaProject( + "P1", + new String[] {"src"}, + new String[] {"JCL_LIB", "/AccessRestrictions/lib.jar"}, + new String[][]{{}, {}}, + new String[][]{{}, {"**/*"}}, + null/*no project*/, + null/*no inclusion pattern*/, + null/*no exclusion pattern*/, + null/*no exported project*/, + "bin", + null/*no source outputs*/, + null/*no inclusion pattern*/, + null/*no exclusion pattern*/, + "1.4"); + this.createFolder("/P1/src/p11"); + this.createFile( + "/P1/src/p11/Y11.java", + "package p11;\n"+ + "public class YY11 {\n"+ + " void foo() {\n"+ + " X\n"+ + " }\n"+ + "}"); + waitUntilIndexesReady(); + + // do completion + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(); + ICompilationUnit cu= getCompilationUnit("P1", "src", "p11", "Y11.java"); + + String str = cu.getSource(); + String completeBehind = "X"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + cu.codeComplete(cursorLocation, requestor); + + assertResults( + "X[TYPE_REF]{p.X, p, Lp.X;, null, 50}", + requestor.getResults()); + } finally { + this.deleteProject("AccessRestrictions"); + this.deleteProject("P1"); + JavaCore.setOptions(oldOptions); + } +} } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests3.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests3.java index d6b8dd60f..a18ac50a1 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests3.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests3.java @@ -1190,6 +1190,7 @@ public void testBug575397a() throws Exception { int cursorLocation = str.indexOf(completeAfter) + completeAfter.length(); this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); assertResults( + "class[FIELD_REF]{class, null, Ljava.lang.Class<LThread;>;, class, null, 51}\n" + "sleep[METHOD_REF]{sleep(), LThread;, (I)V, sleep, (millis), 51}", requestor.getResults()); } finally { @@ -1255,6 +1256,7 @@ public void testBug575397c() throws Exception { "serialVersionUID[FIELD_REF]{serialVersionUID, Ljava.lang.Enum<LThread$State;>;, J, serialVersionUID, null, 49}\n" + "BLOCKED[FIELD_REF]{BLOCKED, LThread$State;, LThread$State;, BLOCKED, null, 51}\n" + "NEW[FIELD_REF]{NEW, LThread$State;, LThread$State;, NEW, null, 51}\n" + + "class[FIELD_REF]{class, null, Ljava.lang.Class<LThread$State;>;, class, null, 51}\n" + "valueOf[METHOD_REF]{valueOf(), LThread$State;, (Ljava.lang.String;)LThread$State;, valueOf, (arg0), 51}\n" + "values[METHOD_REF]{values(), LThread$State;, ()[LThread$State;, values, null, 51}", requestor.getResults()); @@ -1262,4 +1264,259 @@ public void testBug575397c() throws Exception { deleteProject("P"); } } +public void testBug575631_comment0() throws Exception { + try { + createJavaProject("P", new String[] {"src"}, new String[]{"JCL11_LIB"}, "bin", "11"); + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/P/src/ContentAssist.java", + "import java.util.Calendar;\n" + + "class ZoneId {}\n" + + "class LocalDateTime {\n" + + " static LocalDateTime now() { return null; }\n" + + " static LocalDateTime now(ZoneId id) { return null; }\n" + + "}\n" + + "public class ContentAssist {\n" + + " public static void staticMethod() {\n" + + " if (true) {\n" + + " LocalDateTime.now\n" + + " Calendar calendar = Calendar.getInstance();\n" + + " }\n" + + " }\n" + + "}\n"); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeAfter = "LocalDateTime.now"; + int cursorLocation = str.indexOf(completeAfter) + completeAfter.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + assertResults( + "now[METHOD_REF]{now(), LLocalDateTime;, ()LLocalDateTime;, now, null, 55}\n" + + "now[METHOD_REF]{now(), LLocalDateTime;, (LZoneId;)LLocalDateTime;, now, (id), 55}", + requestor.getResults()); + } finally { + deleteProject("P"); + } +} +public void testBug575631_comment1a() throws Exception { + try { + createJavaProject("P", new String[] {"src"}, new String[]{"JCL11_LIB"}, "bin", "11"); + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/P/src/missing_proposals_for_static_fields_and_methods.java", + "\n" + + "class System {\n" + + " static Object out;\n" + + " static Object getEnv() { return null; }\n" + + "}\n" + + "class missing_proposals_for_static_fields_and_methods {\n" + + " void sample(String foo) {\n" + + " if (foo == null) {\n" + + " System. // <- missing: \"out\", \"getenv()\", etc. (similar to bug 574267)\n" + + " System.out.println();\n" + + " }\n" + + " System. // <- here content assist works fine\n" + + " }\n" + + "}\n"); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeAfter = "System."; + int cursorLocation = str.indexOf(completeAfter) + completeAfter.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + assertResults( + "class[FIELD_REF]{class, null, Ljava.lang.Class<LSystem;>;, class, null, 51}\n" + + "getEnv[METHOD_REF]{getEnv(), LSystem;, ()Ljava.lang.Object;, getEnv, null, 51}\n" + + "out[FIELD_REF]{out, LSystem;, Ljava.lang.Object;, out, null, 51}", + requestor.getResults()); + } finally { + deleteProject("P"); + } +} +public void testBug575631_comment1b() throws Exception { + try { + createJavaProject("P", new String[] {"src"}, new String[]{"JCL11_LIB"}, "bin", "11"); + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/P/src/missing_proposals_for_static_fields_and_methods.java", + "\n" + + "class System {\n" + + " static Object out;\n" + + " static Object getEnv() { return null; }\n" + + "}\n" + + "class missing_proposals_for_static_fields_and_methods {\n" + + " void sample(String foo) {\n" + + " if (foo == null) {\n" + + " sample(\"\");\n" + + " } else {\n" + + " System. // <- missing: \"out\", \"getenv()\", etc. (similar to bug 574215)\n" + + " System.out.println();\n" + + " }\n" + + " System. // <- here content assist works fine\n" + + " }\n" + + "}\n"); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeAfter = "System."; + int cursorLocation = str.indexOf(completeAfter) + completeAfter.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + assertResults( + "class[FIELD_REF]{class, null, Ljava.lang.Class<LSystem;>;, class, null, 51}\n" + + "getEnv[METHOD_REF]{getEnv(), LSystem;, ()Ljava.lang.Object;, getEnv, null, 51}\n" + + "out[FIELD_REF]{out, LSystem;, Ljava.lang.Object;, out, null, 51}", + requestor.getResults()); + } finally { + deleteProject("P"); + } +} +public void testBug575631_comment3() throws Exception { + try { + createJavaProject("P", new String[] {"src"}, new String[]{"JCL11_LIB"}, "bin", "11"); + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/P/src/X.java", + "class OutputStream {\n" + + " void println() {}\n" + + "}\n" + + "interface Runnable { void run(); }\n" + + "class System {\n" + + " static OutputStream out;\n" + + " static Object getEnv() { return null; }\n" + + "}\n" + + "class X {\n" + + " void foo() {\n" + + " Runnable r = () -> {\n" + + " System.out.\n" + + " System.out.println();\n" + + " };\n" + + " }\n" + + "}\n"); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeAfter = "System.out."; + int cursorLocation = str.indexOf(completeAfter) + completeAfter.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + assertResults( + "clone[METHOD_REF]{clone(), Ljava.lang.Object;, ()Ljava.lang.Object;, clone, null, 60}\n" + + "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), 60}\n" + + "finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, finalize, null, 60}\n" + + "getClass[METHOD_REF]{getClass(), Ljava.lang.Object;, ()Ljava.lang.Class<+Ljava.lang.Object;>;, getClass, null, 60}\n" + + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, 60}\n" + + "notify[METHOD_REF]{notify(), Ljava.lang.Object;, ()V, notify, null, 60}\n" + + "notifyAll[METHOD_REF]{notifyAll(), Ljava.lang.Object;, ()V, notifyAll, null, 60}\n" + + "println[METHOD_REF]{println(), LOutputStream;, ()V, println, null, 60}\n" + + "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, 60}\n" + + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, ()V, wait, null, 60}\n" + + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (J)V, wait, (millis), 60}\n" + + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (JI)V, wait, (millis, nanos), 60}", + requestor.getResults()); + } finally { + deleteProject("P"); + } +} +public void testBug575631_comment3b() throws Exception { + // method invocation inside lambda in field initializer + try { + createJavaProject("P", new String[] {"src"}, new String[]{"JCL11_LIB"}, "bin", "11"); + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/P/src/X.java", + "class OutputStream {\n" + + " void println() {}\n" + + "}\n" + + "interface Runnable { void run(); }\n" + + "class System {\n" + + " static OutputStream out;\n" + + " static Object getEnv() { return null; }\n" + + "}\n" + + "class X {\n" + + " Runnable r = () -> {\n" + + " System.out.\n" + + " System.out.println();\n" + + " };\n" + + "}\n"); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeAfter = "System.out."; + int cursorLocation = str.indexOf(completeAfter) + completeAfter.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + assertResults( + "clone[METHOD_REF]{clone(), Ljava.lang.Object;, ()Ljava.lang.Object;, clone, null, 60}\n" + + "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), 60}\n" + + "finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, finalize, null, 60}\n" + + "getClass[METHOD_REF]{getClass(), Ljava.lang.Object;, ()Ljava.lang.Class<+Ljava.lang.Object;>;, getClass, null, 60}\n" + + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, 60}\n" + + "notify[METHOD_REF]{notify(), Ljava.lang.Object;, ()V, notify, null, 60}\n" + + "notifyAll[METHOD_REF]{notifyAll(), Ljava.lang.Object;, ()V, notifyAll, null, 60}\n" + + "println[METHOD_REF]{println(), LOutputStream;, ()V, println, null, 60}\n" + + "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, 60}\n" + + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, ()V, wait, null, 60}\n" + + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (J)V, wait, (millis), 60}\n" + + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (JI)V, wait, (millis, nanos), 60}", + requestor.getResults()); + } finally { + deleteProject("P"); + } +} +public void testBug575631_comment3c() throws Exception { + // variable declaration in lambda in field initializer + try { + createJavaProject("P", new String[] {"src"}, new String[]{"JCL11_LIB"}, "bin", "11"); + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/P/src/X.java", + "class OutputStream {\n" + + " void println() {}\n" + + "}\n" + + "interface Consumer { void consume(int); }\n" + + "class Number{}\n" + + "class System {\n" + + " static OutputStream out;\n" + + " static Object getEnv() { return null; }\n" + + "}\n" + + "class X {\n" + + " Consumer r = (int number) -> {\n" + + " Number \n" + + " System.out.println();\n" + + " };\n" + + "}\n"); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeAfter = "Number "; + int cursorLocation = str.indexOf(completeAfter) + completeAfter.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + assertResults( + "number[VARIABLE_DECLARATION]{number, null, LNumber;, number, null, 48}", // FIXME: should be number2 => https://bugs.eclipse.org/576781 + requestor.getResults()); + } finally { + deleteProject("P"); + } +} +public void testBug575631_comment3d() throws Exception { + // first of two arguments in method invocation in lambda in field initializer + // overloads should be selected by the existing second argument + // no separating ',' yet. + try { + createJavaProject("P", new String[] {"src"}, new String[]{"JCL11_LIB"}, "bin", "11"); + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/P/src/X.java", + "interface BiConsumer { void consume(int,boolean); }\n" + + "class X {\n" + + " BiConsumer r = (int number, boolean bool) -> {\n" + + " bar( number);\n" + + " };\n" + + " void bar(int i, String s) {}\n" + + " void bar(boolean b, int j) {}\n" + + "}\n"); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeAfter = "bar("; + int cursorLocation = str.indexOf(completeAfter) + completeAfter.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + assertResults( + "bar[METHOD_REF]{, LX;, (ZI)V, bar, (b, j), 56}", // select overload with int as 2nd arg + requestor.getResults()); + } finally { + deleteProject("P"); + } +} } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java index 072cbe50d..48a203c57 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java @@ -438,6 +438,9 @@ public class CompletionTestsRequestor2 extends CompletionRequestor { case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION : buffer.append("ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION"); //$NON-NLS-1$ break; + case CompletionProposal.LAMBDA_EXPRESSION : + buffer.append("LAMBDA_EXPRESSION"); //$NON-NLS-1$ + break; default : buffer.append("PROPOSAL"); //$NON-NLS-1$ break; @@ -709,4 +712,8 @@ public class CompletionTestsRequestor2 extends CompletionRequestor { } return null; } + + public char[][] getExpectedTypesSignatures() { + return this.context.getExpectedTypesSignatures(); + } } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java index a3962cb39..44b931943 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java @@ -11609,6 +11609,7 @@ public void test0360() throws JavaModelException { this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); assertResults( + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" + "get[METHOD_REF]{, Ltest.util.List<Ljava.lang.String;>;, (I)Ljava.lang.String;, get, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_UNQUALIFIED + R_NON_RESTRICTED) + "}", requestor.getResults()); } @@ -11676,6 +11677,7 @@ public void test0362() throws JavaModelException { this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); assertResults( + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" + "abs[METHOD_REF]{, Ltest.util.Math;, (I)I, abs, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_UNQUALIFIED + R_NON_RESTRICTED) + "}", requestor.getResults()); } @@ -11706,6 +11708,7 @@ public void test0363() throws JavaModelException { this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); assertResults( + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" + "abs[METHOD_REF]{, Ltest.util.Math;, (I)I, abs, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_UNQUALIFIED + R_NON_RESTRICTED) + "}", requestor.getResults()); } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExclusionPatternsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExclusionPatternsTests.java index 028b7ad48..0222e0dab 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExclusionPatternsTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExclusionPatternsTests.java @@ -435,6 +435,8 @@ public void testIsOnClasspath1() throws CoreException { ICompilationUnit cu = getCompilationUnit("/P/src/p/A.java"); assertTrue("CU should be on classpath", this.project.isOnClasspath(cu)); + + assertResourceOnClasspathEntry(this.project, file, "/P/src"); } /* * Ensures that a cu that is excluded is not on the classpath of the project. @@ -450,6 +452,8 @@ public void testIsOnClasspath2() throws CoreException { ); assertTrue("Resource should not be on classpath", !this.project.isOnClasspath(file)); + assertResourceNotOnClasspathEntry(this.project, file); + ICompilationUnit cu = getCompilationUnit("/P/src/p/A.java"); assertTrue("CU should not be on classpath", !this.project.isOnClasspath(cu)); } @@ -461,6 +465,8 @@ public void testIsOnClasspath3() throws CoreException { createFolder("/P/src/p"); IFile file = createFile("/P/src/p/readme.txt", ""); assertTrue("Resource should be on classpath", this.project.isOnClasspath(file)); + + assertResourceOnClasspathEntry(this.project, file, "/P/src"); } /* * Ensures that a non-java resource that is excluded is not on the classpath of the project. @@ -470,6 +476,8 @@ public void testIsOnClasspath4() throws CoreException { createFolder("/P/src/p"); IFile file = createFile("/P/src/p/readme.txt", ""); assertTrue("Resource should not be on classpath", !this.project.isOnClasspath(file)); + + assertResourceNotOnClasspathEntry(this.project, file); } /* * Ensures that an excluded nested source folder doesn't appear as a non-java resource of the outer folder. diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/InclusionPatternsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/InclusionPatternsTests.java index 5d2c0bada..19c2b4080 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/InclusionPatternsTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/InclusionPatternsTests.java @@ -537,6 +537,8 @@ public void testIsOnClasspath1() throws CoreException { ); assertTrue("Resource should not be on classpath", !this.project.isOnClasspath(file)); + assertResourceNotOnClasspathEntry(this.project, file); + ICompilationUnit cu = getCompilationUnit("/P/src/p/A.java"); assertTrue("CU should not be on classpath", !this.project.isOnClasspath(cu)); } @@ -554,6 +556,8 @@ public void testIsOnClasspath2() throws CoreException { ); assertTrue("Resource should be on classpath", this.project.isOnClasspath(file)); + assertResourceOnClasspathEntry(this.project, file, "/P/src"); + ICompilationUnit cu = getCompilationUnit("/P/src/p/A.java"); assertTrue("CU should be on classpath", this.project.isOnClasspath(cu)); } @@ -565,6 +569,7 @@ public void testIsOnClasspath3() throws CoreException { createFolder("/P/src/p"); IFile file = createFile("/P/src/p/readme.txt", ""); assertTrue("Resource should not be on classpath", !this.project.isOnClasspath(file)); + assertResourceNotOnClasspathEntry(this.project, file); } /* * Ensures that a non-java resource that is included is on the classpath of the project. @@ -574,6 +579,7 @@ public void testIsOnClasspath4() throws CoreException { createFolder("/P/src/p"); IFile file = createFile("/P/src/p/readme.txt", ""); assertTrue("Resource should be on classpath", this.project.isOnClasspath(file)); + assertResourceOnClasspathEntry(this.project, file, "/P/src"); } /* * Ensures that moving a folder that contains an included package reports the correct delta. diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests16.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests16.java index bdc899282..1eb2eceab 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests16.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests16.java @@ -193,4 +193,62 @@ public void _testBug570399_002() throws Exception { deleteProject(p); } } +public void testBug576448_001() throws Exception { + if (!isJRE16) + return; + IJavaProject p = createJava16Project("p"); + createFolder("/p/src/a"); + try { + createFile("p/src/a/X.java", + "package a;\n"+ + "import a.Interface.NestedInterface;\n"+ + "import a.Interface.NestedInterface2;\n"+ + "\n"+ + "public record X(String someString, NestedInterface someInterface) implements NestedInterface2 {\n"+ + " public X(NestedInterface someInterface) {\n"+ + " this(null, someInterface); // <- error here\n"+ + " }\n"+ + " public X(String someString, NestedInterface someInterface) {\n"+ + " this.someString = someString;\n"+ + " this.someInterface = someInterface;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(\"hello\");\n"+ + " }\n"+ + "}"); + createFile("p/src/a/Interface.java", + "package a;\n"+ + "public interface Interface {\n"+ + " interface NestedInterface {\n"+ + " }\n"+ + " interface NestedInterface2 {\n"+ + " String someString();\n"+ + " NestedInterface someInterface();\n"+ + " static NestedInterface2 create(String s, NestedInterface n) {\n"+ + " return new X(s, n);\n"+ + " }\n"+ + " static NestedInterface2 create(NestedInterface n) {\n"+ + " return new X(n);\n"+ + " }\n"+ + " }\n"+ + "}"); + + p.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); + IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + assertMarkers("markers in p", + "", + markers); + + this.workingCopy = getCompilationUnit("p/src/X.java").getWorkingCopy(this.wcOwner, null); + this.problemRequestor.initialize(this.workingCopy.getSource().toCharArray()); + this.workingCopy.reconcile(JLS_LATEST, true, this.wcOwner, null); + assertProblems("Expecting no problems", + "----------\n" + + "----------\n", + this.problemRequestor); + this.workingCopy.discardWorkingCopy(); + } finally { + deleteProject(p); + } +} } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SubwordCompletionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SubwordCompletionTests.java index d3773047b..a6e80433a 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SubwordCompletionTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SubwordCompletionTests.java @@ -897,6 +897,7 @@ public void testDontPreventInsertionOfExactMatch() throws JavaModelException { this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); assertResults( + "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED ) + "}\n" + "put[METHOD_REF]{, Ljava.util.Map<Ljava.lang.String;Ljava.lang.String;>;, (Ljava.lang.String;Ljava.lang.String;)Ljava.lang.String;, put, (key, value), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED ) + "}", requestor.getResults()); } |