From f304b20cc02397744baf41cb0dc0b74ce28c2602 Mon Sep 17 00:00:00 2001 From: comp500 Date: Fri, 8 Oct 2021 18:15:32 +0100 Subject: [PATCH 1/2] Add applied MixinInfo to target class rather than mixin class In MixinInfo#postApply, the MixinInfo reference was being added to the ClassInfo of the mixin itself, rather than the classes the mixin is applied to. This meant that Mixins.getMixinsForClass would only return MixinInfo on mixin classes themselves, not their target classes, and ClassInfo#getAppliedMixins() was empty for target classes. This change fixes the behaviour to resolve the ClassInfo of the target class and add the MixinInfo to that. --- .../java/org/spongepowered/asm/mixin/transformer/MixinInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fb5b365ac..925bff9a0 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java @@ -1374,7 +1374,7 @@ public void postApply(String transformedName, ClassNode targetClass) throws Exce } this.parent.postApply(transformedName, targetClass); - this.info.addAppliedMixin(this); + ClassInfo.fromClassNode(targetClass).addAppliedMixin(this); } /* (non-Javadoc) From 1240888e225a392cc9bcb99e98efe5e622abb8ca Mon Sep 17 00:00:00 2001 From: comp500 Date: Mon, 14 Aug 2023 20:45:01 +0100 Subject: [PATCH 2/2] Expose info of mixins targeting a class and info from a mixin class Allow external code to query the list of mixins that target a class, including mixins that were not applied, by exposing getMixins; this method wasn't used internally but exposing it allows external error handlers greater visibility of mixins targeting a class. ClassInfo.mixin is also exposed with getMixinInfo to allow external code to retrieve mixin metadata from a class. This supersedes the need for some other methods like isMixin and isLoadable, but these are kept for compatibility. --- .../asm/mixin/transformer/ClassInfo.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java index 9e45c5355..c94a70444 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java @@ -938,8 +938,8 @@ void addAppliedMixin(MixinInfo mixin) { /** * Get all mixins which target this class */ - Set getMixins() { - return this.isMixin ? Collections.emptySet() : Collections.unmodifiableSet(this.mixins); + public Set getMixins() { + return this.isMixin ? Collections.emptySet() : Collections.unmodifiableSet(this.mixins); } /** @@ -955,6 +955,13 @@ public Set getAppliedMixins() { public boolean isMixin() { return this.isMixin; } + + /** + * Get mixin metadata for this class, if it is a mixin + */ + public IMixinInfo getMixinInfo() { + return this.mixin; + } /** * Get whether this class is loadable mixin