File: TreeToString.md

package info (click to toggle)
error-prone-java 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 23,204 kB
  • sloc: java: 222,992; xml: 1,319; sh: 25; makefile: 7
file content (14 lines) | stat: -rw-r--r-- 748 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
`Tree#toString` shouldn't be used for Trees deriving from the code being
compiled, as it discards whitespace and comments.

This check only runs inside Error Prone code. Suggested replacements include:

*   Prefer `VisitorState#getConstantExpression` for escaping constants in
    generated code.
*   `VisitorState#getSourceForNode` : it will give you the original source text.
    Note that for synthetic trees (e.g.: implicit constructors), that source may
    be `null`.
*   If the string representation was being used for comparison with keywords
    like `this` and `super`, try `tree.getName().contentEquals("this")`
*   One can also get the symbol name and use it for comparison :
    `ASTHelpers.getSymbol(tree).getSimpleName().toString()`