Class XReflectASM<T extends ReflectiveProxyObject>
XReflection.proxify(Class)
instead.
This is basically similar to ReflectASM (with another updated version of it by hyee), except that instead of relying on the same reflection-based API where members are accessed by their name in forms of strings and parameters are passed to get the object, we use actual interfaces which increases readability and performance.
Also something similar, specifically with Minecraft in mind was created named REghZyASMWrappers.
TODO We could also replace loaded classes, but that sounds too unreliable. That means we can't really use real constructors, fields or static members as it'd require replacing the caller with a method, and replacing classes isn't really something most plugins are willing to setup. But using ASM, we can use non-final abstract/non-interface classes.
I haven't confirmed this. But it seems like Paper's remapper also has a system that attempts to optimize some reflection access by generating a proxy for them?
You can see the a class that similarly resembles the generated class in the test sources named ASMGeneratedSample
.
We could also take inspiration from java.lang.invoke.InnerClassLambdaMetafactory
which generates something similar.
TODO Cleanup this class, it's really crowded in here.
- Since:
- 14.0.0
- See Also:
-
Field Summary
Fields inherited from class org.objectweb.asm.ClassVisitor
api, cv
-
Constructor Summary
ConstructorsConstructorDescriptionXReflectASM
(Class<T> templateClass, Class<?> targetClass, ClassOverloadedMethods<ProxyMethodInfo> mapped) -
Method Summary
Modifier and TypeMethodDescriptioncreate()
void
generate()
byte[]
static org.objectweb.asm.Type
@NotNull Class
<?> static <T extends ReflectiveProxyObject>
XReflectASM<T> void
verify
(boolean silent) void
visit
(int version, int access, String name, String signature, String superName, String[] interfaces) org.objectweb.asm.AnnotationVisitor
visitAnnotation
(String descriptor, boolean visible) void
visitEnd()
org.objectweb.asm.FieldVisitor
visitField
(int access, String name, String descriptor, String signature, Object value) org.objectweb.asm.MethodVisitor
visitMethod
(int access, String name, String descriptor, String signature, String[] exceptions) void
visitSource
(String source, String debug) org.objectweb.asm.AnnotationVisitor
visitTypeAnnotation
(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) void
writeToFile
(Path folder) Methods inherited from class org.objectweb.asm.ClassVisitor
getDelegate, visitAttribute, visitInnerClass, visitModule, visitNestHost, visitNestMember, visitOuterClass, visitPermittedSubclass, visitRecordComponent
-
Constructor Details
-
XReflectASM
public XReflectASM(Class<T> templateClass, Class<?> targetClass, ClassOverloadedMethods<ProxyMethodInfo> mapped)
-
-
Method Details
-
proxify
-
create
-
verify
public void verify(boolean silent) -
writeToFile
-
generate
public void generate() -
getBytecode
public byte[] getBytecode() -
visitAnnotation
- Overrides:
visitAnnotation
in classorg.objectweb.asm.ClassVisitor
-
visitTypeAnnotation
public org.objectweb.asm.AnnotationVisitor visitTypeAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) - Overrides:
visitTypeAnnotation
in classorg.objectweb.asm.ClassVisitor
-
visit
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) - Overrides:
visit
in classorg.objectweb.asm.ClassVisitor
-
visitSource
- Overrides:
visitSource
in classorg.objectweb.asm.ClassVisitor
-
visitEnd
public void visitEnd()- Overrides:
visitEnd
in classorg.objectweb.asm.ClassVisitor
-
visitField
public org.objectweb.asm.FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) - Overrides:
visitField
in classorg.objectweb.asm.ClassVisitor
-
visitMethod
public org.objectweb.asm.MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) - Overrides:
visitMethod
in classorg.objectweb.asm.ClassVisitor
-
getType
-
loadClass
-