Converted code to Kotlin
This commit is contained in:
@@ -168,20 +168,59 @@
|
|||||||
name='com.intellij.codeInsight.editorActions.CopyPasteReferenceProcessor void restoreReferences(com.intellij.codeInsight.editorActions.ReferenceData[], TRef[]) 1'>
|
name='com.intellij.codeInsight.editorActions.CopyPasteReferenceProcessor void restoreReferences(com.intellij.codeInsight.editorActions.ReferenceData[], TRef[]) 1'>
|
||||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
</item>
|
</item>
|
||||||
<item
|
<item name='com.intellij.codeInsight.editorActions.ExtendWordSelectionHandler boolean canSelect(com.intellij.psi.PsiElement) 0'>
|
||||||
name='com.intellij.codeInsight.editorActions.JoinLinesHandlerDelegate int tryJoinLines(com.intellij.openapi.editor.Document, com.intellij.psi.PsiFile, int, int) 0'>
|
|
||||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
</item>
|
</item>
|
||||||
<item
|
<item
|
||||||
name='com.intellij.codeInsight.editorActions.JoinLinesHandlerDelegate int tryJoinLines(com.intellij.openapi.editor.Document, com.intellij.psi.PsiFile, int, int) 1'>
|
name='com.intellij.codeInsight.editorActions.ExtendWordSelectionHandler java.util.List<com.intellij.openapi.util.TextRange> select(com.intellij.psi.PsiElement, java.lang.CharSequence, int, com.intellij.openapi.editor.Editor)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
<annotation name='kotlin.jvm.KotlinSignature'>
|
||||||
|
<val name="value"
|
||||||
|
val=""fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List<TextRange>""/>
|
||||||
|
</annotation>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
name='com.intellij.codeInsight.editorActions.ExtendWordSelectionHandler java.util.List<com.intellij.openapi.util.TextRange> select(com.intellij.psi.PsiElement, java.lang.CharSequence, int, com.intellij.openapi.editor.Editor) 0'>
|
||||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
</item>
|
</item>
|
||||||
<item
|
<item
|
||||||
name='com.intellij.codeInsight.editorActions.JoinRawLinesHandlerDelegate int tryJoinRawLines(com.intellij.openapi.editor.Document, com.intellij.psi.PsiFile, int, int) 0'>
|
name='com.intellij.codeInsight.editorActions.ExtendWordSelectionHandler java.util.List<com.intellij.openapi.util.TextRange> select(com.intellij.psi.PsiElement, java.lang.CharSequence, int, com.intellij.openapi.editor.Editor) 1'>
|
||||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
</item>
|
</item>
|
||||||
<item
|
<item
|
||||||
name='com.intellij.codeInsight.editorActions.JoinRawLinesHandlerDelegate int tryJoinRawLines(com.intellij.openapi.editor.Document, com.intellij.psi.PsiFile, int, int) 1'>
|
name='com.intellij.codeInsight.editorActions.ExtendWordSelectionHandler java.util.List<com.intellij.openapi.util.TextRange> select(com.intellij.psi.PsiElement, java.lang.CharSequence, int, com.intellij.openapi.editor.Editor) 3'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
name='com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase java.util.List<com.intellij.openapi.util.TextRange> expandToWholeLine(java.lang.CharSequence, com.intellij.openapi.util.TextRange)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
name='com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase java.util.List<com.intellij.openapi.util.TextRange> expandToWholeLine(java.lang.CharSequence, com.intellij.openapi.util.TextRange) 0'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
name='com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase java.util.List<com.intellij.openapi.util.TextRange> expandToWholeLine(java.lang.CharSequence, com.intellij.openapi.util.TextRange) 1'>
|
||||||
|
<annotation name='org.jetbrains.annotations.Nullable'/>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
name='com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase java.util.List<com.intellij.openapi.util.TextRange> expandToWholeLine(java.lang.CharSequence, com.intellij.openapi.util.TextRange, boolean)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
name='com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase java.util.List<com.intellij.openapi.util.TextRange> expandToWholeLine(java.lang.CharSequence, com.intellij.openapi.util.TextRange, boolean) 0'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
name='com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase java.util.List<com.intellij.openapi.util.TextRange> select(com.intellij.psi.PsiElement, java.lang.CharSequence, int, com.intellij.openapi.editor.Editor)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
<annotation name='kotlin.jvm.KotlinSignature'>
|
||||||
|
<val name="value"
|
||||||
|
val=""fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List<TextRange>""/>
|
||||||
|
</annotation>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
name='com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase java.util.List<com.intellij.openapi.util.TextRange> select(com.intellij.psi.PsiElement, java.lang.CharSequence, int, com.intellij.openapi.editor.Editor) 3'>
|
||||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
</item>
|
</item>
|
||||||
</root>
|
</root>
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<root>
|
||||||
|
<item name='com.intellij.codeInsight.editorActions.wordSelection.BasicSelectioner boolean canSelect(com.intellij.psi.PsiElement) 0'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
name='com.intellij.codeInsight.editorActions.wordSelection.BasicSelectioner boolean canSelectBasic(com.intellij.psi.PsiElement) 0'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
</root>
|
||||||
@@ -1,4 +1,16 @@
|
|||||||
<root>
|
<root>
|
||||||
|
<item name='com.intellij.openapi.util.text.LineTokenizer java.lang.String[] tokenize(char[], boolean)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item name='com.intellij.openapi.util.text.LineTokenizer java.lang.String[] tokenize(char[], boolean, boolean)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item name='com.intellij.openapi.util.text.LineTokenizer java.lang.String[] tokenize(char[], int, int, boolean)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item name='com.intellij.openapi.util.text.LineTokenizer java.lang.String[] tokenize(char[], int, int, boolean, boolean)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
<item name='com.intellij.openapi.util.text.StringUtil java.lang.String decapitalize(java.lang.String)'>
|
<item name='com.intellij.openapi.util.text.StringUtil java.lang.String decapitalize(java.lang.String)'>
|
||||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2013 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 com.intellij.psi.impl.source.tree.LeafPsiElement;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetBlockExpression;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetWhenExpression;
|
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Originally from IDEA platform: CodeBlockOrInitializerSelectioner
|
|
||||||
*/
|
|
||||||
public class JetCodeBlockSelectioner extends BasicSelectioner {
|
|
||||||
public boolean canSelect(PsiElement e) {
|
|
||||||
return e instanceof JetBlockExpression || e instanceof JetWhenExpression;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
|
|
||||||
List<TextRange> result = new ArrayList<TextRange>();
|
|
||||||
|
|
||||||
result.add(e.getTextRange());
|
|
||||||
|
|
||||||
ASTNode[] children = e.getNode().getChildren(null);
|
|
||||||
if (children.length == 0) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
int start = findOpeningBrace(children);
|
|
||||||
int end = findClosingBrace(children, start);
|
|
||||||
|
|
||||||
result.addAll(expandToWholeLine(editorText, new TextRange(start, end)));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int findOpeningBrace(ASTNode[] children) {
|
|
||||||
int start = children[children.length - 1].getTextRange().getStartOffset();
|
|
||||||
for (int i = 0; i < children.length; i++) {
|
|
||||||
PsiElement child = children[i].getPsi();
|
|
||||||
|
|
||||||
if (child instanceof LeafPsiElement) {
|
|
||||||
if (((LeafPsiElement) child).getElementType() == JetTokens.LBRACE) {
|
|
||||||
int j = i + 1;
|
|
||||||
|
|
||||||
while (children[j] instanceof PsiWhiteSpace) {
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
|
|
||||||
start = children[j].getTextRange().getStartOffset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int findClosingBrace(ASTNode[] children, int startOffset) {
|
|
||||||
int end = children[children.length - 1].getTextRange().getEndOffset();
|
|
||||||
for (int i = 0; i < children.length; i++) {
|
|
||||||
PsiElement child = children[i].getPsi();
|
|
||||||
|
|
||||||
if (child instanceof LeafPsiElement) {
|
|
||||||
if (((LeafPsiElement) child).getElementType() == JetTokens.RBRACE) {
|
|
||||||
int j = i - 1;
|
|
||||||
|
|
||||||
while (children[j] instanceof PsiWhiteSpace && children[j].getTextRange().getStartOffset() > startOffset) {
|
|
||||||
j--;
|
|
||||||
}
|
|
||||||
|
|
||||||
end = children[j].getTextRange().getEndOffset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.intellij.psi.impl.source.tree.LeafPsiElement
|
||||||
|
import org.jetbrains.jet.lang.psi.JetBlockExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetWhenExpression
|
||||||
|
import org.jetbrains.jet.lexer.JetTokens
|
||||||
|
|
||||||
|
import java.util.ArrayList
|
||||||
|
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Originally from IDEA platform: CodeBlockOrInitializerSelectioner
|
||||||
|
*/
|
||||||
|
public class JetCodeBlockSelectioner : BasicSelectioner() {
|
||||||
|
override fun canSelect(e: PsiElement): Boolean {
|
||||||
|
return e is JetBlockExpression || e is JetWhenExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List<TextRange> {
|
||||||
|
val result = ArrayList<TextRange>()
|
||||||
|
|
||||||
|
val children = e.getNode()!!.getChildren(null)
|
||||||
|
|
||||||
|
val start = findOpeningBrace(children)
|
||||||
|
val end = findClosingBrace(children, start)
|
||||||
|
|
||||||
|
result.add(e.getTextRange()!!)
|
||||||
|
result.addAll(ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, TextRange(start, end)))
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
class object {
|
||||||
|
public fun findOpeningBrace(children: Array<ASTNode>): Int {
|
||||||
|
var start = children.last().getTextRange()!!.getStartOffset()
|
||||||
|
for ((i, child) in children.withIndices()) {
|
||||||
|
if (child is LeafPsiElement) {
|
||||||
|
if (child.getElementType() == JetTokens.LBRACE) {
|
||||||
|
var j = i + 1
|
||||||
|
while (children[j] is PsiWhiteSpace) {
|
||||||
|
j++
|
||||||
|
}
|
||||||
|
|
||||||
|
start = children[j].getTextRange()!!.getStartOffset()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return start
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun findClosingBrace(children: Array<ASTNode>, startOffset: Int): Int {
|
||||||
|
var end = children[children.size - 1].getTextRange()!!.getEndOffset()
|
||||||
|
for ((i, child) in children.withIndices()) {
|
||||||
|
if (child is LeafPsiElement) {
|
||||||
|
if (child.getElementType() == JetTokens.RBRACE) {
|
||||||
|
var j = i - 1
|
||||||
|
while (children[j] is PsiWhiteSpace && children[j].getTextRange()!!.getStartOffset() > startOffset) {
|
||||||
|
j--
|
||||||
|
}
|
||||||
|
|
||||||
|
end = children[j].getTextRange()!!.getEndOffset()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2013 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.tree.TokenSet;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetParameterList;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetTypeArgumentList;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetTypeParameterList;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetValueArgumentList;
|
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class JetListSelectioner extends BasicSelectioner {
|
|
||||||
@Override
|
|
||||||
public boolean canSelect(PsiElement e) {
|
|
||||||
return e instanceof JetParameterList || e instanceof JetValueArgumentList ||
|
|
||||||
e instanceof JetTypeParameterList || e instanceof JetTypeArgumentList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
|
|
||||||
ASTNode node = e.getNode();
|
|
||||||
ASTNode startNode = node.findChildByType(TokenSet.create(JetTokens.LPAR, JetTokens.LT));
|
|
||||||
ASTNode endNode = node.findChildByType(TokenSet.create(JetTokens.RPAR, JetTokens.GT));
|
|
||||||
if (startNode != null && endNode != null) {
|
|
||||||
return Arrays.asList(new TextRange(startNode.getStartOffset() + 1, endNode.getStartOffset()));
|
|
||||||
} else {
|
|
||||||
return Arrays.asList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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.tree.TokenSet
|
||||||
|
import org.jetbrains.jet.lang.psi.JetParameterList
|
||||||
|
import org.jetbrains.jet.lang.psi.JetTypeArgumentList
|
||||||
|
import org.jetbrains.jet.lang.psi.JetTypeParameterList
|
||||||
|
import org.jetbrains.jet.lang.psi.JetValueArgumentList
|
||||||
|
import org.jetbrains.jet.lexer.JetTokens
|
||||||
|
|
||||||
|
import java.util.Arrays
|
||||||
|
|
||||||
|
public class JetListSelectioner : BasicSelectioner() {
|
||||||
|
override fun canSelect(e: PsiElement): Boolean {
|
||||||
|
return e is JetParameterList || e is JetValueArgumentList || e is JetTypeParameterList || e is JetTypeArgumentList
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List<TextRange> {
|
||||||
|
val node = e.getNode()!!
|
||||||
|
val startNode = node.findChildByType(TokenSet.create(JetTokens.LPAR, JetTokens.LT))
|
||||||
|
val endNode = node.findChildByType(TokenSet.create(JetTokens.RPAR, JetTokens.GT))
|
||||||
|
if (startNode != null && endNode != null) {
|
||||||
|
return Arrays.asList<TextRange>(TextRange(startNode.getStartOffset() + 1, endNode.getStartOffset()))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Arrays.asList<TextRange>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
-114
@@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2013 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.openapi.editor.Editor;
|
|
||||||
import com.intellij.openapi.util.TextRange;
|
|
||||||
import com.intellij.openapi.util.text.LineTokenizer;
|
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import com.intellij.psi.PsiWhiteSpace;
|
|
||||||
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetBlockExpression;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetWhenEntry;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetWhenExpression;
|
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Originally from IDEA platform: StatementGroupSelectioner
|
|
||||||
*/
|
|
||||||
public class JetStatementGroupSelectioner extends BasicSelectioner {
|
|
||||||
@Override
|
|
||||||
public boolean canSelect(PsiElement e) {
|
|
||||||
return e instanceof JetExpression || e instanceof JetWhenEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
|
|
||||||
List<TextRange> result = new ArrayList<TextRange>();
|
|
||||||
|
|
||||||
PsiElement parent = e.getParent();
|
|
||||||
|
|
||||||
if (!(parent instanceof JetBlockExpression) && !(parent instanceof JetWhenExpression)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PsiElement startElement = e;
|
|
||||||
PsiElement endElement = e;
|
|
||||||
|
|
||||||
|
|
||||||
while (startElement.getPrevSibling() != null) {
|
|
||||||
PsiElement sibling = startElement.getPrevSibling();
|
|
||||||
|
|
||||||
if (sibling instanceof LeafPsiElement) {
|
|
||||||
if (((LeafPsiElement) sibling).getElementType() == JetTokens.LBRACE) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sibling instanceof PsiWhiteSpace) {
|
|
||||||
PsiWhiteSpace whiteSpace = (PsiWhiteSpace) sibling;
|
|
||||||
|
|
||||||
String[] strings = LineTokenizer.tokenize(whiteSpace.getText().toCharArray(), false);
|
|
||||||
if (strings.length > 2) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
startElement = sibling;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (startElement instanceof PsiWhiteSpace) {
|
|
||||||
startElement = startElement.getNextSibling();
|
|
||||||
}
|
|
||||||
|
|
||||||
while (endElement.getNextSibling() != null) {
|
|
||||||
PsiElement sibling = endElement.getNextSibling();
|
|
||||||
|
|
||||||
if (sibling instanceof LeafPsiElement) {
|
|
||||||
if (((LeafPsiElement) sibling).getElementType() == JetTokens.RBRACE) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sibling instanceof PsiWhiteSpace) {
|
|
||||||
PsiWhiteSpace whiteSpace = (PsiWhiteSpace) sibling;
|
|
||||||
|
|
||||||
String[] strings = LineTokenizer.tokenize(whiteSpace.getText().toCharArray(), false);
|
|
||||||
if (strings.length > 2) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
endElement = sibling;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (endElement instanceof PsiWhiteSpace) {
|
|
||||||
endElement = endElement.getPrevSibling();
|
|
||||||
}
|
|
||||||
|
|
||||||
result.addAll(expandToWholeLine(editorText, new TextRange(startElement.getTextRange().getStartOffset(),
|
|
||||||
endElement.getTextRange().getEndOffset())));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+80
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* 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.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.util.TextRange
|
||||||
|
import com.intellij.openapi.util.text.LineTokenizer
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.PsiWhiteSpace
|
||||||
|
import com.intellij.psi.impl.source.tree.LeafPsiElement
|
||||||
|
import org.jetbrains.jet.lang.psi.JetBlockExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetWhenEntry
|
||||||
|
import org.jetbrains.jet.lang.psi.JetWhenExpression
|
||||||
|
import org.jetbrains.jet.lexer.JetTokens
|
||||||
|
|
||||||
|
import java.util.ArrayList
|
||||||
|
import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Originally from IDEA platform: StatementGroupSelectioner
|
||||||
|
*/
|
||||||
|
public class JetStatementGroupSelectioner : BasicSelectioner() {
|
||||||
|
override fun canSelect(e: PsiElement)
|
||||||
|
= e is JetExpression || e is JetWhenEntry
|
||||||
|
|
||||||
|
override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List<TextRange> {
|
||||||
|
val parent = e.getParent()
|
||||||
|
if (parent !is JetBlockExpression && parent !is JetWhenExpression) {
|
||||||
|
return listOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
var startElement = e
|
||||||
|
while (startElement.getPrevSibling() != null) {
|
||||||
|
val sibling = startElement.getPrevSibling()
|
||||||
|
|
||||||
|
if (sibling is LeafPsiElement && sibling.getElementType() == JetTokens.LBRACE) break
|
||||||
|
|
||||||
|
if (sibling is PsiWhiteSpace && LineTokenizer.tokenize(sibling.getText()!!.toCharArray(), false).size > 2) break
|
||||||
|
|
||||||
|
startElement = sibling!!
|
||||||
|
}
|
||||||
|
|
||||||
|
while (startElement is PsiWhiteSpace) {
|
||||||
|
startElement = startElement.getNextSibling()!!
|
||||||
|
}
|
||||||
|
|
||||||
|
var endElement = e
|
||||||
|
while (endElement.getNextSibling() != null) {
|
||||||
|
val sibling = endElement.getNextSibling()
|
||||||
|
|
||||||
|
if (sibling is LeafPsiElement && sibling.getElementType() == JetTokens.RBRACE) break
|
||||||
|
|
||||||
|
if (sibling is PsiWhiteSpace && LineTokenizer.tokenize(sibling.getText()!!.toCharArray(), false).size > 2) break
|
||||||
|
|
||||||
|
endElement = sibling!!
|
||||||
|
}
|
||||||
|
|
||||||
|
while (endElement is PsiWhiteSpace) {
|
||||||
|
endElement = endElement.getPrevSibling()!!
|
||||||
|
}
|
||||||
|
|
||||||
|
return ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, TextRange(startElement.getTextRange()!!.getStartOffset(), endElement.getTextRange()!!.getEndOffset()))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user