Preserve correct context through injection passes

This commit is contained in:
Mumfrey committed 2016-02-08 15:19:01 +00:00
1 parent 6e32c0069d
commit 1431501407
4 files changed
+32 -19

No files matched your search

@@ -177,11 +177,9 @@ public class MixinApplicator {
protected final Logger logger = LogManager.getLogger("mixin");
/**
* Session ID, used as a check when parsing {@link MixinMerged} annotations
* to prevent them being applied at compile time by people trying to
* circumvent mixin application
* Target class context
*/
protected final String sessionId;
protected final TargetClassContext context;
/**
* Target class name
@@ -194,7 +192,7 @@ public class MixinApplicator {
protected final ClassNode targetClass;
MixinApplicator(TargetClassContext context) {
this.sessionId = context.getSessionId();
this.context = context;
this.targetName = context.getName();
this.targetClass = context.getClassNode();
}
@@ -207,7 +205,7 @@ public class MixinApplicator {
for (MixinInfo mixin : mixins) {
this.logger.log(mixin.getLoggingLevel(), "Mixing {} from {} into {}", mixin.getName(), mixin.getParent(), this.targetName);
mixinContexts.add(mixin.createContextFor(this.targetClass));
mixinContexts.add(mixin.createContextFor(this.context));
}
MixinTargetContext current = null;
@@ -400,12 +398,7 @@ public class MixinApplicator {
}
this.targetClass.methods.add(method);
mixin.getTargetClassInfo().addMethod(method);
ASMHelper.setVisibleAnnotation(method, MixinMerged.class,
"mixin", mixin.getClassName(),
"priority", mixin.getPriority(),
"sessionId", this.sessionId);
mixin.addMergedMethod(method);
}
/**
@@ -431,7 +424,7 @@ public class MixinApplicator {
String sessionId = ASMHelper.<String>getAnnotationValue(merged, "sessionId");
if (!this.sessionId.equals(sessionId)) {
if (!this.context.getSessionId().equals(sessionId)) {
throw new ClassFormatError("Invalid @MixinMerged annotation found in" + mixin + " at " + method.name + " in " + this.targetClass.name);
}
@@ -702,7 +702,7 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
* @param target
* @return new context
*/
public MixinTargetContext createContextFor(ClassNode target) {
public MixinTargetContext createContextFor(TargetClassContext target) {
ClassNode classNode = this.getClassNode(ClassReader.EXPAND_FRAMES);
return this.createPreProcessor(classNode).prepare().createContextFor(target);
}
@@ -153,7 +153,7 @@ class MixinPreProcessor {
// stub
}
MixinTargetContext createContextFor(ClassNode target) {
MixinTargetContext createContextFor(TargetClassContext target) {
MixinTargetContext context = new MixinTargetContext(this.mixin, this.classNode, target);
this.attach(context);
return context;
@@ -102,6 +102,11 @@ public class MixinTargetContext implements IReferenceMapperContext {
*/
private final Map<FieldNode, Field> shadowFields = new LinkedHashMap<FieldNode, Field>();
/**
* List of methods successfully merged from this mixin
*/
private final List<MethodNode> mergedMethods = new ArrayList<MethodNode>();
/**
* Information about methods in the target class, used to keep track of
* transformations we apply
@@ -142,11 +147,11 @@ public class MixinTargetContext implements IReferenceMapperContext {
* @param classNode Mixin classnode
* @param target target class
*/
MixinTargetContext(MixinInfo mixin, ClassNode classNode, ClassNode target) {
MixinTargetContext(MixinInfo mixin, ClassNode classNode, TargetClassContext context) {
this.mixin = mixin;
this.classNode = classNode;
this.targetClass = target;
this.targetClassInfo = ClassInfo.forName(target.name);
this.targetClass = context.getClassNode();
this.targetClassInfo = ClassInfo.forName(this.targetClass.name);
this.inheritsFromMixin = mixin.getClassInfo().hasMixinInHierarchy() || this.targetClassInfo.hasMixinTargetInHierarchy();
this.detachedSuper = !this.classNode.superName.equals(this.targetClass.superName);
this.requireVersion(classNode.version);
@@ -166,6 +171,21 @@ public class MixinTargetContext implements IReferenceMapperContext {
this.shadowFields.put(fieldNode, fieldInfo);
}
/**
* Callback from the applicator which notifies us that a method was merged
*
* @param method
*/
void addMergedMethod(MethodNode method) {
this.mergedMethods.add(method);
this.targetClassInfo.addMethod(method);
// ASMHelper.setVisibleAnnotation(method, MixinMerged.class,
// "mixin", this.getClassName(),
// "priority", this.getPriority(),
// "sessionId", this.sessionId);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@@ -886,7 +906,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
public void prepareInjections() {
this.injectors.clear();
for (MethodNode method : this.targetClass.methods) {
for (MethodNode method : this.mergedMethods) {
InjectionInfo injectInfo = InjectionInfo.parse(this, method);
if (injectInfo == null) {
continue;