public class VisitorState extends Object
Modifier and Type | Field and Description |
---|---|
com.sun.tools.javac.util.Context |
context |
Constructor and Description |
---|
VisitorState(com.sun.tools.javac.util.Context context) |
VisitorState(com.sun.tools.javac.util.Context context,
DescriptionListener listener) |
VisitorState(com.sun.tools.javac.util.Context context,
DescriptionListener listener,
Map<String,BugPattern.SeverityLevel> severityMap,
ErrorProneOptions errorProneOptions) |
Modifier and Type | Method and Description |
---|---|
com.sun.tools.javac.code.Type |
arrayTypeForType(com.sun.tools.javac.code.Type baseType)
Build an Array Type from another Type
|
ErrorProneOptions |
errorProneOptions() |
<T extends com.sun.source.tree.Tree> |
findEnclosing(Class<? extends T>... classes)
Find the first enclosing tree node of one of the given types.
|
com.sun.source.util.TreePath |
findPathToEnclosing(Class<? extends com.sun.source.tree.Tree>... classes)
Returns the
TreePath to the nearest tree node of one of the given types. |
int |
getEndPosition(com.sun.source.tree.Tree node)
Returns the end position of the node, or -1 if it is not available.
|
com.sun.tools.javac.util.Name |
getName(String nameStr) |
NullnessAnalysis |
getNullnessAnalysis() |
com.sun.source.util.TreePath |
getPath() |
CharSequence |
getSourceCode()
Gets the current source file.
|
String |
getSourceForNode(com.sun.source.tree.Tree tree)
Gets the original source code that represents the given node.
|
com.sun.tools.javac.code.Symbol |
getSymbolFromString(String symStr) |
com.sun.tools.javac.code.Symtab |
getSymtab() |
List<ErrorProneToken> |
getTokensForNode(com.sun.source.tree.Tree tree)
Returns the list of
Tokens.Token s for the given JCTree . |
com.sun.tools.javac.tree.TreeMaker |
getTreeMaker() |
com.sun.tools.javac.code.Type |
getType(com.sun.tools.javac.code.Type baseType,
boolean isArray,
List<com.sun.tools.javac.code.Type> typeParams)
Build an instance of a Type.
|
com.sun.tools.javac.code.Type |
getTypeFromString(String typeStr)
Given the binary name of a class, returns the
Type . |
com.sun.tools.javac.code.Types |
getTypes() |
com.sun.tools.javac.code.Symbol.ModuleSymbol |
inferModule(com.sun.tools.javac.util.Name flatName)
Infers a module symbol for the given flat class name.
|
boolean |
isAndroidCompatible()
Returns true if the compilation is targeting Android.
|
void |
reportMatch(Description description) |
VisitorState |
withPath(com.sun.source.util.TreePath path) |
public VisitorState(com.sun.tools.javac.util.Context context)
public VisitorState(com.sun.tools.javac.util.Context context, DescriptionListener listener)
public VisitorState(com.sun.tools.javac.util.Context context, DescriptionListener listener, Map<String,BugPattern.SeverityLevel> severityMap, ErrorProneOptions errorProneOptions)
public VisitorState withPath(com.sun.source.util.TreePath path)
public com.sun.source.util.TreePath getPath()
public com.sun.tools.javac.tree.TreeMaker getTreeMaker()
public com.sun.tools.javac.code.Types getTypes()
public com.sun.tools.javac.code.Symtab getSymtab()
public NullnessAnalysis getNullnessAnalysis()
public ErrorProneOptions errorProneOptions()
public void reportMatch(Description description)
public com.sun.tools.javac.util.Name getName(String nameStr)
public com.sun.tools.javac.code.Type getTypeFromString(String typeStr)
Type
.
If this method returns null, the compiler doesn't have access to this type, which means that if you are comparing other types to this for equality or the subtype relation, your result would always be false even if it could create the type. Thus it might be best to bail out early in your matcher if this method returns null on your type of interest.
typeStr
- the JLS 13.1 binary name of the class, e.g. "java.util.Map$Entry"
Type
, or null if it cannot be foundpublic com.sun.tools.javac.code.Symbol.ModuleSymbol inferModule(com.sun.tools.javac.util.Name flatName)
public com.sun.tools.javac.code.Symbol getSymbolFromString(String symStr)
symStr
- the string representation of a symbolpublic com.sun.tools.javac.code.Type getType(com.sun.tools.javac.code.Type baseType, boolean isArray, List<com.sun.tools.javac.code.Type> typeParams)
public com.sun.tools.javac.code.Type arrayTypeForType(com.sun.tools.javac.code.Type baseType)
@SafeVarargs public final com.sun.source.util.TreePath findPathToEnclosing(Class<? extends com.sun.source.tree.Tree>... classes)
TreePath
to the nearest tree node of one of the given types. To instead
retrieve the element directly, use findEnclosing(Class...)
.null
if there is no match@SafeVarargs public final <T extends com.sun.source.tree.Tree> T findEnclosing(Class<? extends T>... classes)
null
if there is no matchpublic CharSequence getSourceCode()
public String getSourceForNode(com.sun.source.tree.Tree tree)
Note that this may be different from what is returned by calling .toString() on the node. This returns exactly what is in the source code, whereas .toString() pretty-prints the node from its AST representation.
public List<ErrorProneToken> getTokensForNode(com.sun.source.tree.Tree tree)
Tokens.Token
s for the given JCTree
.
This is moderately expensive (the source of the node has to be re-lexed), so it should only be used if a fix is already going to be emitted.
public int getEndPosition(com.sun.source.tree.Tree node)
public boolean isAndroidCompatible()
Copyright © 2018. All rights reserved.