Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated equals check in equals? #1751

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,16 @@ final class $className implements $annotationName, `java.io.Serializable` {

@`java.lang.Override`
public boolean equals($equalsParameterType o) {
if (o == this) {
return true;
int objectPropertyCount = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done at compile time, so it shouldn't be done at run time.

for ($m in $members) {
if (!$m.kind.primitive) {
objectPropertyCount++;
}
}

if (objectPropertyCount > 1) {
if (o == this) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Braces don't match, so apparently this PR has never been tested.

return true;
}
if (o instanceof $annotationName) {

Expand Down
12 changes: 10 additions & 2 deletions value/src/main/java/com/google/auto/value/processor/autovalue.vm
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,16 @@ ${modifiers}class $subclass$formalTypes extends $origClass$actualTypes {

@`java.lang.Override`
public boolean equals($equalsParameterType o) {
if (o == this) {
return true;
int objectPropertyCount = 0;
for ($m in $members) {
if (!$m.kind.primitive) {
objectPropertyCount++;
}
}

if (objectPropertyCount > 1) {
if (o == this) {
return true;
}
if (o instanceof $origClass) {

Expand Down
12 changes: 10 additions & 2 deletions value/userguide/generated-builder-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ final class AutoValue_Animal extends Animal {

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
int objectPropertyCount = 0;
for ($m in $members) {
if (!$m.kind.primitive) {
objectPropertyCount++;
}
}

if (objectPropertyCount > 1) {
if (o == this) {
return true;
}
if (o instanceof Animal) {
Animal that = (Animal) o;
Expand Down
12 changes: 10 additions & 2 deletions value/userguide/generated-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ final class AutoValue_Animal extends Animal {

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
int objectPropertyCount = 0;
for ($m in $members) {
if (!$m.kind.primitive) {
objectPropertyCount++;
}
}

if (objectPropertyCount > 1) {
if (o == this) {
return true;
}
if (o instanceof Animal) {
Animal that = (Animal) o;
Expand Down