mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-10 13:17:09 +07:00
IJPL-207762 [command completion] move java command completion factory to FE
GitOrigin-RevId: 8b328dba7131b5dbc966d03112f23a835943bff0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d327bf69b2
commit
2cfa848a3a
@@ -95,5 +95,7 @@
|
||||
<declarationRangeHandler key="com.intellij.psi.PsiMethod"
|
||||
implementationClass="com.intellij.codeInsight.hint.MethodDeclarationRangeHandler"/>
|
||||
|
||||
<codeInsight.completion.command.factory language="JAVA" implementationClass="com.intellij.codeInsight.completion.commands.JavaCommandCompletionFactory" />
|
||||
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.completion.commands;
|
||||
|
||||
import com.intellij.codeInsight.completion.command.CommandCompletionFactory;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiJShellFile;
|
||||
import com.intellij.psi.PsiJavaFile;
|
||||
import com.intellij.psi.PsiJavaToken;
|
||||
import com.intellij.psi.PsiParameterList;
|
||||
import com.intellij.psi.PsiTypeElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class JavaCommandCompletionFactory implements CommandCompletionFactory, DumbAware {
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(@NotNull PsiFile psiFile, int offset) {
|
||||
if (!(psiFile instanceof PsiJavaFile)) return false;
|
||||
//Doesn't work well. Disable for now
|
||||
if (psiFile instanceof PsiJShellFile) return false;
|
||||
if (isInsideParameterList(psiFile, offset)) return false;
|
||||
if (isInsideStringLiteral(psiFile, offset)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isInsideStringLiteral(@NotNull PsiFile file, int offset) {
|
||||
PsiElement elementAt = file.findElementAt(offset);
|
||||
if (!(elementAt instanceof PsiJavaToken psiJavaToken &&
|
||||
(psiJavaToken.getTokenType() == JavaTokenType.STRING_LITERAL ||
|
||||
psiJavaToken.getTokenType() == JavaTokenType.TEXT_BLOCK_LITERAL
|
||||
))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return psiJavaToken.getTextRange().containsOffset(offset);
|
||||
}
|
||||
|
||||
private static boolean isInsideParameterList(@NotNull PsiFile psiFile, int offset) {
|
||||
PsiElement elementAt = psiFile.findElementAt(offset);
|
||||
if (elementAt == null) return false;
|
||||
if (!(elementAt.getParent() instanceof PsiParameterList)) return false;
|
||||
PsiElement prevLeaf = PsiTreeUtil.prevLeaf(elementAt, true);
|
||||
if (!(prevLeaf instanceof PsiJavaToken javaToken && javaToken.textMatches("."))) return false;
|
||||
PsiElement prevPrevLeaf = PsiTreeUtil.prevLeaf(prevLeaf, true);
|
||||
return PsiTreeUtil.getParentOfType(prevPrevLeaf, PsiTypeElement.class) != null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user