Bump 0.6.11, fix lambda merging & improve Unique, fixes #100, fixes #181

This commit is contained in:
Mumfrey committed 2017-06-14 15:43:36 +01:00
1 parent 8a169bb7c0
commit b558323da3
7 files changed
+92 -17

No files matched your search

@@ -62,7 +62,7 @@ public abstract class MixinBootstrap {
/**
* Subsystem version
*/
public static final String VERSION = "0.6.10";
public static final String VERSION = "0.6.11";
// Consts
private static final String LAUNCH_PACKAGE = "org.spongepowered.asm.launch.";
@@ -315,6 +315,10 @@ public final class ClassInfo extends TreeInfo {
return (this.modifiers & Opcodes.ACC_FINAL) != 0;
}
public boolean isSynthetic() {
return (this.modifiers & Opcodes.ACC_SYNTHETIC) != 0;
}
public boolean isUnique() {
return this.unique;
}
@@ -447,7 +447,7 @@ class MixinApplicatorStandard {
}
this.targetClass.methods.add(method);
mixin.addMergedMethod(method);
mixin.methodMerged(method);
if (method.signature != null) {
SignatureVisitor sv = mixin.getSignature().getRemapper();
@@ -218,6 +218,7 @@ class MixinPreProcessorStandard {
}
if (this.attachInjectorMethod(context, mixinMethod)) {
context.addMixinMethod(mixinMethod);
continue;
}
@@ -236,11 +237,13 @@ class MixinPreProcessorStandard {
}
if (this.attachUniqueMethod(context, mixinMethod)) {
context.addMixinMethod(mixinMethod);
iter.remove();
continue;
}
this.attachMethod(mixinMethod);
context.addMixinMethod(mixinMethod);
}
}
@@ -379,7 +382,7 @@ class MixinPreProcessorStandard {
protected boolean attachUniqueMethod(MixinTargetContext context, MixinMethodNode mixinMethod) {
Method method = this.mixin.getClassInfo().findMethod(mixinMethod, ClassInfo.INCLUDE_ALL);
if (method == null || (!method.isUnique() && !this.mixin.isUnique())) {
if (method == null || ((!method.isUnique() && !this.mixin.isUnique()) && !method.isSynthetic())) {
return false;
}
@@ -388,20 +391,22 @@ class MixinPreProcessorStandard {
return false;
}
String type = method.isUnique() ? "@Unique" : "synthetic";
if ((mixinMethod.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) != 0) {
String uniqueName = context.getUniqueName(mixinMethod, false);
MixinPreProcessorStandard.logger.log(this.mixin.getLoggingLevel(), "Renaming @Unique method {}{} to {} in {}",
mixinMethod.name, mixinMethod.desc, uniqueName, this.mixin);
MixinPreProcessorStandard.logger.log(this.mixin.getLoggingLevel(), "Renaming {} method {}{} to {} in {}",
type, mixinMethod.name, mixinMethod.desc, uniqueName, this.mixin);
mixinMethod.name = method.renameTo(uniqueName);
return false;
}
if (this.strictUnique) {
throw new InvalidMixinException(this.mixin, "Method conflict, @Unique method " + mixinMethod.name + " in " + this.mixin
throw new InvalidMixinException(this.mixin, "Method conflict, " + type + " method " + mixinMethod.name + " in " + this.mixin
+ " cannot overwrite " + target.name + target.desc + " in " + context.getTarget());
}
MixinPreProcessorStandard.logger.warn("Discarding @Unique public method {} in {} because it already exists in {}", mixinMethod.name,
MixinPreProcessorStandard.logger.warn("Discarding {} public method {} in {} because it already exists in {}", type, mixinMethod.name,
this.mixin, context.getTarget());
return true;
@@ -58,6 +58,7 @@ import org.spongepowered.asm.mixin.injection.throwables.InjectionValidationExcep
import org.spongepowered.asm.mixin.refmap.IMixinContext;
import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Field;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
import org.spongepowered.asm.mixin.transformer.ClassInfo.SearchType;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Traversal;
import org.spongepowered.asm.mixin.transformer.meta.MixinMerged;
@@ -208,15 +209,20 @@ public class MixinTargetContext implements IMixinContext {
void addAccessorMethod(MethodNode method, Class<? extends Annotation> type) {
this.accessors.add(AccessorInfo.of(this, method, type));
}
void addMixinMethod(MethodNode method) {
this.targetClass.addMixinMethod(method);
}
/**
* Callback from the applicator which notifies us that a method was merged
*
* @param method merged method
*/
void addMergedMethod(MethodNode method) {
void methodMerged(MethodNode method) {
this.mergedMethods.add(method);
this.targetClassInfo.addMethod(method);
this.targetClass.methodMerged(method);
Annotations.setVisible(method, MixinMerged.class,
"mixin", this.getClassName(),
@@ -455,6 +461,10 @@ public class MixinTargetContext implements IMixinContext {
if (methodRef.getOwner().equals(this.getClassRef())) {
methodRef.setOwner(this.targetClass.getName());
Method md = this.mixin.getClassInfo().findMethod(methodRef.getName(), methodRef.getDesc(), ClassInfo.INCLUDE_ALL);
if (md != null && md.isRenamed() && md.getOriginalName().equals(methodRef.getName()) && md.isSynthetic()) {
methodRef.setName(md.getName());
}
} else if ((this.detachedSuper || this.inheritsFromMixin)) {
if (methodRef.getOpcode() == Opcodes.INVOKESPECIAL) {
this.updateStaticBinding(method, methodRef);
@@ -846,7 +856,7 @@ public class MixinTargetContext implements IMixinContext {
}
}
return this.targetClass.findAliasedMethod(aliases, method.desc);
return this.targetClass.findMethod(aliases, method.desc);
}
MethodNode findRemappedMethod(MethodNode method) {
@@ -1114,7 +1124,9 @@ public class MixinTargetContext implements IMixinContext {
List<MethodNode> methods = new ArrayList<MethodNode>();
for (AccessorInfo accessor : this.accessors) {
methods.add(accessor.generate());
MethodNode generated = accessor.generate();
this.targetClass.addMixinMethod(generated);
methods.add(generated);
}
return methods;
@@ -26,10 +26,14 @@ package org.spongepowered.asm.mixin.transformer;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.lib.tree.AnnotationNode;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.FieldNode;
@@ -39,8 +43,8 @@ import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
import org.spongepowered.asm.mixin.injection.struct.Target;
import org.spongepowered.asm.mixin.transformer.meta.SourceMap;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.Annotations;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.ClassSignature;
/**
@@ -48,6 +52,11 @@ import org.spongepowered.asm.util.ClassSignature;
*/
class TargetClassContext {
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger("mixin");
/**
* Transformer session ID
*/
@@ -88,7 +97,14 @@ class TargetClassContext {
* transformations we apply
*/
private final Map<String, Target> targetMethods = new HashMap<String, Target>();
/**
* Information about methods which have been discovered by mixin
* preprocessors in this pass but which have not yet been merged into the
* target class.
*/
private final Set<MethodNode> mixinMethods = new HashSet<MethodNode>();
/**
* Unique method and field indices
*/
@@ -200,8 +216,31 @@ class TargetClassContext {
void mergeSignature(ClassSignature signature) {
this.signature.merge(signature);
}
/**
* Add the specified method to the pending mixin methods set
*
* @param method method to add
*/
void addMixinMethod(MethodNode method) {
this.mixinMethods.add(method);
}
void methodMerged(MethodNode method) {
if (!this.mixinMethods.remove(method)) {
TargetClassContext.logger.debug("Unexpected: Merged unregistered method {}{} in {}", method.name, method.desc, this);
}
}
MethodNode findMethod(Deque<String> aliases, String desc) {
return this.findAliasedMethod(aliases, desc, true);
}
MethodNode findAliasedMethod(Deque<String> aliases, String desc) {
return this.findAliasedMethod(aliases, desc, false);
}
private MethodNode findAliasedMethod(Deque<String> aliases, String desc, boolean includeMixinMethods) {
String alias = aliases.poll();
if (alias == null) {
return null;
@@ -213,6 +252,14 @@ class TargetClassContext {
}
}
if (includeMixinMethods) {
for (MethodNode target : this.mixinMethods) {
if (target.name.equals(alias) && target.desc.equals(desc)) {
return target;
}
}
}
return this.findAliasedMethod(aliases, desc);
}
@@ -277,10 +324,9 @@ class TargetClassContext {
throw new IllegalStateException("Mixins already applied to target class " + this.className);
}
this.applied = true;
MixinApplicatorStandard applicator = this.createApplicator();
applicator.apply(this.mixins);
this.createApplicator().apply(this.mixins);
this.classNode.signature = this.signature.toString();
this.checkMerges();
}
private MixinApplicatorStandard createApplicator() {
@@ -290,6 +336,14 @@ class TargetClassContext {
return new MixinApplicatorStandard(this);
}
private void checkMerges() {
for (MethodNode method : this.mixinMethods) {
if (!method.name.startsWith("<")) {
TargetClassContext.logger.debug("Unexpected: Registered method {}{} in {} was not merged", method.name, method.desc, this);
}
}
}
/**
* Process {@link Debug} annotations on the class after application
*/