This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 258201 - Add TreeUtilities.pathFor with bias
Summary: Add TreeUtilities.pathFor with bias
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 8.2
Hardware: PC Linux
: P3 normal (vote)
Assignee: Dusan Balek
Depends on:
Reported: 2016-03-01 14:26 UTC by Svata Dedic
Modified: 2016-03-01 14:27 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description Svata Dedic 2016-03-01 14:26:54 UTC
The current pathFor() requires that the position is *within* the tree; it will return the enclosing tree if the position is right at the start of a tree. The behaviour was developed for code completion and serves its purpose.

But on other places in the code, pathFor is "misused" passing offset + 1; this may lead however to another invalid result, if the (original) position is e.g. at the closing curly brace (}) of a method or a block -- in the implementation, the PathFinder locates the correct tree, but the compensation at the end of pathFor will go up and return the enclosing class for position "closing curly brace + 1". Some errors are reported at the curly brace, e.g. missing return statement, possibly others.

It would be much cleaner to provide an alternative method to locate tree "at" the position for non-completion users. 
There are many usages, where the current behaviour is OK, since they are implemented so they take start of token (of nonzero length), so adding +1 is no prob in such place - but usage even those could be more readable if the new alternative method is available.