checkstyle / checkstyle/checkstyle
Create a utility to identify parameters/variables for checks to use
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 4.2k
- Avg merge
- 22h 23m
- Merged PRs (30d)
- 232
Description
I like to create new checks for use in my projects. One thing that almost all checks need is a way to identify if an ident is a field/variable/parameter and to examine the context of the line knowing this information. Sometimes I need to re-look at the variables type, and sometimes name clashes make the check more complicated.
Unfortunately there is no utility in checkstyle to help check makers do this and we are forced to make assumptions or to re-invent the wheel.
[One check that does do in-depth analysis of variables is RequireThisCheck](https://github.com/checkstyle/checkstyle/blob/32e2b7ba57e189074662d84a04535a87c3a19b0c/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/RequireThisCheck.java#L209-L226).
It would be great if we could take this analysis out of the Check and move it to a common utility so all can make use of it.
We could call this utility `FrameTrackingUtil` and give it the following methods. `RequireThisCheck.beginTree` can be moved into `FrameTrackingUtil.reset`.
We can give it the following methods to make use of.
`getVariablesByName` can find the variables/parameters/etc in the given scope of the current method and return it's AST.
`getMethodByName` can find the method in the given scope of the current class and return it's AST.
`getVariables` can return all the variables in the given scope.
`getMethods` can return all the methods in the given scope.
etc...
This could be a sort of `AbstractTypeAware` utility, but it won't use the deprecated `Class` lookup and be restricted to only the current file being examined.
Contributor guide
Assessment
This issue has not been assessed yet.