Class SelfAssignment
- java.lang.Object
-
- com.google.errorprone.bugpatterns.BugChecker
-
- com.google.errorprone.bugpatterns.SelfAssignment
-
- All Implemented Interfaces:
BugChecker.AssignmentTreeMatcher
,BugChecker.VariableTreeMatcher
,Suppressible
,Serializable
public class SelfAssignment extends BugChecker implements BugChecker.AssignmentTreeMatcher, BugChecker.VariableTreeMatcher
TODO(eaftan): Consider cases where the parent is not a statement or there is no parent?- Author:
- [email protected] (Eddie Aftandilian), [email protected] (Scott Johnson)
- 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 extends Object,B extends Object>, 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 SelfAssignment()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Description
describeForAssignment(com.sun.source.tree.AssignmentTree assignmentTree, VisitorState state)
We expect that the lhs is a field and the rhs is an identifier, specifically a parameter to the method.Description
describeForVarDecl(com.sun.source.tree.VariableTree tree, VisitorState state)
Description
matchAssignment(com.sun.source.tree.AssignmentTree tree, VisitorState state)
Description
matchVariable(com.sun.source.tree.VariableTree tree, VisitorState state)
-
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
-
-
-
-
Method Detail
-
matchAssignment
public Description matchAssignment(com.sun.source.tree.AssignmentTree tree, VisitorState state)
- Specified by:
matchAssignment
in interfaceBugChecker.AssignmentTreeMatcher
-
matchVariable
public Description matchVariable(com.sun.source.tree.VariableTree tree, VisitorState state)
- Specified by:
matchVariable
in interfaceBugChecker.VariableTreeMatcher
-
describeForVarDecl
public Description describeForVarDecl(com.sun.source.tree.VariableTree tree, VisitorState state)
-
describeForAssignment
public Description describeForAssignment(com.sun.source.tree.AssignmentTree assignmentTree, VisitorState state)
We expect that the lhs is a field and the rhs is an identifier, specifically a parameter to the method. We base our suggested fixes on this expectation.Case 1: If lhs is a field and rhs is an identifier, find a method parameter of the same type and similar name and suggest it as the rhs. (Guess that they have misspelled the identifier.)
Case 2: If lhs is a field and rhs is not an identifier, find a method parameter of the same type and similar name and suggest it as the rhs.
Case 3: If lhs is not a field and rhs is an identifier, find a class field of the same type and similar name and suggest it as the lhs.
Case 4: Otherwise suggest deleting the assignment.
-
-