Improve parsing of an invalid SmaliMethod with no .end method

This ensures that we still generate a SmaliMethod in this case, instead
of erroring out when not matching the END_METHOD_DIRECTIVE and aborting
the main SmaliMethod mark.
This commit is contained in:
Ben Gruver 2015-02-14 18:09:29 -08:00
parent 4a9e7df53e
commit aa06a4c782
4 changed files with 43 additions and 1 deletions

View File

@ -308,13 +308,17 @@ method
mark().done(SmaliElementTypes.MODIFIER_LIST);
}
: METHOD_DIRECTIVE access_list member_name method_prototype statements_and_directives
END_METHOD_DIRECTIVE
end_method_directive
{ marker.done(SmaliElementTypes.METHOD); };
catch [RecognitionException re] {
recover(input, re);
reportError(marker, re, false);
}
end_method_directive
: END_METHOD_DIRECTIVE;
statements_and_directives
: (
( ordered_method_item

View File

@ -101,4 +101,5 @@ public class ParserTest extends ParsingTestCase {
public void testParamListInvalidParameter() throws Exception { doTest(true); }
public void testSuperClassInvalidSyntax() throws Exception { doTest(true); }
public void testSuperClassInvalidSyntax2() throws Exception { doTest(true); }
public void testInvalidMethod() throws Exception { doTest(true); }
}

View File

@ -0,0 +1,4 @@
.class Ltest;
.super Ljava/lang/Object;
.method .blah

View File

@ -0,0 +1,33 @@
smali.FILE
SmaliClass(CLASS)
SmaliModifierList(MODIFIER_LIST)
<empty list>
SmaliExtendsList(EXTENDS_LIST)
<empty list>
SmaliImplementsList(IMPLEMENTS_LIST)
<empty list>
PsiElement(CLASS_STATEMENT)
PsiElement(CLASS_DIRECTIVE)('.class')
PsiWhiteSpace(' ')
PsiElement(ACCESS_LIST)
<empty list>
PsiElement(CLASS_TYPE)
PsiElement(CLASS_DESCRIPTOR)('Ltest;')
PsiWhiteSpace('\n')
PsiElement(SUPER_STATEMENT)
PsiElement(SUPER_DIRECTIVE)('.super')
PsiWhiteSpace(' ')
PsiElement(CLASS_TYPE)
PsiElement(CLASS_DESCRIPTOR)('Ljava/lang/Object;')
PsiWhiteSpace('\n\n')
SmaliMethod(METHOD)
SmaliModifierList(MODIFIER_LIST)
<empty list>
PsiElement(METHOD_DIRECTIVE)('.method')
PsiWhiteSpace(' ')
PsiElement(ACCESS_LIST)
<empty list>
PsiErrorElement:no viable alternative at input '.blah'
PsiElement(BAD_CHARACTER)('.blah')
SmaliMethodPrototype(METHOD_PROTOTYPE)
<empty list>