GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing github.com — [java] Merge different increment/decrement expressions by oowekyala · Pull Request #1890 · pmd/pmd Conversation
Member
The current grammar has PreDecrementExpression, PreIncrementExpression, and PostfixExpression to represent mutation expressions.
This PR makes two contributions:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
adangel
reviewed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oowekyala I've added a samples section here: https://github.com/pmd/pmd/wiki/Java_clean_changes#merge-different-increment-and-decrement-expressions Only two things I'd change for now:
Let me know, if you agree and whether I should change it.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not so sure about the name. "IncrementExpression" doesn't sound right, since the node can also be a decrement expression... I had a look at how eclipse jdt exposes this: They have a PrefixExpression and a PostfixExpression. So they combine the grammar in a different way....
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO PrefixExpr + PostfixExpr are not so great because they share the two operators AFAIK there's no term for "decrement or increment" expression. Maybe "XcrementExpression"? Just kidding 😆 However there is a term for something that is "either postfix or prefix": "unary". Maybe then, it would make sense to merge IncrementExpression into UnaryExpression and have an attribute for whether it's prefix or postfix instead. That way we have a single node, and also a single enum for unary operators too. Wdyt?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if merging IncrementExpr with UnaryExpr is helpful - In the current use cases in the rules, we would then need to check for the operator, right? (At least in AvoidReassigningLoopVariablesRule)
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsUh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. …mentOp.java Co-Authored-By: Andreas Dangel <[email protected]>
adangel
approved these changes
oowekyala
added a commit
to oowekyala/pmd
that referenced
this pull request
Among the different possible categorisations
of unary expressions, this is probably the
most logical and easiest to document.
Here's a comparison of different possible
categorisations. Note: `_++` is the postfix
increment operator, while `++_` is the prefix
one - idem for decrement. The last one is the
one implemented by this commit.
\## 6.0.x
```
Unary = { -, + }
UnaryNotPlusMinus { !, ~ }
PreIncrement = { ++_ }
PreDecrement { --_ }
Postfix { _++, _++ }
```
* Very assymmetric, splits operators based on parsing
concerns
\## Before pmd#1890:
```
Unary = { -, + , !, ~ }
PreIncrement = { ++_ }
PreDecrement { --_ }
Postfix { _++, _++ }
```
* Minor simplification
\## pmd#1890:
```
Unary = Prefix \ { ++_, --_ })
Increment ( { ++ , -- } x (postfix, prefix) )
```
* Names are weird (IncrementExpr may be decrement, Unary != Increment
even though semantically, Increment \subset Unary)
* No possibility to introduce a supertype (what would it be?)
* But easy to match all increment/decrement expressions
\## JLS (also, Eclipse):
```
Prefix = { !, ~, -, +, ++_, --_ }
Postfix = { _++, _-- }
```
* Both can have super interface UnaryExpr
* This allows matching all increment/decrement expressions easily too
* Easiest to document, JLS like, AST like
* Fits well with `InfixExpr`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersUh oh!
There was an error while loading. Please reload this page. AssigneesLabels
in:ast
ProjectsDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. | ||||||||||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |