Skip to content

[java] Separate receiver parameter from formal parameter #1980

Merged
oowekyala merged 9 commits into
pmd:java-grammarfrom
oowekyala:grammar-receiver
Sep 27, 2019
Merged

[java] Separate receiver parameter from formal parameter #1980
oowekyala merged 9 commits into
pmd:java-grammarfrom
oowekyala:grammar-receiver

Conversation

@oowekyala

Copy link
Copy Markdown
Member

This introduces a new node type, ReceiverParameter. This is because a receiver parameter is not a formal parameter, even though it looks like one: it doesn't declare a variable, and doesn't affect the arity of the method or constructor. It's so rarely used that giving it its own node avoids matching it by mistake and simplifies the API and grammar of the ubiquitous FormalParameter and VariableDeclaratorId.

This also simplifies the few places where we pay attention to the receiver parameter --- to ignore it.

So for example:

CodeOld ASTNew AST
(@A Foo this, Foo other)
FormalParameters
  + FormalParameter[@ReceiverParameter=true()]
    + ClassOrInterfaceType
       + Annotation "A"
    + VariableDeclaratorId[@Image="this", @ReceiverParameter=true()]
  + FormalParameter
    + ClassOrInterfaceType
    + VariableDeclaratorId "other"
FormalParameters
  + ReceiverParameter
    + ClassOrInterfaceType
       + Annotation "A"
  + FormalParameter
    + ClassOrInterfaceType
    + VariableDeclaratorId "other"

@oowekyala oowekyala added the in:ast About the AST structure or API, the parsing step label Aug 15, 2019
@oowekyala oowekyala added this to the 7.0.0 milestone Aug 15, 2019
@ghost

ghost commented Sep 25, 2019

Copy link
Copy Markdown
1 Message
📖 No java rules are changed!

Generated by 🚫 Danger

@oowekyala oowekyala merged commit 16a89b5 into pmd:java-grammar Sep 27, 2019
@oowekyala oowekyala deleted the grammar-receiver branch October 1, 2019 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in:ast About the AST structure or API, the parsing step

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant