diff --git a/src/main/java/de/dhbwstuttgart/bytecode/funN/FunNGenerator.java b/src/main/java/de/dhbwstuttgart/bytecode/funN/FunNGenerator.java index 5b6a9e442..3a651c938 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/funN/FunNGenerator.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/funN/FunNGenerator.java @@ -39,13 +39,13 @@ public class FunNGenerator implements FunNUtilities{ private final String methodName = "apply"; private final int bytecodeVersion = V1_8; - private static final String objectSuperType = Type.getInternalName(Object.class).replace('.','/'); - private static final RefType objectRefType = new RefType(new JavaClassName(objectSuperType), null); - private static final String objectSignature = applySignature(objectRefType); + private final String objectSuperType = Type.getInternalName(Object.class).replace('.','/'); + private final RefType objectRefType = new RefType(new JavaClassName(objectSuperType), null); + private final String objectSignature = applySignature(objectRefType); - private static String applyDescriptor(RefTypeOrTPHOrWildcardOrGeneric a) { return a.acceptTV(new TypeToDescriptor(true)); } - private static String applySignature(RefTypeOrTPHOrWildcardOrGeneric a) { return a.acceptTV(new TypeToSignature(true)); } - private static String applyNameDescriptor(RefTypeOrTPHOrWildcardOrGeneric a){ return a instanceof TypePlaceholder ? applyNameDescriptor(objectRefType) : String.format("L%s;", applyDescriptor(a)); } + private String applyDescriptor(RefTypeOrTPHOrWildcardOrGeneric a) { return a.acceptTV(new TypeToDescriptor(true)); } + private String applySignature(RefTypeOrTPHOrWildcardOrGeneric a) { return a.acceptTV(new TypeToSignature(true)); } + private String applyNameDescriptor(RefTypeOrTPHOrWildcardOrGeneric a){ return a instanceof TypePlaceholder ? "LTPH;" : String.format("L%s;", applyDescriptor(a)); } @Override public byte[] generateSuperBytecode(int numberArguments) { @@ -86,14 +86,16 @@ public class FunNGenerator implements FunNUtilities{ boolean containsGeneric = false; String genericSignature = "<"; - for (int currentTypArgumentIndex = 0; currentTypArgumentIndex < argumentTypes.size(); currentTypArgumentIndex++) { - RefTypeOrTPHOrWildcardOrGeneric typArgument = argumentTypes.get(currentTypArgumentIndex); - if (typArgument instanceof GenericRefType){ - GenericRefType generic = (GenericRefType) typArgument; + for (RefTypeOrTPHOrWildcardOrGeneric typeArgument : parameters) { + //ToDo Etienne: Refactor + if (typeArgument instanceof GenericRefType){ + GenericRefType generic = (GenericRefType) typeArgument; + if(genericSignature.contains(generic.getParsedName())) continue; genericSignature += String.format("%s:%s", generic.getParsedName(), applyDescriptor(generic)); containsGeneric = true; - } else if(typArgument instanceof TypePlaceholder){ - TypePlaceholder placeholder = (TypePlaceholder) typArgument; + } else if(typeArgument instanceof TypePlaceholder){ + TypePlaceholder placeholder = (TypePlaceholder) typeArgument; + if(genericSignature.contains(applySignature(placeholder).substring(1))) continue; genericSignature += String.format("%s:%s", applySignature(placeholder).substring(1), objectSignature); containsGeneric = true; } @@ -109,12 +111,11 @@ public class FunNGenerator implements FunNUtilities{ @Override public String getSpecializedClassName(List argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType) { - if (returnType instanceof TypePlaceholder) returnType = objectRefType; return String.format("Fun%d$$%s%s", argumentTypes.size(), argumentTypes .stream() - .map(FunNGenerator::applyNameDescriptor) + .map(this::applyNameDescriptor) .collect(Collectors.joining()), applyNameDescriptor(returnType)) .replace('/', '$') diff --git a/src/test/resources/bytecode/javFiles/OLFun.jav b/src/test/resources/bytecode/javFiles/OLFun.jav index 4896f948f..adf8c6a85 100644 --- a/src/test/resources/bytecode/javFiles/OLFun.jav +++ b/src/test/resources/bytecode/javFiles/OLFun.jav @@ -1,6 +1,6 @@ import java.lang.String; -//import java.lang.Integer; -//import java.lang.Double; +import java.lang.Integer; +import java.lang.Double; import java.util.Vector; import java.lang.Boolean; diff --git a/src/test/resources/bytecode/javFiles/OLFun2.jav b/src/test/resources/bytecode/javFiles/OLFun2.jav index fd57e1841..406c0d98d 100644 --- a/src/test/resources/bytecode/javFiles/OLFun2.jav +++ b/src/test/resources/bytecode/javFiles/OLFun2.jav @@ -1,6 +1,6 @@ import java.lang.String; -//import java.lang.Integer; -//import java.lang.Double; +import java.lang.Integer; +import java.lang.Double; import java.util.Vector; import java.lang.Boolean;