Class AbstractToString
java.lang.Object
com.google.errorprone.bugpatterns.BugChecker
com.google.errorprone.bugpatterns.AbstractToString
- All Implemented Interfaces:
BugChecker.BinaryTreeMatcher
,BugChecker.CompoundAssignmentTreeMatcher
,BugChecker.MethodInvocationTreeMatcher
,Suppressible
,Serializable
- Direct Known Subclasses:
AnnotationMirrorToString
,AnnotationValueToString
,ArrayToString
,LiteProtoToString
,ObjectToString
,StreamToString
,SymbolToString
,TreeToString
,TypeToString
public abstract class AbstractToString extends BugChecker implements BugChecker.BinaryTreeMatcher, BugChecker.MethodInvocationTreeMatcher, BugChecker.CompoundAssignmentTreeMatcher
An abstract matcher for implicit and explicit calls to
Object.toString()
, for use on
types that do not have a human-readable toString()
implementation.
See examples in StreamToString
and ArrayToString
.
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.errorprone.bugpatterns.BugChecker
BugChecker.AnnotatedTypeTreeMatcher, BugChecker.AnnotationTreeMatcher, BugChecker.ArrayAccessTreeMatcher, BugChecker.ArrayTypeTreeMatcher, BugChecker.AssertTreeMatcher, BugChecker.AssignmentTreeMatcher, BugChecker.BinaryTreeMatcher, BugChecker.BlockTreeMatcher, BugChecker.BreakTreeMatcher, BugChecker.CaseTreeMatcher, BugChecker.CatchTreeMatcher, BugChecker.ClassTreeMatcher, BugChecker.CompilationUnitTreeMatcher, BugChecker.CompoundAssignmentTreeMatcher, BugChecker.ConditionalExpressionTreeMatcher, BugChecker.ContinueTreeMatcher, BugChecker.DoWhileLoopTreeMatcher, BugChecker.EmptyStatementTreeMatcher, BugChecker.EnhancedForLoopTreeMatcher, BugChecker.ExpressionStatementTreeMatcher, BugChecker.ForLoopTreeMatcher, BugChecker.IdentifierTreeMatcher, BugChecker.IfTreeMatcher, BugChecker.ImportTreeMatcher, BugChecker.InstanceOfTreeMatcher, BugChecker.IntersectionTypeTreeMatcher, BugChecker.LabeledStatementTreeMatcher, BugChecker.LambdaExpressionTreeMatcher, BugChecker.LiteralTreeMatcher, BugChecker.MemberReferenceTreeMatcher, BugChecker.MemberSelectTreeMatcher, BugChecker.MethodInvocationTreeMatcher, BugChecker.MethodTreeMatcher, BugChecker.ModifiersTreeMatcher, BugChecker.NewArrayTreeMatcher, BugChecker.NewClassTreeMatcher, BugChecker.ParameterizedTypeTreeMatcher, BugChecker.ParenthesizedTreeMatcher, BugChecker.PrimitiveTypeTreeMatcher, BugChecker.ReturnTreeMatcher, BugChecker.SuppressibleTreePathScanner<A,B>, BugChecker.SwitchTreeMatcher, BugChecker.SynchronizedTreeMatcher, BugChecker.ThrowTreeMatcher, BugChecker.TryTreeMatcher, BugChecker.TypeCastTreeMatcher, BugChecker.TypeParameterTreeMatcher, BugChecker.UnaryTreeMatcher, BugChecker.UnionTypeTreeMatcher, BugChecker.VariableTreeMatcher, BugChecker.WhileLoopTreeMatcher, BugChecker.WildcardTreeMatcher
-
Constructor Summary
Constructors Constructor Description AbstractToString()
-
Method Summary
Modifier and Type Method Description protected boolean
allowableToStringKind(com.google.errorprone.bugpatterns.AbstractToString.ToStringKind toStringKind)
Whether this kind of toString call is allowable for this check.protected Optional<String>
descriptionMessageForDefaultMatch(com.sun.tools.javac.code.Type type, VisitorState state)
Adds the description message for match on the type without fixes.protected abstract Optional<Fix>
implicitToStringFix(com.sun.source.tree.ExpressionTree tree, VisitorState state)
Constructs a fix for an implicit toString call, e.g.Description
matchBinary(com.sun.source.tree.BinaryTree tree, VisitorState state)
Description
matchCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree tree, VisitorState state)
Description
matchMethodInvocation(com.sun.source.tree.MethodInvocationTree tree, VisitorState state)
protected abstract Optional<Fix>
toStringFix(com.sun.source.tree.Tree parent, com.sun.source.tree.ExpressionTree expression, VisitorState state)
Constructs a fix for an explicit toString call, e.g.protected abstract TypePredicate
typePredicate()
The type to match on.Methods inherited from class com.google.errorprone.bugpatterns.BugChecker
allNames, buildDescription, buildDescription, buildDescription, canonicalName, customSuppressionAnnotations, defaultSeverity, describeMatch, describeMatch, describeMatch, describeMatch, describeMatch, describeMatch, disableable, equals, hashCode, isSuppressed, isSuppressed, isSuppressed, isSuppressed, linkUrl, message, supportsSuppressWarnings, suppressedByAnyOf, suppressedRegions
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.google.errorprone.matchers.Suppressible
allNames, canonicalName, customSuppressionAnnotations, supportsSuppressWarnings, suppressedByAnyOf
-
Constructor Details
-
AbstractToString
public AbstractToString()
-
-
Method Details
-
typePredicate
The type to match on. -
implicitToStringFix
protected abstract Optional<Fix> implicitToStringFix(com.sun.source.tree.ExpressionTree tree, VisitorState state)Constructs a fix for an implicit toString call, e.g. from string concatenation or from passing an argument toprintln
orStringBuilder.append
.- Parameters:
tree
- the tree node for the expression being converted to a String
-
descriptionMessageForDefaultMatch
protected Optional<String> descriptionMessageForDefaultMatch(com.sun.tools.javac.code.Type type, VisitorState state)Adds the description message for match on the type without fixes. -
allowableToStringKind
protected boolean allowableToStringKind(com.google.errorprone.bugpatterns.AbstractToString.ToStringKind toStringKind)Whether this kind of toString call is allowable for this check. -
toStringFix
protected abstract Optional<Fix> toStringFix(com.sun.source.tree.Tree parent, com.sun.source.tree.ExpressionTree expression, VisitorState state)Constructs a fix for an explicit toString call, e.g. fromObject.toString()
orString.valueOf()
.- Parameters:
parent
- the expression's parent (e.g.String.valueOf(expression)
)
-
matchMethodInvocation
public Description matchMethodInvocation(com.sun.source.tree.MethodInvocationTree tree, VisitorState state)- Specified by:
matchMethodInvocation
in interfaceBugChecker.MethodInvocationTreeMatcher
-
matchBinary
- Specified by:
matchBinary
in interfaceBugChecker.BinaryTreeMatcher
-
matchCompoundAssignment
public Description matchCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree tree, VisitorState state)- Specified by:
matchCompoundAssignment
in interfaceBugChecker.CompoundAssignmentTreeMatcher
-