diff --git a/src/main/java/cn/maxpixel/mcdecompiler/asm/ClassifiedMappingRemapper.java b/src/main/java/cn/maxpixel/mcdecompiler/asm/ClassifiedMappingRemapper.java index 5d7aa3f..7ec3f08 100644 --- a/src/main/java/cn/maxpixel/mcdecompiler/asm/ClassifiedMappingRemapper.java +++ b/src/main/java/cn/maxpixel/mcdecompiler/asm/ClassifiedMappingRemapper.java @@ -254,12 +254,14 @@ private Optional processSuperField(String owner, String name) { } private PairedMapping reduceField(PairedMapping left, PairedMapping right) { + if (left == right) return left; int leftAcc = extraClassesInformation.getAccessFlags(left.getOwned().owner.mapping.unmappedName, left.unmappedName) & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE); int rightAcc = extraClassesInformation.getAccessFlags(right.getOwned().owner.mapping.unmappedName, right.unmappedName) & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE); if((leftAcc & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0) { - if((rightAcc & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0) throw new IllegalArgumentException("This can't happen!"); + if((rightAcc & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0) + throw new IllegalArgumentException("This can't happen!"); return left; } else if((rightAcc & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0) return right; else if(Modifier.isPrivate(leftAcc) || Modifier.isPrivate(rightAcc)) diff --git a/src/main/java/cn/maxpixel/mcdecompiler/mapping/collection/ClassMapping.java b/src/main/java/cn/maxpixel/mcdecompiler/mapping/collection/ClassMapping.java index 6e90ce8..c43ccba 100644 --- a/src/main/java/cn/maxpixel/mcdecompiler/mapping/collection/ClassMapping.java +++ b/src/main/java/cn/maxpixel/mcdecompiler/mapping/collection/ClassMapping.java @@ -256,8 +256,7 @@ public static void setMappedNamespace(ClassMapping that = (ClassMapping) o; + if (!(o instanceof ClassMapping that)) return false; return mapping.equals(that.mapping) && methods.equals(that.methods) && fields.equals(that.fields); } diff --git a/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/Descriptor.java b/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/Descriptor.java index 103a501..eddbcfe 100644 --- a/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/Descriptor.java +++ b/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/Descriptor.java @@ -22,6 +22,8 @@ import org.intellij.lang.annotations.Subst; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + /** * Descriptor component for paired mappings */ @@ -30,7 +32,7 @@ public class Descriptor implements Component { public @NotNull String unmappedDescriptor; public Descriptor(@NotNull String unmappedDescriptor) { - this.unmappedDescriptor = unmappedDescriptor; + this.unmappedDescriptor = Objects.requireNonNull(unmappedDescriptor); } public void reverseUnmapped(ClassifiedMappingRemapper remapper) { @@ -42,7 +44,7 @@ public void reverseUnmapped(ClassifiedMappingRemapper remapper) { } public void setUnmappedDescriptor(@NotNull String unmappedDescriptor) { - this.unmappedDescriptor = unmappedDescriptor; + this.unmappedDescriptor = Objects.requireNonNull(unmappedDescriptor); } @Override @@ -65,7 +67,7 @@ public static class Mapped implements Component { public @NotNull String mappedDescriptor; public Mapped(@NotNull String mappedDescriptor) { - this.mappedDescriptor = mappedDescriptor; + this.mappedDescriptor = Objects.requireNonNull(mappedDescriptor); } public void reverseMapped(ClassifiedMappingRemapper remapper) { @@ -77,7 +79,7 @@ public void reverseMapped(ClassifiedMappingRemapper remapper) { } public void setMappedDescriptor(@NotNull String mappedDescriptor) { - this.mappedDescriptor = mappedDescriptor; + this.mappedDescriptor = Objects.requireNonNull(mappedDescriptor); } @Override @@ -102,7 +104,7 @@ public static class Namespaced extends Descriptor { public Namespaced(@NotNull String unmappedDescriptor, @NotNull String descriptorNamespace) { super(unmappedDescriptor); - this.descriptorNamespace = descriptorNamespace; + this.descriptorNamespace = Objects.requireNonNull(descriptorNamespace); } public @NotNull String getDescriptorNamespace() { @@ -110,7 +112,7 @@ public Namespaced(@NotNull String unmappedDescriptor, @NotNull String descriptor } public void setDescriptorNamespace(@NotNull String descriptorNamespace) { - this.descriptorNamespace = descriptorNamespace; + this.descriptorNamespace = Objects.requireNonNull(descriptorNamespace); } @Override diff --git a/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/Documented.java b/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/Documented.java index 8b3a6d6..c17a49a 100644 --- a/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/Documented.java +++ b/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/Documented.java @@ -30,4 +30,16 @@ public String getDoc() { public void setDoc(String doc) { this.doc = Objects.requireNonNull(doc, "null documentation isn't meaningful huh?"); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Documented that)) return false; + return Objects.equals(doc, that.doc); + } + + @Override + public int hashCode() { + return Objects.hashCode(doc); + } } \ No newline at end of file diff --git a/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/LineNumber.java b/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/LineNumber.java index 75dd5bf..275bf32 100644 --- a/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/LineNumber.java +++ b/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/LineNumber.java @@ -45,4 +45,16 @@ public int getEndLineNumber() { public void setEndLineNumber(int endLineNumber) { this.endLineNumber = endLineNumber; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof LineNumber that)) return false; + return startLineNumber == that.startLineNumber && endLineNumber == that.endLineNumber; + } + + @Override + public int hashCode() { + return 31 * startLineNumber + endLineNumber; + } } \ No newline at end of file diff --git a/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/LocalVariableTable.java b/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/LocalVariableTable.java index 725d8fc..4dc5ce8 100644 --- a/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/LocalVariableTable.java +++ b/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/LocalVariableTable.java @@ -52,6 +52,18 @@ public void reverseAll(ClassifiedMappingRemapper remapper) { values.forEach(v -> v.reverse(remapper)); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof LocalVariableTable that)) return false; + return Objects.equals(lvt, that.lvt); + } + + @Override + public int hashCode() { + return Objects.hashCode(lvt); + } + public static class Namespaced implements Component, NameGetter.Namespaced { private String unmappedNamespace; private String mappedNamespace; @@ -96,5 +108,17 @@ public void setMappedNamespace(@NotNull String namespace) { this.mappedNamespace = Objects.requireNonNull(namespace); values.forEach(v -> v.setMappedNamespace(mappedNamespace)); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Namespaced that)) return false; + return Objects.equals(unmappedNamespace, that.unmappedNamespace) && Objects.equals(mappedNamespace, that.mappedNamespace) && Objects.equals(lvt, that.lvt); + } + + @Override + public int hashCode() { + return Objects.hash(unmappedNamespace, mappedNamespace, lvt); + } } } \ No newline at end of file diff --git a/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/Owned.java b/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/Owned.java index 5051378..ba5ef1f 100644 --- a/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/Owned.java +++ b/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/Owned.java @@ -21,6 +21,8 @@ import cn.maxpixel.mcdecompiler.mapping.Mapping; import cn.maxpixel.mcdecompiler.mapping.collection.ClassMapping; +import java.util.Objects; + public class Owned implements Component { public ClassMapping owner; @@ -31,4 +33,16 @@ public ClassMapping getOwner() { public void setOwner(ClassMapping owner) { this.owner = owner; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Owned owned)) return false; + return Objects.equals(owner.mapping, owned.owner.mapping); + } + + @Override + public int hashCode() { + return Objects.hashCode(owner.mapping); + } } \ No newline at end of file diff --git a/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/StaticIdentifiable.java b/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/StaticIdentifiable.java index 9aa8aaf..4b12806 100644 --- a/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/StaticIdentifiable.java +++ b/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/StaticIdentifiable.java @@ -28,4 +28,16 @@ public boolean isStatic() { public void setStatic(boolean isStatic) { this.isStatic = isStatic; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof StaticIdentifiable that)) return false; + return isStatic == that.isStatic; + } + + @Override + public int hashCode() { + return Boolean.hashCode(isStatic); + } } \ No newline at end of file