expression statement parsing

This commit is contained in:
Maxim Medvedev
2011-04-13 11:35:00 +04:00
parent 6416565a0c
commit a579736209
10 changed files with 163 additions and 1 deletions
@@ -152,7 +152,7 @@ public abstract class TokenSets implements GroovyTokenTypes, GroovyElementTypes
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);
COMPOSITE_SHIFT_SIGN, kIN, kINSTANCEOF, kAS);
public static final TokenSet DOTS = TokenSet.create(mSPREAD_DOT, mOPTIONAL_DOT, mMEMBER_POINTER, mDOT);
@@ -141,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();
@@ -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);
}
@@ -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);
}
}
@@ -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()}
}
@@ -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(])(']')
@@ -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')
@@ -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')