Improve error handling for annotation element parsing

This commit is contained in:
Ben Gruver 2015-02-21 12:43:13 -08:00
parent 1325537f8a
commit 251d6073b9
3 changed files with 32 additions and 1 deletions

View File

@ -723,13 +723,21 @@ annotation_element
Marker nameMarker = null; Marker nameMarker = null;
} }
: { nameMarker = mark(); } simple_name { nameMarker.done(SmaliElementTypes.ANNOTATION_ELEMENT_NAME); } : { nameMarker = mark(); } simple_name { nameMarker.done(SmaliElementTypes.ANNOTATION_ELEMENT_NAME); }
EQUAL literal equal literal
{ marker.done(SmaliElementTypes.ANNOTATION_ELEMENT); }; { marker.done(SmaliElementTypes.ANNOTATION_ELEMENT); };
catch [RecognitionException re] { catch [RecognitionException re] {
recover(input, re); recover(input, re);
reportError(marker, re, false); reportError(marker, re, false);
} }
equal
: EQUAL;
catch [RecognitionException re] {
Marker errorMarker = mark();
recover(input, re);
reportError(errorMarker, re, false);
}
annotation annotation
@init { @init {
Marker marker = mark(); Marker marker = mark();

View File

@ -4,3 +4,6 @@
.annotation runtime .blah .annotation runtime .blah
.end annotation .end annotation
.annotation runtime Lblah;
blah .blah .blah
.end annotation

View File

@ -27,4 +27,24 @@ smali.FILE
PsiWhiteSpace('\n') PsiWhiteSpace('\n')
PsiElement(ANNOTATION_PARAMETER_LIST) PsiElement(ANNOTATION_PARAMETER_LIST)
<empty list> <empty list>
PsiElement(END_ANNOTATION_DIRECTIVE)('.end annotation')
PsiWhiteSpace('\n\n')
SmaliAnnotation(ANNOTATION)
PsiElement(ANNOTATION_DIRECTIVE)('.annotation')
PsiWhiteSpace(' ')
PsiElement(ANNOTATION_VISIBILITY)('runtime')
PsiWhiteSpace(' ')
PsiElement(CLASS_TYPE)
PsiElement(CLASS_DESCRIPTOR)('Lblah;')
PsiWhiteSpace('\n ')
PsiElement(ANNOTATION_PARAMETER_LIST)
PsiElement(ANNOTATION_ELEMENT)
PsiElement(ANNOTATION_ELEMENT_NAME)
PsiElement(SIMPLE_NAME)('blah')
PsiWhiteSpace(' ')
PsiErrorElement:mismatched input '.blah' expecting EQUAL
PsiElement(BAD_CHARACTER)('.blah')
PsiWhiteSpace(' ')
PsiElement(BAD_CHARACTER)('.blah')
PsiWhiteSpace('\n')
PsiElement(END_ANNOTATION_DIRECTIVE)('.end annotation') PsiElement(END_ANNOTATION_DIRECTIVE)('.end annotation')