diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 2d123eeb3f3..cca97afde60 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -491,6 +491,7 @@ + diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinInvokedExpressionSelectioner.kt b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinInvokedExpressionSelectioner.kt new file mode 100644 index 00000000000..e785b35246b --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinInvokedExpressionSelectioner.kt @@ -0,0 +1,38 @@ +/* + * 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.KtDotQualifiedExpression +import org.jetbrains.kotlin.psi.KtNameReferenceExpression +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset + +class KotlinInvokedExpressionSelectioner : ExtendWordSelectionHandlerBase() { + override fun canSelect(e: PsiElement?): Boolean { + return e is KtDotQualifiedExpression + } + + override fun select(e: PsiElement?, editorText: CharSequence?, cursorOffset: Int, editor: Editor): List? { + if (e !is KtDotQualifiedExpression) return null + val endOffset = e.selectorExpression?.children?.firstOrNull { it is KtNameReferenceExpression }?.endOffset ?: return null + return listOf(TextRange(e.startOffset, endOffset)) + } +} \ No newline at end of file diff --git a/idea/testData/wordSelection/InvokedExpression/0.kt b/idea/testData/wordSelection/InvokedExpression/0.kt new file mode 100644 index 00000000000..384604702ce --- /dev/null +++ b/idea/testData/wordSelection/InvokedExpression/0.kt @@ -0,0 +1,4 @@ +fun foo() { + val bar = 1 + bar.and(1.and(1)).and(1) +} diff --git a/idea/testData/wordSelection/InvokedExpression/1.kt b/idea/testData/wordSelection/InvokedExpression/1.kt new file mode 100644 index 00000000000..8097384dc25 --- /dev/null +++ b/idea/testData/wordSelection/InvokedExpression/1.kt @@ -0,0 +1,4 @@ +fun foo() { + val bar = 1 + bar.and(1.and(1)).and(1) +} diff --git a/idea/testData/wordSelection/InvokedExpression/2.kt b/idea/testData/wordSelection/InvokedExpression/2.kt new file mode 100644 index 00000000000..429ec321fd4 --- /dev/null +++ b/idea/testData/wordSelection/InvokedExpression/2.kt @@ -0,0 +1,4 @@ +fun foo() { + val bar = 1 + bar.and(1.and(1)).and(1) +} diff --git a/idea/testData/wordSelection/InvokedExpression/3.kt b/idea/testData/wordSelection/InvokedExpression/3.kt new file mode 100644 index 00000000000..9227fa4418c --- /dev/null +++ b/idea/testData/wordSelection/InvokedExpression/3.kt @@ -0,0 +1,4 @@ +fun foo() { + val bar = 1 + bar.and(1.and(1)).and(1) +} diff --git a/idea/testData/wordSelection/InvokedExpression/4.kt b/idea/testData/wordSelection/InvokedExpression/4.kt new file mode 100644 index 00000000000..84789a30efc --- /dev/null +++ b/idea/testData/wordSelection/InvokedExpression/4.kt @@ -0,0 +1,4 @@ +fun foo() { + val bar = 1 + bar.and(1.and(1)).and(1) +} \ No newline at end of file diff --git a/idea/testData/wordSelection/InvokedExpression/5.kt b/idea/testData/wordSelection/InvokedExpression/5.kt new file mode 100644 index 00000000000..2720da0b805 --- /dev/null +++ b/idea/testData/wordSelection/InvokedExpression/5.kt @@ -0,0 +1,4 @@ +fun foo() { + val bar = 1 + bar.and(1.and(1)).and(1) +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java b/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java index e74cc5caadf..cce94470a65 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java @@ -74,6 +74,10 @@ public class WordSelectionTest extends KotlinLightCodeInsightFixtureTestCase { public void testMultiDeclaration() { doTest(); } + public void testInvokedExpression() { + doTest(); + } + private void doTest() { String dirName = getTestName(false);