Class XReflectASM<T extends ReflectiveProxyObject>

java.lang.Object
org.objectweb.asm.ClassVisitor
com.cryptomorin.xseries.reflection.asm.XReflectASM<T>

@Internal public final class XReflectASM<T extends ReflectiveProxyObject> extends org.objectweb.asm.ClassVisitor
This class should not be accessed directly, use 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:
  • Constructor Details

  • Method Details

    • proxify

      public static <T extends ReflectiveProxyObject> XReflectASM<T> proxify(Class<T> interfaceClass)
    • create

      @NotNull public T create()
    • verify

      public void verify(boolean silent)
    • writeToFile

      public void writeToFile(Path folder)
    • generate

      public void generate()
    • getBytecode

      public byte[] getBytecode()
    • visitAnnotation

      public org.objectweb.asm.AnnotationVisitor visitAnnotation(String descriptor, boolean visible)
      Overrides:
      visitAnnotation in class org.objectweb.asm.ClassVisitor
    • visitTypeAnnotation

      public org.objectweb.asm.AnnotationVisitor visitTypeAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible)
      Overrides:
      visitTypeAnnotation in class org.objectweb.asm.ClassVisitor
    • visit

      public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
      Overrides:
      visit in class org.objectweb.asm.ClassVisitor
    • visitSource

      public void visitSource(String source, String debug)
      Overrides:
      visitSource in class org.objectweb.asm.ClassVisitor
    • visitEnd

      public void visitEnd()
      Overrides:
      visitEnd in class org.objectweb.asm.ClassVisitor
    • visitField

      public org.objectweb.asm.FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value)
      Overrides:
      visitField in class org.objectweb.asm.ClassVisitor
    • visitMethod

      public org.objectweb.asm.MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions)
      Overrides:
      visitMethod in class org.objectweb.asm.ClassVisitor
    • getType

      public static org.objectweb.asm.Type getType(String className)
    • loadClass

      @NotNull public @NotNull Class<?> loadClass()