use of dyvilx.tools.asm.MethodVisitor in project Dyvil by Dyvil.
the class AnnotationProxyFactory method generateToString.
private void generateToString(@NonNull ClassWriter classWriter) {
final MethodVisitor toString = classWriter.visitMethod(PUBLIC, "toString", "()Ljava/lang/String;", null, null);
toString.visitCode();
toString.visitLdcInsn('<' + this.annotationType.getName() + ">");
toString.visitInsn(Opcodes.ARETURN);
toString.visitMaxs(-1, -1);
toString.visitEnd();
}
use of dyvilx.tools.asm.MethodVisitor in project Dyvil by Dyvil.
the class AnnotationMetadata method write.
@Override
public void write(ClassWriter writer) throws BytecodeException {
for (IParameter parameter : this.theClass.getParameters()) {
final StringBuilder desc = new StringBuilder("()");
parameter.getType().appendExtendedName(desc);
final MethodVisitor methodVisitor = writer.visitMethod(Modifiers.PUBLIC | Modifiers.ABSTRACT, parameter.getInternalName(), desc.toString(), null, null);
final IValue argument = parameter.getValue();
if (argument != null && argument.isAnnotationConstant()) {
final AnnotationVisitor av = methodVisitor.visitAnnotationDefault();
argument.writeAnnotationValue(av, parameter.getInternalName());
av.visitEnd();
}
methodVisitor.visitEnd();
}
}
use of dyvilx.tools.asm.MethodVisitor in project Dyvil by Dyvil.
the class AnonymousClassLMF method generateFactory.
private void generateFactory() {
MethodVisitor m = this.cw.visitMethod(PRIVATE | STATIC, NAME_FACTORY, this.invokedType.toMethodDescriptorString(), null, null);
m.visitCode();
m.visitTypeInsn(NEW, this.lambdaClassName);
m.visitInsn(Opcodes.DUP);
int parameterCount = this.parameterCount;
for (int typeIndex = 0, varIndex = 0; typeIndex < parameterCount; typeIndex++) {
Class<?> argType = this.invokedType.parameterType(typeIndex);
m.visitVarInsn(getLoadOpcode(argType), varIndex);
varIndex += getParameterSize(argType);
}
m.visitMethodInsn(INVOKESPECIAL, this.lambdaClassName, "<init>", this.constructorType.toMethodDescriptorString(), false);
m.visitInsn(ARETURN);
m.visitMaxs(-1, -1);
m.visitEnd();
}
use of dyvilx.tools.asm.MethodVisitor in project Dyvil by Dyvil.
the class AnonymousClassLMF method generateSAM.
private void generateSAM() {
MethodVisitor mv = this.cw.visitMethod(PUBLIC, this.samMethodName, this.samMethodType.toMethodDescriptorString(), null, null);
mv.visitCode();
if (this.implKind == MethodHandleInfo.REF_newInvokeSpecial) {
mv.visitTypeInsn(NEW, this.implMethodClassName);
mv.visitInsn(DUP);
}
for (int i = 0; i < this.parameterCount; i++) {
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, this.lambdaClassName, this.argNames[i], this.argDescs[i]);
}
this.convertArgumentTypes(mv, this.samMethodType);
// Invoke the method we want to forward to
mv.visitMethodInsn(invocationOpcode(this.implKind), this.implMethodClassName, this.implMethodName, this.implMethodDesc, this.implDefiningClass.isInterface());
// Convert the return value (if any) and return it
// Note: if adapting from non-void to void, the 'return'
// instruction will pop the unneeded result
Class<?> samReturnClass = this.samMethodType.returnType();
TypeConverter.convertType(mv, this.implMethodReturnClass, samReturnClass, samReturnClass);
mv.visitInsn(getReturnOpcode(samReturnClass));
// Maxs computed by ClassWriter.COMPUTE_MAXS,these arguments ignored
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
use of dyvilx.tools.asm.MethodVisitor in project Dyvil by Dyvil.
the class PropertyReferenceMetafactory method generateToString.
private void generateToString(@NonNull ClassWriter classWriter) {
MethodVisitor toString = classWriter.visitMethod(PUBLIC, "toString", "()Ljava/lang/String;", null, null);
toString.visitCode();
toString.visitLdcInsn('<' + this.refClass.getName() + ">");
toString.visitInsn(Opcodes.ARETURN);
toString.visitMaxs(-1, -1);
toString.visitEnd();
}
Aggregations