terryyin / lizard

A simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.
Other
1.82k stars 248 forks source link

Failed to detect method following an abstract method that does not have method body but with 'throws' in Java #309

Closed cg122 closed 3 years ago

cg122 commented 3 years ago

See the following failed test case added to testJava.py:

    def test_abstract_function_without_body_with_throws_following_method(self):
        result = get_java_function_list("abstract void fun() throws e; void fun2(){}")
        self.assertEqual("fun", result[0].name)          # passed
        self.assertEqual(2, len(result))                 # failed

Result function list includes fun, but not fun2. fun2 is considered part of fun().

If no throws in abstract method:

    def test_abstract_function_without_body_following_method(self):
        result = get_java_function_list("abstract void fun(); void fun1(){}")
        self.assertEqual("fun1", result[0].name)         # passed
        self.assertEqual(2, len(result))                 # failed

Result function list includes fun1, but not fun.

terryyin commented 3 years ago

Hmmm, I agree with you. Abstract method shouldn’t be counted. And not dealing with the abstract keyword lead to this bug.

On 26 Jan 2021, at 4:26 PM, Chushu Gao notifications@github.com wrote:

See the following failed test case added to testJava.py:

def test_abstract_function_without_body_with_throws_following_method(self):
    result = get_java_function_list("abstract void fun() throws e; void fun2(){}")
    self.assertEqual("fun", result[0].name)          # passed
    self.assertEqual(2, len(result))                 # failed

Result function list includes fun, but not fun2. fun2 is considered part of fun().

If no throws in abstract method:

def test_abstract_function_without_body_following_method(self):
    result = get_java_function_list("abstract void fun(); void fun1(){}")
    self.assertEqual("fun1", result[0].name)         # passed
    self.assertEqual(2, len(result))                 # failed

Result function list includes fun1, but not fun.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/terryyin/lizard/issues/309, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGASYS2NNBK4QEO7IOO233S3Z4DRANCNFSM4WTBTAIA.

terryyin commented 3 years ago

This is fixed by https://github.com/terryyin/lizard/commit/4891f116489fc5ae9cab781da1264352ad00e749