Search code examples
antlrantlr4code-translation

Antlr 4 - Java grammar rule "Explicit Generic Invocation" never gets visited


I was building a listener to translate all java method calls A.Foo(args) to A.Bar(args). It appeared to me that the rule:

expression '.' explicitGenericInvocation

Is the most fitting rule to listen to. However, after visual inspection of the tree, I realized that all java method calls are recognized as the rule

expression '(' expressionList? ')'

whereas the expression term is further matched to

expression '.' Identifier

It seems that the expression rule overrides the explicitGenericInvocation rule all the time. Is this intended or is there a flaw in the java grammar? If it is intended, then what is the correct interpretation of the rule explicitGenericInvocation?


Solution

  • explicitGenericInvocation must start with nonWildcardTypeArguments which is <...>. a.Foo(args) therefore matches the general rule instead of the specialized one for generic types.