KT-12697 Expand selection action select ": Type" (#898)

This commit is contained in:
Yoshinori Isogai
2016-08-22 19:35:23 +09:00
committed by Dmitry Jemerov
parent b3b83e344b
commit 4669fb3ca7
33 changed files with 191 additions and 9 deletions
+2
View File
@@ -496,6 +496,8 @@
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinListSelectioner"/>
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinStringLiteralSelectioner"/>
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinInvokedExpressionSelectioner"/>
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinTypeSelectioner"/>
<extendWordSelectionHandler implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinSuperTypeSelectioner"/>
<basicWordSelectionFilter implementation="org.jetbrains.kotlin.idea.editor.wordSelection.KotlinWordSelectionFilter"/>
<typedHandler implementation="org.jetbrains.kotlin.idea.editor.KotlinTypedHandler"/>
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2016 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.editor.wordSelection
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.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtObjectDeclaration
import org.jetbrains.kotlin.psi.KtSuperTypeList
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.psi.psiUtil.startOffset
class KotlinSuperTypeSelectioner : ExtendWordSelectionHandlerBase() {
override fun canSelect(e: PsiElement?): Boolean {
return e is KtSuperTypeList && e.getStrictParentOfType<KtObjectDeclaration>() == null
}
override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List<TextRange>? {
val colonPosition = e.getStrictParentOfType<KtClass>()?.getColon()?.startOffset ?: return null
return listOf(TextRange(colonPosition, e.endOffset))
}
}
@@ -0,0 +1,44 @@
/*
* Copyright 2010-2016 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.editor.wordSelection
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.kotlin.psi.KtCallableDeclaration
import org.jetbrains.kotlin.psi.KtObjectDeclaration
import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.psi.KtTypeReference
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.psi.psiUtil.startOffset
class KotlinTypeSelectioner : ExtendWordSelectionHandlerBase() {
override fun canSelect(e: PsiElement?): Boolean {
return e is KtTypeReference
&& e.getStrictParentOfType<KtObjectDeclaration>() == null
&& e.getStrictParentOfType<KtParameter>() == null
}
override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List<TextRange>? {
if (e.getStrictParentOfType<KtObjectDeclaration>() != null) return null
val colonPosition = e.getStrictParentOfType<KtCallableDeclaration>()?.colon?.startOffset ?: return null
return listOf(TextRange(colonPosition, e.endOffset))
}
}
@@ -0,0 +1,2 @@
class Foo : Bar(), <caret>Bar2<Bar3>?, Bar4 {
}
@@ -0,0 +1,2 @@
class Foo : Bar(), <selection><caret>Bar2</selection><Bar3>?, Bar4 {
}
@@ -0,0 +1,2 @@
class Foo : Bar(), <selection><caret>Bar2<Bar3></selection>?, Bar4 {
}
@@ -0,0 +1,2 @@
class Foo : Bar(), <selection><caret>Bar2<Bar3>?</selection>, Bar4 {
}
@@ -0,0 +1,2 @@
class Foo : <selection>Bar(), <caret>Bar2<Bar3>?, Bar4</selection> {
}
@@ -0,0 +1,2 @@
class Foo <selection>: Bar(), <caret>Bar2<Bar3>?, Bar4</selection> {
}
@@ -0,0 +1,2 @@
<selection>class Foo : Bar(), <caret>Bar2<Bar3>?, Bar4 {
}</selection>
+2
View File
@@ -0,0 +1,2 @@
class Foo : <caret>Bar {
}
+2
View File
@@ -0,0 +1,2 @@
class Foo : <selection><caret>Bar</selection> {
}
+2
View File
@@ -0,0 +1,2 @@
class Foo <selection>: <caret>Bar</selection> {
}
+2
View File
@@ -0,0 +1,2 @@
<selection>class Foo : <caret>Bar {
}</selection>
+1
View File
@@ -0,0 +1 @@
val foo: <caret>Int? = 1
+1
View File
@@ -0,0 +1 @@
val foo: <selection><caret>Int</selection>? = 1
+1
View File
@@ -0,0 +1 @@
val foo: <selection><caret>Int?</selection> = 1
+1
View File
@@ -0,0 +1 @@
val foo<selection>: <caret>Int?</selection> = 1
@@ -1,4 +1,4 @@
<selection>fun a() : <caret>Int {}</selection> // fun a
fun a() <selection>: <caret>Int</selection> {} // fun a
fun b() : Short {
f()
@@ -1,4 +1,4 @@
<selection>fun a() : <caret>Int {} // fun a</selection>
<selection>fun a() : <caret>Int {}</selection> // fun a
fun b() : Short {
f()
@@ -1,5 +1,5 @@
<selection>fun a() : <caret>Int {} // fun a
</selection>
<selection>fun a() : <caret>Int {} // fun a</selection>
fun b() : Short {
f()
}
@@ -0,0 +1,5 @@
<selection>fun a() : <caret>Int {} // fun a
</selection>
fun b() : Short {
f()
}
@@ -1,7 +1,6 @@
fun a() : Int {}
// TODO: Refactor
<selection>fun b() : <caret>Short {
fun b() <selection>: <caret>Short</selection> {
f()
}
</selection>
@@ -1,7 +1,7 @@
fun a() : Int {}
<selection>// TODO: Refactor
fun b() : <caret>Short {
// TODO: Refactor
<selection>fun b() : <caret>Short {
f()
}
</selection>
</selection>
@@ -0,0 +1,7 @@
fun a() : Int {}
<selection>// TODO: Refactor
fun b() : <caret>Short {
f()
}
</selection>
+9
View File
@@ -0,0 +1,9 @@
window.addMouseListener(object : <caret>MouseAdapter() {
override fun mouseClicked(e: MouseEvent) {
// ...
}
override fun mouseEntered(e: MouseEvent) {
// ...
}
})
+9
View File
@@ -0,0 +1,9 @@
window.addMouseListener(object : <selection><caret>MouseAdapter</selection>() {
override fun mouseClicked(e: MouseEvent) {
// ...
}
override fun mouseEntered(e: MouseEvent) {
// ...
}
})
+9
View File
@@ -0,0 +1,9 @@
window.addMouseListener(object : <selection><caret>MouseAdapter()</selection> {
override fun mouseClicked(e: MouseEvent) {
// ...
}
override fun mouseEntered(e: MouseEvent) {
// ...
}
})
+9
View File
@@ -0,0 +1,9 @@
window.addMouseListener(<selection>object : <caret>MouseAdapter() {
override fun mouseClicked(e: MouseEvent) {
// ...
}
override fun mouseEntered(e: MouseEvent) {
// ...
}
}</selection>)
+2
View File
@@ -0,0 +1,2 @@
fun foo(a: Array<String>, b: <caret>Int) {
}
+2
View File
@@ -0,0 +1,2 @@
fun foo(a: Array<String>, b: <selection><caret>Int</selection>) {
}
+2
View File
@@ -0,0 +1,2 @@
fun foo(a: Array<String>, <selection>b: <caret>Int</selection>) {
}
@@ -45,6 +45,10 @@ public class WordSelectionTest extends KotlinLightCodeInsightFixtureTestCase {
public void testValueParameters() { doTest(); }
public void testValueParameters2() {
doTest();
}
public void testDocComment() { doTest(); }
public void testFunctionWithLineCommentBefore() { doTest(); }
@@ -78,6 +82,20 @@ public class WordSelectionTest extends KotlinLightCodeInsightFixtureTestCase {
doTest();
}
public void testDefiningVariable() { doTest(); }
public void testDefiningSuperClass() {
doTest();
}
public void testDefiningMultipleSuperClass() {
doTest();
}
public void testObjectExpression() {
doTest();
}
private void doTest() {
String dirName = getTestName(false);