forked from JavaTX/JavaCompilerCore
Generics werden in Signature richtig dargestellt und die passende
Deskriptoren werden richtig erzeugt
This commit is contained in:
parent
d4a59517d3
commit
6a2a8313e6
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.bytecode.descriptor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
@ -44,17 +45,28 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
if(method.hasGen()) {
|
||||
String fpDesc = fp.getType().acceptTV(new TypeToDescriptor());
|
||||
if(method.getGenericsAndBoundsMethod().containsKey(fpDesc)) {
|
||||
desc += "L"+method.getGenericsAndBoundsMethod().get(fpDesc)+ ";";
|
||||
String bound = getBound(fpDesc, method.getGenericsAndBoundsMethod());
|
||||
desc += "L"+bound+ ";";
|
||||
}else if(method.getGenericsAndBounds().containsKey(fpDesc)){
|
||||
desc += "L"+method.getGenericsAndBounds().get(fpDesc)+ ";";
|
||||
String bound = getBound(fpDesc, method.getGenericsAndBounds());
|
||||
desc += "L"+bound+ ";";
|
||||
}else {
|
||||
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
if(resType.subSequence(0, 4).equals("TPH ")) {
|
||||
if(resType.contains("TPH ")/*resType.subSequence(0, 4).equals("TPH ")*/) {
|
||||
// Bound ist immer Object
|
||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||
} else {
|
||||
desc += "L"+resType+ ";";
|
||||
// TODO::
|
||||
if(method.getGenericsAndBounds().containsKey(resType)) {
|
||||
String bound = getBound(resType, method.getGenericsAndBounds());
|
||||
desc += "L"+bound+ ";";
|
||||
}else if(method.getGenericsAndBoundsMethod().containsKey(resType)) {
|
||||
String bound = getBound(resType, method.getGenericsAndBoundsMethod());
|
||||
desc += "L"+bound+ ";";
|
||||
} else {
|
||||
desc += "L"+resType+ ";";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,11 +90,21 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
desc += ")L"+method.getGenericsAndBounds().get(ret)+ ";";
|
||||
}else {
|
||||
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
if(resType.subSequence(0, 4).equals("TPH ")) {
|
||||
if(resType.contains("TPH ")/*resType.subSequence(0, 4).equals("TPH ")*/) {
|
||||
// desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
|
||||
desc += ")" + "L"+Type.getInternalName(Object.class)+ ";";
|
||||
} else {
|
||||
desc += ")" + "L"+resType+ ";";
|
||||
// TODO::
|
||||
if(method.getGenericsAndBounds().containsKey(resType)) {
|
||||
String bound = getBound(resType, method.getGenericsAndBounds());
|
||||
desc += ")L"+bound+ ";";
|
||||
}else if(method.getGenericsAndBoundsMethod().containsKey(resType)) {
|
||||
String bound = getBound(resType, method.getGenericsAndBoundsMethod());
|
||||
desc += ")L"+bound+ ";";
|
||||
} else {
|
||||
desc += ")L"+resType+ ";";
|
||||
}
|
||||
// desc += ")" + "L"+resType+ ";";
|
||||
}
|
||||
}
|
||||
}else {
|
||||
@ -93,6 +115,15 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
return desc;
|
||||
}
|
||||
|
||||
private String getBound(String fpDesc, HashMap<String, String> genericsAndBounds) {
|
||||
String start = genericsAndBounds.get(fpDesc);
|
||||
while(genericsAndBounds.containsKey(start)) {
|
||||
start = genericsAndBounds.get(start);
|
||||
}
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(NormalConstructor constructor) {
|
||||
String desc = "(";
|
||||
|
@ -290,7 +290,8 @@ public class Signature {
|
||||
break;
|
||||
case "GRT":
|
||||
GenericRefType g = (GenericRefType) t;
|
||||
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()).substring(1));
|
||||
// sv.visitTypeVariable(g.acceptTV(new TypeToSignature()).substring(1));
|
||||
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()));
|
||||
break;
|
||||
case "TPH":
|
||||
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
|
||||
@ -307,7 +308,16 @@ public class Signature {
|
||||
System.out.println(" Signature FUN$$: "+r);
|
||||
sv.visitInterface().visitClassType(sig2.substring(1, sig2.length()));
|
||||
} else {
|
||||
sv.visitClassType(sig2.substring(1, sig2.length()));
|
||||
// Kann zwischen GenericRefType und RefType nicht unterscheiden
|
||||
// Deswegen wird immer geprüft, ob der Name in Generic Maps liegt
|
||||
String n = sig2.substring(1, sig2.length()-1);
|
||||
if(genericsAndBoundsMethod.containsKey(n) || genericsAndBounds.containsKey(n)) {
|
||||
sv.visitTypeVariable(n);
|
||||
} else {
|
||||
sv.visitClassType(n);
|
||||
sv.visitEnd();
|
||||
}
|
||||
// sv.visitClassType(n);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user