mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-20 12:19:52 +00:00
Strip final flag from Mutable shadow targets, closes #124
This commit is contained in:
1 parent
f19f4deac6
commit
244303cd3d
5 files changed
+26
-7
No files matched your search
@@ -24,10 +24,13 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.FieldNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.InvalidInjectionException;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Field;
|
||||
|
||||
/**
|
||||
* Applicator for interface mixins, mainly just disables things which aren't
|
||||
@@ -67,7 +70,8 @@ public class InterfaceMixinApplicator extends MixinApplicator {
|
||||
@Override
|
||||
protected void applyFields(MixinTargetContext mixin) {
|
||||
// shadow fields have no meaning for interfaces, just spam the dev with messages
|
||||
for (FieldNode shadow : mixin.getShadowFields()) {
|
||||
for (Entry<FieldNode, Field> entry : mixin.getShadowFields()) {
|
||||
FieldNode shadow = entry.getKey();
|
||||
this.logger.error("Ignoring redundant @Shadow field {}:{} in {}", shadow.name, shadow.desc, mixin);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.Deque;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -51,6 +52,7 @@ import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Field;
|
||||
import org.spongepowered.asm.mixin.transformer.meta.MixinMerged;
|
||||
import org.spongepowered.asm.mixin.transformer.meta.MixinRenamed;
|
||||
import org.spongepowered.asm.util.ASMHelper;
|
||||
@@ -307,15 +309,21 @@ public class MixinApplicator {
|
||||
* @param mixin
|
||||
*/
|
||||
protected void applyFields(MixinTargetContext mixin) {
|
||||
this.mergeShadowFieldAnnotations(mixin);
|
||||
this.mergeShadowFields(mixin);
|
||||
this.mergeNewFields(mixin);
|
||||
}
|
||||
|
||||
protected void mergeShadowFieldAnnotations(MixinTargetContext mixin) {
|
||||
for (FieldNode shadow : mixin.getShadowFields()) {
|
||||
protected void mergeShadowFields(MixinTargetContext mixin) {
|
||||
for (Entry<FieldNode, Field> entry : mixin.getShadowFields()) {
|
||||
FieldNode shadow = entry.getKey();
|
||||
FieldNode target = this.findTargetField(shadow);
|
||||
if (target != null) {
|
||||
this.mergeAnnotations(shadow, target);
|
||||
|
||||
// Strip the FINAL flag from @Mutable non-private fields
|
||||
if (entry.getValue().isDecoratedMutable() && !MixinApplicator.hasFlag(target, Opcodes.ACC_PRIVATE)) {
|
||||
target.access &= ~Opcodes.ACC_FINAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +345,8 @@ class MixinPreProcessor {
|
||||
// Public static fields will fall foul of early static binding in java, including them in a mixin is an error condition
|
||||
if (MixinApplicator.hasFlag(field, Opcodes.ACC_STATIC)
|
||||
&& !MixinApplicator.hasFlag(field, Opcodes.ACC_PRIVATE)
|
||||
&& !MixinApplicator.hasFlag(field, Opcodes.ACC_SYNTHETIC)) {
|
||||
&& !MixinApplicator.hasFlag(field, Opcodes.ACC_SYNTHETIC)
|
||||
&& shadow == null) {
|
||||
throw new InvalidMixinException(context, String.format("Mixin %s contains non-private static field %s:%s",
|
||||
context, field.name, field.desc));
|
||||
}
|
||||
|
||||
@@ -833,8 +833,8 @@ public class MixinTargetContext implements IReferenceMapperContext {
|
||||
*
|
||||
* @return shadow fields in the mixin
|
||||
*/
|
||||
public Collection<FieldNode> getShadowFields() {
|
||||
return this.shadowFields.keySet();
|
||||
public Set<Entry<FieldNode, Field>> getShadowFields() {
|
||||
return this.shadowFields.entrySet();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -767,6 +767,12 @@ public class MixinTransformer extends TreeTransformer {
|
||||
this.errorState = true;
|
||||
|
||||
MixinInfo mixin = ex.getMixin();
|
||||
|
||||
if (mixin == null) {
|
||||
this.logger.error("InvalidMixinException has no mixin!", ex);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
MixinConfig config = mixin.getParent();
|
||||
Phase phase = mixin.getPhase();
|
||||
ErrorAction action = config.isRequired() ? ErrorAction.ERROR : ErrorAction.WARN;
|
||||
|
||||
Reference in new issue
Block a user