diff options
author | cushon <cushon@google.com> | 2018-10-25 16:41:49 -0700 |
---|---|---|
committer | Liam Miller-Cushon <cushon@google.com> | 2018-10-25 17:56:55 -0700 |
commit | 424f4517a7aa99f64a3981158fa0b753c1788b66 (patch) | |
tree | 8fbed3e8aaa9e107d7165c4c5a565e84fbac2b76 | |
parent | 483f08e08c55d908ed6d581ce1de70ccb9bfb524 (diff) | |
download | turbine-424f4517a7aa99f64a3981158fa0b753c1788b66.tar.gz |
Implement ClassValue equals and hashCode
(now that Type also implements equals and hashCode)
MOE_MIGRATED_REVID=218773629
-rw-r--r-- | java/com/google/turbine/binder/bound/ClassValue.java | 7 | ||||
-rw-r--r-- | javatests/com/google/turbine/model/ConstTest.java | 12 |
2 files changed, 15 insertions, 4 deletions
diff --git a/java/com/google/turbine/binder/bound/ClassValue.java b/java/com/google/turbine/binder/bound/ClassValue.java index 50f0c59..a75db42 100644 --- a/java/com/google/turbine/binder/bound/ClassValue.java +++ b/java/com/google/turbine/binder/bound/ClassValue.java @@ -18,6 +18,7 @@ package com.google.turbine.binder.bound; import com.google.turbine.model.Const; import com.google.turbine.type.Type; +import java.util.Objects; /** A class literal constant. */ public class ClassValue extends Const { @@ -45,13 +46,11 @@ public class ClassValue extends Const { @Override public int hashCode() { - // TODO(cushon): implement a hasher for Types. - return System.identityHashCode(this); + return Objects.hash(type); } @Override public boolean equals(Object obj) { - // TODO(cushon): implement equality for Types. - return this == obj; + return obj instanceof ClassValue && type().equals(((ClassValue) obj).type()); } } diff --git a/javatests/com/google/turbine/model/ConstTest.java b/javatests/com/google/turbine/model/ConstTest.java index 9b34343..7940124 100644 --- a/javatests/com/google/turbine/model/ConstTest.java +++ b/javatests/com/google/turbine/model/ConstTest.java @@ -20,7 +20,10 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.testing.EqualsTester; import com.google.turbine.binder.bound.AnnotationValue; +import com.google.turbine.binder.bound.ClassValue; import com.google.turbine.binder.sym.ClassSymbol; +import com.google.turbine.type.Type.ClassTy; +import com.google.turbine.type.Type.PrimTy; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -68,6 +71,15 @@ public class ConstTest { new ClassSymbol("test/Anno"), ImmutableMap.of("value", new Const.IntValue(4))), new AnnotationValue( new ClassSymbol("test/Anno"), ImmutableMap.of("value", new Const.IntValue(4)))) + .addEqualityGroup( + new ClassValue(ClassTy.asNonParametricClassTy(new ClassSymbol("test/Clazz"))), + new ClassValue(ClassTy.asNonParametricClassTy(new ClassSymbol("test/Clazz")))) + .addEqualityGroup( + new ClassValue(ClassTy.asNonParametricClassTy(new ClassSymbol("test/Other"))), + new ClassValue(ClassTy.asNonParametricClassTy(new ClassSymbol("test/Other")))) + .addEqualityGroup( + new ClassValue(PrimTy.create(TurbineConstantTypeKind.INT, ImmutableList.of())), + new ClassValue(PrimTy.create(TurbineConstantTypeKind.INT, ImmutableList.of()))) .testEquals(); } } |