diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index 6226695b0628..9d2c921c3fca 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -316,6 +316,7 @@ + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyArgListSelectioner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyArgListSelectioner.java index 6339efa59bd4..89c546a2a2d7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyArgListSelectioner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyArgListSelectioner.java @@ -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; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyBlockStatementsSelectioner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyBlockStatementsSelectioner.java index 284d07a52812..eb023ac2a806 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyBlockStatementsSelectioner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyBlockStatementsSelectioner.java @@ -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; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyDocParamsSelectioner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyDocParamsSelectioner.java index aa20ae7c05b3..ac6421aa0dc4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyDocParamsSelectioner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyDocParamsSelectioner.java @@ -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; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyBasicSelectioner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyElseSelectioner.java similarity index 53% rename from plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyBasicSelectioner.java rename to plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyElseSelectioner.java index 1ad5ef95820f..e4d847583ff4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyBasicSelectioner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyElseSelectioner.java @@ -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 select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) { - List 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())); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyGStringSelectioner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyGStringSelectioner.java index d8d2f3cab198..2a1e1cf5a3f9 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyGStringSelectioner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyGStringSelectioner.java @@ -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; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyLiteralSelectioner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyLiteralSelectioner.java index bc3db214428f..40997c865382 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyLiteralSelectioner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyLiteralSelectioner.java @@ -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); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyParameterListSelectioner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyParameterListSelectioner.java index a684a71f98fe..ca8b94f6eda5 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyParameterListSelectioner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyParameterListSelectioner.java @@ -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; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyTypeCastSelectioner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyTypeCastSelectioner.java index 8b99b6e16a02..ea948d867ad5 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyTypeCastSelectioner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/selection/GroovyTypeCastSelectioner.java @@ -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; } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyActionsTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyActionsTest.groovy index 5bb933390cb9..fabf90f28352 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyActionsTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyActionsTest.groovy @@ -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 { + } +} +''', '''\ +def foo() { + if (a){ + } + else { + } +} +''') + } + private void doTestForSelectWord(int count, String input, String expected) throws Exception { myFixture.configureByText("a.groovy", input); selectWord(count)