c2nes / javalang

Pure Python Java parser and tools
MIT License
737 stars 161 forks source link

Unexpected behavior for generic method invocation with explicit typing #105

Open cedricrupb opened 3 years ago

cedricrupb commented 3 years ago

Issue

For a method invocation dummyObject.<Type>test(), it is expected that AST representation includes dummyObject as the qualifier and test as the member (method call). However, Javalang would parse dummyObject as the member and ignores the method call at all.

Version

javalang 0.13.0 Python 3.8

Minimal example

import javalang

code = """
public class MinimalExample {

    public static void testMinimal(Object dummyObject){
        TestResult result = dummyObject.<TestResult>dummyFunction();
    }

}
"""

tree = javalang.parse.parse(code)
print(tree.types[0].body[0].body[0])

Output:

LocalVariableDeclaration(
annotations=[],
declarators=[
   VariableDeclarator(dimensions=[], 
        initializer=
                 MethodInvocation(arguments=[], 
                                       member=dummyObject, 
                                       postfix_operators=[], 
                                       prefix_operators=[], 
                                       qualifier=, selectors=[],
                                       type_arguments=[TypeArgument(pattern_type=None, type=ReferenceType(arguments=None,   dimensions=[], name=TestResult, sub_type=None))]), name=result)
          ], 
          modifiers=set(), 
          type=ReferenceType(arguments=None, dimensions=[], name=TestResult, sub_type=None)
)