<indexPatternBuilder implementation="org.jetbrains.plugins.groovy.util.GroovyIndexPatternBuilder"/>
+ <basicWordSelectionFilter implementation="org.jetbrains.plugins.groovy.editor.selection.GroovyWordSelectionFilter"/>
<extendWordSelectionHandler implementation="org.jetbrains.plugins.groovy.editor.selection.GroovyLiteralSelectioner"/>
<extendWordSelectionHandler implementation="org.jetbrains.plugins.groovy.editor.selection.GroovyBlockStatementsSelectioner"/>
<extendWordSelectionHandler implementation="org.jetbrains.plugins.groovy.editor.selection.GroovyTypeCastSelectioner"/>
<extendWordSelectionHandler implementation="org.jetbrains.plugins.groovy.editor.selection.GroovyDocParamsSelectioner"/>
<extendWordSelectionHandler implementation="org.jetbrains.plugins.groovy.editor.selection.GroovyArgListSelectioner"/>
+ <extendWordSelectionHandler implementation="org.jetbrains.plugins.groovy.editor.selection.GroovyGStringSelectioner" order="before wordSelectioner"/>
+ <extendWordSelectionHandler implementation="org.jetbrains.plugins.groovy.editor.selection.GroovyParameterListSelectioner"/>
<methodReferencesSearch implementation="org.jetbrains.plugins.groovy.findUsages.AccessorReferencesSearcher"/>
<methodReferencesSearch implementation="org.jetbrains.plugins.groovy.findUsages.MethodLateBoundReferencesSearcher"/>
package org.jetbrains.plugins.groovy.editor.selection;
-import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandler;
+import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandlerBase;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
-import com.intellij.util.text.CharArrayUtil;
-import java.util.ArrayList;
import java.util.List;
/**
* @author ilyas
*/
-public abstract class GroovyBasicSelectioner implements ExtendWordSelectionHandler {
-
+public abstract class GroovyBasicSelectioner extends ExtendWordSelectionHandlerBase {
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
-
- final TextRange originalRange = e.getTextRange();
- List<TextRange> ranges = expandToWholeLine(editorText, originalRange, true);
-
- if (ranges.size() == 1 && ranges.contains(originalRange)) {
- ranges = expandToWholeLine(editorText, originalRange, false);
- }
-
- List<TextRange> result = new ArrayList<TextRange>();
- result.addAll(ranges);
- return result;
- }
-
- static List<TextRange> expandToWholeLine(CharSequence text, TextRange range, boolean isSymmetric) {
- int textLength = text.length();
- List<TextRange> result = new ArrayList<TextRange>();
-
- if (range == null) {
- return result;
- }
-
- boolean hasNewLines = false;
-
- for (int i = range.getStartOffset(); i < range.getEndOffset(); i++) {
- char c = text.charAt(i);
-
- if (c == '\r' || c == '\n') {
- hasNewLines = true;
- break;
- }
- }
-
- if (!hasNewLines) {
- result.add(range);
- }
-
-
- int startOffset = range.getStartOffset();
- int endOffset = range.getEndOffset();
- int index1 = CharArrayUtil.shiftBackward(text, startOffset - 1, " \t");
- if (endOffset > startOffset && text.charAt(endOffset - 1) == '\n' || text.charAt(endOffset - 1) == '\r') {
- endOffset--;
- }
- int index2 = Math.min(textLength, CharArrayUtil.shiftForward(text, endOffset, " \t"));
-
- if (index1 < 0
- || text.charAt(index1) == '\n'
- || text.charAt(index1) == '\r'
- || index2 == textLength
- || text.charAt(index2) == '\n'
- || text.charAt(index2) == '\r') {
-
- if (!isSymmetric) {
- if (index1 < 0 || text.charAt(index1) == '\n' || text.charAt(index1) == '\r') {
- startOffset = index1 + 1;
- }
-
- if (index2 == textLength || text.charAt(index2) == '\n' || text.charAt(index2) == '\r') {
- endOffset = index2;
- if (endOffset < textLength) {
- endOffset++;
- if (endOffset < textLength && text.charAt(endOffset - 1) == '\r' && text.charAt(endOffset) == '\n') {
- endOffset++;
- }
- }
- }
-
- result.add(new TextRange(startOffset, endOffset));
- } else {
- if ((index1 < 0 || text.charAt(index1) == '\n' || text.charAt(index1) == '\r') &&
- (index2 == textLength || text.charAt(index2) == '\n' || text.charAt(index2) == '\r')) {
- startOffset = index1 + 1;
- endOffset = index2;
- if (endOffset < textLength) {
- endOffset++;
- if (endOffset < textLength && text.charAt(endOffset - 1) == '\r' && text.charAt(endOffset) == '\n') {
- endOffset++;
- }
- }
- result.add(new TextRange(startOffset, endOffset));
- } else {
- result.add(range);
- }
- }
- } else {
- result.add(range);
- }
-
- return result;
+ List<TextRange> ranges = super.select(e, editorText, cursorOffset, editor);
+ return ranges;
}
-
-
}
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.mGSTRING_CONTENT;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
+import org.jetbrains.plugins.groovy.lang.psi.util.GrStringUtil;
import java.util.List;
if (node == null) return false;
ASTNode[] children = node.getChildren(null);
return children.length == 1 &&
- (children[0].getElementType() == GroovyTokenTypes.mSTRING_LITERAL ||
+ (children[0].getElementType() == GroovyTokenTypes.mSTRING_LITERAL ||
children[0].getElementType() == GroovyTokenTypes.mGSTRING_LITERAL);
}
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
List<TextRange> result = super.select(e, editorText, cursorOffset, editor);
- TextRange range = e.getTextRange();
+/* TextRange range = e.getTextRange();
if (range.getLength() <= 2) {
result.add(range);
- } else {
+ }
+ else {
result.add(new TextRange(range.getStartOffset() + 1, range.getEndOffset() - 1));
+ }*/
+
+ int startOffset = -1;
+ int endOffset = -1;
+ final String text = e.getText();
+ final int stringOffset = e.getTextOffset();
+ if (e.getNode().getElementType() == mGSTRING_CONTENT) {
+ int cur;
+ int index = -1;
+ while (true) {
+ cur = text.indexOf('\n', index + 1);
+ if (cur < 0 || cur + stringOffset > cursorOffset) break;
+ index = cur;
+ }
+ if (index >= 0) {
+ startOffset = stringOffset + index + 1;
+ }
+
+ index = text.indexOf('\n', cursorOffset - stringOffset);
+ if (index >= 0) {
+ endOffset = stringOffset + index + 1;
+ }
}
+
+ if (startOffset >= 0 && endOffset >= 0) {
+ result.add(new TextRange(startOffset, endOffset));
+ }
+
+ final String content = GrStringUtil.removeQuotes(text);
+
+ final int offset = stringOffset + text.indexOf(content);
+ result.add(new TextRange(offset, offset + content.length()));
return result;
}
}
\ No newline at end of file
-/* The following code was generated by JFlex 1.4.1 on 12.10.09 13:24 */
+/* The following code was generated by JFlex 1.4.1 on 15.10.09 16:49 */
/*
* Copyright 2000-2007 JetBrains s.r.o.
import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
-
-import java.util.Stack;
+import java.util.*;
+import java.lang.reflect.Field;
+import org.jetbrains.annotations.NotNull;
/**
* This class is a scanner generated by
* <a href="http://www.jflex.de/">JFlex</a> 1.4.1
- * on 12.10.09 13:24 from the specification file
+ * on 15.10.09 16:49 from the specification file
* <tt>groovy.flex</tt>
*/
public class _GroovyLexer implements FlexLexer, GroovyTokenTypes {
"\0\u0460\0\u04a6\0\u04ec\0\u0532\0\u0578\0\u05be\0\u0604\0\u064a"+
"\0\u0690\0\u06d6\0\u0690\0\u071c\0\u0762\0\u07a8\0\u07ee\0\u0834"+
"\0\u087a\0\u08c0\0\u0906\0\u094c\0\u0992\0\u09d8\0\u0a1e\0\u0a64"+
- "\0\u0aaa\0\u0af0\0\u0b36\0\u0690\0\u0b7c\0\u0bc2\0\u0c08\0\u0c4e"+
+ "\0\u0aaa\0\u0af0\0\u0b36\0\u087a\0\u0b7c\0\u0bc2\0\u0c08\0\u0c4e"+
"\0\u0c94\0\u0cda\0\u0690\0\u0690\0\u0d20\0\u0d66\0\u0690\0\u0690"+
"\0\u0690\0\u0690\0\u0690\0\u0690\0\u0dac\0\u0df2\0\u0690\0\u0e38"+
"\0\u0e7e\0\u0ec4\0\u0f0a\0\u0690\0\u0690\0\u0f50\0\u0f96\0\u0fdc"+
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 =
- "\21\0\1\1\6\0\1\11\1\1\1\11\20\1\1\11"+
- "\6\1\2\11\2\1\6\11\2\1\1\11\4\1\2\11"+
- "\6\1\1\11\1\1\2\11\1\1\1\11\2\1\1\0"+
- "\2\11\1\7\1\1\1\11\1\1\2\3\1\11\1\1"+
- "\1\11\2\1\2\11\2\1\3\11\1\1\1\11\2\1"+
- "\5\11\5\1\1\11\2\1\1\11\1\1\1\11\1\3"+
- "\1\11\3\1\1\11\1\1\1\11\1\1\1\0\3\1"+
- "\1\11\1\1\2\11\1\1\6\11\2\0\15\1\5\11"+
- "\1\0\1\1\1\11\11\1\2\0\2\1\1\0\1\1"+
- "\2\11\1\1\1\11\1\1\1\0\1\11\1\0\6\11"+
- "\21\1\1\0\2\1\2\5\3\0\2\1\1\0\3\1"+
- "\2\0\3\1\1\5\1\0\2\1\1\11\1\1\1\0"+
- "\17\1\2\11\14\1\1\11\1\1\1\11\1\1\4\11"+
- "\1\0\25\1\2\11\1\0\10\1\2\11\30\1\3\0"+
- "\1\1\1\0\1\11\24\1\1\15\1\0\5\1\1\11"+
- "\1\0\21\1\2\0\1\1\1\0\24\1\1\0\15\1"+
- "\2\0\63\1";
+ "\21\0\1\1\6\0\1\11\1\1\1\11\27\1\2\11"+
+ "\2\1\6\11\2\1\1\11\4\1\2\11\6\1\1\11"+
+ "\1\1\2\11\1\1\1\11\2\1\1\0\2\11\1\7"+
+ "\1\1\1\11\1\1\2\3\1\11\1\1\1\11\2\1"+
+ "\2\11\2\1\3\11\1\1\1\11\2\1\5\11\5\1"+
+ "\1\11\2\1\1\11\1\1\1\11\1\3\1\11\3\1"+
+ "\1\11\1\1\1\11\1\1\1\0\3\1\1\11\1\1"+
+ "\2\11\1\1\6\11\2\0\15\1\5\11\1\0\1\1"+
+ "\1\11\11\1\2\0\2\1\1\0\1\1\2\11\1\1"+
+ "\1\11\1\1\1\0\1\11\1\0\6\11\21\1\1\0"+
+ "\2\1\2\5\3\0\2\1\1\0\3\1\2\0\3\1"+
+ "\1\5\1\0\2\1\1\11\1\1\1\0\17\1\2\11"+
+ "\14\1\1\11\1\1\1\11\1\1\4\11\1\0\25\1"+
+ "\2\11\1\0\10\1\2\11\30\1\3\0\1\1\1\0"+
+ "\1\11\24\1\1\15\1\0\5\1\1\11\1\0\21\1"+
+ "\2\0\1\1\1\0\24\1\1\0\15\1\2\0\63\1";
private static int [] zzUnpackAttribute() {
int [] result = new int[482];
mLETTER = [:letter:] | "_"
-mIDENT = {mLETTER} ({mLETTER} | {mDIGIT} | \$)*
+mIDENT = ({mLETTER}|\$) ({mLETTER} | {mDIGIT} | \$)*
mIDENT_NOBUCKS = {mLETTER} ({mLETTER} | {mDIGIT})*
}
}
- if (parent instanceof GrTypeDefinition && PsiModifier.STATIC.equals(modifier)) {
- if (((GrTypeDefinition)parent).getContainingClass() == null) return true;
- }
-
return false;
}
final GrClosableBlock closableBlock = ((GrStringInjection)child).getClosableBlock();
final GrReferenceExpression refExpr = (GrReferenceExpression)closableBlock.getStatements()[0];
final GrReferenceExpression copy = (GrReferenceExpression)refExpr.copy();
- closableBlock.replace(copy);
+ final ASTNode oldNode = closableBlock.getNode();
+ oldNode.getTreeParent().replaceChild(oldNode, copy.getNode());
}
}
}
if (qualifier != null) {
if (qualifier instanceof GrReferenceExpression) {
PsiElement qualifierResolved = ((GrReferenceExpression)qualifier).resolve();
- if (qualifierResolved instanceof PsiClass) { //static context
+ if (qualifierResolved instanceof PsiClass || qualifierResolved instanceof PsiPackage) { //static context
if (owner instanceof PsiClass) {
return true;
}
}
public void testSelectWordBeforeMethod() throws Throwable {
+ doTestForSelectWord(1);
+ }
+
+ public void testSWInGString1() throws Exception {doTestForSelectWord(1);}
+ public void testSWInGString2() throws Exception {doTestForSelectWord(2);}
+ public void testSWInGString3() throws Exception {doTestForSelectWord(3);}
+ public void testSWInGString4() throws Exception {doTestForSelectWord(4);}
+ public void testSWInGString5() throws Exception {doTestForSelectWord(5);}
+ public void testSWInParameterList() throws Exception {doTestForSelectWord(3);}
+
+ private void doTestForSelectWord(int count) throws Exception {
myFixture.configureByFile(getTestName(false) + ".groovy");
- performEditorAction(IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET);
+ myFixture.getEditor().getSettings().setCamelWords(true);
+ for (int i = 0; i < count; i++) {
+ performEditorAction(IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET);
+ }
myFixture.checkResultByFile(getTestName(false) + "_after.groovy");
}
}
public void testRawOverridedMethod() throws Exception {doTest();}
+
+ public void testFQNJavaClassesUsages() throws Exception {
+ doTest();
+ }
}
\ No newline at end of file
public void testDeclaration$decl7() throws Throwable { doTest(); }
public void testDeclaration$decl8() throws Throwable { doTest(); }
public void testDeclaration$decl9() throws Throwable { doTest(); }
+ public void testDeclaration$dollar() throws Throwable {doTest();}
public void testDeclaration$groovyMain() throws Throwable { doTest(); }
public void testDeclaration$GRVY1451() throws Throwable { doTest("declaration/GRVY-1451.test"); }
public void testDeclaration$methodCallAsMultiDecl() throws Throwable { doTest(); }