[java] disables completion in module names (IDEA-164010) appcode/171.989 pycharm/171.990
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Tue, 15 Nov 2016 17:14:34 +0000 (18:14 +0100)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Tue, 15 Nov 2016 17:14:52 +0000 (18:14 +0100)
java/java-impl/src/com/intellij/codeInsight/completion/JavaModuleCompletion.java
java/java-tests/testSrc/com/intellij/codeInsight/completion/ModuleCompletionTest.kt

index c3a9a344c9a8423a5ccff27db8eee9c8452fcc6f..0602af3e842ef844c91c385faf7fa3544287eead 100644 (file)
@@ -88,18 +88,21 @@ class JavaModuleCompletion {
   }
 
   private static void addModuleReferences(PsiElement context, Consumer<LookupElement> result) {
-    PsiJavaModule host = PsiTreeUtil.getParentOfType(context, PsiJavaModule.class);
-    if (host != null) {
-      String hostName = host.getModuleName();
-      Project project = context.getProject();
-      JavaModuleNameIndex index = JavaModuleNameIndex.getInstance();
-      GlobalSearchScope scope = ProjectScope.getAllScope(project);
-      index.processAllKeys(project, name -> {
-        if (!name.equals(hostName) && index.get(name, project, scope).size() == 1) {
-          result.consume(new OverrideableSpace(LookupElementBuilder.create(name), TailType.SEMICOLON));
-        }
-        return true;
-      });
+    PsiElement statement = context.getParent();
+    if (!(statement instanceof PsiJavaModule)) {
+      PsiElement host = statement.getParent();
+      if (host instanceof PsiJavaModule) {
+        String hostName = ((PsiJavaModule)host).getModuleName();
+        Project project = context.getProject();
+        JavaModuleNameIndex index = JavaModuleNameIndex.getInstance();
+        GlobalSearchScope scope = ProjectScope.getAllScope(project);
+        index.processAllKeys(project, name -> {
+          if (!name.equals(hostName) && index.get(name, project, scope).size() == 1) {
+            result.consume(new OverrideableSpace(LookupElementBuilder.create(name), TailType.SEMICOLON));
+          }
+          return true;
+        });
+      }
     }
   }
 
index e022580dda2bc3aba3d2d4921a24e04bfa72c8f9..f8b08724043c2a415c23fcff105a4c3206a01fce 100644 (file)
@@ -26,6 +26,7 @@ class ModuleCompletionTest : LightJava9ModulesCodeInsightFixtureTestCase() {
   }
 
   fun testFileHeader() = complete("<caret>", "module <caret>")
+  fun testModuleName() = variants("module M<caret>")
   fun testStatements1() = variants("module M { <caret> }", "requires", "exports", "uses", "provides")
   fun testStatements2() = complete("module M { requires X; ex<caret> }", "module M { requires X; exports <caret> }")
   fun testModuleRef() = complete("module M { requires M<caret> }", "module M { requires M2;<caret> }")