From bcc0d5fa645b6525d021e6061edac1ecfd52a8d8 Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Thu, 26 Feb 2015 09:37:16 -0800 Subject: [PATCH] Improve error handling for missing reference_type_descriptor --- smalidea/src/main/antlr3/smalideaParser.g | 5 ++ .../test/java/org/jf/smalidea/ParserTest.java | 1 + .../testData/InvalidMethodReference.smalidea | 4 ++ smalidea/testData/InvalidMethodReference.txt | 46 +++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 smalidea/testData/InvalidMethodReference.smalidea create mode 100644 smalidea/testData/InvalidMethodReference.txt diff --git a/smalidea/src/main/antlr3/smalideaParser.g b/smalidea/src/main/antlr3/smalideaParser.g index 2501f5f0..e0576569 100644 --- a/smalidea/src/main/antlr3/smalideaParser.g +++ b/smalidea/src/main/antlr3/smalideaParser.g @@ -540,6 +540,11 @@ nonvoid_type_descriptor reference_type_descriptor : class_descriptor | array_descriptor; + catch [RecognitionException re] { + Marker marker = mark(); + recover(input, re); + reportError(marker, re, false); + } null_literal @init { Marker marker = mark(); } diff --git a/smalidea/src/test/java/org/jf/smalidea/ParserTest.java b/smalidea/src/test/java/org/jf/smalidea/ParserTest.java index 5d584c55..416af4de 100644 --- a/smalidea/src/test/java/org/jf/smalidea/ParserTest.java +++ b/smalidea/src/test/java/org/jf/smalidea/ParserTest.java @@ -54,6 +54,7 @@ public class ParserTest extends LightCodeInsightParsingTestCase { public void testParamListInvalidParameter() throws Exception { doTest(true); } public void testSuperClassInvalidSyntax() throws Exception { doTest(true); } public void testSuperClassInvalidSyntax2() throws Exception { doTest(true); } + public void testInvalidMethodReference() throws Exception { doTest(true); } public void testInvalidMethod() throws Exception { doTest(true); } public void testInvalidMethod2() throws Exception { doTest(true); } public void testInvalidMethod3() throws Exception { doTest(true); } diff --git a/smalidea/testData/InvalidMethodReference.smalidea b/smalidea/testData/InvalidMethodReference.smalidea new file mode 100644 index 00000000..d4789e00 --- /dev/null +++ b/smalidea/testData/InvalidMethodReference.smalidea @@ -0,0 +1,4 @@ +.method blah()V +.registers 1 +invoke-virtual {v0}, .blah-> +.end method \ No newline at end of file diff --git a/smalidea/testData/InvalidMethodReference.txt b/smalidea/testData/InvalidMethodReference.txt new file mode 100644 index 00000000..38932f65 --- /dev/null +++ b/smalidea/testData/InvalidMethodReference.txt @@ -0,0 +1,46 @@ +smali.FILE + SmaliClass(CLASS) + SmaliExtendsList(EXTENDS_LIST) + + SmaliImplementsList(IMPLEMENTS_LIST) + + SmaliMethod(METHOD) + SmaliThrowsList(THROWS_LIST) + + PsiElement(METHOD_DIRECTIVE)('.method') + PsiWhiteSpace(' ') + SmaliModifierList(MODIFIER_LIST) + + PsiElement(MEMBER_NAME) + PsiElement(SIMPLE_NAME)('blah') + SmaliMethodPrototype(METHOD_PROTOTYPE) + PsiElement(OPEN_PAREN)('(') + SmaliMethodParamList(METHOD_PARAM_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)('1') + PsiWhiteSpace('\n') + PsiElement(INSTRUCTION) + PsiElement(INSTRUCTION_FORMAT35c_METHOD)('invoke-virtual') + PsiWhiteSpace(' ') + PsiElement(OPEN_BRACE)('{') + PsiElement(REGISTER_REFERENCE) + PsiElement(REGISTER)('v0') + PsiElement(CLOSE_BRACE)('}') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + PsiElement(METHOD_REFERENCE) + PsiErrorElement:no viable alternative at input '.blah-' + PsiElement(BAD_CHARACTER)('.blah-') + PsiElement(BAD_CHARACTER)('>') + PsiWhiteSpace('\n') + PsiElement(MEMBER_NAME) + + PsiElement(END_METHOD_DIRECTIVE)('.end method') \ No newline at end of file