Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian Honnen2020-05-12 10:07:24 +0000
committerJulian Honnen2020-05-12 13:38:22 +0000
commitf9f9c212151b509b8e4a2cb93adba21fc546d492 (patch)
tree3dcfbdecfaaa67cd15257646d18632571d2761e9
parent1da17a63369d617b3654f6410ae0c21ac63dcc5b (diff)
downloadeclipse.jdt.core-f9f9c212151b509b8e4a2cb93adba21fc546d492.tar.gz
eclipse.jdt.core-f9f9c212151b509b8e4a2cb93adba21fc546d492.tar.xz
eclipse.jdt.core-f9f9c212151b509b8e4a2cb93adba21fc546d492.zip
Bug 563010 - propose static interface methods on missing types
NameReference::isTypeAccess returned false for problem bindings. That breaks MethodBinding::canBeSeenBy for static interface methods on missing types. Changed NameReference::isTypeAccess to check the binding's kind instead of its type. Change-Id: Iab438a4b1061097ed0bda891a06fd6b6c5471ba3 Signed-off-by: Julian Honnen <julian.honnen@vector.com>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionWithMissingTypesTests_1_8.java93
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java1
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/NameReference.java4
3 files changed, 96 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionWithMissingTypesTests_1_8.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionWithMissingTypesTests_1_8.java
new file mode 100644
index 0000000000..1c9b27abab
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionWithMissingTypesTests_1_8.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Julian Honnen.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Julian Honnen - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.model;
+
+import java.util.Hashtable;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+
+import junit.framework.Test;
+
+public class CompletionWithMissingTypesTests_1_8 extends AbstractJavaModelCompletionTests {
+
+public CompletionWithMissingTypesTests_1_8(String name) {
+ super(name);
+}
+@Override
+public void setUpSuite() throws Exception {
+ if (COMPLETION_PROJECT == null) {
+ COMPLETION_PROJECT = setUpJavaProject("Completion", "1.8");
+ } else {
+ setUpProjectCompliance(COMPLETION_PROJECT, "1.8");
+ }
+ super.setUpSuite();
+}
+static {
+// TESTS_NAMES = new String[] { "testZZZ"};
+}
+public static Test suite() {
+ return buildModelTestSuite(CompletionWithMissingTypesTests_1_8.class);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=563010
+public void testStaticInterfaceMethod() throws JavaModelException {
+ this.oldOptions = JavaCore.getOptions();
+
+ try {
+ Hashtable<String, String> options = new Hashtable<>(this.oldOptions);
+ options.put(JavaCore.CODEASSIST_VISIBILITY_CHECK, JavaCore.ENABLED);
+ JavaCore.setOptions(options);
+
+ this.workingCopies = new ICompilationUnit[3];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Test.java",
+ "package test;"+
+ "public class Test {\n" +
+ " void foo() {\n" +
+ " MissingType.foo\n" +
+ " }\n" +
+ "}\n");
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Completion/src/missing/MissingType.java",
+ "package missing;"+
+ "public interface MissingType {\n" +
+ " void foo1()\n" +
+ " static void foo2() {}\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "MissingType.foo";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_INHERITED + R_NON_RESTRICTED
+ + R_NO_PROBLEMS;
+ int start1 = str.lastIndexOf("MissingType.") + "MissingType.".length();
+ int end1 = start1 + "foo".length();
+ int start2 = str.indexOf("MissingType");
+ int end2 = start2 + "MissingType".length();
+ assertResults(
+ "foo2[METHOD_REF]{foo2(), Lmissing.MissingType;, ()V, foo2, null, ["+start1+", "+end1+"], " + (relevance1) + "}\n" +
+ " MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}",
+ requestor.getResults());
+ } finally {
+ JavaCore.setOptions(this.oldOptions);
+ }
+}
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java
index ceb49bcfa7..2f21415578 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/RunCompletionModelTests.java
@@ -47,6 +47,7 @@ public class RunCompletionModelTests extends junit.framework.TestCase {
COMPLETION_SUITES.add(CompletionWithMissingTypesTests.class);
COMPLETION_SUITES.add(CompletionWithMissingTypesTests2.class);
COMPLETION_SUITES.add(CompletionWithMissingTypesTests_1_5.class);
+ COMPLETION_SUITES.add(CompletionWithMissingTypesTests_1_8.class);
COMPLETION_SUITES.add(SnippetCompletionContextTests.class);
COMPLETION_SUITES.add(SubstringCompletionTests.class);
COMPLETION_SUITES.add(SubwordCompletionTests.class);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/NameReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/NameReference.java
index 022279ac1f..21889a7bf9 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/NameReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/NameReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -71,7 +71,7 @@ public boolean isSuperAccess() {
@Override
public boolean isTypeAccess() {
// null is acceptable when we are resolving the first part of a reference
- return this.binding == null || this.binding instanceof ReferenceBinding;
+ return this.binding == null || (this.binding.kind() & Binding.TYPE) != 0;
}
@Override

Back to the top