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:
-
Nested Class Summary
Nested classes/interfaces inherited from class BugChecker
BugChecker.AnnotatedTypeTreeMatcher, BugChecker.AnnotationTreeMatcher, BugChecker.ArrayAccessTreeMatcher, BugChecker.ArrayTypeTreeMatcher, BugChecker.AssertTreeMatcher, BugChecker.AssignmentTreeMatcher, BugChecker.BinaryTreeMatcher, BugChecker.BindingPatternTreeMatcher, 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.ExportsTreeMatcher, 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.ModuleTreeMatcher, BugChecker.NewArrayTreeMatcher, BugChecker.NewClassTreeMatcher, BugChecker.OpensTreeMatcher, BugChecker.PackageTreeMatcher, BugChecker.ParameterizedTypeTreeMatcher, BugChecker.ParenthesizedTreeMatcher, BugChecker.PrimitiveTypeTreeMatcher, BugChecker.ProvidesTreeMatcher, BugChecker.RequiresTreeMatcher, BugChecker.ReturnTreeMatcher, BugChecker.SuppressibleTreePathScanner<R,P>, BugChecker.SwitchExpressionTreeMatcher, BugChecker.SwitchTreeMatcher, BugChecker.SynchronizedTreeMatcher, BugChecker.ThrowTreeMatcher, BugChecker.TryTreeMatcher, BugChecker.TypeCastTreeMatcher, BugChecker.TypeParameterTreeMatcher, BugChecker.UnaryTreeMatcher, BugChecker.UnionTypeTreeMatcher, BugChecker.UsesTreeMatcher, BugChecker.VariableTreeMatcher, BugChecker.WhileLoopTreeMatcher, BugChecker.WildcardTreeMatcher, BugChecker.YieldTreeMatcher -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanallowableToStringKind(com.google.errorprone.bugpatterns.AbstractToString.ToStringKind toStringKind) Whether this kind of toString call is allowable for this check.descriptionMessageForDefaultMatch(com.sun.tools.javac.code.Type type, VisitorState state) Adds the description message for match on the type without fixes.implicitToStringFix(ExpressionTree tree, VisitorState state) Constructs a fix for an implicit toString call, e.g. from string concatenation or from passing an argument toprintlnorStringBuilder.append.matchBinary(BinaryTree tree, VisitorState state) matchCompoundAssignment(CompoundAssignmentTree tree, VisitorState state) matchMethodInvocation(MethodInvocationTree tree, VisitorState state) toStringFix(Tree parent, ExpressionTree expression, VisitorState state) Constructs a fix for an explicit toString call, e.g. fromObject.toString()orString.valueOf().protected abstract TypePredicateThe type to match on.Methods inherited from class 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, suppressedRegionsMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Suppressible
allNames, canonicalName, customSuppressionAnnotations, supportsSuppressWarnings, suppressedByAnyOf
-
Constructor Details
-
AbstractToString
-
-
Method Details
-
typePredicate
The type to match on. -
implicitToStringFix
Constructs a fix for an implicit toString call, e.g. from string concatenation or from passing an argument toprintlnorStringBuilder.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(Tree parent, 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
- Specified by:
matchMethodInvocationin interfaceBugChecker.MethodInvocationTreeMatcher
-
matchBinary
- Specified by:
matchBinaryin interfaceBugChecker.BinaryTreeMatcher
-
matchCompoundAssignment
- Specified by:
matchCompoundAssignmentin interfaceBugChecker.CompoundAssignmentTreeMatcher
-