From 23eab0c9a4af07e9251942b59e19d11e8047508f Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Tue, 19 Jun 2018 14:56:22 +0200 Subject: [PATCH] TPHs, die nicht in ParameterListe der Methode vorkommen, werden in Signature geschrieben --- .../dhbwstuttgart/bytecode/BytecodeGen.java | 10 ++++--- .../bytecode/signature/Signature.java | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java index 0d467b77..69acdefc 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java @@ -283,12 +283,16 @@ public class BytecodeGen implements ASTVisitor { break; } } - + HashMap subAndSuperTph = new HashMap<>(); for(GenericInsertPair p : allPairs) { + // Tph2.jav + if(subAndSuperTph.containsKey(p.TA1)) { + if(methodTphs.contains(subAndSuperTph.get(p.TA1))) + continue; + } subAndSuperTph.put(p.TA1, p.TA2); } - int numOfVisitedPairs = 0; for(TypePlaceholder subTph: subAndSuperTph.keySet()) { @@ -320,7 +324,6 @@ public class BytecodeGen implements ASTVisitor { TypePlaceholder subTphRes = tphsInRel.get(0); // Die größte Supertype TypePlaceholder superTphRes = tphsInRel.get(tphsInRel.size()-1); - int i = 2; while(!methodTphs.contains(superTphRes) && (tphsInRel.size()-i) >0) { superTphRes = tphsInRel.get(tphsInRel.size()-i); @@ -330,7 +333,6 @@ public class BytecodeGen implements ASTVisitor { GenericInsertPair sPair = new GenericInsertPair(subTphRes, superTphRes); simplifiedPairs.add(sPair); } - return simplifiedPairs; } diff --git a/src/de/dhbwstuttgart/bytecode/signature/Signature.java b/src/de/dhbwstuttgart/bytecode/signature/Signature.java index 2860cc83..7b222770 100644 --- a/src/de/dhbwstuttgart/bytecode/signature/Signature.java +++ b/src/de/dhbwstuttgart/bytecode/signature/Signature.java @@ -147,6 +147,33 @@ public class Signature { } } + for(GenericInsertPair p:methodPairs) { + String name = p.TA1.getName()+"$"; + if(!genericsAndBoundsMethod.containsKey(name)) { + sw.visitFormalTypeParameter(name); + sw.visitClassBound().visitTypeVariable(p.TA2.getName()+"$"); + genericsAndBoundsMethod.put(name, p.TA2.getName()+"$"); + } + } + + ArrayList types = new ArrayList<>(); + ArrayList superTypes = new ArrayList<>(); + + for(GenericInsertPair p : methodPairs) { + types.add(p.TA1); + superTypes.add(p.TA2); + } + + for(GenericInsertPair p : methodPairs) { + String name = p.TA2.getName()+"$"; + if(!types.contains(p.TA2) && !genericsAndBoundsMethod.containsKey(name)) { + String bound = Type.getInternalName(Object.class); + sw.visitFormalTypeParameter(name); + sw.visitClassBound().visitClassType(bound); + genericsAndBoundsMethod.put(name, bound); + sw.visitClassBound().visitEnd(); + } + } } // visit each method-parameter to create the signature