diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml
index 3229ab4efa2..dc494e83d1b 100644
--- a/idea/src/META-INF/plugin.xml
+++ b/idea/src/META-INF/plugin.xml
@@ -318,6 +318,8 @@
+
+
diff --git a/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinDeclarationSelectioner.kt b/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinDeclarationSelectioner.kt
new file mode 100644
index 00000000000..35e2502573a
--- /dev/null
+++ b/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinDeclarationSelectioner.kt
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2010-2014 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.jet.plugin.editor.wordSelection
+
+import com.intellij.codeInsight.editorActions.wordSelection.BasicSelectioner
+import com.intellij.psi.PsiElement
+import com.intellij.openapi.editor.Editor
+import com.intellij.openapi.util.TextRange
+import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase
+import org.jetbrains.jet.lang.psi.JetDeclaration
+import java.util.ArrayList
+import org.jetbrains.jet.lang.psi.psiUtil.siblings
+import com.intellij.psi.PsiComment
+import com.intellij.psi.PsiWhiteSpace
+
+public class KotlinDeclarationSelectioner : BasicSelectioner() {
+ override fun canSelect(e: PsiElement)
+ = e is JetDeclaration
+
+ override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List? {
+ val result = ArrayList()
+
+ val firstChild = e.getFirstChild()
+ val firstNonComment = firstChild
+ .siblings(forward = true, withItself = true)
+ .first { it !is PsiComment && it !is PsiWhiteSpace }
+
+ val lastChild = e.getLastChild()
+ val lastNonComment = lastChild
+ .siblings(forward = false, withItself = true)
+ .first { it !is PsiComment && it !is PsiWhiteSpace }
+
+ if (firstNonComment != firstChild || lastNonComment != lastChild) {
+ val start = firstNonComment.getTextRange().getStartOffset()
+ val end = lastNonComment.getTextRange().getEndOffset()
+ result.addAll(ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, TextRange(start, end)))
+ }
+
+ result.addAll(ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, e.getTextRange()))
+
+ return result
+ }
+}
\ No newline at end of file
diff --git a/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinDocCommentSelectioner.kt b/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinDocCommentSelectioner.kt
new file mode 100644
index 00000000000..3124a2a86f3
--- /dev/null
+++ b/idea/src/org/jetbrains/jet/plugin/editor/wordSelection/KotlinDocCommentSelectioner.kt
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2010-2014 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.jet.plugin.editor.wordSelection
+
+import com.intellij.codeInsight.editorActions.wordSelection.BasicSelectioner
+import com.intellij.lang.ASTNode
+import com.intellij.openapi.editor.Editor
+import com.intellij.openapi.util.TextRange
+import com.intellij.psi.PsiElement
+import com.intellij.psi.PsiWhiteSpace
+import org.jetbrains.jet.lexer.JetTokens
+
+import java.util.ArrayList
+import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase
+import org.jetbrains.jet.kdoc.psi.api.KDoc
+
+public class KotlinDocCommentSelectioner : BasicSelectioner() {
+ override fun canSelect(e: PsiElement)
+ = e is KDoc
+
+ override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List? {
+ return ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, e.getTextRange())
+ }
+}
diff --git a/idea/testData/wordSelection/DocComment/0.kt b/idea/testData/wordSelection/DocComment/0.kt
new file mode 100644
index 00000000000..93c542bde07
--- /dev/null
+++ b/idea/testData/wordSelection/DocComment/0.kt
@@ -0,0 +1,9 @@
+package p
+
+/**
+ * Doc comment here
+ */
+fun foo() {
+}
+
+fun bar(){}
\ No newline at end of file
diff --git a/idea/testData/wordSelection/DocComment/1.kt b/idea/testData/wordSelection/DocComment/1.kt
new file mode 100644
index 00000000000..6dd793ca964
--- /dev/null
+++ b/idea/testData/wordSelection/DocComment/1.kt
@@ -0,0 +1,9 @@
+package p
+
+/**
+ * Doc comment here
+ */
+fun foo() {
+}
+
+fun bar(){}
\ No newline at end of file
diff --git a/idea/testData/wordSelection/DocComment/2.kt b/idea/testData/wordSelection/DocComment/2.kt
new file mode 100644
index 00000000000..fd83a3b8faf
--- /dev/null
+++ b/idea/testData/wordSelection/DocComment/2.kt
@@ -0,0 +1,9 @@
+package p
+
+/**
+ * Doc comment here
+ */
+fun foo() {
+}
+
+fun bar(){}
\ No newline at end of file
diff --git a/idea/testData/wordSelection/DocComment/3.kt b/idea/testData/wordSelection/DocComment/3.kt
new file mode 100644
index 00000000000..c8344f7e538
--- /dev/null
+++ b/idea/testData/wordSelection/DocComment/3.kt
@@ -0,0 +1,9 @@
+package p
+
+/**
+ * Doc comment here
+ */
+fun foo() {
+}
+
+fun bar(){}
\ No newline at end of file
diff --git a/idea/testData/wordSelection/DocComment/4.kt b/idea/testData/wordSelection/DocComment/4.kt
new file mode 100644
index 00000000000..835877107c0
--- /dev/null
+++ b/idea/testData/wordSelection/DocComment/4.kt
@@ -0,0 +1,9 @@
+package p
+
+/**
+ * Doc comment here
+ */
+fun foo() {
+}
+
+fun bar(){}
\ No newline at end of file
diff --git a/idea/testData/wordSelection/FunctionWithLineCommentAfter/0.kt b/idea/testData/wordSelection/FunctionWithLineCommentAfter/0.kt
new file mode 100644
index 00000000000..65387371ec7
--- /dev/null
+++ b/idea/testData/wordSelection/FunctionWithLineCommentAfter/0.kt
@@ -0,0 +1,5 @@
+fun a() : Int {} // fun a
+
+fun b() : Short {
+ f()
+}
diff --git a/idea/testData/wordSelection/FunctionWithLineCommentAfter/1.kt b/idea/testData/wordSelection/FunctionWithLineCommentAfter/1.kt
new file mode 100644
index 00000000000..a497bd38d70
--- /dev/null
+++ b/idea/testData/wordSelection/FunctionWithLineCommentAfter/1.kt
@@ -0,0 +1,5 @@
+fun a() : Int {} // fun a
+
+fun b() : Short {
+ f()
+}
diff --git a/idea/testData/wordSelection/FunctionWithLineCommentAfter/2.kt b/idea/testData/wordSelection/FunctionWithLineCommentAfter/2.kt
new file mode 100644
index 00000000000..69bb376cf30
--- /dev/null
+++ b/idea/testData/wordSelection/FunctionWithLineCommentAfter/2.kt
@@ -0,0 +1,5 @@
+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
new file mode 100644
index 00000000000..02d25ec1ca7
--- /dev/null
+++ b/idea/testData/wordSelection/FunctionWithLineCommentAfter/3.kt
@@ -0,0 +1,5 @@
+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
new file mode 100644
index 00000000000..4aab5a46d79
--- /dev/null
+++ b/idea/testData/wordSelection/FunctionWithLineCommentAfter/4.kt
@@ -0,0 +1,5 @@
+fun a() : Int {} // fun a
+
+fun b() : Short {
+ f()
+}
diff --git a/idea/testData/wordSelection/FunctionWithLineCommentBefore/0.kt b/idea/testData/wordSelection/FunctionWithLineCommentBefore/0.kt
new file mode 100644
index 00000000000..0f9081a185d
--- /dev/null
+++ b/idea/testData/wordSelection/FunctionWithLineCommentBefore/0.kt
@@ -0,0 +1,6 @@
+fun a() : Int {}
+
+// TODO: Refactor
+fun b() : Short {
+ f()
+}
diff --git a/idea/testData/wordSelection/FunctionWithLineCommentBefore/1.kt b/idea/testData/wordSelection/FunctionWithLineCommentBefore/1.kt
new file mode 100644
index 00000000000..25d6585346e
--- /dev/null
+++ b/idea/testData/wordSelection/FunctionWithLineCommentBefore/1.kt
@@ -0,0 +1,6 @@
+fun a() : Int {}
+
+// TODO: Refactor
+fun b() : Short {
+ f()
+}
diff --git a/idea/testData/wordSelection/FunctionWithLineCommentBefore/2.kt b/idea/testData/wordSelection/FunctionWithLineCommentBefore/2.kt
new file mode 100644
index 00000000000..ae3e19e2c71
--- /dev/null
+++ b/idea/testData/wordSelection/FunctionWithLineCommentBefore/2.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/FunctionWithLineCommentBefore/3.kt b/idea/testData/wordSelection/FunctionWithLineCommentBefore/3.kt
new file mode 100644
index 00000000000..9890809da6d
--- /dev/null
+++ b/idea/testData/wordSelection/FunctionWithLineCommentBefore/3.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/LineComment/0.kt b/idea/testData/wordSelection/LineComment/0.kt
new file mode 100644
index 00000000000..8f7f7a82cd2
--- /dev/null
+++ b/idea/testData/wordSelection/LineComment/0.kt
@@ -0,0 +1,8 @@
+package p
+
+class C{
+ // This is a val
+ val v = 1
+
+ fun foo(){}
+}
diff --git a/idea/testData/wordSelection/LineComment/1.kt b/idea/testData/wordSelection/LineComment/1.kt
new file mode 100644
index 00000000000..9ad0a34b607
--- /dev/null
+++ b/idea/testData/wordSelection/LineComment/1.kt
@@ -0,0 +1,8 @@
+package p
+
+class C{
+ // This is a val
+ val v = 1
+
+ fun foo(){}
+}
diff --git a/idea/testData/wordSelection/LineComment/2.kt b/idea/testData/wordSelection/LineComment/2.kt
new file mode 100644
index 00000000000..31e8be0dcb4
--- /dev/null
+++ b/idea/testData/wordSelection/LineComment/2.kt
@@ -0,0 +1,8 @@
+package p
+
+class C{
+ // This is a val
+ val v = 1
+
+ fun foo(){}
+}
diff --git a/idea/testData/wordSelection/LineComment/3.kt b/idea/testData/wordSelection/LineComment/3.kt
new file mode 100644
index 00000000000..b6170ab0b68
--- /dev/null
+++ b/idea/testData/wordSelection/LineComment/3.kt
@@ -0,0 +1,8 @@
+package p
+
+class C{
+ // This is a val
+ val v = 1
+
+ fun foo(){}
+}
diff --git a/idea/testData/wordSelection/LineComment/4.kt b/idea/testData/wordSelection/LineComment/4.kt
new file mode 100644
index 00000000000..372c6cbf07a
--- /dev/null
+++ b/idea/testData/wordSelection/LineComment/4.kt
@@ -0,0 +1,8 @@
+package p
+
+class C{
+ // This is a val
+ val v = 1
+
+ fun foo(){}
+}
diff --git a/idea/testData/wordSelection/LineComment/5.kt b/idea/testData/wordSelection/LineComment/5.kt
new file mode 100644
index 00000000000..a25eb526270
--- /dev/null
+++ b/idea/testData/wordSelection/LineComment/5.kt
@@ -0,0 +1,8 @@
+package p
+
+class C{
+ // This is a val
+ val v = 1
+
+ fun foo(){}
+}
diff --git a/idea/testData/wordSelection/SimpleComment/0.kt b/idea/testData/wordSelection/SimpleComment/0.kt
new file mode 100644
index 00000000000..369d0fbc855
--- /dev/null
+++ b/idea/testData/wordSelection/SimpleComment/0.kt
@@ -0,0 +1,7 @@
+package p
+
+/* This is a comment */
+fun foo() {
+}
+
+fun bar(){}
\ No newline at end of file
diff --git a/idea/testData/wordSelection/SimpleComment/1.kt b/idea/testData/wordSelection/SimpleComment/1.kt
new file mode 100644
index 00000000000..99b3866d4ec
--- /dev/null
+++ b/idea/testData/wordSelection/SimpleComment/1.kt
@@ -0,0 +1,7 @@
+package p
+
+/* This is a comment */
+fun foo() {
+}
+
+fun bar(){}
\ No newline at end of file
diff --git a/idea/testData/wordSelection/SimpleComment/2.kt b/idea/testData/wordSelection/SimpleComment/2.kt
new file mode 100644
index 00000000000..5af97d14f0a
--- /dev/null
+++ b/idea/testData/wordSelection/SimpleComment/2.kt
@@ -0,0 +1,7 @@
+package p
+
+/* This is a comment */
+fun foo() {
+}
+
+fun bar(){}
\ No newline at end of file
diff --git a/idea/testData/wordSelection/SimpleComment/3.kt b/idea/testData/wordSelection/SimpleComment/3.kt
new file mode 100644
index 00000000000..0cafcb0c4ad
--- /dev/null
+++ b/idea/testData/wordSelection/SimpleComment/3.kt
@@ -0,0 +1,7 @@
+package p
+
+/* This is a comment */
+fun foo() {
+}
+
+fun bar(){}
\ No newline at end of file
diff --git a/idea/testData/wordSelection/SimpleComment/4.kt b/idea/testData/wordSelection/SimpleComment/4.kt
new file mode 100644
index 00000000000..f83c98f95fd
--- /dev/null
+++ b/idea/testData/wordSelection/SimpleComment/4.kt
@@ -0,0 +1,7 @@
+package p
+
+/* This is a comment */
+fun foo() {
+}
+
+fun bar(){}
\ No newline at end of file
diff --git a/idea/testData/wordSelection/Statements/10.kt b/idea/testData/wordSelection/Statements/10.kt
index 29dab7c1e26..0dfa15e2d0b 100644
--- a/idea/testData/wordSelection/Statements/10.kt
+++ b/idea/testData/wordSelection/Statements/10.kt
@@ -10,7 +10,7 @@ fun main(args : Array) {
}
}
-fun foo() : Unit {
+fun foo() : Unit {
println() {
println()
diff --git a/idea/testData/wordSelection/Statements/11.kt b/idea/testData/wordSelection/Statements/11.kt
index bfd75290e19..29dab7c1e26 100644
--- a/idea/testData/wordSelection/Statements/11.kt
+++ b/idea/testData/wordSelection/Statements/11.kt
@@ -1,4 +1,4 @@
-fun main(args : Array) {
+fun main(args : Array) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
@@ -10,7 +10,7 @@
}
}
-fun foo() : Unit {
+fun foo() : Unit {
println() {
println()
diff --git a/idea/testData/wordSelection/Statements/12.kt b/idea/testData/wordSelection/Statements/12.kt
new file mode 100644
index 00000000000..bfd75290e19
--- /dev/null
+++ b/idea/testData/wordSelection/Statements/12.kt
@@ -0,0 +1,24 @@
+fun main(args : Array) {
+ for (i in 1..100) {
+ when {
+ i%3 == 0 -> {print("Fizz"); continue;}
+ i%5 == 0 -> {print("Buzz"); continue;}
+
+ (i%3 != 0 && i%5 != 0) -> {print(i); continue;}
+ else -> println()
+ }
+ }
+}
+
+fun foo() : Unit {
+ println() {
+ println()
+
+
+ println()
+ println()
+ }
+
+ println(array(1, 2, 3))
+ println()
+}
\ No newline at end of file
diff --git a/idea/testData/wordSelection/Statements/6.kt b/idea/testData/wordSelection/Statements/6.kt
index d3128f07ee9..5aa29188de8 100644
--- a/idea/testData/wordSelection/Statements/6.kt
+++ b/idea/testData/wordSelection/Statements/6.kt
@@ -17,8 +17,8 @@ fun foo() : Unit {
println()
println()
- }
-
+ }
+
println(array(1, 2, 3))
println()
}
\ No newline at end of file
diff --git a/idea/testData/wordSelection/Statements/7.kt b/idea/testData/wordSelection/Statements/7.kt
index f8d8d794f83..d3128f07ee9 100644
--- a/idea/testData/wordSelection/Statements/7.kt
+++ b/idea/testData/wordSelection/Statements/7.kt
@@ -11,7 +11,7 @@ fun main(args : Array) {
}
fun foo() : Unit {
- println() {
+ println() {
println()
diff --git a/idea/testData/wordSelection/Statements/8.kt b/idea/testData/wordSelection/Statements/8.kt
index 24da15d38ea..f8d8d794f83 100644
--- a/idea/testData/wordSelection/Statements/8.kt
+++ b/idea/testData/wordSelection/Statements/8.kt
@@ -18,7 +18,7 @@ fun foo() : Unit {
println()
println()
}
-
+
println(array(1, 2, 3))
println()
-}
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/idea/testData/wordSelection/Statements/9.kt b/idea/testData/wordSelection/Statements/9.kt
index 0dfa15e2d0b..24da15d38ea 100644
--- a/idea/testData/wordSelection/Statements/9.kt
+++ b/idea/testData/wordSelection/Statements/9.kt
@@ -10,8 +10,8 @@ fun main(args : Array) {
}
}
-fun foo() : Unit {
- println() {
+fun foo() : Unit {
+ println() {
println()
@@ -21,4 +21,4 @@ fun foo() : Unit {
println(array(1, 2, 3))
println()
-}
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/idea/tests/org/jetbrains/jet/plugin/WordSelectionTest.java b/idea/tests/org/jetbrains/jet/plugin/WordSelectionTest.java
index 3e64811e018..9ea95f70b3d 100644
--- a/idea/tests/org/jetbrains/jet/plugin/WordSelectionTest.java
+++ b/idea/tests/org/jetbrains/jet/plugin/WordSelectionTest.java
@@ -23,29 +23,27 @@ import org.jetbrains.annotations.NotNull;
import java.io.File;
public class WordSelectionTest extends JetLightCodeInsightFixtureTestCase {
- public void testStatements() {
- doTest();
- }
+ public void testStatements() { doTest(); }
- public void testWhenEntries() {
- doTest();
- }
+ public void testWhenEntries() { doTest(); }
- public void testTypeArguments() {
- doTest();
- }
+ public void testTypeArguments() { doTest(); }
- public void testValueArguments() {
- doTest();
- }
+ public void testValueArguments() { doTest(); }
- public void testTypeParameters() {
- doTest();
- }
+ public void testTypeParameters() { doTest(); }
- public void testValueParameters() {
- doTest();
- }
+ public void testValueParameters() { doTest(); }
+
+ public void testDocComment() { doTest(); }
+
+ public void testFunctionWithLineCommentBefore() { doTest(); }
+
+ public void testFunctionWithLineCommentAfter() { doTest(); }
+
+ public void testLineComment() { doTest(); }
+
+ public void testSimpleComment() { doTest(); }
private void doTest() {
String dirName = getTestName(false);