use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class Declaration method tryParseWithGenerics.
private static IElementType tryParseWithGenerics(@NotNull PsiBuilder builder, boolean isInClass, boolean isInAnnotation, @Nullable String typeDefinitionName, @NotNull GroovyParser parser, boolean modifiersParsed, boolean expressionPossible, boolean acceptTypeParameters) {
if (acceptTypeParameters) {
TypeParameters.parse(builder);
} else {
final PsiBuilder.Marker error = builder.mark();
TypeParameters.parse(builder);
error.error(GroovyBundle.message("type.parameters.are.unexpected"));
}
//point to begin of type or variable
PsiBuilder.Marker checkMarker = builder.mark();
switch(TypeSpec.parse(builder, false, expressionPossible)) {
case PATH_REF:
case REF_WITH_TYPE_PARAMS:
checkMarker.drop();
break;
case FAIL:
checkMarker.rollbackTo();
break;
case IDENTIFIER:
// declaration name element can be parsed as type element
IElementType result = VariableDefinitions.parseDefinitions(builder, isInClass, isInAnnotation, typeDefinitionName, modifiersParsed, false, parser);
if (result == GroovyElementTypes.WRONGWAY) {
checkMarker.rollbackTo();
} else {
checkMarker.drop();
return result;
}
}
return VariableDefinitions.parseDefinitions(builder, isInClass, isInAnnotation, typeDefinitionName, modifiersParsed, false, parser);
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class Declaration method parseDeclarationWithoutGenerics.
private static IElementType parseDeclarationWithoutGenerics(@NotNull PsiBuilder builder, boolean isInClass, boolean isInAnnotation, @Nullable String typeDefinitionName, @NotNull GroovyParser parser, boolean modifiersParsed, boolean expressionPossible) {
//point to begin of type or variable
PsiBuilder.Marker checkMarker = builder.mark();
ReferenceElement.ReferenceElementResult typeResult = TypeSpec.parse(builder, false, expressionPossible);
if (typeResult == ReferenceElement.ReferenceElementResult.FAIL) {
//if type wasn't recognized trying parse VariableDeclaration
checkMarker.rollbackTo();
if (isInAnnotation) {
builder.error(GroovyBundle.message("type.expected"));
}
//current token isn't identifier
return VariableDefinitions.parseDefinitions(builder, isInClass, isInAnnotation, typeDefinitionName, modifiersParsed, true, parser);
} else {
//type was recognized, identifier here
//starts after type
IElementType varDeclarationTop = VariableDefinitions.parseDefinitions(builder, isInClass, isInAnnotation, typeDefinitionName, modifiersParsed, false, parser);
if (varDeclarationTop == GroovyElementTypes.WRONGWAY) {
if (typeResult == ReferenceElement.ReferenceElementResult.REF_WITH_TYPE_PARAMS) {
checkMarker.drop();
return GroovyElementTypes.VARIABLE_DEFINITION_ERROR;
}
checkMarker.rollbackTo();
if (isInAnnotation) {
builder.error(GroovyBundle.message("type.expected"));
}
//starts before "type" identifier, here can't be tuple, because next token is identifier (we are in "type recognized" branch)
return VariableDefinitions.parseDefinitions(builder, isInClass, isInAnnotation, typeDefinitionName, modifiersParsed, false, parser);
} else {
checkMarker.drop();
return varDeclarationTop;
}
}
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class Declaration method parse.
public static boolean parse(@NotNull PsiBuilder builder, boolean isInClass, boolean isInAnnotation, @Nullable String typeDefinitionName, @NotNull GroovyParser parser) {
PsiBuilder.Marker declMarker = builder.mark();
//allows error messages
boolean modifiersParsed = Modifiers.parse(builder, parser);
final boolean methodStart = GroovyTokenTypes.mLT == builder.getTokenType();
final IElementType type = parseAfterModifiers(builder, isInClass, isInAnnotation, typeDefinitionName, parser, modifiersParsed);
if (type == GroovyElementTypes.WRONGWAY) {
if (modifiersParsed && methodStart) {
declMarker.error(GroovyBundle.message("method.definitions.expected"));
return false;
}
declMarker.rollbackTo();
if (modifiersParsed) {
builder.error(GroovyBundle.message("variable.definitions.expected"));
}
return false;
}
if (type != null) {
declMarker.done(type);
} else {
declMarker.drop();
}
return true;
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class VariableDefinitions method parseVar.
private static IElementType parseVar(PsiBuilder builder, boolean isInClass, boolean hasModifiers, GroovyParser parser, boolean LParenth) {
// a = b, c = d
PsiBuilder.Marker varAssMarker = builder.mark();
final IElementType declarator = parseDeclarator(builder, LParenth);
if (declarator != GroovyElementTypes.WRONGWAY) {
final boolean wasAssignment = parseAssignment(builder, parser);
if (declarator == GroovyElementTypes.TUPLE_DECLARATION) {
varAssMarker.drop();
if (!wasAssignment) {
builder.error(GroovyBundle.message("assignment.expected"));
return GroovyElementTypes.WRONGWAY;
}
} else if (isInClass) {
// a = b, c = d
varAssMarker.done(GroovyElementTypes.FIELD);
} else {
varAssMarker.done(GroovyElementTypes.VARIABLE);
}
if (declarator != GroovyElementTypes.TUPLE_DECLARATION) {
while (ParserUtils.getToken(builder, GroovyTokenTypes.mCOMMA)) {
ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
if (GroovyElementTypes.WRONGWAY.equals(parseVariableOrField(builder, isInClass, parser)) && declarator == GroovyTokenTypes.mIDENT) {
//parse b = d
return GroovyElementTypes.VARIABLE_DEFINITION_ERROR;
}
}
}
if (isInClass && declarator == GroovyElementTypes.TUPLE_DECLARATION) {
builder.error(GroovyBundle.message("tuple.cant.be.placed.in.class"));
}
return GroovyElementTypes.VARIABLE_DEFINITION;
} else {
varAssMarker.drop();
builder.error(GroovyBundle.message("identifier.expected"));
return GroovyElementTypes.WRONGWAY;
}
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class ExpressionStatement method parse.
public static Result parse(PsiBuilder builder, GroovyParser parser) {
PsiBuilder.Marker marker = builder.mark();
final IElementType result = parseExpressionStatement(builder, parser);
if (result != GroovyElementTypes.CALL_EXPRESSION && result != GroovyElementTypes.PATH_METHOD_CALL) {
marker.drop();
return result == GroovyElementTypes.WRONGWAY ? Result.WRONG_WAY : Result.EXPRESSION;
}
boolean isExprStatement = result == GroovyElementTypes.CALL_EXPRESSION;
while (true) {
boolean nameParsed = namePartParse(builder, parser) == GroovyElementTypes.REFERENCE_EXPRESSION;
PsiBuilder.Marker exprStatement;
if (nameParsed) {
exprStatement = marker.precede();
marker.done(GroovyElementTypes.REFERENCE_EXPRESSION);
} else {
exprStatement = marker;
}
if (builder.getTokenType() == GroovyTokenTypes.mLPAREN) {
PrimaryExpression.methodCallArgsParse(builder, parser);
exprStatement.done(GroovyElementTypes.PATH_METHOD_CALL);
} else if (GroovyTokenTypes.mLBRACK.equals(builder.getTokenType()) && !ParserUtils.lookAhead(builder, GroovyTokenTypes.mLBRACK, GroovyTokenTypes.mCOLON) && !ParserUtils.lookAhead(builder, GroovyTokenTypes.mLBRACK, GroovyTokenTypes.mNLS, GroovyTokenTypes.mCOLON)) {
PathExpression.indexPropertyArgsParse(builder, parser);
exprStatement.done(GroovyElementTypes.PATH_INDEX_PROPERTY);
boolean isCall = false;
if (GroovyTokenTypes.mLPAREN.equals(builder.getTokenType())) {
PrimaryExpression.methodCallArgsParse(builder, parser);
isCall = true;
} else if (GroovyTokenTypes.mLCURLY.equals(builder.getTokenType())) {
PsiBuilder.Marker argsMarker = builder.mark();
argsMarker.done(GroovyElementTypes.ARGUMENTS);
isCall = true;
}
while (GroovyTokenTypes.mLCURLY.equals(builder.getTokenType())) {
OpenOrClosableBlock.parseClosableBlock(builder, parser);
}
if (isCall) {
exprStatement = exprStatement.precede();
exprStatement.done(GroovyElementTypes.PATH_METHOD_CALL);
}
} else if (nameParsed && CommandArguments.parseCommandArguments(builder, parser)) {
isExprStatement = true;
exprStatement.done(GroovyElementTypes.CALL_EXPRESSION);
} else {
exprStatement.drop();
break;
}
marker = exprStatement.precede();
}
return isExprStatement ? Result.EXPR_STATEMENT : Result.EXPRESSION;
}
Aggregations