-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRewriteProcessor.java
More file actions
31 lines (24 loc) · 1.24 KB
/
RewriteProcessor.java
File metadata and controls
31 lines (24 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package io.papermc.classfile;
import io.papermc.classfile.method.MethodRewrite;
import io.papermc.classfile.method.MethodRewriteIndex;
import io.papermc.classfile.method.transform.BridgeMethodRegistry;
import io.papermc.classfile.transform.TransformContext;
import java.lang.classfile.ClassFile;
import java.lang.classfile.ClassModel;
import java.lang.classfile.ClassTransform;
import java.util.List;
public class RewriteProcessor {
private static final ClassFile CLASS_FILE = ClassFile.of();
private final MethodRewriteIndex methodIndex;
public RewriteProcessor(final List<MethodRewrite> methodRewrites) {
this.methodIndex = new MethodRewriteIndex(methodRewrites);
}
public byte[] rewrite(final byte[] input) {
final ClassModel inputModel = CLASS_FILE.parse(input);
final BridgeMethodRegistry bridges = new BridgeMethodRegistry();
final TransformContext context = TransformContext.create(inputModel.thisClass().asSymbol(), bridges);
final ClassTransform transform = ClassTransform.transformingMethods(MethodRewrite.createTransform(this.methodIndex, context))
.andThen(ClassTransform.endHandler(bridges::emitAll));
return CLASS_FILE.transformClass(inputModel, transform);
}
}