Verbesserung der Methode generateSuperFunNInterface in ByteCodeForFunNGenerator und Kommentare.

This commit is contained in:
Etienne Zink 2022-03-16 16:04:03 +01:00
parent 59d50bd2c6
commit ac6980b5e0
2 changed files with 7 additions and 6 deletions

View File

@ -99,22 +99,22 @@ public class ByteCodeForFunNGenerator {
*/
public static boolean generateSuperFunNInterface(int numberOfParameters, File path){
if(alreadyGeneratedFunN.contains(numberOfParameters)) return true;
//ToDo Etienne: Generierung der Signaturen/Deskriptoren vielleicht auslagern?
//ToDo Etienne: Generierung der Signaturen/Deskriptoren vielleicht auslagern? Bzw. schauen ob nicht schon vorhanden und anpassen!
String className = String.format("Fun%d$$", numberOfParameters);
String classSignature = "<";
String methodSignature = "(";
String methodDescriptor = "(";
for (int parameter = 1; parameter <= numberOfParameters; parameter++) {
classSignature += String.format("T%d:Ljava/lang/Object;", parameter);
classSignature += String.format("T%d:L%s;", parameter, Type.getInternalName(Object.class));
methodSignature += String.format("TT%d;", parameter);
methodDescriptor += "Ljava/lang/Object;";
methodDescriptor += String.format("L%s;", Type.getInternalName(Object.class));
}
classSignature += "R:Ljava/lang/Object;>Ljava/lang/Object;";
classSignature += String.format("R:L%s;>L%s;",Type.getInternalName(Object.class),Type.getInternalName(Object.class));
methodSignature += ")TR;";
methodDescriptor += ")Ljava/lang/Object;";
methodDescriptor += String.format(")L%s;",Type.getInternalName(Object.class));
ClassWriter classWriter = new ClassWriter(0);
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, className, classSignature, "java/lang/Object", null);
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, className, classSignature, Type.getInternalName(Object.class), null);
MethodVisitor methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, "apply", methodDescriptor, methodSignature, null);
methodVisitor.visitEnd();

View File

@ -225,6 +225,7 @@ public class MethodCallHelper {
ByteCodeForFunNGenerator.generateBCForFunN(methCall.arglist,methodDescriptor,path);
}
//ToDo Etienne: Für Type Erasure wichtig
public String getDescriptorOfApplyMethod(String methodCallType) {
return new DescriptorToString().createDescForFunN(methCall.arglist, methodCallType);
}