Minor, extract methods
This commit is contained in:
@@ -541,26 +541,37 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
*/
|
*/
|
||||||
private boolean parseAnnotation(AnnotationParsingMode mode) {
|
private boolean parseAnnotation(AnnotationParsingMode mode) {
|
||||||
if (at(LBRACKET)) {
|
if (at(LBRACKET)) {
|
||||||
|
return parseAnnotationList(mode);
|
||||||
|
}
|
||||||
|
else if (mode.allowShortAnnotations && at(IDENTIFIER)) {
|
||||||
|
parseAnnotationEntry();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (mode.allowAtAnnotations && at(AT)) {
|
||||||
|
if (myBuilder.rawLookup(1) == IDENTIFIER) {
|
||||||
|
parseAnnotationEntry();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
errorAndAdvance("Expected annotation identifier after '@'", 1); // AT
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean parseAnnotationList(AnnotationParsingMode mode) {
|
||||||
PsiBuilder.Marker annotation = mark();
|
PsiBuilder.Marker annotation = mark();
|
||||||
|
|
||||||
myBuilder.disableNewlines();
|
myBuilder.disableNewlines();
|
||||||
advance(); // LBRACKET
|
advance(); // LBRACKET
|
||||||
|
|
||||||
if (mode.isFileAnnotationParsingMode) {
|
if (!parseAnnotationTargetIfNeeded(mode)) {
|
||||||
if (mode == FILE_ANNOTATIONS_WHEN_PACKAGE_OMITTED && !(at(FILE_KEYWORD) && lookahead(1) == COLON)) {
|
|
||||||
annotation.rollbackTo();
|
annotation.rollbackTo();
|
||||||
myBuilder.restoreNewlinesState();
|
myBuilder.restoreNewlinesState();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String message = "Expecting \"" + FILE_KEYWORD.getValue() + COLON.getValue() + "\" prefix for file annotations";
|
|
||||||
expect(FILE_KEYWORD, message);
|
|
||||||
expect(COLON, message, TokenSet.create(IDENTIFIER, RBRACKET));
|
|
||||||
}
|
|
||||||
else if (at(FILE_KEYWORD) && lookahead(1) == COLON) {
|
|
||||||
errorAndAdvance("File annotations are only allowed before package declaration", 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!at(IDENTIFIER)) {
|
if (!at(IDENTIFIER)) {
|
||||||
error("Expecting a list of annotations");
|
error("Expecting a list of annotations");
|
||||||
}
|
}
|
||||||
@@ -584,21 +595,23 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
annotation.done(ANNOTATION);
|
annotation.done(ANNOTATION);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (mode.allowShortAnnotations && at(IDENTIFIER)) {
|
|
||||||
parseAnnotationEntry();
|
// Returns true if we should continue parse annotation
|
||||||
return true;
|
private boolean parseAnnotationTargetIfNeeded(AnnotationParsingMode mode) {
|
||||||
}
|
if (mode.isFileAnnotationParsingMode) {
|
||||||
else if (mode.allowAtAnnotations && at(AT)) {
|
if (mode == FILE_ANNOTATIONS_WHEN_PACKAGE_OMITTED && !(at(FILE_KEYWORD) && lookahead(1) == COLON)) {
|
||||||
if (myBuilder.rawLookup(1) == IDENTIFIER) {
|
return false;
|
||||||
parseAnnotationEntry();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
errorAndAdvance("Expected annotation identifier after '@'", 1); // AT
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
String message = "Expecting \"" + FILE_KEYWORD.getValue() + COLON.getValue() + "\" prefix for file annotations";
|
||||||
|
expect(FILE_KEYWORD, message);
|
||||||
|
expect(COLON, message, TokenSet.create(IDENTIFIER, RBRACKET));
|
||||||
|
}
|
||||||
|
else if (at(FILE_KEYWORD) && lookahead(1) == COLON) {
|
||||||
|
errorAndAdvance("File annotations are only allowed before package declaration", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user