Skip to content

Commit 0f5753f

Browse files
graememorganError Prone Team
authored and
Error Prone Team
committed
Reverse Yoda conditions in EP.
PiperOrigin-RevId: 500146362
1 parent f36a502 commit 0f5753f

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

check_api/src/main/java/com/google/errorprone/matchers/Matchers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public static Matcher<? super MethodInvocationTree> receiverSameAsArgument(int a
298298
return ASTHelpers.sameVariable(fieldAccess.getExpression(), arg);
299299
} else if (methodSelect instanceof JCIdent) {
300300
// A bare method call: "equals(foo)". Receiver is implicitly "this".
301-
return "this".equals(arg.toString());
301+
return arg.toString().equals("this");
302302
}
303303

304304
return false;
@@ -990,7 +990,7 @@ public static Matcher<VariableTree> variableInitializer(
990990
* constant, parameter to a method, etc.
991991
*/
992992
public static Matcher<VariableTree> isField() {
993-
return (variableTree, state) -> ElementKind.FIELD == getSymbol(variableTree).getKind();
993+
return (variableTree, state) -> getSymbol(variableTree).getKind() == ElementKind.FIELD;
994994
}
995995

996996
/** Matches if a {@link ClassTree} is an enum declaration. */

core/src/main/java/com/google/errorprone/bugpatterns/LambdaFunctionalInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private boolean methodCallsMeetConditions(Symbol sym, VisitorState state) {
217217

218218
for (MethodInvocationTree methodInvocationTree : methodCallMap.values()) {
219219
if (methodInvocationTree.getArguments().stream()
220-
.filter(a -> Kind.LAMBDA_EXPRESSION.equals(a.getKind()))
220+
.filter(a -> a.getKind().equals(Kind.LAMBDA_EXPRESSION))
221221
.filter(a -> hasFunctionAsArg(a, state))
222222
.noneMatch(
223223
a ->

core/src/main/java/com/google/errorprone/bugpatterns/MutablePublicArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private static boolean nonEmptyArrayMatcher(VariableTree arrayExpression, Visito
7373
JCNewArray newArray = (JCNewArray) initializer;
7474
if (!newArray.getDimensions().isEmpty()) {
7575
return !newArray.getDimensions().stream()
76-
.allMatch(e -> Objects.equals(0, ASTHelpers.constValue(e, Integer.class)));
76+
.allMatch(e -> Objects.equals(ASTHelpers.constValue(e, Integer.class), 0));
7777
}
7878
// For in line array initializer.
7979
return newArray.getInitializers() != null && !newArray.getInitializers().isEmpty();

core/src/main/java/com/google/errorprone/bugpatterns/OutlineNone.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.sun.source.tree.ExpressionTree;
3434
import com.sun.source.tree.MethodInvocationTree;
3535
import java.util.List;
36+
import java.util.Objects;
3637
import java.util.regex.Pattern;
3738

3839
/** Check for the a11y antipattern of setting CSS outline attributes to none or 0. */
@@ -92,7 +93,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
9293
*/
9394
if (GWT_SET_PROPERTY.matches(tree, state)
9495
&& args.size() >= 2
95-
&& "outline".equals(constValue(args.get(0), String.class))
96+
&& Objects.equals(constValue(args.get(0), String.class), "outline")
9697
&& constantNoneOrZero(args.get(1))) {
9798
return describeMatch(tree);
9899
}

core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ private static AnalysisResult analyzeSwitchTree(SwitchTree switchTree) {
152152
} else {
153153
allCasesHaveDefiniteControlFlow &=
154154
!fallsIntoDefaultCase
155-
&& CaseFallThru.DEFINITELY_DOES_NOT_FALL_THRU.equals(caseFallThru);
155+
&& caseFallThru.equals(CaseFallThru.DEFINITELY_DOES_NOT_FALL_THRU);
156156
}
157157
} else {
158158
// Cases other than default
159-
allCasesHaveDefiniteControlFlow &= !CaseFallThru.MAYBE_FALLS_THRU.equals(caseFallThru);
159+
allCasesHaveDefiniteControlFlow &= !caseFallThru.equals(CaseFallThru.MAYBE_FALLS_THRU);
160160
}
161161
}
162162

@@ -248,7 +248,7 @@ private Description convertDirectlyToExpressionSwitch(
248248
// If block is just space or a single "break;" with no explanatory comments, then remove
249249
// it to eliminate redundancy and improve readability
250250
if (trimmedTransformedBlockSource.isEmpty()
251-
|| "break;".equals(trimmedTransformedBlockSource)) {
251+
|| trimmedTransformedBlockSource.equals("break;")) {
252252
replacementCodeBuilder.append("{}");
253253
} else {
254254
replacementCodeBuilder.append("{").append(transformedBlockSource).append("\n}");
@@ -319,7 +319,7 @@ private static Optional<String> extractCommentsBeforeRemovedBreak(
319319
private static ImmutableList<StatementTree> filterOutRedundantBreak(CaseTree caseTree) {
320320
boolean caseEndsWithUnlabelledBreak =
321321
Streams.findLast(caseTree.getStatements().stream())
322-
.filter(statement -> BREAK.equals(statement.getKind()))
322+
.filter(statement -> statement.getKind().equals(BREAK))
323323
.filter(breakTree -> ((BreakTree) breakTree).getLabel() == null)
324324
.isPresent();
325325
return caseEndsWithUnlabelledBreak

core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
130130
ExpressionTree methodSelectTree = tree.getMethodSelect();
131131
if (methodSelectTree != null) {
132132
String methodSelect = state.getSourceForNode(methodSelectTree);
133-
if ("super".equals(methodSelect)) {
133+
if (methodSelect.equals("super")) {
134134
receiverString = methodSelect;
135135
}
136136
// TODO(kak): Can we omit the `this` case? The getReceiver() call above handles `this`
137-
if ("this".equals(methodSelect)) {
137+
if (methodSelect.equals("this")) {
138138
receiverString = methodSelect;
139139
}
140140
}

0 commit comments

Comments
 (0)