Skip to content

Commit

Permalink
Add annotation node to MethodSliceContext
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Jul 24, 2024
1 parent 64dee8d commit 31326ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private List<AbstractInsnNode> computeInjectionTargetInsns(@Nullable TargetPair
// Parse injection point
InjectionPoint injectionPoint = InjectionPoint.parse(mixinContext, this.methodNode, annotation.unwrap(), atNode.unwrap());
// Find target instructions
InsnList instructions = getSlicedInsns(annotation, this.classNode, this.methodNode, target.classNode(), target.methodNode(), patchContext());
InsnList instructions = getSlicedInsns(annotation, target.classNode(), target.methodNode(), patchContext());
List<AbstractInsnNode> targetInsns = new ArrayList<>();
try {
injectionPoint.find(target.methodNode().desc, instructions, targetInsns);
Expand Down Expand Up @@ -209,15 +209,15 @@ public boolean failsDirtyInjectionCheck() {
return dirtyPair != null && findInjectionTargetInsns(dirtyPair).isEmpty();
}

private InsnList getSlicedInsns(AnnotationHandle parentAnnotation, ClassNode classNode, MethodNode injectorMethod, ClassNode targetClass, MethodNode targetMethod, PatchContext context) {
private InsnList getSlicedInsns(AnnotationHandle parentAnnotation, ClassNode targetClass, MethodNode targetMethod, PatchContext context) {
return parentAnnotation.<AnnotationNode>getValue("slice")
.map(handle -> {
Object value = handle.get();
return value instanceof List<?> list ? (AnnotationNode) list.get(0) : (AnnotationNode) value;
})
.map(sliceAnn -> {
IMixinContext mixinContext = MockMixinRuntime.forClass(classNode.name, targetClass.name, context.environment());
ISliceContext sliceContext = MockMixinRuntime.forSlice(mixinContext, injectorMethod);
IMixinContext mixinContext = MockMixinRuntime.forClass(this.classNode.name, targetClass.name, context.environment());
ISliceContext sliceContext = MockMixinRuntime.forSlice(mixinContext, this.methodNode, this.methodAnnotation.unwrap());
return computeSlicedInsns(sliceContext, sliceAnn, targetMethod);
})
.orElse(targetMethod.instructions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public static IMixinContext forClass(String className, String targetClass, Patch
return new ClassMixinContext(className, targetClass, environment);
}

public static ISliceContext forSlice(IMixinContext context, MethodNode methodNode) {
return new MethodSliceContext(context, methodNode);
public static ISliceContext forSlice(IMixinContext context, MethodNode methodNode, AnnotationNode annotationNode) {
return new MethodSliceContext(context, methodNode, annotationNode);
}

public static InjectionInfo forInjectionInfo(String className, String targetClass, PatchEnvironment environment) {
Expand All @@ -61,7 +61,7 @@ public static InjectionInfo forInjectionInfo(String className, String targetClas
}
}

private record MethodSliceContext(IMixinContext context, MethodNode methodNode) implements ISliceContext {
private record MethodSliceContext(IMixinContext context, MethodNode methodNode, AnnotationNode annotationNode) implements ISliceContext {
@Override
public IMixinContext getMixin() {
return this.context;
Expand All @@ -75,7 +75,7 @@ public String remap(String reference) {
//@formatter:off
@Override public MethodSlice getSlice(String id) {throw new UnsupportedOperationException();}
@Override public MethodNode getMethod() {return this.methodNode;}
@Override public AnnotationNode getAnnotationNode() {throw new UnsupportedOperationException();}
@Override public AnnotationNode getAnnotationNode() {return this.annotationNode;}
@Override public ISelectorContext getParent() {throw new UnsupportedOperationException();}
@Override public IAnnotationHandle getAnnotation() {throw new UnsupportedOperationException();}
@Override public IAnnotationHandle getSelectorAnnotation() {throw new UnsupportedOperationException();}
Expand Down

0 comments on commit 31326ec

Please sign in to comment.