use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class DeclarationParser method eatBrackets.
private boolean eatBrackets(PsiBuilder builder, @Nullable @PropertyKey(resourceBundle = JavaErrorMessages.BUNDLE) String errorKey) {
IElementType tokenType = builder.getTokenType();
if (tokenType != JavaTokenType.LBRACKET && tokenType != JavaTokenType.AT)
return true;
PsiBuilder.Marker marker = builder.mark();
int count = 0;
while (true) {
parseAnnotations(builder);
if (!expect(builder, JavaTokenType.LBRACKET)) {
break;
}
++count;
if (!expect(builder, JavaTokenType.RBRACKET)) {
break;
}
++count;
}
if (count == 0) {
// just annotation, most probably belongs to a next declaration
marker.rollbackTo();
return true;
}
if (errorKey != null) {
marker.error(JavaErrorMessages.message(errorKey));
} else {
marker.drop();
}
boolean paired = count % 2 == 0;
if (!paired) {
error(builder, JavaErrorMessages.message("expected.rbracket"));
}
return paired;
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class DeclarationParser method parseAnnotationParameterList.
@NotNull
private PsiBuilder.Marker parseAnnotationParameterList(final PsiBuilder builder) {
PsiBuilder.Marker list = builder.mark();
if (!expect(builder, JavaTokenType.LPARENTH)) {
done(list, JavaElementType.ANNOTATION_PARAMETER_LIST);
return list;
}
if (expect(builder, JavaTokenType.RPARENTH)) {
done(list, JavaElementType.ANNOTATION_PARAMETER_LIST);
return list;
}
final boolean isFirstParamNamed = parseAnnotationParameter(builder, true);
boolean isFirstParamWarned = false;
boolean afterBad = false;
while (true) {
final IElementType tokenType = builder.getTokenType();
if (tokenType == null) {
error(builder, JavaErrorMessages.message("expected.parameter"));
break;
} else if (expect(builder, JavaTokenType.RPARENTH)) {
break;
} else if (tokenType == JavaTokenType.COMMA) {
final PsiBuilder.Marker errorStart = builder.mark();
final PsiBuilder.Marker errorEnd = builder.mark();
builder.advanceLexer();
final boolean hasParamName = parseAnnotationParameter(builder, false);
if (!isFirstParamNamed && hasParamName && !isFirstParamWarned) {
errorStart.errorBefore(JavaErrorMessages.message("annotation.name.is.missing"), errorEnd);
isFirstParamWarned = true;
} else {
errorStart.drop();
}
errorEnd.drop();
} else if (!afterBad) {
error(builder, JavaErrorMessages.message("expected.comma.or.rparen"));
builder.advanceLexer();
afterBad = true;
} else {
afterBad = false;
parseAnnotationParameter(builder, false);
}
}
done(list, JavaElementType.ANNOTATION_PARAMETER_LIST);
return list;
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class ExpressionParser method parseUnary.
@Nullable
private PsiBuilder.Marker parseUnary(final PsiBuilder builder) {
final IElementType tokenType = builder.getTokenType();
if (PREFIX_OPS.contains(tokenType)) {
final PsiBuilder.Marker unary = builder.mark();
builder.advanceLexer();
final PsiBuilder.Marker operand = parseUnary(builder);
if (operand == null) {
error(builder, JavaErrorMessages.message("expected.expression"));
}
unary.done(JavaElementType.PREFIX_EXPRESSION);
return unary;
} else if (tokenType == JavaTokenType.LPARENTH) {
final PsiBuilder.Marker typeCast = builder.mark();
builder.advanceLexer();
ReferenceParser.TypeInfo typeInfo = myParser.getReferenceParser().parseTypeInfo(builder, ReferenceParser.EAT_LAST_DOT | ReferenceParser.WILDCARD | ReferenceParser.CONJUNCTIONS | ReferenceParser.INCOMPLETE_ANNO);
if (typeInfo == null || !expect(builder, JavaTokenType.RPARENTH)) {
typeCast.rollbackTo();
return parsePostfix(builder);
}
if (PREF_ARITHMETIC_OPS.contains(builder.getTokenType()) && !typeInfo.isPrimitive) {
typeCast.rollbackTo();
return parsePostfix(builder);
}
final PsiBuilder.Marker expr = parseUnary(builder);
if (expr == null) {
if (!typeInfo.isParameterized) {
// cannot parse correct parenthesized expression after correct parameterized type
typeCast.rollbackTo();
return parsePostfix(builder);
} else {
error(builder, JavaErrorMessages.message("expected.expression"));
}
}
typeCast.done(JavaElementType.TYPE_CAST_EXPRESSION);
return typeCast;
} else {
return parsePostfix(builder);
}
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class ExpressionParser method parseArrayInitializer.
@NotNull
public PsiBuilder.Marker parseArrayInitializer(@NotNull PsiBuilder builder, @NotNull IElementType type, @NotNull Function<PsiBuilder, Boolean> elementParser, @NotNull @PropertyKey(resourceBundle = BUNDLE) String missingElementKey) {
final PsiBuilder.Marker arrayInit = builder.mark();
builder.advanceLexer();
boolean first = true;
while (true) {
if (builder.getTokenType() == JavaTokenType.RBRACE) {
builder.advanceLexer();
break;
}
if (builder.getTokenType() == null) {
error(builder, JavaErrorMessages.message("expected.rbrace"));
break;
}
if (!elementParser.fun(builder)) {
if (builder.getTokenType() == JavaTokenType.COMMA) {
if (first && builder.lookAhead(1) == JavaTokenType.RBRACE) {
advance(builder, 2);
break;
}
builder.error(JavaErrorMessages.message(missingElementKey));
} else if (builder.getTokenType() != JavaTokenType.RBRACE) {
error(builder, JavaErrorMessages.message("expected.rbrace"));
break;
}
}
first = false;
final IElementType tokenType = builder.getTokenType();
if (tokenType == JavaTokenType.COMMA) {
builder.advanceLexer();
} else if (tokenType != JavaTokenType.RBRACE) {
error(builder, JavaErrorMessages.message("expected.comma"));
}
}
arrayInit.done(type);
return arrayInit;
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class ExpressionParser method parseRelational.
@Nullable
private PsiBuilder.Marker parseRelational(final PsiBuilder builder) {
PsiBuilder.Marker left = parseExpression(builder, ExprType.SHIFT);
if (left == null)
return null;
IElementType tokenType;
while ((tokenType = getGtTokenType(builder)) != null) {
final IElementType toCreate;
final ExprType toParse;
if (RELATIONAL_OPS.contains(tokenType)) {
toCreate = JavaElementType.BINARY_EXPRESSION;
toParse = ExprType.SHIFT;
} else if (tokenType == JavaTokenType.INSTANCEOF_KEYWORD) {
toCreate = JavaElementType.INSTANCE_OF_EXPRESSION;
toParse = ExprType.TYPE;
} else {
break;
}
final PsiBuilder.Marker expression = left.precede();
advanceGtToken(builder, tokenType);
final PsiBuilder.Marker right = parseExpression(builder, toParse);
if (right == null) {
error(builder, JavaErrorMessages.message(toParse == ExprType.TYPE ? "expected.type" : "expected.expression"));
expression.done(toCreate);
return expression;
}
expression.done(toCreate);
left = expression;
}
return left;
}
Aggregations