package de.dhbwstuttgart.target.tree; import de.dhbwstuttgart.target.tree.expression.TargetBlock; import de.dhbwstuttgart.target.tree.type.TargetType; import org.objectweb.asm.Opcodes; import java.util.List; import java.util.Set; public record TargetMethod(int access, String name, TargetBlock block, Signature signature, Signature txSignature) { public record Signature(Set generics, List parameters, TargetType returnType) { } public static String getDescriptor(TargetType returnType, TargetType... parameters) { String ret = "("; for (var parameterType : parameters) { ret += parameterType.toSignature(); } ret += ")"; if (returnType == null) ret += "V"; else ret += returnType.toSignature(); return ret; } public static String getSignature(Set generics, List parameters, TargetType returnType) { String ret = ""; if (generics.size() > 0) { ret += "<"; for (var generic : generics) { ret += generic.name() + ":" + generic.bound().toDescriptor(); } ret += ">"; } ret += "("; for (var param : parameters) { ret += param.pattern().type().toDescriptor(); } ret += ")"; if (returnType == null) ret += "V"; else ret += returnType.toDescriptor(); return ret; } public String getDescriptor() { return getDescriptor(signature.returnType, signature.parameters.stream().map(mp -> mp.pattern().type()).toArray(TargetType[]::new)); } public String getSignature() { return getSignature(signature.generics, signature.parameters, signature.returnType); } public String getTXSignature() { return getSignature(txSignature.generics, txSignature.parameters, txSignature.returnType); } public boolean isStatic() { return (access & Opcodes.ACC_STATIC) != 0; } }