/** * Called after the main expression evaluation method has been generated, this * method will callback any registered FieldAdders or ClinitAdders to add any * extra information to the class representing the compiled expression. */ public void finish() { if (this.fieldAdders != null) { for (FieldAdder fieldAdder : this.fieldAdders) { fieldAdder.generateField(this.classWriter, this); } } if (this.clinitAdders != null) { MethodVisitor mv = this.classWriter.visitMethod(ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); this.nextFreeVariableId = 0; // to 0 because there is no 'this' in a clinit for (ClinitAdder clinitAdder : this.clinitAdders) { clinitAdder.generateCode(mv, this); } mv.visitInsn(RETURN); mv.visitMaxs(0,0); // not supplied due to COMPUTE_MAXS mv.visitEnd(); } }
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv = cw.visitMethod(ACC_PUBLIC, "getValue", "(Ljava/lang/Object;Lorg/springframework/expression/EvaluationContext;)Ljava/lang/Object;", null, new String[ ]{"org/springframework/expression/EvaluationException"});
/** * Called after the main expression evaluation method has been generated, this * method will callback any registered FieldAdders or ClinitAdders to add any * extra information to the class representing the compiled expression. */ public void finish() { if (this.fieldAdders != null) { for (FieldAdder fieldAdder : this.fieldAdders) { fieldAdder.generateField(this.classWriter, this); } } if (this.clinitAdders != null) { MethodVisitor mv = this.classWriter.visitMethod(ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); this.nextFreeVariableId = 0; // to 0 because there is no 'this' in a clinit for (ClinitAdder clinitAdder : this.clinitAdders) { clinitAdder.generateCode(mv, this); } mv.visitInsn(RETURN); mv.visitMaxs(0,0); // not supplied due to COMPUTE_MAXS mv.visitEnd(); } }
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv = cw.visitMethod(ACC_PUBLIC, "getValue", "(Ljava/lang/Object;Lorg/springframework/expression/EvaluationContext;)Ljava/lang/Object;", null, new String[ ]{"org/springframework/expression/EvaluationException"});
MethodVisitor con = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); con.visitCode(); con.visitVarInsn(Opcodes.ALOAD, 0); MethodVisitor callCon = cw.visitMethod(Opcodes.ACC_PUBLIC, "call", "(Lio/gomint/event/Event;)V", null, null); callCon.visitCode(); callCon.visitVarInsn(Opcodes.ALOAD, 0);
/** * 创建get方法 * @param cw * @param classGenerator */ public static void visitGetMethod(ClassWriter cw,ClassGeneratorEntity classGenerator) { classGenerator.getFieldGenerators().forEach(fieldGenerator -> { String methodName = "get" + String.valueOf(Character.toUpperCase(fieldGenerator.getName().charAt(0))) + fieldGenerator.getName().substring(1); MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, methodName, "()" + fieldGenerator.getDescriptor(), null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, classGenerator.getGeneratorName(), fieldGenerator.getName(), fieldGenerator.getDescriptor()); mv.visitInsn(ARETURN); mv.visitMaxs(0, 1); mv.visitEnd(); }); }
/** * 创建set方法 * @param cw * @param classGenerator */ public static void visitSetMethod(ClassWriter cw,ClassGeneratorEntity classGenerator) { classGenerator.getFieldGenerators().forEach(fieldGenerator -> { String methodName = "set" + String.valueOf(Character.toUpperCase(fieldGenerator.getName().charAt(0))) + fieldGenerator.getName().substring(1); MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, methodName, "(" + fieldGenerator.getDescriptor() + ")V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); // set 入参 mv.visitVarInsn(ALOAD, 1); mv.visitFieldInsn(PUTFIELD, classGenerator.getGeneratorName(), fieldGenerator.getName(), fieldGenerator.getDescriptor()); mv.visitInsn(RETURN); mv.visitMaxs(1, 2); mv.visitEnd(); }); }
private void visitDefaultConstructor(ClassWriter cw) { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, INIT, "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, JAVA_LANG_OBJECT, INIT, "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); // (0, 0) = computed via ClassWriter.COMPUTE_MAXS mv.visitEnd(); }
/** * 创建构造器 * @param cw */ public static void visitDefaultConstructor(ClassWriter cw) { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, INIT, "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, JAVA_LANG_OBJECT, INIT, "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
/** * Called after the main expression evaluation method has been generated, this * method will callback any registered FieldAdders or ClinitAdders to add any * extra information to the class representing the compiled expression. */ public void finish() { if (this.fieldAdders != null) { for (FieldAdder fieldAdder : this.fieldAdders) { fieldAdder.generateField(this.classWriter, this); } } if (this.clinitAdders != null) { MethodVisitor mv = this.classWriter.visitMethod(ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); this.nextFreeVariableId = 0; // to 0 because there is no 'this' in a clinit for (ClinitAdder clinitAdder : this.clinitAdders) { clinitAdder.generateCode(mv, this); } mv.visitInsn(RETURN); mv.visitMaxs(0,0); // not supplied due to COMPUTE_MAXS mv.visitEnd(); } }
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv = cw.visitMethod(ACC_PUBLIC, "getValue", "(Ljava/lang/Object;Lorg/springframework/expression/EvaluationContext;)Ljava/lang/Object;", null, new String[ ]{"org/springframework/expression/EvaluationException"});
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_VARARGS, CREATE_METHOD_NAME, "([Ljava/lang/Object;)Ljava/lang/Object;", null, null); mv.visitCode();
private static void visitBeanGetter(PersistentEntity<?, ?> entity, String internalClassName, ClassWriter cw) { // public Object getBean() MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getBean", String.format("()%s", referenceName(JAVA_LANG_OBJECT)), null, null); mv.visitCode(); Label l0 = new Label(); // return this.bean mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, internalClassName, BEAN_FIELD, getAccessibleTypeReferenceName(entity)); mv.visitInsn(ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable(THIS_REF, referenceName(internalClassName), null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); }
MethodVisitor mv = cw.visitMethod(ACC_STATIC, CINIT, voidNoArgMethodDescriptor, null, null); mv.visitCode(); mv.visitLdcInsn(Type.getType(clazz)); mv = cw.visitMethod(ACC_PUBLIC, INIT, voidNoArgMethodDescriptor, null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv = cw.visitMethod(ACC_PUBLIC, INIT, voidArgClassAndIntDescriptor, null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv = cw.visitMethod(ACC_PUBLIC, NEW_INSTANCE, customTypeNoArgDesc, null, null); mv = cw.visitMethod(ACC_PUBLIC + ACC_BRIDGE + ACC_SYNTHETIC, NEW_INSTANCE, NEW_INSTANCE_DESC, null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0);
MethodVisitor mv = cw.visitMethod(ACC_STATIC, CINIT, voidNoArgMethodDescriptor, null, null); mv.visitCode(); mv.visitLdcInsn(Type.getType(clazz)); mv = cw.visitMethod(ACC_PUBLIC, INIT, voidNoArgMethodDescriptor, null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv = cw.visitMethod(ACC_PUBLIC, INIT, voidArgClassAndIntDescriptor, null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv = cw.visitMethod(ACC_PUBLIC, NEW_INSTANCE, customTypeNoArgDesc, null, null); mv = cw.visitMethod(ACC_PUBLIC + ACC_BRIDGE + ACC_SYNTHETIC, NEW_INSTANCE, NEW_INSTANCE_DESC, null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0);
mv = cw.visitMethod(ACC_PUBLIC, INIT, String.format("(%s)V", getAccessibleTypeReferenceName(entity)), null, null);
List<PersistentProperty<?>> persistentProperties, String internalClassName, ClassWriter cw) { MethodVisitor mv = cw.visitMethod(ACC_STATIC, CLINIT, "()V", null, null); mv.visitCode(); Label l0 = new Label();
List<PersistentProperty<?>> persistentProperties, String internalClassName, ClassWriter cw) { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getProperty", "(Lorg/springframework/data/mapping/PersistentProperty;)Ljava/lang/Object;", "(Lorg/springframework/data/mapping/PersistentProperty<*>;)Ljava/lang/Object;", null);
List<PersistentProperty<?>> persistentProperties, String internalClassName, ClassWriter cw) { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "setProperty", "(Lorg/springframework/data/mapping/PersistentProperty;Ljava/lang/Object;)V", "(Lorg/springframework/data/mapping/PersistentProperty<*>;Ljava/lang/Object;)V", null);