From 38b5af0f1efc993aaa7aa4e2c97580f1271a0fb6 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 24eafa86d..6948d69e7 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java @@ -1376,7 +1376,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 54f148f2283ceb5a99eac78f55721d5760d8a854 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 538198cda..90ad30628 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java @@ -941,8 +941,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); } /** @@ -958,6 +958,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