Revert "Introduce a DexMethod-backed DexMethodSignature"
This reverts commit 28f3001f6f3f270d8b1f8086431194280e7cb21c.
Reason for revert: Build failure
Change-Id: I1788034aa80d25227aaa4b31f469918a66dff385
diff --git a/src/main/java/com/android/tools/r8/graph/DexEncodedMethod.java b/src/main/java/com/android/tools/r8/graph/DexEncodedMethod.java
index a20c5e4..c2b204e 100644
--- a/src/main/java/com/android/tools/r8/graph/DexEncodedMethod.java
+++ b/src/main/java/com/android/tools/r8/graph/DexEncodedMethod.java
@@ -403,7 +403,7 @@
}
public DexMethodSignature getSignature() {
- return DexMethodSignature.create(getReference());
+ return new DexMethodSignature(getReference());
}
public DexType returnType() {
diff --git a/src/main/java/com/android/tools/r8/graph/DexItemFactory.java b/src/main/java/com/android/tools/r8/graph/DexItemFactory.java
index cf1f4b5..0100fd5 100644
--- a/src/main/java/com/android/tools/r8/graph/DexItemFactory.java
+++ b/src/main/java/com/android/tools/r8/graph/DexItemFactory.java
@@ -2254,7 +2254,7 @@
String baseName, DexType holder, DexProto proto, Predicate<DexMethodSignature> isFresh) {
return createFreshMember(
name -> {
- DexMethodSignature trySignature = DexMethodSignature.create(name, proto);
+ DexMethodSignature trySignature = new DexMethodSignature(proto, name);
if (isFresh.test(trySignature)) {
return Optional.of(trySignature);
} else {
diff --git a/src/main/java/com/android/tools/r8/graph/DexMethod.java b/src/main/java/com/android/tools/r8/graph/DexMethod.java
index 5eaf805..c5cb0ff 100644
--- a/src/main/java/com/android/tools/r8/graph/DexMethod.java
+++ b/src/main/java/com/android/tools/r8/graph/DexMethod.java
@@ -157,7 +157,7 @@
}
public DexMethodSignature getSignature() {
- return DexMethodSignature.create(this);
+ return new DexMethodSignature(this);
}
@Override
diff --git a/src/main/java/com/android/tools/r8/graph/DexMethodSignature.java b/src/main/java/com/android/tools/r8/graph/DexMethodSignature.java
index abbc9bb..74d464f 100644
--- a/src/main/java/com/android/tools/r8/graph/DexMethodSignature.java
+++ b/src/main/java/com/android/tools/r8/graph/DexMethodSignature.java
@@ -9,28 +9,36 @@
import com.android.tools.r8.utils.structural.StructuralSpecification;
import java.util.Objects;
-public abstract class DexMethodSignature implements StructuralItem<DexMethodSignature> {
+public class DexMethodSignature implements StructuralItem<DexMethodSignature> {
- DexMethodSignature() {}
+ private final DexProto proto;
+ private final DexString name;
- public static DexMethodSignature create(DexMethod method) {
- return new MethodBased(method);
+ public DexMethodSignature(DexMethod method) {
+ this(method.proto, method.name);
}
- public static DexMethodSignature create(DexString name, DexProto proto) {
- return new NameAndProtoBased(name, proto);
+ public DexMethodSignature(DexProto proto, DexString name) {
+ assert proto != null;
+ assert name != null;
+ this.proto = proto;
+ this.name = name;
}
- public abstract DexString getName();
-
- public abstract DexProto getProto();
-
public int getArity() {
- return getProto().getArity();
+ return proto.getArity();
+ }
+
+ public DexString getName() {
+ return name;
+ }
+
+ public DexProto getProto() {
+ return proto;
}
public DexType getReturnType() {
- return getProto().getReturnType();
+ return proto.returnType;
}
@Override
@@ -43,11 +51,11 @@
}
public DexMethodSignature withName(DexString name) {
- return create(name, getProto());
+ return new DexMethodSignature(proto, name);
}
public DexMethodSignature withProto(DexProto proto) {
- return create(getName(), proto);
+ return new DexMethodSignature(proto, name);
}
public DexMethod withHolder(ProgramDefinition definition, DexItemFactory dexItemFactory) {
@@ -55,7 +63,7 @@
}
public DexMethod withHolder(DexReference reference, DexItemFactory dexItemFactory) {
- return dexItemFactory.createMethod(reference.getContextType(), getProto(), getName());
+ return dexItemFactory.createMethod(reference.getContextType(), proto, name);
}
@Override
@@ -63,12 +71,12 @@
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DexMethodSignature that = (DexMethodSignature) o;
- return getProto() == that.getProto() && getName() == that.getName();
+ return proto == that.proto && name == that.name;
}
@Override
public int hashCode() {
- return Objects.hash(getProto(), getName());
+ return Objects.hash(proto, name);
}
@Override
@@ -78,7 +86,7 @@
@Override
public String toString() {
- return "Method Signature " + getName() + " " + getProto();
+ return "Method Signature " + name + " " + proto.toString();
}
private String toSourceString() {
@@ -90,53 +98,13 @@
if (includeReturnType) {
builder.append(getReturnType().toSourceString()).append(" ");
}
- builder.append(getName()).append("(");
+ builder.append(name).append("(");
for (int i = 0; i < getArity(); i++) {
if (i != 0) {
builder.append(", ");
}
- builder.append(getProto().parameters.values[i].toSourceString());
+ builder.append(proto.parameters.values[i].toSourceString());
}
return builder.append(")").toString();
}
-
- static class MethodBased extends DexMethodSignature {
-
- private final DexMethod method;
-
- MethodBased(DexMethod method) {
- this.method = method;
- }
-
- @Override
- public DexString getName() {
- return method.getName();
- }
-
- @Override
- public DexProto getProto() {
- return method.getProto();
- }
- }
-
- static class NameAndProtoBased extends DexMethodSignature {
-
- private final DexString name;
- private final DexProto proto;
-
- NameAndProtoBased(DexString name, DexProto proto) {
- this.name = name;
- this.proto = proto;
- }
-
- @Override
- public DexString getName() {
- return name;
- }
-
- @Override
- public DexProto getProto() {
- return proto;
- }
- }
}
diff --git a/src/main/java/com/android/tools/r8/graph/MethodMapBacking.java b/src/main/java/com/android/tools/r8/graph/MethodMapBacking.java
index 748abb4..8f705d4 100644
--- a/src/main/java/com/android/tools/r8/graph/MethodMapBacking.java
+++ b/src/main/java/com/android/tools/r8/graph/MethodMapBacking.java
@@ -115,7 +115,7 @@
@Override
DexEncodedMethod getMethod(DexProto methodProto, DexString methodName) {
- return methodMap.get(DexMethodSignature.create(methodName, methodProto));
+ return methodMap.get(new DexMethodSignature(methodProto, methodName));
}
private DexEncodedMethod getMethod(Predicate<DexEncodedMethod> predicate) {