| Summary: | Erroneous local variable's problems reported at surrounding ParenthesizedExpression | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Chris West (Faux) <eclipse> | ||||||
| Component: | Core | Assignee: | Olivier Thomann <Olivier_Thomann> | ||||||
| Status: | VERIFIED FIXED | QA Contact: | |||||||
| Severity: | normal | ||||||||
| Priority: | P3 | CC: | markus.kell.r, Olivier_Thomann, satyam.kandula, srikanth_sankaran | ||||||
| Version: | 3.5.2 | Flags: | srikanth_sankaran:
review+
|
||||||
| Target Milestone: | 3.6.1 | ||||||||
| Hardware: | All | ||||||||
| OS: | All | ||||||||
| Whiteboard: | |||||||||
| Attachments: |
|
||||||||
Same in 3.6. Only seems to happen for ParenthesizedExpression. When I e.g. add a "-" in front of the "a", the error range becomes correct. Created attachment 169854 [details]
Proposed fix + regression test
Too late for 3.6. Targeting 3.6.1 as the fix is trivial. Created attachment 170032 [details]
Proposed fix + regression test
Updated the patch to match fix for 306464 that belongs to the same file (ProblemReporter).
Srikanth, please review. Patch looks good. Released in HEAD and 3.6.1 (In reply to comment #7) > Released in HEAD and 3.6.1 The code changes didn't go to HEAD -- the test was failing. I have released the code changes to HEAD. Verified for 3.6.1 RC2 using Build id: M20100825-0800 |
Build Identifier: M20100211-1343 If you have a parenthesized expression (ParenthesizedExpression) containing just a variable/field reference (SimpleName), and that local variable is in error (undeclared, possibly uninitialised, etc.), the problem is reported for the entire expression, instead of the expected name. From a UI perspective, this shows as, in: class Scratch { void foo(int q) { foo( ( //^ here a ) //^ to here ); }} ... the entire section between the indicated brackets being underlined in red, including the comment. From an API consumer point of view, the IProblem#getStartPosition() does not refer to the same point as the SimpleName#getStartPosition() for that variable error. Workaround for consumers: private int getRealErrorReportPosition(final SimpleName sn) { ASTNode test = sn; while (test.getParent() instanceof ParenthesizedExpression) test = test.getParent(); return test.getStartPosition(); } Reproducible: Always Steps to Reproduce: 1. Paste the above class into a Java editor. 2. Note that "a" is in error, but the red-underlining for the error situation extends from the (unnecessary) open bracket to the close bracket.