Skip to content

Commit

Permalink
Register Eject into ap.
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Aug 22, 2020
1 parent 8751c51 commit f16fb61
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
36 changes: 36 additions & 0 deletions src/main/java/io/izzel/arclight/mixin/ap/EjectProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.izzel.arclight.mixin.ap;

import io.izzel.arclight.mixin.injector.EjectorInfo;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import java.util.Collections;
import java.util.Set;

public class EjectProvider extends AbstractProcessor {

@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
InjectionInfo.register(EjectorInfo.class);
}

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
return true;
}

@Override
public Set<String> getSupportedAnnotationTypes() {
return Collections.emptySet();
}

@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.RELEASE_8;
}
}
10 changes: 5 additions & 5 deletions src/main/java/io/izzel/arclight/mixin/injector/Ejector.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@

public class Ejector extends Injector {

static class IndirectInvokeData extends InjectorData {
static class EjectInvokeData extends InjectorData {

final MethodInsnNode node;
final Type returnType;
final Type[] targetArgs;
final Type[] handlerArgs;

IndirectInvokeData(Target target, MethodInsnNode node) {
EjectInvokeData(Target target, MethodInsnNode node) {
super(target);
this.node = node;
this.returnType = Type.getReturnType(node.desc);
Expand Down Expand Up @@ -70,7 +70,7 @@ protected void inject(Target target, InjectionNodes.InjectionNode node) {
}

private void injectAtInvoke(Target target, InjectionNodes.InjectionNode node) {
IndirectInvokeData data = new IndirectInvokeData(target, ((MethodInsnNode) node.getCurrentTarget()));
EjectInvokeData data = new EjectInvokeData(target, ((MethodInsnNode) node.getCurrentTarget()));
this.validateIndirectParams(data, data.returnType, data.handlerArgs);
InsnList insnList = new InsnList();

Expand Down Expand Up @@ -110,7 +110,7 @@ protected void injectReturnCode(InsnList callback, Target target) {
}
}

protected AbstractInsnNode invokeCallback(Target target, InsnList insnList, IndirectInvokeData data, Target.Extension extraLocals, Target.Extension extraStack) {
protected AbstractInsnNode invokeCallback(Target target, InsnList insnList, EjectInvokeData data, Target.Extension extraLocals, Target.Extension extraStack) {
extraLocals.add(data.handlerArgs).add(2);
extraStack.add(2);
int[] argMap = this.storeArgs(target, data.handlerArgs, insnList, 0);
Expand Down Expand Up @@ -140,7 +140,7 @@ protected void instanceCallbackInfo(InsnList callback, Target target) {
callback.add(new VarInsnNode(Opcodes.ASTORE, this.callbackInfoVar));
}

protected final void validateIndirectParams(IndirectInvokeData injector, Type returnType, Type... args) {
protected final void validateIndirectParams(EjectInvokeData injector, Type returnType, Type... args) {
String description = String.format("%s %s method %s from %s", this.annotationType, injector, this, this.info.getContext());
int argIndex = 0;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.izzel.arclight.mixin.ap.EjectProvider

0 comments on commit f16fb61

Please sign in to comment.