mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'master' of git.labs.intellij.net:idea/community
This commit is contained in:
+8
@@ -17,6 +17,7 @@ package com.intellij.codeInsight.template.impl;
|
||||
|
||||
import com.intellij.codeInsight.completion.*;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.patterns.PlatformPatterns;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
@@ -42,6 +43,13 @@ public class LiveTemplateCompletionContributor extends CompletionContributor {
|
||||
|
||||
final PsiFile file = parameters.getOriginalFile();
|
||||
final int offset = parameters.getOffset();
|
||||
if (Registry.is("show.live.templates.in.completion")) {
|
||||
for (final TemplateImpl possible : listApplicableTemplates(file, offset)) {
|
||||
result.addElement(new LiveTemplateLookupElement(possible.getKey(), possible));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final String prefix = result.getPrefixMatcher().getPrefix();
|
||||
final TemplateImpl template = findApplicableTemplate(file, offset, prefix);
|
||||
if (template != null) {
|
||||
|
||||
@@ -34,7 +34,6 @@ public class ShowHistoryAction extends EditorHeaderAction implements DumbAware {
|
||||
//ContainerUtil.addAll(shortcuts, ActionManager.getInstance().getAction(IdeActions.ACTION_FIND).getShortcutSet().getShortcuts());
|
||||
ContainerUtil.addAll(shortcuts, ActionManager.getInstance().getAction("IncrementalSearch").getShortcutSet().getShortcuts());
|
||||
}
|
||||
shortcuts.add(new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), null));
|
||||
shortcuts.add(new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_DOWN_MASK), null));
|
||||
|
||||
registerCustomShortcutSet(
|
||||
|
||||
@@ -131,3 +131,4 @@ jvmbugfix.mac.caccessibleLeak=true
|
||||
projectView.showHierarchyErrors=false
|
||||
dir.diff.default.src.folder=
|
||||
dir.diff.default.trg.folder=
|
||||
show.live.templates.in.completion=false
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ package org.jetbrains.plugins.groovy.editor.selection;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock;
|
||||
|
||||
import java.util.List;
|
||||
@@ -68,6 +68,6 @@ public class GroovyBlockStatementsSelectioner extends GroovyBasicSelectioner {
|
||||
}
|
||||
|
||||
private static boolean isWhiteSpace(PsiElement element) {
|
||||
return element != null && GroovyTokenTypes.WHITE_SPACES_SET.contains(element.getNode().getElementType());
|
||||
return element != null && TokenSets.WHITE_SPACES_SET.contains(element.getNode().getElementType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,12 +42,12 @@ class GroovyWordsScanner implements WordsScanner
|
||||
|
||||
while (myLexer.getTokenType() != null) {
|
||||
final IElementType type = myLexer.getTokenType();
|
||||
if (type == mIDENT || KEYWORDS.contains(type)) {
|
||||
if (type == mIDENT || TokenSets.KEYWORDS.contains(type)) {
|
||||
if (occurrence == null) occurrence = new WordOccurrence(fileText,myLexer.getTokenStart(),myLexer.getTokenEnd(), WordOccurrence.Kind.CODE);
|
||||
else occurrence.init(fileText,myLexer.getTokenStart(),myLexer.getTokenEnd(), WordOccurrence.Kind.CODE);
|
||||
if (!processor.process(occurrence)) return;
|
||||
}
|
||||
else if (COMMENT_SET.contains(type)) {
|
||||
else if (TokenSets.COMMENT_SET.contains(type)) {
|
||||
if (!stripWords(processor, fileText,myLexer.getTokenStart(),myLexer.getTokenEnd(), WordOccurrence.Kind.COMMENTS, occurrence)) return;
|
||||
}
|
||||
else if (TokenSets.STRING_LITERALS.contains(type)) {
|
||||
|
||||
@@ -34,7 +34,7 @@ import com.intellij.util.containers.CollectionFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType;
|
||||
import org.jetbrains.plugins.groovy.formatter.processors.GroovyIndentProcessor;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrQualifiedReference;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
@@ -249,8 +249,8 @@ public class GroovyBlockGenerator implements GroovyElementTypes {
|
||||
}
|
||||
|
||||
private static boolean isKeyword(ASTNode node) {
|
||||
return node != null && (GroovyTokenTypes.KEYWORDS.contains(node.getElementType()) ||
|
||||
GroovyTokenTypes.BRACES.contains(node.getElementType()));
|
||||
return node != null && (TokenSets.KEYWORDS.contains(node.getElementType()) ||
|
||||
TokenSets.BRACES.contains(node.getElementType()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-2
@@ -32,6 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
|
||||
/**
|
||||
* @author ilyas
|
||||
@@ -68,12 +69,12 @@ public class GroovyFormattingModelBuilder implements FormattingModelBuilder {
|
||||
@Override
|
||||
protected String replaceWithPsiInLeaf(TextRange textRange, String whiteSpace, ASTNode leafElement) {
|
||||
if (!myCanModifyAllWhiteSpaces) {
|
||||
if (GroovyTokenTypes.WHITE_SPACES_SET.contains(leafElement.getElementType())) return null;
|
||||
if (TokenSets.WHITE_SPACES_SET.contains(leafElement.getElementType())) return null;
|
||||
}
|
||||
|
||||
IElementType elementTypeToUse = TokenType.WHITE_SPACE;
|
||||
ASTNode prevNode = TreeUtil.prevLeaf(leafElement);
|
||||
if (prevNode != null && GroovyTokenTypes.WHITE_SPACES_SET.contains(prevNode.getElementType())) {
|
||||
if (prevNode != null && TokenSets.WHITE_SPACES_SET.contains(prevNode.getElementType())) {
|
||||
elementTypeToUse = prevNode.getElementType();
|
||||
}
|
||||
FormatterUtil.replaceWhiteSpace(whiteSpace, leafElement, elementTypeToUse, textRange);
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMe
|
||||
import static org.jetbrains.plugins.groovy.GroovyFileType.GROOVY_LANGUAGE;
|
||||
import static org.jetbrains.plugins.groovy.lang.groovydoc.lexer.GroovyDocTokenTypes.mGDOC_TAG_VALUE_COMMA;
|
||||
import static org.jetbrains.plugins.groovy.lang.groovydoc.lexer.GroovyDocTokenTypes.mGDOC_TAG_VALUE_LPAREN;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.COMMENT_SET;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.TokenSets.COMMENT_SET;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.kELSE;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.kNEW;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.kSWITCH;
|
||||
|
||||
+3
-2
@@ -25,7 +25,6 @@ import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.plugins.groovy.formatter.GroovyBlock;
|
||||
import org.jetbrains.plugins.groovy.formatter.MethodCallWithoutQualifierBlock;
|
||||
import org.jetbrains.plugins.groovy.formatter.models.spacing.SpacingTokens;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrConditionalExpression;
|
||||
@@ -37,6 +36,8 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner;
|
||||
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.TokenSets.*;
|
||||
|
||||
/**
|
||||
* @author ilyas
|
||||
*/
|
||||
@@ -126,7 +127,7 @@ public abstract class GroovySpacingProcessorBasic extends SpacingTokens implemen
|
||||
return NO_SPACING;
|
||||
}
|
||||
|
||||
if (GroovyTokenTypes.DOTS.contains(leftType)) {
|
||||
if (DOTS.contains(leftType)) {
|
||||
return NO_SPACING_WITH_NEWLINE;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.intellij.psi.impl.cache.impl.todo.LexerBasedTodoIndexer;
|
||||
import com.intellij.psi.impl.cache.impl.todo.TodoOccurrenceConsumer;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyFilterLexer;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
@@ -30,6 +30,6 @@ public class GroovyTodoIndexer extends LexerBasedTodoIndexer {
|
||||
@Override
|
||||
protected Lexer createLexer(TodoOccurrenceConsumer consumer) {
|
||||
final GroovyFilterLexer groovyFilterLexer = new GroovyFilterLexer(new GroovyLexer(), consumer);
|
||||
return new FilterLexer(groovyFilterLexer, new FilterLexer.SetFilter(GroovyTokenTypes.WHITE_SPACES_OR_COMMENTS));
|
||||
return new FilterLexer(groovyFilterLexer, new FilterLexer.SetFilter(TokenSets.WHITE_SPACES_OR_COMMENTS));
|
||||
}
|
||||
}
|
||||
|
||||
+17
-19
@@ -41,9 +41,6 @@ import com.intellij.util.PairConsumer;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyBundle;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
@@ -65,6 +62,8 @@ import java.util.*;
|
||||
import static com.intellij.patterns.PlatformPatterns.psiElement;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.elementType;
|
||||
import static com.intellij.util.containers.CollectionFactory.hashMap;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.*;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.TokenSets.*;
|
||||
|
||||
/**
|
||||
* @author ilyas
|
||||
@@ -138,24 +137,23 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
};
|
||||
|
||||
private static final PsiElementPattern.Capture<PsiElement> STATEMENT_START =
|
||||
psiElement(GroovyElementTypes.mIDENT).andOr(
|
||||
psiElement(mIDENT).andOr(
|
||||
psiElement().afterLeaf(StandardPatterns.or(
|
||||
psiElement().isNull(),
|
||||
psiElement().withElementType(TokenSets.SEPARATORS),
|
||||
psiElement(GroovyElementTypes.mLCURLY),
|
||||
psiElement(GroovyElementTypes.kELSE)
|
||||
psiElement().withElementType(SEPARATORS),
|
||||
psiElement(mLCURLY),
|
||||
psiElement(kELSE)
|
||||
)).andNot(psiElement().withParent(GrTypeDefinitionBody.class))
|
||||
.andNot(psiElement(PsiErrorElement.class)),
|
||||
psiElement().afterLeaf(psiElement(GroovyTokenTypes.mRPAREN)).withSuperParent(2, StandardPatterns.or(
|
||||
psiElement().afterLeaf(psiElement(mRPAREN)).withSuperParent(2, StandardPatterns.or(
|
||||
psiElement(GrForStatement.class),
|
||||
psiElement(GrWhileStatement.class),
|
||||
psiElement(GrIfStatement.class)
|
||||
))
|
||||
);
|
||||
|
||||
private static final ElementPattern<PsiElement> AFTER_NUMBER_LITERAL =
|
||||
psiElement().afterLeaf(psiElement().withElementType(
|
||||
elementType().oneOf(GroovyElementTypes.mNUM_DOUBLE, GroovyElementTypes.mNUM_INT, GroovyElementTypes.mNUM_LONG, GroovyElementTypes.mNUM_FLOAT, GroovyElementTypes.mNUM_BIG_INT, GroovyElementTypes.mNUM_BIG_DECIMAL)));
|
||||
private static final ElementPattern<PsiElement> AFTER_NUMBER_LITERAL = psiElement().afterLeaf(
|
||||
psiElement().withElementType(elementType().oneOf(mNUM_DOUBLE, mNUM_INT, mNUM_LONG, mNUM_FLOAT, mNUM_BIG_INT, mNUM_BIG_DECIMAL)));
|
||||
private static final ElementPattern<PsiElement> AFTER_AT = psiElement().afterLeaf("@");
|
||||
private static final ElementPattern<PsiElement> IN_CATCH_TYPE = psiElement().afterLeaf(psiElement().withText("(").withParent(GrCatchClause.class));
|
||||
|
||||
@@ -526,7 +524,7 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
public static boolean isInPossibleClosureParameter(PsiElement position) { //Closure cl={String x, <caret>...
|
||||
if (position == null) return false;
|
||||
|
||||
if (position instanceof PsiWhiteSpace || position.getNode().getElementType() == GroovyElementTypes.mNLS) {
|
||||
if (position instanceof PsiWhiteSpace || position.getNode().getElementType() == mNLS) {
|
||||
position = FilterPositionUtil.searchNonSpaceNonCommentBack(position);
|
||||
}
|
||||
|
||||
@@ -535,7 +533,7 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
PsiElement parent = position.getParent();
|
||||
if (parent instanceof GrVariable) {
|
||||
PsiElement prev = FilterPositionUtil.searchNonSpaceNonCommentBack(parent);
|
||||
hasCommas = prev != null && prev.getNode().getElementType() == GroovyElementTypes.mCOMMA;
|
||||
hasCommas = prev != null && prev.getNode().getElementType() == mCOMMA;
|
||||
}
|
||||
|
||||
if (parent instanceof GrClosableBlock) {
|
||||
@@ -545,7 +543,7 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
return hasCommas;
|
||||
}
|
||||
|
||||
boolean isComma = sibling instanceof LeafPsiElement && GroovyElementTypes.mCOMMA == ((LeafPsiElement)sibling).getElementType();
|
||||
boolean isComma = sibling instanceof LeafPsiElement && mCOMMA == ((LeafPsiElement)sibling).getElementType();
|
||||
hasCommas |= isComma;
|
||||
|
||||
if (isComma ||
|
||||
@@ -571,22 +569,22 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
HighlighterIterator iterator = ((EditorEx)context.getEditor()).getHighlighter().createIterator(context.getStartOffset());
|
||||
if (iterator.atEnd()) return false;
|
||||
|
||||
if (iterator.getTokenType() == GroovyTokenTypes.mIDENT) {
|
||||
if (iterator.getTokenType() == mIDENT) {
|
||||
iterator.advance();
|
||||
}
|
||||
|
||||
if (!iterator.atEnd() && iterator.getTokenType() == GroovyTokenTypes.mLPAREN) {
|
||||
if (!iterator.atEnd() && iterator.getTokenType() == mLPAREN) {
|
||||
return true;
|
||||
}
|
||||
|
||||
while (!iterator.atEnd() && GroovyTokenTypes.WHITE_SPACES_OR_COMMENTS.contains(iterator.getTokenType())) {
|
||||
while (!iterator.atEnd() && WHITE_SPACES_OR_COMMENTS.contains(iterator.getTokenType())) {
|
||||
iterator.advance();
|
||||
}
|
||||
|
||||
if (iterator.atEnd() || iterator.getTokenType() != GroovyTokenTypes.mIDENT) return false;
|
||||
if (iterator.atEnd() || iterator.getTokenType() != mIDENT) return false;
|
||||
iterator.advance();
|
||||
|
||||
while (!iterator.atEnd() && GroovyTokenTypes.WHITE_SPACES_OR_COMMENTS.contains(iterator.getTokenType())) {
|
||||
while (!iterator.atEnd() && WHITE_SPACES_OR_COMMENTS.contains(iterator.getTokenType())) {
|
||||
iterator.advance();
|
||||
}
|
||||
return true;
|
||||
|
||||
+12
-9
@@ -38,6 +38,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.psi.util.PsiFormatUtilBase;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -48,7 +49,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType;
|
||||
import org.jetbrains.plugins.groovy.GroovyIcons;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
@@ -74,6 +75,8 @@ import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.*;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.TokenSets.*;
|
||||
import static org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils.*;
|
||||
|
||||
/**
|
||||
@@ -104,7 +107,7 @@ public class GroovyCompletionUtil {
|
||||
while (elem != null &&
|
||||
(elem instanceof PsiWhiteSpace ||
|
||||
elem instanceof PsiComment ||
|
||||
GroovyTokenTypes.mNLS.equals(elem.getNode().getElementType()))) {
|
||||
mNLS.equals(elem.getNode().getElementType()))) {
|
||||
elem = elem.getPrevSibling();
|
||||
}
|
||||
return elem;
|
||||
@@ -120,7 +123,7 @@ public class GroovyCompletionUtil {
|
||||
public static boolean isNewStatement(PsiElement element, boolean canBeAfterBrace) {
|
||||
PsiElement previousLeaf = getLeafByOffset(element.getTextRange().getStartOffset() - 1, element);
|
||||
previousLeaf = PsiImplUtil.realPrevious(previousLeaf);
|
||||
if (previousLeaf != null && canBeAfterBrace && GroovyElementTypes.mLCURLY.equals(previousLeaf.getNode().getElementType())) {
|
||||
if (previousLeaf != null && canBeAfterBrace && mLCURLY.equals(previousLeaf.getNode().getElementType())) {
|
||||
return true;
|
||||
}
|
||||
return (previousLeaf == null || SEPARATORS.contains(previousLeaf.getNode().getElementType()));
|
||||
@@ -165,8 +168,8 @@ public class GroovyCompletionUtil {
|
||||
return variableDeclaration.getVariables()[0] == parent;
|
||||
}
|
||||
|
||||
private static final TokenSet SEPARATORS = TokenSet.create(GroovyElementTypes.mNLS,
|
||||
GroovyElementTypes.mSEMI);
|
||||
private static final TokenSet SEPARATORS = TokenSet.create(mNLS,
|
||||
mSEMI);
|
||||
|
||||
public static boolean asSimpleVariable(PsiElement context) {
|
||||
return isInTypeDefinitionBody(context) &&
|
||||
@@ -314,8 +317,8 @@ public class GroovyCompletionUtil {
|
||||
|
||||
private static LookupElementBuilder setTailText(PsiElement element, LookupElementBuilder builder, PsiSubstitutor substitutor) {
|
||||
if (element instanceof PsiMethod) {
|
||||
builder = builder.setTailText(PsiFormatUtil.formatMethod((PsiMethod)element, substitutor, PsiFormatUtil.SHOW_PARAMETERS,
|
||||
PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE));
|
||||
builder = builder.setTailText(PsiFormatUtil.formatMethod((PsiMethod)element, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS,
|
||||
PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE));
|
||||
}
|
||||
else if (element instanceof PsiClass) {
|
||||
String tailText = getPackageText((PsiClass)element);
|
||||
@@ -459,11 +462,11 @@ public class GroovyCompletionUtil {
|
||||
final HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(oldTail);
|
||||
while (!iterator.atEnd()) {
|
||||
final IElementType tokenType = iterator.getTokenType();
|
||||
if (GroovyTokenTypes.WHITE_SPACES_OR_COMMENTS.contains(tokenType)) {
|
||||
if (WHITE_SPACES_OR_COMMENTS.contains(tokenType)) {
|
||||
iterator.advance();
|
||||
continue;
|
||||
}
|
||||
if (tokenType == GroovyTokenTypes.mRPAREN) {
|
||||
if (tokenType == mRPAREN) {
|
||||
offset = iterator.getEnd();
|
||||
}
|
||||
break;
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.filters.ElementFilter;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrForStatement;
|
||||
@@ -42,7 +42,7 @@ public class ControlStructureFilter implements ElementFilter {
|
||||
PsiElement prevSibling = context.getPrevSibling();
|
||||
if (context.getParent() instanceof GrReferenceElement && prevSibling != null && prevSibling.getNode() != null) {
|
||||
ASTNode node = prevSibling.getNode();
|
||||
return !GroovyTokenTypes.DOTS.contains(node.getElementType());
|
||||
return !TokenSets.DOTS.contains(node.getElementType());
|
||||
}
|
||||
if (GroovyCompletionUtil.isNewStatement(context, true)) {
|
||||
final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(offset - 1, context);
|
||||
|
||||
+3
-2
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.filters.ElementFilter;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
@@ -40,9 +41,9 @@ public class BuiltInTypeAsArgumentFilter implements ElementFilter {
|
||||
PsiElement previous = PsiImplUtil.realPrevious(parent.getPrevSibling());
|
||||
if (parent instanceof GrReferenceElement && parent.getParent() instanceof GrArgumentList) {
|
||||
PsiElement prevSibling = context.getPrevSibling();
|
||||
if (parent instanceof GrReferenceElement && prevSibling != null && prevSibling.getNode() != null) {
|
||||
if (prevSibling != null && prevSibling.getNode() != null) {
|
||||
ASTNode node = prevSibling.getNode();
|
||||
return !GroovyTokenTypes.DOTS.contains(node.getElementType());
|
||||
return !TokenSets.DOTS.contains(node.getElementType());
|
||||
} else {
|
||||
return !(previous != null && GroovyTokenTypes.mAT.equals(previous.getNode().getElementType()));
|
||||
}
|
||||
|
||||
+2
-1
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.completion.filters.exprs.InstanceOfFilter;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
|
||||
@@ -63,7 +64,7 @@ public class BuiltInTypeFilter implements ElementFilter {
|
||||
PsiElement prevSibling = context.getPrevSibling();
|
||||
if (parent instanceof GrReferenceElement && prevSibling != null && prevSibling.getNode() != null) {
|
||||
ASTNode node = prevSibling.getNode();
|
||||
return !GroovyTokenTypes.DOTS.contains(node.getElementType());
|
||||
return !TokenSets.DOTS.contains(node.getElementType());
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
+3
-2
@@ -32,6 +32,7 @@ import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.containers.hash.HashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString;
|
||||
@@ -84,7 +85,7 @@ public class GroovyFoldingBuilder implements FoldingBuilder, GroovyElementTypes,
|
||||
usedComments.add(current);
|
||||
continue;
|
||||
}
|
||||
if (WHITE_SPACES_SET.contains(elementType)) {
|
||||
if (TokenSets.WHITE_SPACES_SET.contains(elementType)) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@@ -282,7 +283,7 @@ public class GroovyFoldingBuilder implements FoldingBuilder, GroovyElementTypes,
|
||||
}
|
||||
|
||||
private static boolean isMultiLineStringLiteral(ASTNode node) {
|
||||
return (STRING_LITERAL_SET.contains(node.getElementType()) || node.getElementType().equals(GSTRING)) &&
|
||||
return (TokenSets.STRING_LITERAL_SET.contains(node.getElementType()) || node.getElementType().equals(GSTRING)) &&
|
||||
isMultiline(node.getPsi()) &&
|
||||
isWellEndedString(node.getPsi());
|
||||
}
|
||||
|
||||
+7
-5
@@ -22,10 +22,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
|
||||
|
||||
import static org.jetbrains.plugins.groovy.lang.groovydoc.parser.GroovyDocElementTypes.*;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.TokenSets.*;
|
||||
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
@@ -41,8 +43,8 @@ public abstract class GrDocCommentUtil {
|
||||
if (element == null) return null;
|
||||
final ASTNode node = element.getNode();
|
||||
if (node == null) return null;
|
||||
if (GroovyElementTypes.GROOVY_DOC_COMMENT.equals(node.getElementType()) ||
|
||||
!GroovyElementTypes.WHITE_SPACES_OR_COMMENTS.contains(node.getElementType())) {
|
||||
if (GROOVY_DOC_COMMENT.equals(node.getElementType()) ||
|
||||
!WHITE_SPACES_OR_COMMENTS.contains(node.getElementType())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -64,8 +66,8 @@ public abstract class GrDocCommentUtil {
|
||||
if (element == null) return null;
|
||||
final ASTNode node = element.getNode();
|
||||
if (node == null) return null;
|
||||
if (GroovyElementTypes.GROOVY_DOC_COMMENT.equals(node.getElementType()) ||
|
||||
!GroovyElementTypes.WHITE_SPACES_OR_COMMENTS.contains(node.getElementType())) {
|
||||
if (GROOVY_DOC_COMMENT.equals(node.getElementType()) ||
|
||||
!WHITE_SPACES_OR_COMMENTS.contains(node.getElementType())) {
|
||||
break;
|
||||
}
|
||||
element = element.getPrevSibling();
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
|
||||
import static com.intellij.psi.search.UsageSearchContext.*;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.*;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.TokenSets.COMMENT_SET;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.TokenSets.STRING_LITERALS;
|
||||
|
||||
/**
|
||||
@@ -36,7 +37,7 @@ public class GroovyFilterLexer extends BaseFilterLexer {
|
||||
public void advance() {
|
||||
final IElementType tokenType = getDelegate().getTokenType();
|
||||
|
||||
if (tokenType == mIDENT || KEYWORDS.contains(tokenType)) {
|
||||
if (tokenType == mIDENT || TokenSets.KEYWORDS.contains(tokenType)) {
|
||||
addOccurrenceInToken(IN_CODE);
|
||||
}
|
||||
else if (STRING_LITERALS.contains(tokenType)) {
|
||||
|
||||
@@ -16,11 +16,8 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.lang.lexer;
|
||||
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.parser.GroovyDocElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
|
||||
/**
|
||||
* Interface that contains all tokens returned by GroovyLexer
|
||||
@@ -40,7 +37,6 @@ public interface GroovyTokenTypes extends GroovyDocElementTypes {
|
||||
|
||||
IElementType mWS = new GroovyElementType("white space");
|
||||
IElementType mNLS = new GroovyElementType("new line");
|
||||
TokenSet WHITE_SPACES_SET = TokenSet.create(mWS, mNLS, TokenType.WHITE_SPACE);
|
||||
|
||||
/* **************************************************************************************************
|
||||
* Comments
|
||||
@@ -49,7 +45,6 @@ public interface GroovyTokenTypes extends GroovyDocElementTypes {
|
||||
IElementType mSH_COMMENT = new GroovyElementType("shell comment");
|
||||
IElementType mSL_COMMENT = new GroovyElementType("line comment");
|
||||
IElementType mML_COMMENT = new GroovyElementType("block comment");
|
||||
TokenSet COMMENT_SET = TokenSet.create(mML_COMMENT, mSH_COMMENT, mSL_COMMENT, GROOVY_DOC_COMMENT);
|
||||
|
||||
/* **************************************************************************************************
|
||||
* Identifiers
|
||||
@@ -74,7 +69,6 @@ public interface GroovyTokenTypes extends GroovyDocElementTypes {
|
||||
|
||||
IElementType mSTRING_LITERAL = new GroovyElementType("string");
|
||||
IElementType mGSTRING_LITERAL = new GroovyElementType("Gstring");
|
||||
TokenSet STRING_LITERAL_SET = TokenSet.create(mSTRING_LITERAL, mGSTRING_LITERAL);
|
||||
|
||||
IElementType mGSTRING_BEGIN = new GroovyElementType("Gstring begin");
|
||||
IElementType mGSTRING_CONTENT = new GroovyElementType("Gstring content");
|
||||
@@ -211,27 +205,4 @@ public interface GroovyTokenTypes extends GroovyDocElementTypes {
|
||||
IElementType kVOID = new GroovyElementType("void");
|
||||
IElementType kVOLATILE = new GroovyElementType("volatile");
|
||||
IElementType kWHILE = new GroovyElementType("while");
|
||||
|
||||
TokenSet KEYWORDS = TokenSet
|
||||
.create(kABSTRACT, kAS, kASSERT, kBOOLEAN, kBREAK, kBYTE, kCASE, kCATCH, kCHAR, kCLASS, kCONTINUE, kDEF, kDEFAULT, kDOUBLE, kELSE,
|
||||
kEXTENDS, kENUM, kFALSE, kFINAL, kFLOAT, kFOR, kFINALLY, kIF, kIMPLEMENTS, kIMPORT, kIN, kINSTANCEOF, kINT, kINTERFACE, kLONG,
|
||||
kNATIVE, kNEW, kNULL, kPACKAGE, kPRIVATE, kPROTECTED, kPUBLIC, kRETURN, kSHORT, kSTATIC, kSTRICTFP, kSUPER, kSWITCH,
|
||||
kSYNCHRONIZED, kTHIS, kTHROW, kTHROWS, kTRANSIENT, kTRUE, kTRY, kVOID, kVOLATILE, kWHILE);
|
||||
|
||||
TokenSet BRACES = TokenSet.create(mLBRACK, mRBRACK, mLPAREN, mRPAREN, mLCURLY, mRCURLY);
|
||||
|
||||
TokenSet ASSIGN_OP_SET = TokenSet
|
||||
.create(mASSIGN, mBAND_ASSIGN, mBOR_ASSIGN, mBSR_ASSIGN, mBXOR_ASSIGN, mDIV_ASSIGN, mMINUS_ASSIGN, mMOD_ASSIGN, mPLUS_ASSIGN,
|
||||
mSL_ASSIGN, mSR_ASSIGN, mSTAR_ASSIGN, mSTAR_STAR_ASSIGN);
|
||||
|
||||
TokenSet UNARY_OP_SET = TokenSet.create(mBNOT, mLNOT, mMINUS, mDEC, mPLUS, mINC);
|
||||
TokenSet POSTFIX_UNARY_OP_SET = TokenSet.create(mDEC, mINC);
|
||||
|
||||
TokenSet BINARY_OP_SET =
|
||||
TokenSet.create(mBAND, mBOR, mBXOR, mDIV, mEQUAL, mGE, mGT, mLAND, mLOR, mLT, mLE, mMINUS, mMOD, mPLUS, mSTAR, mSTAR_STAR, mNOT_EQUAL,
|
||||
mCOMPARE_TO, GroovyElementTypes.COMPOSITE_SHIFT_SIGN);
|
||||
|
||||
TokenSet DOTS = TokenSet.create(mSPREAD_DOT, mOPTIONAL_DOT, mMEMBER_POINTER, mDOT);
|
||||
|
||||
TokenSet WHITE_SPACES_OR_COMMENTS = TokenSet.orSet(WHITE_SPACES_SET, COMMENT_SET);
|
||||
}
|
||||
|
||||
@@ -16,14 +16,16 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.lang.lexer;
|
||||
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
|
||||
/**
|
||||
* Utility classdef, tha contains various useful TokenSets
|
||||
*
|
||||
* @author ilyas
|
||||
*/
|
||||
public abstract class TokenSets implements GroovyTokenTypes {
|
||||
public abstract class TokenSets implements GroovyTokenTypes, GroovyElementTypes {
|
||||
|
||||
public static TokenSet COMMENTS_TOKEN_SET = TokenSet.create(
|
||||
mSL_COMMENT,
|
||||
@@ -43,14 +45,6 @@ public abstract class TokenSets implements GroovyTokenTypes {
|
||||
mGDOC_WHITESPACE
|
||||
);
|
||||
|
||||
public static TokenSet SUSPICIOUS_EXPRESSION_STATEMENT_START_TOKEN_SET = TokenSet.create(
|
||||
mMINUS,
|
||||
mPLUS,
|
||||
mLBRACK,
|
||||
mLPAREN,
|
||||
mLCURLY
|
||||
);
|
||||
|
||||
public static final TokenSet NUMBERS = TokenSet.create(mNUM_INT,
|
||||
mNUM_BIG_DECIMAL,
|
||||
mNUM_BIG_INT,
|
||||
@@ -88,6 +82,13 @@ public abstract class TokenSets implements GroovyTokenTypes {
|
||||
|
||||
public static final TokenSet PROPERTY_NAMES = TokenSet.create(mIDENT, mSTRING_LITERAL, mGSTRING_LITERAL);
|
||||
|
||||
public static final TokenSet KEYWORDS = TokenSet.create(kABSTRACT, kAS, kASSERT, kBOOLEAN, kBREAK, kBYTE, kCASE, kCATCH, kCHAR, kCLASS,
|
||||
kCONTINUE, kDEF, kDEFAULT, kDOUBLE, kELSE, kEXTENDS, kENUM, kFALSE, kFINAL,
|
||||
kFLOAT, kFOR, kFINALLY, kIF, kIMPLEMENTS, kIMPORT, kIN, kINSTANCEOF, kINT,
|
||||
kINTERFACE, kLONG, kNATIVE, kNEW, kNULL, kPACKAGE, kPRIVATE, kPROTECTED, kPUBLIC,
|
||||
kRETURN, kSHORT, kSTATIC, kSTRICTFP, kSUPER, kSWITCH, kSYNCHRONIZED, kTHIS,
|
||||
kTHROW, kTHROWS, kTRANSIENT, kTRUE, kTRY, kVOID, kVOLATILE, kWHILE);
|
||||
|
||||
public static TokenSet REFERENCE_NAMES = TokenSet.orSet(KEYWORDS, PROPERTY_NAMES, NUMBERS);
|
||||
public static TokenSet REFERENCE_NAMES_WITHOUT_NUMBERS = TokenSet.orSet(KEYWORDS, PROPERTY_NAMES);
|
||||
|
||||
@@ -133,4 +134,27 @@ public abstract class TokenSets implements GroovyTokenTypes {
|
||||
mGE,
|
||||
kIN
|
||||
);
|
||||
public static final TokenSet WHITE_SPACES_SET = TokenSet.create(mWS, mNLS, TokenType.WHITE_SPACE);
|
||||
|
||||
public static final TokenSet COMMENT_SET = TokenSet.create(mML_COMMENT, mSH_COMMENT, mSL_COMMENT, GROOVY_DOC_COMMENT);
|
||||
|
||||
public static final TokenSet STRING_LITERAL_SET = TokenSet.create(mSTRING_LITERAL, mGSTRING_LITERAL);
|
||||
|
||||
public static final TokenSet BRACES = TokenSet.create(mLBRACK, mRBRACK, mLPAREN, mRPAREN, mLCURLY, mRCURLY);
|
||||
|
||||
public static final TokenSet ASSIGN_OP_SET = TokenSet.create(mASSIGN, mBAND_ASSIGN, mBOR_ASSIGN, mBSR_ASSIGN, mBXOR_ASSIGN, mDIV_ASSIGN,
|
||||
mMINUS_ASSIGN, mMOD_ASSIGN, mPLUS_ASSIGN, mSL_ASSIGN, mSR_ASSIGN,
|
||||
mSTAR_ASSIGN, mSTAR_STAR_ASSIGN);
|
||||
|
||||
public static final TokenSet UNARY_OP_SET = TokenSet.create(mBNOT, mLNOT, mMINUS, mDEC, mPLUS, mINC);
|
||||
|
||||
public static final TokenSet POSTFIX_UNARY_OP_SET = TokenSet.create(mDEC, mINC);
|
||||
|
||||
public static final TokenSet BINARY_OP_SET = TokenSet.create(mBAND, mBOR, mBXOR, mDIV, mEQUAL, mGE, mGT, mLAND, mLOR, mLT, mLE, mMINUS,
|
||||
mMOD, mPLUS, mSTAR, mSTAR_STAR, mNOT_EQUAL, mCOMPARE_TO,
|
||||
COMPOSITE_SHIFT_SIGN, kIN, kINSTANCEOF, kAS);
|
||||
|
||||
public static final TokenSet DOTS = TokenSet.create(mSPREAD_DOT, mOPTIONAL_DOT, mMEMBER_POINTER, mDOT);
|
||||
|
||||
public static final TokenSet WHITE_SPACES_OR_COMMENTS = TokenSet.orSet(WHITE_SPACES_SET, COMMENT_SET);
|
||||
}
|
||||
|
||||
+2
-2
@@ -28,8 +28,7 @@ import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.expressions.a
|
||||
import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.expressions.primary.PrimaryExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.parsing.util.ParserUtils;
|
||||
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.TokenSets.NUMBERS;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.TokenSets.SEPARATORS;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.TokenSets.*;
|
||||
import static org.jetbrains.plugins.groovy.lang.parser.parsing.statements.expressions.arithmetic.PathExpression.Result.METHOD_CALL;
|
||||
import static org.jetbrains.plugins.groovy.lang.parser.parsing.statements.expressions.arithmetic.PathExpression.Result.WRONG_WAY;
|
||||
|
||||
@@ -142,6 +141,7 @@ public class ExpressionStatement implements GroovyElementTypes {
|
||||
}
|
||||
|
||||
private static GroovyElementType namePartParse(PsiBuilder builder, GroovyParser parser) {
|
||||
if (BINARY_OP_SET.contains(builder.getTokenType())) return WRONGWAY;
|
||||
final GroovyElementType type = PathExpression.namePartParse(builder, parser);
|
||||
if (type == WRONGWAY && NUMBERS.contains(builder.getTokenType())) {
|
||||
builder.advanceLexer();
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ public class ArgumentList implements GroovyElementTypes {
|
||||
return true;
|
||||
}
|
||||
else if (ParserUtils.lookAhead(builder, mIDENT, mCOLON) ||
|
||||
KEYWORDS.contains(builder.getTokenType()) ||
|
||||
TokenSets.KEYWORDS.contains(builder.getTokenType()) ||
|
||||
mSTRING_LITERAL.equals(builder.getTokenType()) ||
|
||||
mGSTRING_LITERAL.equals(builder.getTokenType()) ||
|
||||
mREGEX_LITERAL.equals(builder.getTokenType())) {
|
||||
|
||||
+2
-1
@@ -21,6 +21,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.plugins.groovy.GroovyBundle;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyParser;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.blocks.OpenOrClosableBlock;
|
||||
@@ -237,7 +238,7 @@ public class PathExpression implements GroovyElementTypes {
|
||||
PrimaryExpression.parenthesizedExprParse(builder, parser);
|
||||
return PATH_PROPERTY_REFERENCE;
|
||||
}
|
||||
if (KEYWORDS.contains(builder.getTokenType())) {
|
||||
if (TokenSets.KEYWORDS.contains(builder.getTokenType())) {
|
||||
builder.advanceLexer();
|
||||
return REFERENCE_EXPRESSION;
|
||||
}
|
||||
|
||||
+8
@@ -67,6 +67,10 @@ public abstract class GroovyPsiElementImpl extends ASTWrapperPsiElement implemen
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* don't remove. it is used by inheritors
|
||||
*/
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void removeElements(PsiElement[] elements) throws IncorrectOperationException {
|
||||
removeElements(this, elements);
|
||||
}
|
||||
@@ -84,6 +88,10 @@ public abstract class GroovyPsiElementImpl extends ASTWrapperPsiElement implemen
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* don't remove. it is used by inheritors
|
||||
*/
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void removeStatement() throws IncorrectOperationException {
|
||||
removeStatement(this);
|
||||
}
|
||||
|
||||
+2
-1
@@ -47,6 +47,7 @@ import org.jetbrains.plugins.groovy.lang.psi.stubs.GrModifierListStub;
|
||||
* @autor: Dmitry.Krasilschikov
|
||||
* @date: 18.03.2007
|
||||
*/
|
||||
@SuppressWarnings({"StaticFieldReferencedViaSubclass"})
|
||||
public class GrModifierListImpl extends GrStubElementBase<GrModifierListStub> implements GrModifierList, StubBasedPsiElement<GrModifierListStub> {
|
||||
public static final TObjectIntHashMap<String> NAME_TO_MODIFIER_FLAG_MAP = new TObjectIntHashMap<String>();
|
||||
private static final ArrayFactory<GrAnnotation> ARRAY_FACTORY = new ArrayFactory<GrAnnotation>() {
|
||||
@@ -256,7 +257,7 @@ public class GrModifierListImpl extends GrStubElementBase<GrModifierListStub> im
|
||||
|
||||
if (getTextLength() == 0) {
|
||||
final PsiElement nextSibling = getNextSibling();
|
||||
if (nextSibling != null && GroovyTokenTypes.WHITE_SPACES_SET.contains(nextSibling.getNode().getElementType())) {
|
||||
if (nextSibling != null && TokenSets.WHITE_SPACES_SET.contains(nextSibling.getNode().getElementType())) {
|
||||
nextSibling.delete();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -29,6 +29,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.extensions.GroovyNamedArgumentProvider;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel;
|
||||
@@ -69,7 +70,7 @@ public class GrArgumentLabelImpl extends GroovyPsiElementImpl implements GrArgum
|
||||
if (!(nameElement instanceof LeafPsiElement)) return null;
|
||||
|
||||
IElementType elementType = ((LeafPsiElement)nameElement).getElementType();
|
||||
if (elementType != GroovyElementTypes.mIDENT && !CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getPsiTypeName(elementType))) {
|
||||
if (elementType != GroovyTokenTypes.mIDENT && !CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getPsiTypeName(elementType))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -161,7 +162,7 @@ public class GrArgumentLabelImpl extends GroovyPsiElementImpl implements GrArgum
|
||||
}
|
||||
|
||||
final IElementType elemType = element.getNode().getElementType();
|
||||
if (GroovyTokenTypes.mIDENT == elemType || GroovyTokenTypes.KEYWORDS.contains(elemType)) {
|
||||
if (GroovyTokenTypes.mIDENT == elemType || TokenSets.KEYWORDS.contains(elemType)) {
|
||||
return element.getText();
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -1,13 +1,11 @@
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl.statements.arguments;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.AbstractElementManipulator;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.GroovyStringLiteralManipulator;
|
||||
|
||||
@@ -18,7 +16,7 @@ public class GrArgumentLabelManipulator extends AbstractElementManipulator<GrArg
|
||||
@Override
|
||||
public TextRange getRangeInElement(GrArgumentLabel element) {
|
||||
final PsiElement nameElement = element.getNameElement();
|
||||
if (nameElement instanceof LeafPsiElement && GroovyTokenTypes.STRING_LITERAL_SET.contains(((LeafPsiElement)nameElement).getElementType())) {
|
||||
if (nameElement instanceof LeafPsiElement && TokenSets.STRING_LITERAL_SET.contains(((LeafPsiElement)nameElement).getElementType())) {
|
||||
return GroovyStringLiteralManipulator.getLiteralRange(nameElement.getText());
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -23,11 +23,11 @@ import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.impl.source.tree.TreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
@@ -226,12 +226,12 @@ public class GrArgumentListImpl extends GroovyPsiElementImpl implements GrArgume
|
||||
public void deleteChildInternal(@NotNull ASTNode child) {
|
||||
PsiElement element = child.getPsi();
|
||||
if (element instanceof GrExpression || element instanceof GrNamedArgument) {
|
||||
ASTNode prev = TreeUtil.skipElementsBack(child.getTreePrev(), GroovyTokenTypes.WHITE_SPACES_OR_COMMENTS);
|
||||
ASTNode prev = TreeUtil.skipElementsBack(child.getTreePrev(), TokenSets.WHITE_SPACES_OR_COMMENTS);
|
||||
if (prev != null && prev.getElementType() == mCOMMA) {
|
||||
super.deleteChildInternal(prev);
|
||||
}
|
||||
else {
|
||||
ASTNode next = TreeUtil.skipElements(child.getTreeNext(), GroovyTokenTypes.WHITE_SPACES_OR_COMMENTS);
|
||||
ASTNode next = TreeUtil.skipElements(child.getTreeNext(), TokenSets.WHITE_SPACES_OR_COMMENTS);
|
||||
if (next != null && next.getElementType() == mCOMMA) {
|
||||
deleteChildInternal(next);
|
||||
}
|
||||
|
||||
+2
-5
@@ -32,6 +32,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrControlFlowOwner;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
@@ -70,10 +71,6 @@ public abstract class GrBlockImpl extends LazyParseablePsiElement implements GrC
|
||||
return GroovyPsiElementImpl.replaceWithStatement(this, statement);
|
||||
}
|
||||
|
||||
public void removeStatement() throws IncorrectOperationException {
|
||||
GroovyPsiElementImpl.removeStatement(this);
|
||||
}
|
||||
|
||||
public void subtreeChanged() {
|
||||
super.subtreeChanged();
|
||||
putUserData(CONTROL_FLOW, null);
|
||||
@@ -170,7 +167,7 @@ public abstract class GrBlockImpl extends LazyParseablePsiElement implements GrC
|
||||
return element;
|
||||
}
|
||||
private static boolean isNls(PsiElement element) {
|
||||
if (!GroovyTokenTypes.WHITE_SPACES_SET.contains(element.getNode().getElementType())) return false;
|
||||
if (!TokenSets.WHITE_SPACES_SET.contains(element.getNode().getElementType())) return false;
|
||||
String text = element.getText();
|
||||
return text.contains("\n") || text.contains("\r");
|
||||
}
|
||||
|
||||
+7
@@ -22,6 +22,7 @@ import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
@@ -36,6 +37,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
@@ -220,4 +222,9 @@ public class GrClosableBlockImpl extends GrBlockImpl implements GrClosableBlock
|
||||
public PsiType getReturnType() {
|
||||
return GroovyPsiManager.getInstance(getProject()).getType(this, ourTypesCalculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStatement() throws IncorrectOperationException {
|
||||
GroovyPsiElementImpl.removeStatement(this);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTupleDeclaration;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression;
|
||||
@@ -66,7 +66,7 @@ public class GrAssignmentExpressionImpl extends GrExpressionImpl implements GrAs
|
||||
}
|
||||
|
||||
public IElementType getOperationToken() {
|
||||
return findChildByType(GroovyTokenTypes.ASSIGN_OP_SET).getNode().getElementType();
|
||||
return findNotNullChildByType(TokenSets.ASSIGN_OP_SET).getNode().getElementType();
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
|
||||
+13
-13
@@ -36,9 +36,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.codeInsight.GroovyTargetElementEvaluator;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
@@ -70,6 +68,8 @@ import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.*;
|
||||
|
||||
/**
|
||||
* @author ilyas
|
||||
*/
|
||||
@@ -282,7 +282,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
PsiElement nameElement = getReferenceNameElement();
|
||||
if (nameElement != null) {
|
||||
IElementType nodeType = nameElement.getNode().getElementType();
|
||||
if (nodeType == GroovyElementTypes.mSTRING_LITERAL || nodeType == GroovyElementTypes.mGSTRING_LITERAL) {
|
||||
if (nodeType == mSTRING_LITERAL || nodeType == mGSTRING_LITERAL) {
|
||||
return GrStringUtil.removeQuotes(nameElement.getText());
|
||||
}
|
||||
|
||||
@@ -403,7 +403,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
|
||||
final GroovyResolveResult resolveResult = advancedResolve();
|
||||
PsiElement resolved = resolveResult.getElement();
|
||||
if (dotType == GroovyTokenTypes.mMEMBER_POINTER) {
|
||||
if (dotType == mMEMBER_POINTER) {
|
||||
if (resolved instanceof PsiMethod) {
|
||||
return GrClosureType.create((PsiMethod) resolved, resolveResult.getSubstitutor());
|
||||
}
|
||||
@@ -427,7 +427,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
result = ((PsiVariable) resolved).getType();
|
||||
} else
|
||||
if (resolved instanceof PsiMethod) {
|
||||
if (dotType == GroovyTokenTypes.mMEMBER_POINTER) {
|
||||
if (dotType == mMEMBER_POINTER) {
|
||||
return TypesUtil.createTypeByFQClassName(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, this);
|
||||
}
|
||||
PsiMethod method = (PsiMethod) resolved;
|
||||
@@ -498,7 +498,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
result = resolveResult.getSubstitutor().substitute(result);
|
||||
result = TypesUtil.boxPrimitiveType(result, getManager(), getResolveScope());
|
||||
}
|
||||
if (dotType != GroovyTokenTypes.mSPREAD_DOT) {
|
||||
if (dotType != mSPREAD_DOT) {
|
||||
return result;
|
||||
} else {
|
||||
return ResolveUtil.getListTypeForSpreadOperator(this, result);
|
||||
@@ -621,7 +621,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (getDotTokenType() != GroovyTokenTypes.mSPREAD_DOT) {
|
||||
if (getDotTokenType() != mSPREAD_DOT) {
|
||||
if (!processQualifier(processor, qualifier)) return false;
|
||||
} else {
|
||||
if (!processQualifierForSpreadDot(processor, qualifier)) return false;
|
||||
@@ -771,7 +771,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
}
|
||||
|
||||
Kind getKind() {
|
||||
if (getDotTokenType() == GroovyTokenTypes.mMEMBER_POINTER) return Kind.METHOD_OR_PROPERTY;
|
||||
if (getDotTokenType() == mMEMBER_POINTER) return Kind.METHOD_OR_PROPERTY;
|
||||
|
||||
PsiElement parent = getParent();
|
||||
if (parent instanceof GrMethodCallExpression || parent instanceof GrApplicationStatement) {
|
||||
@@ -787,12 +787,12 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
}
|
||||
|
||||
public boolean hasAt() {
|
||||
return findChildByType(GroovyTokenTypes.mAT) != null;
|
||||
return findChildByType(mAT) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMemberPointer() {
|
||||
return findChildByType(GroovyTokenTypes.mMEMBER_POINTER) != null;
|
||||
return findChildByType(mMEMBER_POINTER) != null;
|
||||
}
|
||||
|
||||
public boolean isReferenceTo(PsiElement element) {
|
||||
@@ -803,7 +803,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
|
||||
if (element instanceof PsiMethod && target instanceof PsiMethod) {
|
||||
PsiMethod[] superMethods = ((PsiMethod)target).findSuperMethods(false);
|
||||
if (Arrays.asList(superMethods).contains((PsiMethod)element)) {
|
||||
if (Arrays.asList(superMethods).contains(element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -834,12 +834,12 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
|
||||
@Nullable
|
||||
public PsiElement getDotToken() {
|
||||
return findChildByType(GroovyTokenTypes.DOTS);
|
||||
return findChildByType(TokenSets.DOTS);
|
||||
}
|
||||
|
||||
public void replaceDotToken(PsiElement newDot) {
|
||||
if (newDot == null) return;
|
||||
if (!GroovyTokenTypes.DOTS.contains(newDot.getNode().getElementType())) return;
|
||||
if (!TokenSets.DOTS.contains(newDot.getNode().getElementType())) return;
|
||||
final PsiElement oldDot = getDotToken();
|
||||
if (oldDot == null) return;
|
||||
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
@@ -105,7 +106,7 @@ public class GrUnaryExpressionImpl extends GrExpressionImpl implements GrUnaryEx
|
||||
}
|
||||
|
||||
public PsiElement getOperationToken() {
|
||||
PsiElement opElement = findChildByType(GroovyTokenTypes.UNARY_OP_SET);
|
||||
PsiElement opElement = findChildByType(TokenSets.UNARY_OP_SET);
|
||||
assert opElement != null;
|
||||
return opElement;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMemberReference;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
|
||||
@@ -87,6 +86,7 @@ import java.util.*;
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
@SuppressWarnings({"StaticFieldReferencedViaSubclass"})
|
||||
public class PsiUtil {
|
||||
public static final Logger LOG = Logger.getInstance("org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil");
|
||||
public static final Key<JavaIdentifier> NAME_IDENTIFIER = new Key<JavaIdentifier>("Java Identifier");
|
||||
@@ -507,7 +507,7 @@ public class PsiUtil {
|
||||
return isInStaticContext(refExpression, null);
|
||||
}
|
||||
|
||||
public static boolean isInStaticContext(GrQualifiedReference refExpression, PsiClass targetClass) {
|
||||
public static boolean isInStaticContext(GrQualifiedReference refExpression, @Nullable PsiClass targetClass) {
|
||||
if (refExpression.getQualifier() != null) {
|
||||
PsiElement qualifier = refExpression.getQualifier();
|
||||
if (qualifier instanceof GrReferenceExpression) return ((GrReferenceExpression)qualifier).resolve() instanceof PsiClass;
|
||||
@@ -832,7 +832,7 @@ public class PsiUtil {
|
||||
//noinspection ConstantConditions
|
||||
while (elem != null &&
|
||||
elem.getNode() != null &&
|
||||
GroovyElementTypes.WHITE_SPACES_OR_COMMENTS.contains(elem.getNode().getElementType())) {
|
||||
TokenSets.WHITE_SPACES_OR_COMMENTS.contains(elem.getNode().getElementType())) {
|
||||
if (forward) {
|
||||
elem = elem.getNextSibling();
|
||||
}
|
||||
@@ -1068,10 +1068,6 @@ public class PsiUtil {
|
||||
return element instanceof LeafElement && ((LeafElement)element).getElementType() == type;
|
||||
}
|
||||
|
||||
public static boolean isLeafElementOfType(@Nullable PsiElement element, TokenSet tokenSet) {
|
||||
return element instanceof LeafElement && tokenSet.contains(((LeafElement)element).getElementType());
|
||||
}
|
||||
|
||||
public static GrNamedArgument[] getFirstMapNamedArguments(GrCall grCall) {
|
||||
GrNamedArgument[] res = grCall.getNamedArguments();
|
||||
if (res.length > 0) return res;
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -46,14 +47,6 @@ public class GroovyNamesUtil {
|
||||
return lexer.getTokenType() == null;
|
||||
}
|
||||
|
||||
public static boolean isKeyword(String text) {
|
||||
Lexer lexer = new GroovyLexer();
|
||||
lexer.start(text);
|
||||
if (lexer.getTokenType() == null || !GroovyTokenTypes.KEYWORDS.contains(lexer.getTokenType())) return false;
|
||||
lexer.advance();
|
||||
return lexer.getTokenType() == null;
|
||||
}
|
||||
|
||||
public static ArrayList<String> camelizeString(String str) {
|
||||
ArrayList<String> res = new ArrayList<String>();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
+3
-15
@@ -73,7 +73,7 @@ import static org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.skipParentheses
|
||||
public abstract class GroovyRefactoringUtil {
|
||||
|
||||
public static final Collection<String> KEYWORDS = ContainerUtil.map(
|
||||
GroovyTokenTypes.KEYWORDS.getTypes(), StringUtil.createToStringFunction(IElementType.class));
|
||||
TokenSets.KEYWORDS.getTypes(), StringUtil.createToStringFunction(IElementType.class));
|
||||
|
||||
private static final String[] finalModifiers = new String[]{PsiModifier.FINAL};
|
||||
|
||||
@@ -102,11 +102,11 @@ public abstract class GroovyRefactoringUtil {
|
||||
final Class<T> klass) {
|
||||
PsiElement element1 = file.getViewProvider().findElementAt(startOffset, file.getLanguage());
|
||||
PsiElement element2 = file.getViewProvider().findElementAt(endOffset - 1, file.getLanguage());
|
||||
if (GroovyTokenTypes.WHITE_SPACES_SET.contains(element1.getNode().getElementType())) {
|
||||
if (TokenSets.WHITE_SPACES_SET.contains(element1.getNode().getElementType())) {
|
||||
startOffset = element1.getTextRange().getEndOffset();
|
||||
element1 = file.getViewProvider().findElementAt(startOffset, file.getLanguage());
|
||||
}
|
||||
if (GroovyTokenTypes.WHITE_SPACES_SET.contains(element2.getNode().getElementType())) {
|
||||
if (TokenSets.WHITE_SPACES_SET.contains(element2.getNode().getElementType())) {
|
||||
endOffset = element2.getTextRange().getStartOffset();
|
||||
element2 = file.getViewProvider().findElementAt(endOffset - 1, file.getLanguage());
|
||||
}
|
||||
@@ -389,18 +389,6 @@ public abstract class GroovyRefactoringUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasTailReturnExpression(GrMethod method) {
|
||||
if (method.getReturnType() == PsiType.VOID) {
|
||||
return false;
|
||||
}
|
||||
GrOpenBlock body = method.getBlock();
|
||||
if (body == null) return false;
|
||||
GrStatement[] statements = body.getStatements();
|
||||
if (statements.length == 0) return false;
|
||||
GrStatement last = statements[statements.length - 1];
|
||||
return last instanceof GrExpression && PsiType.VOID != ((GrExpression) last).getType();
|
||||
}
|
||||
|
||||
|
||||
public static String getMethodSignature(PsiMethod method) {
|
||||
MethodSignature signature = method.getSignature(PsiSubstitutor.EMPTY);
|
||||
|
||||
+3
-2
@@ -34,6 +34,7 @@ import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.impl.GrDocCommentUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
|
||||
@@ -168,7 +169,7 @@ public class MoveGroovyClassHandler implements MoveClassHandler {
|
||||
if (packageDefinition != null) packageDefinition.delete();
|
||||
|
||||
PsiElement cur = newFile.getFirstChild();
|
||||
while (cur != null && GroovyTokenTypes.WHITE_SPACES_SET.contains(cur.getNode().getElementType())) {
|
||||
while (cur != null && TokenSets.WHITE_SPACES_SET.contains(cur.getNode().getElementType())) {
|
||||
cur = cur.getNextSibling();
|
||||
}
|
||||
if (cur != null && cur != newFile.getFirstChild()) {
|
||||
@@ -177,7 +178,7 @@ public class MoveGroovyClassHandler implements MoveClassHandler {
|
||||
}
|
||||
|
||||
cur = newFile.getLastChild();
|
||||
while (cur != null && GroovyTokenTypes.WHITE_SPACES_SET.contains(cur.getNode().getElementType())) {
|
||||
while (cur != null && TokenSets.WHITE_SPACES_SET.contains(cur.getNode().getElementType())) {
|
||||
cur = cur.getPrevSibling();
|
||||
}
|
||||
if (cur != null && cur != newFile.getLastChild()) {
|
||||
|
||||
+6
@@ -254,4 +254,10 @@ public class ExpressionsParsingTest extends GroovyParsingTestCase {
|
||||
public void testcommandExpr$not() {doTest()}
|
||||
public void testcommandExpr$methodCall() {doTest()}
|
||||
public void testcommandExpr$indexProperty() {doTest()}
|
||||
|
||||
public void testcommandExpr$instanceof() {doTest()}
|
||||
public void testcommandExpr$instanceof2() {doTest()}
|
||||
public void testcommandExpr$in() {doTest()}
|
||||
public void testcommandExpr$as() {doTest()}
|
||||
public void testcommandExpr$arrayAccess() {doTest()}
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
def b = foo [1] instanceof String
|
||||
-----
|
||||
Groovy script
|
||||
Variable definitions
|
||||
Modifiers
|
||||
PsiElement(def)('def')
|
||||
PsiWhiteSpace(' ')
|
||||
Variable
|
||||
PsiElement(identifier)('b')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(=)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
Instanceof expression
|
||||
Property by index
|
||||
Reference expression
|
||||
PsiElement(identifier)('foo')
|
||||
PsiWhiteSpace(' ')
|
||||
Arguments
|
||||
PsiElement([)('[')
|
||||
Literal
|
||||
PsiElement(Integer)('1')
|
||||
PsiElement(])(']')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(instanceof)('instanceof')
|
||||
PsiWhiteSpace(' ')
|
||||
Type element
|
||||
Reference element
|
||||
PsiElement(identifier)('String')
|
||||
@@ -0,0 +1,26 @@
|
||||
def string = foo a as String
|
||||
-----
|
||||
Groovy script
|
||||
Variable definitions
|
||||
Modifiers
|
||||
PsiElement(def)('def')
|
||||
PsiWhiteSpace(' ')
|
||||
Variable
|
||||
PsiElement(identifier)('string')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(=)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
Call expression
|
||||
Reference expression
|
||||
PsiElement(identifier)('foo')
|
||||
PsiWhiteSpace(' ')
|
||||
Command arguments
|
||||
Safe cast expression
|
||||
Reference expression
|
||||
PsiElement(identifier)('a')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(as)('as')
|
||||
PsiWhiteSpace(' ')
|
||||
Type element
|
||||
Reference element
|
||||
PsiElement(identifier)('String')
|
||||
@@ -0,0 +1,35 @@
|
||||
def contains = abc() in [1, 2, 3]
|
||||
-----
|
||||
Groovy script
|
||||
Variable definitions
|
||||
Modifiers
|
||||
PsiElement(def)('def')
|
||||
PsiWhiteSpace(' ')
|
||||
Variable
|
||||
PsiElement(identifier)('contains')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(=)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
Relational expression
|
||||
Method call
|
||||
Reference expression
|
||||
PsiElement(identifier)('abc')
|
||||
Arguments
|
||||
PsiElement(()('(')
|
||||
PsiElement())(')')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(in)('in')
|
||||
PsiWhiteSpace(' ')
|
||||
Generalized list
|
||||
PsiElement([)('[')
|
||||
Literal
|
||||
PsiElement(Integer)('1')
|
||||
PsiElement(,)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
Literal
|
||||
PsiElement(Integer)('2')
|
||||
PsiElement(,)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
Literal
|
||||
PsiElement(Integer)('3')
|
||||
PsiElement(])(']')
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
def inst = foo() instanceof String
|
||||
-----
|
||||
Groovy script
|
||||
Variable definitions
|
||||
Modifiers
|
||||
PsiElement(def)('def')
|
||||
PsiWhiteSpace(' ')
|
||||
Variable
|
||||
PsiElement(identifier)('inst')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(=)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
Instanceof expression
|
||||
Method call
|
||||
Reference expression
|
||||
PsiElement(identifier)('foo')
|
||||
Arguments
|
||||
PsiElement(()('(')
|
||||
PsiElement())(')')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(instanceof)('instanceof')
|
||||
PsiWhiteSpace(' ')
|
||||
Type element
|
||||
Reference element
|
||||
PsiElement(identifier)('String')
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
def inst = foo arg instanceof String
|
||||
-----
|
||||
Groovy script
|
||||
Variable definitions
|
||||
Modifiers
|
||||
PsiElement(def)('def')
|
||||
PsiWhiteSpace(' ')
|
||||
Variable
|
||||
PsiElement(identifier)('inst')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(=)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
Call expression
|
||||
Reference expression
|
||||
PsiElement(identifier)('foo')
|
||||
PsiWhiteSpace(' ')
|
||||
Command arguments
|
||||
Instanceof expression
|
||||
Reference expression
|
||||
PsiElement(identifier)('arg')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(instanceof)('instanceof')
|
||||
PsiWhiteSpace(' ')
|
||||
Type element
|
||||
Reference element
|
||||
PsiElement(identifier)('String')
|
||||
Reference in New Issue
Block a user