| Summary: | [ast rewrite] must ensure that replacing PrefixExpression's operand doesn't collapse "- -x" to "--x" | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Jay Arthanareeswaran <jarthana> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | daniel_megert, markus.kell.r, timo.kinnunen |
| Version: | 4.2 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | stalebug | ||
| Bug Depends on: | |||
| Bug Blocks: | 405096 | ||
|
Description
Jay Arthanareeswaran
This is quite hard to fix. It's not only about removing parentheses, but it can happen in any rewrite operation where a PrefixExpression's operand is replaced, e.g. here:
int[] array = new int[-foo()];
private int foo() { // inline foo()
return -128;
}
ASTRewriteAnalyzer#ensureSpaceBeforeReplace(ASTNode) implements something similar for problems where a keyword must be followed by whitespace. But the implementation just always inserts a space, even if it's not strictly necessary. E.g. in the quick fix that removes the unnecessary cast here:
private String bar() {
return(String)("");
}
If we do the same for PrefixExpression, then there are many more cases where we unnecessarily insert a space (e.g. when you have simply 128 above).
So the space can only be inserted *after* the operand has been rewritten and the first character of the replacement text can be inspected.
Note that JDT UI worked around this problem by keeping more parentheses than necessary (bug 405096). Related problems exist in combination with InfixExpressions, e.g.: int i = 1-(-128); This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |