From bbdac72be56e89587c87616a1cb08c27759131ef Mon Sep 17 00:00:00 2001 From: BenLewis Date: Sat, 24 Oct 2015 09:07:41 +1300 Subject: [PATCH] Fixed false positive of changes to soft interfaces --- .../asm/mixin/transformer/InterfaceInfo.java | 22 +++++++++++++ .../asm/mixin/transformer/MixinInfo.java | 31 ++++++++++++------- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java index 1b3baaec..d51321db 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java @@ -178,4 +178,26 @@ public class InterfaceInfo extends TreeInfo { return new InterfaceInfo(mixin, prefix, iface); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + InterfaceInfo that = (InterfaceInfo) o; + + return this.mixin.equals(that.mixin) && this.prefix.equals(that.prefix) && this.iface.equals(that.iface); + } + + @Override + public int hashCode() { + int result = this.mixin.hashCode(); + result = 31 * result + this.prefix.hashCode(); + result = 31 * result + this.iface.hashCode(); + return result; + } } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java index 140407e9..b21ffe91 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java @@ -76,7 +76,8 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { byte[] mixinBytes; /** - * All interfaces implemented by this mixin, including soft implementations + * All interfaces implemented by this mixin, including soft + * implementations */ final Set interfaces = new HashSet(); @@ -96,8 +97,8 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { final ClassInfo classInfo; /** - * True if the superclass of the mixin is not the direct superclass - * of one or more targets + * True if the superclass of the mixin is not the direct + * superclass of one or more targets */ boolean detachedSuper; @@ -134,6 +135,9 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { } private class ReloadedState extends ValidationState { + /** + * The previous validation state to compare the changes to + */ final ValidationState parent; ReloadedState(ValidationState parent, byte[] mixinBytes) { @@ -141,6 +145,10 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { this.parent = parent; } + /** + * Validates that the changes are allowed to be made, these restrictions + * only exits while reloading mixins. + */ void validateChanges() { if (!this.syntheticInnerClasses.equals(this.parent.syntheticInnerClasses)) { throw new MixinReloadException(MixinInfo.this, "Cannot change inner classes"); @@ -216,12 +224,12 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { private final transient IMixinConfigPlugin plugin; /** - * Holds state that currently is not fully initialised + * Holds state that currently is not fully initialised or validated */ private transient ValidationState uninitialisedState; /** - * Holds state that can be reloaded + * Holds the current validated state */ private transient ValidationState validationState; @@ -375,7 +383,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { /** * Performs pre-flight checks on the mixin * - * @param state ReloadableState to validate + * @param state State to validate */ private void validateMixin(ValidationState state) { // isInner (shouldn't) return true for static inner classes @@ -442,8 +450,8 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { for (InnerClassNode inner : state.validationClassNode.innerClasses) { ClassInfo innerClass = ClassInfo.forName(inner.name); if (innerClass.isSynthetic() && innerClass.isProbablyStatic()) { - if ((inner.outerName != null && inner.outerName.equals(state.classInfo.getName())) || - inner.name.startsWith(state.validationClassNode.name + "$")) { + if ((inner.outerName != null && inner.outerName.equals(state.classInfo.getName())) + || inner.name.startsWith(state.validationClassNode.name + "$")) { state.syntheticInnerClasses.add(inner.name); } else { throw new InvalidMixinException(this, "Unhandled synthetic inner class found: " + inner.name); @@ -453,8 +461,8 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { } /** - * Current state, either the initialised state or the uninitialised state if - * it initialising for the first time. Should never return null. + * Current state, either the validated state or the uninitialised state if + * the mixin is initialising for the first time. Should never return null. */ private ValidationState getCurrentState() { if (this.validationState == null) { @@ -639,8 +647,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { if (this.uninitialisedState != null) { throw new IllegalStateException("Cannot reload mixin while it is initialising"); } - ReloadedState state = new ReloadedState(this.validationState, mixinBytes); - this.uninitialisedState = state; + this.uninitialisedState = new ReloadedState(this.validationState, mixinBytes); this.validate(); }