Verbesserung FunNGenerator:

Generics werden nicht mehr mehrfach hinzugefügt.
TPHS werden im Klassenname als LTPH angegeben, so entsteht keine Uneindeutigkeit zu Klassen mit Object (ohne TPH) im Klassenname.
This commit is contained in:
Etienne Zink 2022-03-29 19:19:31 +02:00
parent c65102d89a
commit eebb07ec8b
3 changed files with 19 additions and 18 deletions

View File

@ -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<RefTypeOrTPHOrWildcardOrGeneric> 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('/', '$')

View File

@ -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;

View File

@ -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;