mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-83654 Select Word action does not select 'else' branch
This commit is contained in:
@@ -316,6 +316,7 @@
|
||||
<extendWordSelectionHandler implementation="org.jetbrains.plugins.groovy.editor.selection.GroovyArgListSelectioner"/>
|
||||
<extendWordSelectionHandler implementation="org.jetbrains.plugins.groovy.editor.selection.GroovyGStringSelectioner" order="before wordSelectioner"/>
|
||||
<extendWordSelectionHandler implementation="org.jetbrains.plugins.groovy.editor.selection.GroovyParameterListSelectioner"/>
|
||||
<extendWordSelectionHandler implementation="org.jetbrains.plugins.groovy.editor.selection.GroovyElseSelectioner"/>
|
||||
|
||||
<methodReferencesSearch implementation="org.jetbrains.plugins.groovy.findUsages.AccessorMethodReferencesSearcher"/>
|
||||
<methodReferencesSearch implementation="org.jetbrains.plugins.groovy.findUsages.MethodLateBoundReferencesSearcher"/>
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.editor.selection;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -28,7 +29,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author ilyas
|
||||
*/
|
||||
public class GroovyArgListSelectioner extends GroovyBasicSelectioner {
|
||||
public class GroovyArgListSelectioner extends ExtendWordSelectionHandlerBase {
|
||||
public boolean canSelect(PsiElement e) {
|
||||
return e instanceof GrArgumentList || e.getParent() instanceof GrReferenceExpression && e.getParent().getParent() instanceof GrCall;
|
||||
}
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.editor.selection;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -27,7 +28,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author ilyas
|
||||
*/
|
||||
public class GroovyBlockStatementsSelectioner extends GroovyBasicSelectioner {
|
||||
public class GroovyBlockStatementsSelectioner extends ExtendWordSelectionHandlerBase {
|
||||
|
||||
public boolean canSelect(PsiElement e) {
|
||||
return e instanceof GrCodeBlock;
|
||||
|
||||
+4
-5
@@ -16,11 +16,10 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.editor.selection;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrTypeCastExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodParams;
|
||||
|
||||
import java.util.List;
|
||||
@@ -28,7 +27,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author ilyas
|
||||
*/
|
||||
public class GroovyDocParamsSelectioner extends GroovyBasicSelectioner {
|
||||
public class GroovyDocParamsSelectioner extends ExtendWordSelectionHandlerBase {
|
||||
public boolean canSelect(PsiElement e) {
|
||||
return e instanceof GrDocMethodParams;
|
||||
}
|
||||
|
||||
+21
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,22 +13,37 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.plugins.groovy.editor.selection;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ilyas
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public abstract class GroovyBasicSelectioner extends ExtendWordSelectionHandlerBase {
|
||||
public class GroovyElseSelectioner extends ExtendWordSelectionHandlerBase {
|
||||
@Override
|
||||
public boolean canSelect(PsiElement e) {
|
||||
return e instanceof GrIfStatement;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
|
||||
List<TextRange> ranges = super.select(e, editorText, cursorOffset, editor);
|
||||
return ranges;
|
||||
if (!(e instanceof GrIfStatement)) return null;
|
||||
|
||||
GrIfStatement ifSt = (GrIfStatement)e;
|
||||
GrStatement branch = ifSt.getElseBranch();
|
||||
PsiElement elseKeyword = ifSt.getElseKeyword();
|
||||
if (branch == null || elseKeyword == null) return null;
|
||||
|
||||
return expandToWholeLine(editorText, new TextRange(elseKeyword.getTextRange().getStartOffset(), branch.getTextRange().getEndOffset()));
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.editor.selection;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase;
|
||||
import com.intellij.codeInsight.editorActions.SelectWordUtil;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -33,7 +34,7 @@ import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.*;
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
public class GroovyGStringSelectioner extends GroovyBasicSelectioner {
|
||||
public class GroovyGStringSelectioner extends ExtendWordSelectionHandlerBase {
|
||||
public boolean canSelect(PsiElement e) {
|
||||
PsiElement parent = e.getParent();
|
||||
return parent instanceof GrStringInjection || parent instanceof GrString;
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.editor.selection;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -33,7 +34,7 @@ import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.*;
|
||||
/**
|
||||
* @author ilyas
|
||||
*/
|
||||
public class GroovyLiteralSelectioner extends GroovyBasicSelectioner {
|
||||
public class GroovyLiteralSelectioner extends ExtendWordSelectionHandlerBase {
|
||||
public boolean canSelect(PsiElement e) {
|
||||
PsiElement parent = e.getParent();
|
||||
return isLiteral(e) || isLiteral(parent);
|
||||
|
||||
+2
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.editor.selection;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -26,7 +27,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
public class GroovyParameterListSelectioner extends GroovyBasicSelectioner {
|
||||
public class GroovyParameterListSelectioner extends ExtendWordSelectionHandlerBase {
|
||||
@Override
|
||||
public boolean canSelect(PsiElement e) {
|
||||
return e instanceof GrParameterList || e.getParent() instanceof GrParameterList;
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.editor.selection;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -27,7 +28,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author ilyas
|
||||
*/
|
||||
public class GroovyTypeCastSelectioner extends GroovyBasicSelectioner {
|
||||
public class GroovyTypeCastSelectioner extends ExtendWordSelectionHandlerBase {
|
||||
public boolean canSelect(PsiElement e) {
|
||||
return e instanceof GrTypeCastExpression;
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ import org.jetbrains.plugins.groovy.util.TestUtils
|
||||
public class GroovyActionsTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
protected String getBasePath() {
|
||||
return TestUtils.getTestDataPath() + "groovy/actions/";
|
||||
return TestUtils.testDataPath + "groovy/actions/";
|
||||
}
|
||||
|
||||
public void testSelectWordBeforeMethod() throws Throwable {
|
||||
doTestForSelectWord(1);
|
||||
doTestForSelectWord 1;
|
||||
}
|
||||
|
||||
public void testSWInGString1() throws Exception {doTestForSelectWord(1);}
|
||||
@@ -58,6 +58,24 @@ public class GroovyActionsTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
public void testSWInCodeBlock() throws Exception {doTestForSelectWord 3}
|
||||
|
||||
public void testElseBranch() {
|
||||
doTestForSelectWord (3, '''\
|
||||
def foo() {
|
||||
if (a){
|
||||
}
|
||||
else <caret>{
|
||||
}
|
||||
}
|
||||
''', '''\
|
||||
def foo() {
|
||||
if (a){
|
||||
}
|
||||
<selection> else <caret>{
|
||||
}
|
||||
</selection>}
|
||||
''')
|
||||
}
|
||||
|
||||
private void doTestForSelectWord(int count, String input, String expected) throws Exception {
|
||||
myFixture.configureByText("a.groovy", input);
|
||||
selectWord(count)
|
||||
|
||||
Reference in New Issue
Block a user