use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class DeclarationParser method parseModifierList.
@NotNull
public Pair<PsiBuilder.Marker, Boolean> parseModifierList(final PsiBuilder builder, final TokenSet modifiers) {
final PsiBuilder.Marker modList = builder.mark();
boolean isEmpty = true;
while (true) {
final IElementType tokenType = builder.getTokenType();
if (tokenType == null)
break;
if (modifiers.contains(tokenType)) {
builder.advanceLexer();
isEmpty = false;
} else if (tokenType == JavaTokenType.AT) {
if (ElementType.KEYWORD_BIT_SET.contains(builder.lookAhead(1))) {
break;
}
parseAnnotation(builder);
isEmpty = false;
} else {
break;
}
}
done(modList, JavaElementType.MODIFIER_LIST);
return Pair.create(modList, isEmpty);
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class DeclarationParser method parseElementList.
@NotNull
private PsiBuilder.Marker parseElementList(PsiBuilder builder, ListType type) {
final boolean lambda = (type == ListType.LAMBDA_TYPED || type == ListType.LAMBDA_UNTYPED);
final boolean resources = (type == ListType.RESOURCE);
final PsiBuilder.Marker elementList = builder.mark();
final boolean leftParenth = expect(builder, JavaTokenType.LPARENTH);
assert lambda || leftParenth : builder.getTokenType();
final IElementType delimiter = resources ? JavaTokenType.SEMICOLON : JavaTokenType.COMMA;
final String noDelimiterMsg = resources ? "expected.semicolon" : "expected.comma";
final String noElementMsg = resources ? "expected.resource" : "expected.parameter";
PsiBuilder.Marker invalidElements = null;
String errorMessage = null;
boolean delimiterExpected = false;
boolean noElements = true;
while (true) {
final IElementType tokenType = builder.getTokenType();
if (tokenType == null || PARAM_LIST_STOPPERS.contains(tokenType)) {
final boolean noLastElement = !delimiterExpected && (!noElements && !resources || noElements && resources);
if (noLastElement) {
final String key = lambda ? "expected.parameter" : "expected.identifier.or.type";
error(builder, JavaErrorMessages.message(key));
}
if (tokenType == JavaTokenType.RPARENTH) {
if (invalidElements != null) {
invalidElements.error(errorMessage);
invalidElements = null;
}
builder.advanceLexer();
} else {
if (!noLastElement || resources) {
if (invalidElements != null) {
invalidElements.error(errorMessage);
}
invalidElements = null;
if (leftParenth) {
error(builder, JavaErrorMessages.message("expected.rparen"));
}
}
}
break;
}
if (delimiterExpected) {
if (builder.getTokenType() == delimiter) {
delimiterExpected = false;
if (invalidElements != null) {
invalidElements.error(errorMessage);
invalidElements = null;
}
builder.advanceLexer();
continue;
}
} else {
final PsiBuilder.Marker listElement = resources ? parseResource(builder) : lambda ? parseLambdaParameter(builder, type == ListType.LAMBDA_TYPED) : parseParameter(builder, true, false);
if (listElement != null) {
delimiterExpected = true;
if (invalidElements != null) {
invalidElements.errorBefore(errorMessage, listElement);
invalidElements = null;
}
noElements = false;
continue;
}
}
if (invalidElements == null) {
if (builder.getTokenType() == delimiter) {
error(builder, JavaErrorMessages.message(noElementMsg));
builder.advanceLexer();
if (noElements && resources) {
noElements = false;
}
continue;
} else {
invalidElements = builder.mark();
errorMessage = JavaErrorMessages.message(delimiterExpected ? noDelimiterMsg : noElementMsg);
}
}
// adding a reference, not simple tokens allows "Browse .." to work well
final PsiBuilder.Marker ref = myParser.getReferenceParser().parseJavaCodeReference(builder, true, true, false, false);
if (ref == null && builder.getTokenType() != null) {
builder.advanceLexer();
}
}
if (invalidElements != null) {
invalidElements.error(errorMessage);
}
done(elementList, resources ? JavaElementType.RESOURCE_LIST : JavaElementType.PARAMETER_LIST);
return elementList;
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class DeclarationParser method parseClassBodyWithBraces.
public void parseClassBodyWithBraces(final PsiBuilder builder, final boolean isAnnotation, final boolean isEnum) {
assert builder.getTokenType() == JavaTokenType.LBRACE : builder.getTokenType();
builder.advanceLexer();
final PsiBuilder builderWrapper = braceMatchingBuilder(builder);
if (isEnum) {
parseEnumConstants(builderWrapper);
}
parseClassBodyDeclarations(builderWrapper, isAnnotation);
expectOrError(builder, JavaTokenType.RBRACE, "expected.rbrace");
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class DeclarationParser method parseMethodFromLeftParenth.
private PsiBuilder.Marker parseMethodFromLeftParenth(PsiBuilder builder, PsiBuilder.Marker declaration, boolean anno, boolean constructor) {
parseParameterList(builder);
eatBrackets(builder, constructor ? "expected.semicolon" : null);
myParser.getReferenceParser().parseReferenceList(builder, JavaTokenType.THROWS_KEYWORD, JavaElementType.THROWS_LIST, JavaTokenType.COMMA);
if (anno && expect(builder, JavaTokenType.DEFAULT_KEYWORD)) {
parseAnnotationValue(builder);
}
IElementType tokenType = builder.getTokenType();
if (tokenType != JavaTokenType.SEMICOLON && tokenType != JavaTokenType.LBRACE) {
PsiBuilder.Marker error = builder.mark();
// heuristic: going to next line obviously means method signature is over, starting new method (actually, another one completion hack)
CharSequence text = builder.getOriginalText();
Loop: while (true) {
for (int i = builder.getCurrentOffset() - 1; i >= 0; i--) {
char ch = text.charAt(i);
if (ch == '\n')
break Loop;
else if (ch != ' ' && ch != '\t')
break;
}
if (!expect(builder, APPEND_TO_METHOD_SET))
break;
}
error.error(JavaErrorMessages.message("expected.lbrace.or.semicolon"));
}
if (!expect(builder, JavaTokenType.SEMICOLON)) {
if (builder.getTokenType() == JavaTokenType.LBRACE) {
myParser.getStatementParser().parseCodeBlock(builder);
}
}
done(declaration, anno ? JavaElementType.ANNOTATION_METHOD : JavaElementType.METHOD);
return declaration;
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class DeclarationParser method parseClassBodyDeclarations.
public void parseClassBodyDeclarations(final PsiBuilder builder, final boolean isAnnotation) {
final Context context = isAnnotation ? Context.ANNOTATION_INTERFACE : Context.CLASS;
PsiBuilder.Marker invalidElements = null;
while (true) {
final IElementType tokenType = builder.getTokenType();
if (tokenType == null || tokenType == JavaTokenType.RBRACE)
break;
if (tokenType == JavaTokenType.SEMICOLON) {
if (invalidElements != null) {
invalidElements.error(JavaErrorMessages.message("unexpected.token"));
invalidElements = null;
}
builder.advanceLexer();
continue;
}
final PsiBuilder.Marker declaration = parse(builder, context);
if (declaration != null) {
if (invalidElements != null) {
invalidElements.errorBefore(JavaErrorMessages.message("unexpected.token"), declaration);
invalidElements = null;
}
continue;
}
if (invalidElements == null) {
invalidElements = builder.mark();
}
// adding a reference, not simple tokens allows "Browse ..." to work well
final PsiBuilder.Marker ref = myParser.getReferenceParser().parseJavaCodeReference(builder, true, true, false, false);
if (ref == null) {
builder.advanceLexer();
}
}
if (invalidElements != null) {
invalidElements.error(JavaErrorMessages.message("unexpected.token"));
}
}
Aggregations