Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e6266aa
Test case for guardedbychecker bug.
Mar 15, 2019
3b45e8f
RELNOTES: Enable AnnotateFormatMethod by default, and add a strong wa…
graememorgan Mar 19, 2019
07f9c7f
Add fixes for incompatible/required modifiers checks
cushon Mar 20, 2019
c5f99f3
Delete DeprecatedThreadMethods in favour of general-purpose deprecati…
cushon Mar 20, 2019
55a9e0a
New error for reference equality on boxed primitives
cushon Mar 22, 2019
3269b66
Support renaming fields in renameVariable
cushon Mar 22, 2019
66cdb01
Add a defensive null-check
cushon Mar 27, 2019
13f2d76
Make IncompatibleModifiers an error
cushon Mar 28, 2019
885319a
Fix BadImport on ParameterizedType with TYPE_USE annotation
dx404 Mar 28, 2019
d055fdb
Add ModifySourceCollectionInStream check
dx404 Mar 30, 2019
eba27ed
Updated JavaTimeDefaultTimeZone to avoid NPE'ing when the function it
nick-someone Apr 2, 2019
95ebe6a
Add a check for local variables which are of boxed type but do not ne…
awturner Apr 3, 2019
8ef14ba
Provide suggestions for using Truth's Subject.check(...) in 3 cases:
cpovirk Apr 3, 2019
8aa3f18
Omit enclosing class names of constructors in diagnostics
cushon Apr 3, 2019
e66c65a
Add a refactoring to replace trivial lambdas with method references
cushon Apr 5, 2019
e1918bb
Clean up description creation
cushon Apr 5, 2019
b59a3fb
Use a prebuilt JDK 7 -> 8 API diff
cushon Apr 8, 2019
21a262c
New a check to simplify description creation
cushon Apr 8, 2019
427ccb4
Handle casts in SelfAssignment
cushon Apr 8, 2019
ac1b717
Don't complain about deprecated java.lang.Compiler API in JavaLangClash
cushon Apr 8, 2019
dd01c04
Clean up unnecessary lambdas
cushon Apr 8, 2019
45be640
Add a WARNING for using .valueOf(String) on lite proto buffer enums
sumitbhagwani Apr 9, 2019
69709fc
Return -> Returning
graememorgan Apr 9, 2019
b0218c1
Open-source @DoNotMock
Apr 9, 2019
8865ac4
Add Check for Leaking/Mutating an already-forked mutable instance (Bu…
dx404 Apr 10, 2019
c5d9072
Add EmptyBlockTag error-prone check
ash211 Apr 10, 2019
8be863d
Fix a crash in SelfAssignment
cushon Apr 10, 2019
94f0acc
Revert some unnecessary changes
cushon Apr 10, 2019
7fc1daf
Add java.time.temporal.ValueRange#checkValidValue as a method that
nick-someone Apr 11, 2019
ad16bb7
Recognize that it's safe to migrate from == to isEqualTo() for enums.
cpovirk Apr 11, 2019
bc9c078
In UnnecessaryLambda, don't refactor uses that call methods other tha…
cushon Apr 15, 2019
b717c49
Update Gradle plugin check example
tbroyer Apr 15, 2019
3f00c36
TypeParameterUnusedInFormals: Replace `.bound` by
don-vip Apr 15, 2019
6bbafbd
Fix for error-prone ImmutableEnumChecker warning
sumitbhagwani Apr 15, 2019
a902d79
Fix for error-prone AutoValueFinalMethods warning
sumitbhagwani Apr 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Recognize that it's safe to migrate from == to isEqualTo() for enums.
Add a negative test case I should have written for the first CL.

RELNOTES: none

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=243168106
  • Loading branch information
cpovirk authored and ronshapiro committed Apr 16, 2019
commit ad16bb739d2a171ae573c3c2ce15d25ea66149bd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static com.google.errorprone.matchers.Matchers.instanceMethod;
import static com.google.errorprone.matchers.Matchers.staticMethod;
import static com.google.errorprone.util.ASTHelpers.getType;
import static com.google.errorprone.util.ASTHelpers.isSubtype;
import static com.google.errorprone.util.ASTHelpers.stripParentheses;
import static com.sun.source.tree.Tree.Kind.BLOCK;
import static com.sun.source.tree.Tree.Kind.EXPRESSION_STATEMENT;
Expand Down Expand Up @@ -120,7 +121,7 @@ private static ImmutableList<ExpressionTree> findActualAndExpected(
stripParentheses(((UnaryTree) condition).getExpression()), state);

case NOT_EQUAL_TO:
return findActualAndExpectedForBinaryOp((BinaryTree) condition);
return findActualAndExpectedForBinaryOp((BinaryTree) condition, state);

default:
return null;
Expand All @@ -143,15 +144,30 @@ private static ImmutableList<ExpressionTree> findActualAndExpectedForPossibleEqu
}

private static ImmutableList<ExpressionTree> findActualAndExpectedForBinaryOp(
BinaryTree binaryTree) {
if (!getType(binaryTree.getLeftOperand()).isPrimitive()
|| !getType(binaryTree.getRightOperand()).isPrimitive()) {
BinaryTree binaryTree, VisitorState state) {
/*
* It's actually enough for *either* to be a primitive, thanks to autounboxing (and enough for
* *either* to be an enum, since equals() is symmetric). However, it turns out that handling
* those cases catches almost nothing new in practice, and I'm seeing some evidence that "null"
* is considered to be a primitive? or something? That seems wrong, but given the low payoff,
* I'm not going to investigate further.
*/
boolean bothPrimitives =
getType(binaryTree.getLeftOperand()).isPrimitive()
&& getType(binaryTree.getRightOperand()).isPrimitive();
boolean bothEnums =
isEnum(binaryTree.getLeftOperand(), state) && isEnum(binaryTree.getRightOperand(), state);
if (!bothPrimitives && !bothEnums) {
// TODO(cpovirk): Generate an isSameAs() check (if that is what users really want).
return null;
}
return ImmutableList.of(binaryTree.getLeftOperand(), binaryTree.getRightOperand());
}

private static boolean isEnum(ExpressionTree tree, VisitorState state) {
return isSubtype(getType(tree), state.getTypeFromString("java.lang.Enum"), state);
}

/**
* Checks that the statement, after unwrapping any braces, consists of a single call to a {@code
* fail} method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,23 @@ void doesNotHaveInteger(int other) {
fail("had unexpected integer");
}
}

void hasBoxedIntegerSameInstance(Integer expected) {
if (actual().boxedInteger() != expected) {
fail("didn't match expected string instance");
}
}
}

private static final class Foo {
final String string;
final int integer;
final Integer boxedInteger;

Foo(String string, int integer) {
Foo(String string, int integer, Integer boxedInteger) {
this.string = string;
this.integer = integer;
this.boxedInteger = boxedInteger;
}

String string() {
Expand All @@ -56,6 +64,10 @@ int integer() {
return integer;
}

Integer boxedInteger() {
return boxedInteger;
}

Foo otherFoo() {
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ void hasInteger(int expected) {
}
}

void hasKind(Kind expected) {
// BUG: Diagnostic contains: check("kind()").that(actual().kind()).isEqualTo(expected)
if (actual().kind() != expected) {
fail("has kind %s", expected);
}
}

void hasOtherFooInteger(int expected) {
// BUG: Diagnostic contains:
// check("otherFoo().integer()").that(actual().otherFoo().integer()).isEqualTo(expected)
Expand All @@ -66,10 +73,12 @@ void hasOtherFooInteger(int expected) {
private static final class Foo {
final String string;
final int integer;
final Kind kind;

Foo(String string, int integer) {
Foo(String string, int integer, Kind kind) {
this.string = string;
this.integer = integer;
this.kind = kind;
}

String string() {
Expand All @@ -80,8 +89,14 @@ int integer() {
return integer;
}

Kind kind() {
return kind;
}

Foo otherFoo() {
return this;
}
}

private enum Kind {}
}