Improve parsing error recovery for the end method directive

This commit is contained in:
Ben Gruver
2015-02-26 08:55:24 -08:00
parent f35c18489b
commit 24b1063e50
4 changed files with 80 additions and 0 deletions

View File

@ -331,6 +331,11 @@ method
end_method_directive end_method_directive
: END_METHOD_DIRECTIVE; : END_METHOD_DIRECTIVE;
catch [RecognitionException re] {
Marker errorMarker = mark();
recover(input, re);
reportError(errorMarker, re, false);
}
statements_and_directives statements_and_directives
: ( : (

View File

@ -56,4 +56,5 @@ public class ParserTest extends LightCodeInsightParsingTestCase {
public void testSuperClassInvalidSyntax2() throws Exception { doTest(true); } public void testSuperClassInvalidSyntax2() throws Exception { doTest(true); }
public void testInvalidMethod() throws Exception { doTest(true); } public void testInvalidMethod() throws Exception { doTest(true); }
public void testInvalidMethod2() throws Exception { doTest(true); } public void testInvalidMethod2() throws Exception { doTest(true); }
public void testInvalidMethod3() throws Exception { doTest(true); }
} }

View File

@ -0,0 +1,11 @@
.method blah()V
.end
.method return-object()V
.registers 0
.method

View File

@ -0,0 +1,63 @@
smali.FILE
SmaliClass(CLASS)
SmaliExtendsList(EXTENDS_LIST)
<empty list>
SmaliImplementsList(IMPLEMENTS_LIST)
<empty list>
SmaliMethod(METHOD)
SmaliThrowsList(THROWS_LIST)
<empty list>
PsiElement(METHOD_DIRECTIVE)('.method')
PsiWhiteSpace(' ')
SmaliModifierList(MODIFIER_LIST)
<empty list>
PsiElement(MEMBER_NAME)
PsiElement(SIMPLE_NAME)('blah')
SmaliMethodPrototype(METHOD_PROTOTYPE)
PsiElement(OPEN_PAREN)('(')
SmaliMethodParamList(METHOD_PARAM_LIST)
<empty list>
PsiElement(CLOSE_PAREN)(')')
PsiElement(VOID_TYPE)
PsiElement(VOID_TYPE)('V')
PsiWhiteSpace('\n')
PsiErrorElement:mismatched input '.end' expecting END_METHOD_DIRECTIVE
PsiElement(BAD_CHARACTER)('.end')
PsiWhiteSpace('\n\n\n\n')
SmaliMethod(METHOD)
SmaliThrowsList(THROWS_LIST)
<empty list>
PsiElement(METHOD_DIRECTIVE)('.method')
PsiWhiteSpace(' ')
SmaliModifierList(MODIFIER_LIST)
<empty list>
PsiElement(MEMBER_NAME)
PsiElement(INSTRUCTION_FORMAT11x)('return-object')
SmaliMethodPrototype(METHOD_PROTOTYPE)
PsiElement(OPEN_PAREN)('(')
SmaliMethodParamList(METHOD_PARAM_LIST)
<empty list>
PsiElement(CLOSE_PAREN)(')')
PsiElement(VOID_TYPE)
PsiElement(VOID_TYPE)('V')
PsiWhiteSpace('\n')
PsiElement(REGISTERS_STATEMENT)
PsiElement(REGISTERS_DIRECTIVE)('.registers')
PsiWhiteSpace(' ')
PsiElement(LITERAL)
PsiElement(POSITIVE_INTEGER_LITERAL)('0')
PsiErrorElement:missing END_METHOD_DIRECTIVE at '.method'
<empty list>
PsiWhiteSpace('\n\n\n\n')
SmaliMethod(METHOD)
SmaliThrowsList(THROWS_LIST)
<empty list>
PsiElement(METHOD_DIRECTIVE)('.method')
SmaliModifierList(MODIFIER_LIST)
<empty list>
PsiElement(MEMBER_NAME)
PsiErrorElement:no viable alternative at input '<EOF>'
<empty list>
SmaliMethodPrototype(METHOD_PROTOTYPE)
SmaliMethodParamList(METHOD_PARAM_LIST)
<empty list>