mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-81100 Groovy: "Remove unnecessary semicolon" intention shouldn't be shown on code selection if there are no semicolons at all
This commit is contained in:
+14
-4
@@ -19,6 +19,8 @@ import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -59,13 +61,21 @@ public class RemoveUnnecessarySemicolonsIntention implements IntentionAction {
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
if (!(file instanceof GroovyFileBase) || editor.getSelectionModel().hasBlockSelection()) {
|
||||
final SelectionModel selectionModel = editor.getSelectionModel();
|
||||
if (!(file instanceof GroovyFileBase)) return false;
|
||||
if (selectionModel.hasBlockSelection()) return false;
|
||||
|
||||
if (selectionModel.hasSelection()) {
|
||||
final HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(selectionModel.getSelectionStart());
|
||||
final int end = selectionModel.getSelectionEnd();
|
||||
while (!iterator.atEnd()) {
|
||||
if (iterator.getTokenType() == GroovyTokenTypes.mSEMI) return true;
|
||||
if (iterator.getStart() > end) return false;
|
||||
iterator.advance();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (editor.getSelectionModel().hasSelection()) return true;
|
||||
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
if (offset >= editor.getDocument().getTextLength()) offset = editor.getDocument().getTextLength() - 1;
|
||||
final PsiElement element = file.findElementAt(offset);
|
||||
|
||||
Reference in New Issue
Block a user