Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVikas Chandra2018-05-09 18:40:05 +0000
committerVikas Chandra2018-05-15 16:16:23 +0000
commit4fc4d2fdd2a63bb244ba7a023817f19edaf9fefd (patch)
tree43b46b039e84dbdcb57b76d18cdf96e60133a87e
parenta5c6fe3e502bf78378954eb937d30682a59f99e7 (diff)
downloadeclipse.jdt.core-4fc4d2fdd2a63bb244ba7a023817f19edaf9fefd.tar.gz
eclipse.jdt.core-4fc4d2fdd2a63bb244ba7a023817f19edaf9fefd.tar.xz
eclipse.jdt.core-4fc4d2fdd2a63bb244ba7a023817f19edaf9fefd.zip
Bug 533740 - Keyword super/this is proposed in cases where it is notI20180515-2000I20180515-1755I20180515-1620I20180515-1440
allowed Change-Id: I579a5a2fb14c12f72a7fff6b63a687532f8b1bbb Signed-off-by: Vikas Chandra <Vikas.Chandra@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java2
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java41
3 files changed, 40 insertions, 7 deletions
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 c1c8fe0bbf..055a80256e 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
@@ -22064,9 +22064,7 @@ public void test325481b() throws JavaModelException {
"element:RANKING_ATTRIBUTE_V2 completion:RANKING_ATTRIBUTE_V2 relevance:" + relevance +"\n" +
"element:REFERENCE_ATTRIBUTE completion:REFERENCE_ATTRIBUTE relevance:" + relevance +"\n" +
"element:WORK_ATTRIBUTE completion:WORK_ATTRIBUTE relevance:" + relevance +"\n" +
- "element:class completion:class relevance:" + relevance +"\n" +
- "element:super completion:super relevance:" + relevance + "\n" +
- "element:this completion:this relevance:" + relevance,
+ "element:class completion:class relevance:" + relevance,
requestor.getResults());
} finally {
// Restore compliance settings.
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 991b942660..07728ab66d 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
@@ -239,8 +239,6 @@ public void test007() throws JavaModelException {
assertResults(
"class[FIELD_REF]{class, null, Ljava.lang.Class<LX;>;, class, null, " + (R_DEFAULT + 21) + "}\n" +
"f[FIELD_REF]{f, LX;, LFoo;, f, null, " + (R_DEFAULT + 21) + "}\n" +
- "super[KEYWORD]{super, null, null, super, null, " + (R_DEFAULT + 21) + "}\n" +
- "this[KEYWORD]{this, null, null, this, null, " + (R_DEFAULT + 21) + "}\n" +
"x1[FIELD_REF]{x1, LX;, I, x1, null, " + (R_DEFAULT + 51) + "}",
requestor.getResults());
}
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
index 651cb61115..7b3aa9bb30 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
@@ -16,6 +16,7 @@
package org.eclipse.jdt.internal.codeassist;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
@@ -9767,8 +9768,44 @@ public final class CompletionEngine
((scope instanceof MethodScope && !((MethodScope)scope).isStatic)
|| ((methodScope = scope.enclosingMethodScope()) != null && !methodScope.isStatic))) {
if (token.length >= 0) {
- findKeywords(token, new char[][]{Keywords.THIS, Keywords.SUPER}, true, false);
- }
+ boolean isInterface = false;
+ if (receiverType != null) {
+ isInterface = receiverType.isInterface();
+ }
+ if (!isInterface) {
+ findKeywords(token, new char[][] { Keywords.THIS, Keywords.SUPER }, true, false);
+ } else {
+ boolean isEqual = false;
+ char[] enclosingSourceName = null;
+ if(scope.enclosingSourceType() != null)
+ enclosingSourceName = scope.enclosingSourceType().sourceName;
+ char[] receiverSourceName = null;
+ if (receiverType != null) {
+ receiverSourceName = receiverType.sourceName;
+ }
+ if( enclosingSourceName !=null & receiverSourceName !=null)
+ isEqual = Arrays.equals(enclosingSourceName, receiverSourceName);
+ if(isEqual) {
+ findKeywords(token, new char[][] { Keywords.THIS }, true, false);
+ } else {
+ // Check if the enclosing source implements this interface then show super
+ if (scope.enclosingSourceType() != null) {
+ SourceTypeBinding src = scope.enclosingSourceType();
+ ReferenceBinding[] superInterfaces = src.superInterfaces();
+ boolean implemented = false;
+ for (ReferenceBinding referenceBinding : superInterfaces) {
+ if (Arrays.equals(referenceBinding.sourceName, receiverSourceName)) {
+ implemented = true;
+ break;
+ }
+ }
+ if (implemented) {
+ findKeywords(token, new char[][] { Keywords.SUPER }, true, false);
+ }
+ }
+ }
+ }
+ }
}
if (!this.requestor.isIgnored(CompletionProposal.FIELD_REF)) {

Back to the top