diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index a2b55ca662c..d66a357dd95 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -496,6 +496,8 @@ + + diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinSuperTypeSelectioner.kt b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinSuperTypeSelectioner.kt new file mode 100644 index 00000000000..f837815b1cf --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinSuperTypeSelectioner.kt @@ -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() == null + } + + override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List? { + val colonPosition = e.getStrictParentOfType()?.getColon()?.startOffset ?: return null + return listOf(TextRange(colonPosition, e.endOffset)) + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinTypeSelectioner.kt b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinTypeSelectioner.kt new file mode 100644 index 00000000000..613e17942d1 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/editor/wordSelection/KotlinTypeSelectioner.kt @@ -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() == null + && e.getStrictParentOfType() == null + } + + override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List? { + if (e.getStrictParentOfType() != null) return null + val colonPosition = e.getStrictParentOfType()?.colon?.startOffset ?: return null + return listOf(TextRange(colonPosition, e.endOffset)) + } +} diff --git a/idea/testData/wordSelection/DefiningMultipleSuperClass/0.kt b/idea/testData/wordSelection/DefiningMultipleSuperClass/0.kt new file mode 100644 index 00000000000..e8135be85d2 --- /dev/null +++ b/idea/testData/wordSelection/DefiningMultipleSuperClass/0.kt @@ -0,0 +1,2 @@ +class Foo : Bar(), Bar2?, Bar4 { +} \ No newline at end of file diff --git a/idea/testData/wordSelection/DefiningMultipleSuperClass/1.kt b/idea/testData/wordSelection/DefiningMultipleSuperClass/1.kt new file mode 100644 index 00000000000..df7ca07d8cc --- /dev/null +++ b/idea/testData/wordSelection/DefiningMultipleSuperClass/1.kt @@ -0,0 +1,2 @@ +class Foo : Bar(), Bar2?, Bar4 { +} \ No newline at end of file diff --git a/idea/testData/wordSelection/DefiningMultipleSuperClass/2.kt b/idea/testData/wordSelection/DefiningMultipleSuperClass/2.kt new file mode 100644 index 00000000000..6d1ea14afa8 --- /dev/null +++ b/idea/testData/wordSelection/DefiningMultipleSuperClass/2.kt @@ -0,0 +1,2 @@ +class Foo : Bar(), Bar2?, Bar4 { +} \ No newline at end of file diff --git a/idea/testData/wordSelection/DefiningMultipleSuperClass/3.kt b/idea/testData/wordSelection/DefiningMultipleSuperClass/3.kt new file mode 100644 index 00000000000..c1a691dd2f9 --- /dev/null +++ b/idea/testData/wordSelection/DefiningMultipleSuperClass/3.kt @@ -0,0 +1,2 @@ +class Foo : Bar(), Bar2?, Bar4 { +} \ No newline at end of file diff --git a/idea/testData/wordSelection/DefiningMultipleSuperClass/4.kt b/idea/testData/wordSelection/DefiningMultipleSuperClass/4.kt new file mode 100644 index 00000000000..6a8d68efff4 --- /dev/null +++ b/idea/testData/wordSelection/DefiningMultipleSuperClass/4.kt @@ -0,0 +1,2 @@ +class Foo : Bar(), Bar2?, Bar4 { +} \ No newline at end of file diff --git a/idea/testData/wordSelection/DefiningMultipleSuperClass/5.kt b/idea/testData/wordSelection/DefiningMultipleSuperClass/5.kt new file mode 100644 index 00000000000..24d2952a454 --- /dev/null +++ b/idea/testData/wordSelection/DefiningMultipleSuperClass/5.kt @@ -0,0 +1,2 @@ +class Foo : Bar(), Bar2?, Bar4 { +} diff --git a/idea/testData/wordSelection/DefiningMultipleSuperClass/6.kt b/idea/testData/wordSelection/DefiningMultipleSuperClass/6.kt new file mode 100644 index 00000000000..6bd5d001983 --- /dev/null +++ b/idea/testData/wordSelection/DefiningMultipleSuperClass/6.kt @@ -0,0 +1,2 @@ +class Foo : Bar(), Bar2?, Bar4 { +} \ No newline at end of file diff --git a/idea/testData/wordSelection/DefiningSuperClass/0.kt b/idea/testData/wordSelection/DefiningSuperClass/0.kt new file mode 100644 index 00000000000..6647b3374db --- /dev/null +++ b/idea/testData/wordSelection/DefiningSuperClass/0.kt @@ -0,0 +1,2 @@ +class Foo : Bar { +} \ No newline at end of file diff --git a/idea/testData/wordSelection/DefiningSuperClass/1.kt b/idea/testData/wordSelection/DefiningSuperClass/1.kt new file mode 100644 index 00000000000..d113effec45 --- /dev/null +++ b/idea/testData/wordSelection/DefiningSuperClass/1.kt @@ -0,0 +1,2 @@ +class Foo : Bar { +} \ No newline at end of file diff --git a/idea/testData/wordSelection/DefiningSuperClass/2.kt b/idea/testData/wordSelection/DefiningSuperClass/2.kt new file mode 100644 index 00000000000..223f4eb5046 --- /dev/null +++ b/idea/testData/wordSelection/DefiningSuperClass/2.kt @@ -0,0 +1,2 @@ +class Foo : Bar { +} \ No newline at end of file diff --git a/idea/testData/wordSelection/DefiningSuperClass/3.kt b/idea/testData/wordSelection/DefiningSuperClass/3.kt new file mode 100644 index 00000000000..00d97d29736 --- /dev/null +++ b/idea/testData/wordSelection/DefiningSuperClass/3.kt @@ -0,0 +1,2 @@ +class Foo : Bar { +} \ No newline at end of file diff --git a/idea/testData/wordSelection/DefiningVariable/0.kt b/idea/testData/wordSelection/DefiningVariable/0.kt new file mode 100644 index 00000000000..cdbf3820f2b --- /dev/null +++ b/idea/testData/wordSelection/DefiningVariable/0.kt @@ -0,0 +1 @@ +val foo: Int? = 1 \ No newline at end of file diff --git a/idea/testData/wordSelection/DefiningVariable/1.kt b/idea/testData/wordSelection/DefiningVariable/1.kt new file mode 100644 index 00000000000..07999187c17 --- /dev/null +++ b/idea/testData/wordSelection/DefiningVariable/1.kt @@ -0,0 +1 @@ +val foo: Int? = 1 \ No newline at end of file diff --git a/idea/testData/wordSelection/DefiningVariable/2.kt b/idea/testData/wordSelection/DefiningVariable/2.kt new file mode 100644 index 00000000000..e7839e86e47 --- /dev/null +++ b/idea/testData/wordSelection/DefiningVariable/2.kt @@ -0,0 +1 @@ +val foo: Int? = 1 \ No newline at end of file diff --git a/idea/testData/wordSelection/DefiningVariable/3.kt b/idea/testData/wordSelection/DefiningVariable/3.kt new file mode 100644 index 00000000000..6c09de7c7b0 --- /dev/null +++ b/idea/testData/wordSelection/DefiningVariable/3.kt @@ -0,0 +1 @@ +val foo: Int? = 1 \ No newline at end of file diff --git a/idea/testData/wordSelection/FunctionWithLineCommentAfter/2.kt b/idea/testData/wordSelection/FunctionWithLineCommentAfter/2.kt index 69bb376cf30..169cbe2b4d2 100644 --- a/idea/testData/wordSelection/FunctionWithLineCommentAfter/2.kt +++ b/idea/testData/wordSelection/FunctionWithLineCommentAfter/2.kt @@ -1,4 +1,4 @@ -fun a() : Int {} // fun a +fun a() : Int {} // fun a fun b() : Short { f() diff --git a/idea/testData/wordSelection/FunctionWithLineCommentAfter/3.kt b/idea/testData/wordSelection/FunctionWithLineCommentAfter/3.kt index 02d25ec1ca7..69bb376cf30 100644 --- a/idea/testData/wordSelection/FunctionWithLineCommentAfter/3.kt +++ b/idea/testData/wordSelection/FunctionWithLineCommentAfter/3.kt @@ -1,4 +1,4 @@ -fun a() : Int {} // fun a +fun a() : Int {} // fun a fun b() : Short { f() diff --git a/idea/testData/wordSelection/FunctionWithLineCommentAfter/4.kt b/idea/testData/wordSelection/FunctionWithLineCommentAfter/4.kt index 4aab5a46d79..02d25ec1ca7 100644 --- a/idea/testData/wordSelection/FunctionWithLineCommentAfter/4.kt +++ b/idea/testData/wordSelection/FunctionWithLineCommentAfter/4.kt @@ -1,5 +1,5 @@ -fun a() : Int {} // fun a - +fun a() : Int {} // fun a + fun b() : Short { f() } diff --git a/idea/testData/wordSelection/FunctionWithLineCommentAfter/5.kt b/idea/testData/wordSelection/FunctionWithLineCommentAfter/5.kt new file mode 100644 index 00000000000..4aab5a46d79 --- /dev/null +++ b/idea/testData/wordSelection/FunctionWithLineCommentAfter/5.kt @@ -0,0 +1,5 @@ +fun a() : Int {} // fun a + +fun b() : Short { + f() +} diff --git a/idea/testData/wordSelection/FunctionWithLineCommentBefore/2.kt b/idea/testData/wordSelection/FunctionWithLineCommentBefore/2.kt index ae3e19e2c71..25c626ee1e6 100644 --- a/idea/testData/wordSelection/FunctionWithLineCommentBefore/2.kt +++ b/idea/testData/wordSelection/FunctionWithLineCommentBefore/2.kt @@ -1,7 +1,6 @@ fun a() : Int {} // TODO: Refactor -fun b() : Short { +fun b() : Short { f() } - \ No newline at end of file diff --git a/idea/testData/wordSelection/FunctionWithLineCommentBefore/3.kt b/idea/testData/wordSelection/FunctionWithLineCommentBefore/3.kt index 9890809da6d..fe407e5ffa3 100644 --- a/idea/testData/wordSelection/FunctionWithLineCommentBefore/3.kt +++ b/idea/testData/wordSelection/FunctionWithLineCommentBefore/3.kt @@ -1,7 +1,7 @@ fun a() : Int {} -// TODO: Refactor -fun b() : Short { +// TODO: Refactor +fun b() : Short { f() } - \ No newline at end of file + diff --git a/idea/testData/wordSelection/FunctionWithLineCommentBefore/4.kt b/idea/testData/wordSelection/FunctionWithLineCommentBefore/4.kt new file mode 100644 index 00000000000..9890809da6d --- /dev/null +++ b/idea/testData/wordSelection/FunctionWithLineCommentBefore/4.kt @@ -0,0 +1,7 @@ +fun a() : Int {} + +// TODO: Refactor +fun b() : Short { + f() +} + \ No newline at end of file diff --git a/idea/testData/wordSelection/ObjectExpression/0.kt b/idea/testData/wordSelection/ObjectExpression/0.kt new file mode 100644 index 00000000000..81020efc614 --- /dev/null +++ b/idea/testData/wordSelection/ObjectExpression/0.kt @@ -0,0 +1,9 @@ +window.addMouseListener(object : MouseAdapter() { + override fun mouseClicked(e: MouseEvent) { + // ... + } + + override fun mouseEntered(e: MouseEvent) { + // ... + } +}) diff --git a/idea/testData/wordSelection/ObjectExpression/1.kt b/idea/testData/wordSelection/ObjectExpression/1.kt new file mode 100644 index 00000000000..ea831854a7a --- /dev/null +++ b/idea/testData/wordSelection/ObjectExpression/1.kt @@ -0,0 +1,9 @@ +window.addMouseListener(object : MouseAdapter() { + override fun mouseClicked(e: MouseEvent) { + // ... + } + + override fun mouseEntered(e: MouseEvent) { + // ... + } +}) diff --git a/idea/testData/wordSelection/ObjectExpression/2.kt b/idea/testData/wordSelection/ObjectExpression/2.kt new file mode 100644 index 00000000000..722fb450007 --- /dev/null +++ b/idea/testData/wordSelection/ObjectExpression/2.kt @@ -0,0 +1,9 @@ +window.addMouseListener(object : MouseAdapter() { + override fun mouseClicked(e: MouseEvent) { + // ... + } + + override fun mouseEntered(e: MouseEvent) { + // ... + } +}) diff --git a/idea/testData/wordSelection/ObjectExpression/3.kt b/idea/testData/wordSelection/ObjectExpression/3.kt new file mode 100644 index 00000000000..a4719270992 --- /dev/null +++ b/idea/testData/wordSelection/ObjectExpression/3.kt @@ -0,0 +1,9 @@ +window.addMouseListener(object : MouseAdapter() { + override fun mouseClicked(e: MouseEvent) { + // ... + } + + override fun mouseEntered(e: MouseEvent) { + // ... + } +}) diff --git a/idea/testData/wordSelection/ValueParameters2/0.kt b/idea/testData/wordSelection/ValueParameters2/0.kt new file mode 100644 index 00000000000..8d9db0b1100 --- /dev/null +++ b/idea/testData/wordSelection/ValueParameters2/0.kt @@ -0,0 +1,2 @@ +fun foo(a: Array, b: Int) { +} diff --git a/idea/testData/wordSelection/ValueParameters2/1.kt b/idea/testData/wordSelection/ValueParameters2/1.kt new file mode 100644 index 00000000000..d38a719253b --- /dev/null +++ b/idea/testData/wordSelection/ValueParameters2/1.kt @@ -0,0 +1,2 @@ +fun foo(a: Array, b: Int) { +} diff --git a/idea/testData/wordSelection/ValueParameters2/2.kt b/idea/testData/wordSelection/ValueParameters2/2.kt new file mode 100644 index 00000000000..a3e85d7593d --- /dev/null +++ b/idea/testData/wordSelection/ValueParameters2/2.kt @@ -0,0 +1,2 @@ +fun foo(a: Array, b: Int) { +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java b/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java index cce94470a65..eda1e43e43d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/WordSelectionTest.java @@ -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);