use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class ModuleParser method parse.
@Nullable
public PsiBuilder.Marker parse(@NotNull PsiBuilder builder) {
PsiBuilder.Marker module = builder.mark();
PsiBuilder.Marker firstAnnotation = myParser.getDeclarationParser().parseAnnotations(builder);
IElementType type = builder.getTokenType();
String text = type == JavaTokenType.IDENTIFIER ? builder.getTokenText() : null;
if (!(PsiKeyword.OPEN.equals(text) || PsiKeyword.MODULE.equals(text))) {
module.rollbackTo();
return null;
}
PsiBuilder.Marker modifierList = firstAnnotation != null ? firstAnnotation.precede() : builder.mark();
if (PsiKeyword.OPEN.equals(text)) {
mapAndAdvance(builder, JavaTokenType.OPEN_KEYWORD);
text = builder.getTokenText();
}
JavaParserUtil.done(modifierList, JavaElementType.MODIFIER_LIST);
if (PsiKeyword.MODULE.equals(text)) {
mapAndAdvance(builder, JavaTokenType.MODULE_KEYWORD);
} else {
module.drop();
parseExtras(builder, JavaErrorMessages.message("expected.module.declaration"));
return module;
}
if (parseName(builder) == null) {
module.drop();
if (builder.getTokenType() != null) {
parseExtras(builder, JavaErrorMessages.message("expected.module.declaration"));
} else {
error(builder, JavaErrorMessages.message("expected.identifier"));
}
return module;
}
if (!expect(builder, JavaTokenType.LBRACE)) {
if (builder.getTokenType() != null) {
parseExtras(builder, JavaErrorMessages.message("expected.module.declaration"));
} else {
error(builder, JavaErrorMessages.message("expected.lbrace"));
}
} else {
parseModuleContent(builder);
}
JavaParserUtil.done(module, JavaElementType.MODULE);
if (builder.getTokenType() != null) {
parseExtras(builder, JavaErrorMessages.message("unexpected.tokens"));
}
return module;
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class ModuleParser method parseModuleContent.
private void parseModuleContent(PsiBuilder builder) {
IElementType token;
PsiBuilder.Marker invalid = null;
while ((token = builder.getTokenType()) != null) {
if (token == JavaTokenType.RBRACE) {
break;
}
if (token == JavaTokenType.SEMICOLON) {
if (invalid != null) {
invalid.error(JavaErrorMessages.message("expected.module.statement"));
invalid = null;
}
builder.advanceLexer();
continue;
}
PsiBuilder.Marker statement = parseStatement(builder);
if (statement == null) {
if (invalid == null)
invalid = builder.mark();
builder.advanceLexer();
} else if (invalid != null) {
invalid.errorBefore(JavaErrorMessages.message("expected.module.statement"), statement);
invalid = null;
}
}
if (invalid != null) {
invalid.error(JavaErrorMessages.message("expected.module.statement"));
}
if (!expect(builder, JavaTokenType.RBRACE) && invalid == null) {
error(builder, JavaErrorMessages.message("expected.rbrace"));
}
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class ModuleParser method parseName.
private static PsiBuilder.Marker parseName(PsiBuilder builder) {
PsiBuilder.Marker nameElement = builder.mark();
boolean empty = true;
boolean idExpected = true;
while (true) {
IElementType t = builder.getTokenType();
if (t == JavaTokenType.IDENTIFIER) {
if (!idExpected)
error(builder, JavaErrorMessages.message("expected.dot"));
idExpected = false;
} else if (t == JavaTokenType.DOT) {
if (idExpected)
error(builder, JavaErrorMessages.message("expected.identifier"));
idExpected = true;
} else
break;
builder.advanceLexer();
empty = false;
}
if (!empty) {
if (idExpected)
error(builder, JavaErrorMessages.message("expected.identifier"));
nameElement.done(JavaElementType.MODULE_REFERENCE);
return nameElement;
} else {
nameElement.drop();
return null;
}
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class ReferenceParser method parseTypeInfo.
@Nullable
private TypeInfo parseTypeInfo(PsiBuilder builder, int flags, boolean badWildcard) {
if (builder.getTokenType() == null)
return null;
final TypeInfo typeInfo = new TypeInfo();
PsiBuilder.Marker type = builder.mark();
PsiBuilder.Marker anno = myParser.getDeclarationParser().parseAnnotations(builder);
final IElementType tokenType = builder.getTokenType();
if (expect(builder, ElementType.PRIMITIVE_TYPE_BIT_SET)) {
typeInfo.isPrimitive = true;
} else if ((isSet(flags, WILDCARD) || badWildcard) && (tokenType == JavaTokenType.QUEST || isKeywordAny(builder))) {
if (tokenType == JavaTokenType.QUEST) {
builder.advanceLexer();
} else {
dummy(builder);
}
completeWildcardType(builder, isSet(flags, WILDCARD), type);
typeInfo.marker = type;
return typeInfo;
} else if (tokenType == JavaTokenType.IDENTIFIER) {
parseJavaCodeReference(builder, isSet(flags, EAT_LAST_DOT), true, false, false, false, isSet(flags, DIAMONDS), typeInfo);
} else if (isSet(flags, DIAMONDS) && tokenType == JavaTokenType.GT) {
if (anno == null) {
emptyElement(builder, JavaElementType.DIAMOND_TYPE);
} else {
error(builder, JavaErrorMessages.message("expected.identifier"));
typeInfo.hasErrors = true;
}
type.done(JavaElementType.TYPE);
typeInfo.marker = type;
return typeInfo;
} else {
type.drop();
if (anno != null && isSet(flags, INCOMPLETE_ANNO)) {
error(builder, JavaErrorMessages.message("expected.type"));
typeInfo.hasErrors = true;
return typeInfo;
}
return null;
}
while (true) {
type.done(JavaElementType.TYPE);
myParser.getDeclarationParser().parseAnnotations(builder);
final PsiBuilder.Marker bracket = builder.mark();
if (!expect(builder, JavaTokenType.LBRACKET)) {
bracket.drop();
break;
}
if (!expect(builder, JavaTokenType.RBRACKET)) {
bracket.rollbackTo();
break;
}
bracket.drop();
typeInfo.isArray = true;
type = type.precede();
}
if (isSet(flags, ELLIPSIS) && builder.getTokenType() == JavaTokenType.ELLIPSIS) {
type = type.precede();
builder.advanceLexer();
type.done(JavaElementType.TYPE);
typeInfo.isVarArg = true;
}
typeInfo.marker = type;
return typeInfo;
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class ExpressionParser method parseNew.
@NotNull
private PsiBuilder.Marker parseNew(PsiBuilder builder, @Nullable PsiBuilder.Marker start) {
PsiBuilder.Marker newExpr = (start != null ? start.precede() : builder.mark());
builder.advanceLexer();
myParser.getReferenceParser().parseReferenceParameterList(builder, false, true);
PsiBuilder.Marker refOrType;
PsiBuilder.Marker anno = myParser.getDeclarationParser().parseAnnotations(builder);
IElementType tokenType = builder.getTokenType();
if (tokenType == JavaTokenType.IDENTIFIER) {
rollbackTo(anno);
refOrType = myParser.getReferenceParser().parseJavaCodeReference(builder, true, true, true, true);
if (refOrType == null) {
error(builder, JavaErrorMessages.message("expected.identifier"));
newExpr.done(JavaElementType.NEW_EXPRESSION);
return newExpr;
}
} else if (ElementType.PRIMITIVE_TYPE_BIT_SET.contains(tokenType)) {
refOrType = null;
builder.advanceLexer();
} else {
error(builder, JavaErrorMessages.message("expected.identifier"));
newExpr.done(JavaElementType.NEW_EXPRESSION);
return newExpr;
}
if (refOrType != null && builder.getTokenType() == JavaTokenType.LPARENTH) {
parseArgumentList(builder);
if (builder.getTokenType() == JavaTokenType.LBRACE) {
final PsiBuilder.Marker classElement = refOrType.precede();
myParser.getDeclarationParser().parseClassBodyWithBraces(builder, false, false);
classElement.done(JavaElementType.ANONYMOUS_CLASS);
}
newExpr.done(JavaElementType.NEW_EXPRESSION);
return newExpr;
}
anno = myParser.getDeclarationParser().parseAnnotations(builder);
if (builder.getTokenType() != JavaTokenType.LBRACKET) {
rollbackTo(anno);
error(builder, JavaErrorMessages.message(refOrType == null ? "expected.lbracket" : "expected.lparen.or.lbracket"));
newExpr.done(JavaElementType.NEW_EXPRESSION);
return newExpr;
}
int bracketCount = 0;
int dimCount = 0;
while (true) {
anno = myParser.getDeclarationParser().parseAnnotations(builder);
if (builder.getTokenType() != JavaTokenType.LBRACKET) {
rollbackTo(anno);
break;
}
builder.advanceLexer();
if (bracketCount == dimCount) {
final PsiBuilder.Marker dimExpr = parse(builder);
if (dimExpr != null) {
dimCount++;
}
}
bracketCount++;
if (!expectOrError(builder, JavaTokenType.RBRACKET, "expected.rbracket")) {
newExpr.done(JavaElementType.NEW_EXPRESSION);
return newExpr;
}
}
if (dimCount == 0) {
if (builder.getTokenType() == JavaTokenType.LBRACE) {
parseArrayInitializer(builder);
} else {
error(builder, JavaErrorMessages.message("expected.array.initializer"));
}
}
newExpr.done(JavaElementType.NEW_EXPRESSION);
return newExpr;
}
Aggregations