IDEA-136189 "Code completion" proposes to extend the class of the same class
authorpeter <peter@jetbrains.com>
Fri, 13 Feb 2015 17:26:14 +0000 (18:26 +0100)
committerpeter <peter@jetbrains.com>
Fri, 13 Feb 2015 17:39:31 +0000 (18:39 +0100)
java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameCompletionContributor.java
java/java-tests/testData/codeInsight/completion/normal/NoThisClassInExtends.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy

index a256730c816bb96ec4e8266b989e1790cf8e55bd..d36c35ca6e739887670d6e9d52c497f9275c6916 100644 (file)
@@ -25,6 +25,7 @@ import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType;
 import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.patterns.ElementPattern;
 import com.intellij.patterns.PsiJavaElementPattern;
 import com.intellij.psi.*;
 import com.intellij.psi.filters.ClassFilter;
@@ -40,6 +41,7 @@ import org.jetbrains.annotations.NotNull;
 
 import java.util.List;
 
+import static com.intellij.patterns.PsiJavaPatterns.psiClass;
 import static com.intellij.patterns.PsiJavaPatterns.psiElement;
 
 /**
@@ -50,6 +52,8 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
   private static final PsiJavaElementPattern.Capture<PsiElement> IN_TYPE_PARAMETER =
       psiElement().afterLeaf(PsiKeyword.EXTENDS, PsiKeyword.SUPER, "&").withParent(
           psiElement(PsiReferenceList.class).withParent(PsiTypeParameter.class));
+  private static final ElementPattern<PsiElement> IN_EXTENDS_IMPLEMENTS =
+    psiElement().inside(psiElement(PsiReferenceList.class).withParent(psiClass()));
 
   @Override
   public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull final CompletionResultSet _result) {
@@ -86,6 +90,7 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
     final PsiElement insertedElement = parameters.getPosition();
 
     final ElementFilter filter =
+      IN_EXTENDS_IMPLEMENTS.accepts(insertedElement) ? new ExcludeDeclaredFilter(new ClassFilter(PsiClass.class)) :
       IN_TYPE_PARAMETER.accepts(insertedElement) ? new ExcludeDeclaredFilter(new ClassFilter(PsiTypeParameter.class)) :
       JavaCompletionContributor.ANNOTATION_NAME.accepts(insertedElement) ? new AnnotationTypeFilter() :
       TrueFilter.INSTANCE;
diff --git a/java/java-tests/testData/codeInsight/completion/normal/NoThisClassInExtends.java b/java/java-tests/testData/codeInsight/completion/normal/NoThisClassInExtends.java
new file mode 100644 (file)
index 0000000..5ae45bf
--- /dev/null
@@ -0,0 +1,2 @@
+public class Fooxxxx extends Foox<caret>x
+public class Fooxxxx2 {}
index dd28f479f41ca84acf690c1de1e625bae108998d..c8caf6a4c51ce49cd799059bf82ba01e6b1d6277 100644 (file)
@@ -843,6 +843,11 @@ public class ListUtils {
     assertStringItems 'Inner'
   }
 
+  public void testNoThisClassInExtends() throws Throwable {
+    configure()
+    assertStringItems 'Fooxxxx2'
+  }
+
   public void testPrimitiveTypesInForLoop() throws Throwable { doPrimitiveTypeTest() }
   public void testPrimitiveTypesInForLoop2() throws Throwable { doPrimitiveTypeTest() }
   public void testPrimitiveTypesInForLoop3() throws Throwable { doPrimitiveTypeTest() }