Refactor: Don't special case synthetic inner classes.

This was a very strange exception to have in the first place, and the default path works fine.
Notably, you are also allowed to have enums inside Mixins, in which case those would be given different names for each target class and therefore any switch tables referencing them are *not* safe to share.
This commit is contained in:
LlamaLad7 committed 2026-01-16 20:57:13 +00:00
1 parent f982c2f933
commit 12167db076
4 files changed
+9 -138

No files matched your search

@@ -35,11 +35,10 @@ import org.spongepowered.asm.service.MixinService;
* mixins.
*
* <p>Such tasks as {@link MixinCoprocessorAccessor making accessor mixins
* loadable (and transforming the accessors therein)}, {@link
* MixinCoprocessorSyntheticInner exposing synthetic inner classes to all
* consumers} and {@link MixinCoprocessorNestHost applying nest member
* attributes to nest hosts which may themselves not be mixin targets} are
* handled by different coprocessors.</p>
* loadable (and transforming the accessors therein)}, and {@link
* MixinCoprocessorNestHost applying nest member attributes to nest hosts
* which may themselves not be mixin targets} are handled by different
* coprocessors.</p>
*
* <p>These classes were previously encapsulated in a single companion class
* called <tt>MixinPostProcessor</tt>, but the mixture of responsibilities of
@@ -1,104 +0,0 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.asm.mixin.transformer;
import java.util.HashSet;
import java.util.Set;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
/**
* Coprocessor which handles synthetic inner classes in mixins. Since synthetic
* inner classes are usually just switch tables, it is reasonably safe to share
* them amongst all mixin targets. Therefore the class is simply transformed so
* that all members are public.
*
* <p>Nest based-access control could potentially be used where a mixin has a
* single target, and Java 11 or higher is in use, but at the moment it's more
* straightforward to just make everything public.</p>
*/
class MixinCoprocessorSyntheticInner extends MixinCoprocessor {
/**
* Synthetic inner classes in mixins
*/
private final Set<String> syntheticInnerClasses = new HashSet<String>();
MixinCoprocessorSyntheticInner() {
}
@Override
String getName() {
return "syntheticinner";
}
@Override
public void onInit(MixinInfo mixin) {
for (String innerClass : mixin.getSyntheticInnerClasses()) {
this.registerSyntheticInner(innerClass.replace('/', '.'));
}
}
void registerSyntheticInner(String className) {
this.syntheticInnerClasses.add(className);
}
@Override
public boolean couldTransform(String className) {
return this.syntheticInnerClasses.contains(className);
}
/**
* "Pass through" a synthetic inner class. Transforms package-private
* members in the class into public so that they are accessible from their
* new home in the target class
*/
@Override
ProcessResult process(String className, ClassNode classNode) {
if (!this.syntheticInnerClasses.contains(className)) {
return ProcessResult.NONE;
}
classNode.access |= Opcodes.ACC_PUBLIC;
for (FieldNode field : classNode.fields) {
if ((field.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) == 0) {
field.access |= Opcodes.ACC_PUBLIC;
}
}
for (MethodNode method : classNode.methods) {
if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) == 0) {
method.access |= Opcodes.ACC_PUBLIC;
}
}
return ProcessResult.PASSTHROUGH_TRANSFORMED;
}
}
@@ -224,14 +224,9 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
* Interfaces soft-implemented using {@link Implements}
*/
protected final List<InterfaceInfo> softImplements = new ArrayList<InterfaceInfo>();
/**
* Synthetic inner classes
*/
protected final Set<String> syntheticInnerClasses = new HashSet<String>();
/**
* Non-synthetic inner classes
* Inner classes
*/
protected final Set<String> innerClasses = new HashSet<String>();
@@ -286,10 +281,6 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
return this.softImplements;
}
Set<String> getSyntheticInnerClasses() {
return this.syntheticInnerClasses;
}
Set<String> getInnerClasses() {
return this.innerClasses;
}
@@ -420,20 +411,13 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
}
/**
* Read inner class definitions for the class and locate any synthetic
* inner classes so that we can add them to the passthrough set in our
* parent config.
* Read inner class definitions for the class and locate any of our inner classes.
*/
void readInnerClasses() {
for (InnerClassNode inner : this.validationClassNode.innerClasses) {
if ((inner.outerName != null && inner.outerName.equals(this.classInfo.getName()))
|| inner.name.startsWith(this.validationClassNode.name + "$")) {
boolean isStatic = (inner.access & Opcodes.ACC_STATIC) != 0;
boolean isSynthetic = (inner.access & Opcodes.ACC_SYNTHETIC) != 0;
if (isStatic && isSynthetic) {
this.syntheticInnerClasses.add(inner.name);
} else if (!ClassInfo.isMixin(inner.name)) {
if (!ClassInfo.isMixin(inner.name)) {
this.innerClasses.add(inner.name);
}
}
@@ -466,7 +450,7 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
*/
@Override
protected void validateChanges(SubType type, List<ClassInfo> targetClasses) {
if (!this.syntheticInnerClasses.equals(this.previous.syntheticInnerClasses)) {
if (!this.innerClasses.equals(this.previous.innerClasses)) {
throw new MixinReloadException(MixinInfo.this, "Cannot change inner classes");
}
if (!this.interfaces.equals(this.previous.interfaces)) {
@@ -1237,16 +1221,9 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
List<InterfaceInfo> getSoftImplements() {
return Collections.<InterfaceInfo>unmodifiableList(this.getState().getSoftImplements());
}
/**
* Get the synthetic inner classes for this mixin
*/
Set<String> getSyntheticInnerClasses() {
return Collections.<String>unmodifiableSet(this.getState().getSyntheticInnerClasses());
}
/**
* Get the user-defined inner classes for this mixin
* Get the inner classes for this mixin
*/
Set<String> getInnerClasses() {
return Collections.<String>unmodifiableSet(this.getState().getInnerClasses());
@@ -226,7 +226,6 @@ class MixinProcessor {
this.hotSwapper = hotSwapper;
this.coprocessors.add(new MixinCoprocessorPassthrough());
this.coprocessors.add(new MixinCoprocessorSyntheticInner());
this.coprocessors.add(new MixinCoprocessorAccessor(this.sessionId));
this.coprocessors.add(nestHostCoprocessor);