diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index d8df6cc1..d59ece82 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -16,13 +16,34 @@ public class FamilyOfGeneratedGenerics { public HashMap> posOfTPHs = new HashMap<>(); public List classConstraints = new ArrayList<>(); public List methodConstraints = new ArrayList<>(); + public HashMap> methodConstraintsWithPosition = new HashMap<>(); public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor) { this.allConstraints = tphExtractor.allCons; this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph); this.classConstraints = getClassConstraints(allConstraints,posOfTPHs); -// this.methodConstraints = + this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs); + for(MethodAndTPH method: tphExtractor.ListOfMethodsAndTph){ + List methodsAddedToHashMap = new ArrayList<>(); + String currentMethod = method.getId(); + boolean containsCurrentMethod = false; + if(!containsCurrentMethod) { + methodsAddedToHashMap.add(currentMethod); + containsCurrentMethod = true; + List listOfThisMethod = new ArrayList<>(); + HashMap> posOfTPHsForThisMethod = new HashMap<>(); + for(String s: posOfTPHs.keySet()) { + if(posOfTPHs.get(s).snd == currentMethod && posOfTPHs.get(s).snd != null) { + posOfTPHsForThisMethod.put(s,posOfTPHs.get(s)); + System.out.println(posOfTPHsForThisMethod); + } + } + listOfThisMethod = getMethodConstraints(allConstraints,classConstraints,posOfTPHsForThisMethod); + methodConstraintsWithPosition.put(currentMethod, listOfThisMethod); + System.out.println(methodConstraintsWithPosition); + } + } } public static List getClassConstraints(List cs, HashMap> posOfTphs) { //Inputparameter List constraintsSet weg diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/PairMethodAndConstraint.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/PairMethodAndConstraint.java new file mode 100644 index 00000000..c8f44ea6 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/PairMethodAndConstraint.java @@ -0,0 +1,47 @@ +package de.dhbwstuttgart.bytecode.insertGenerics; + +import java.util.Objects; + +/** A generic class for pairs. + * + *

This is NOT part of any supported API. + * If you write code that depends on this, you do so at your own risk. + * This code and its internal interfaces are subject to change or + * deletion without notice. + */ + + +public class PairMethodAndConstraint { + public final A fst; + public final B snd; + + public PairMethodAndConstraint(A fst, B snd) { + this.fst = fst; + this.snd = snd; + } + + public String toString() { + return "PairTphMethod[" + fst + "," + snd + "]"; + } + + public boolean equals(Object other) { + return + other instanceof PairMethodAndConstraint && + Objects.equals(fst, ((PairMethodAndConstraint)other).fst) && + Objects.equals(snd, ((PairMethodAndConstraint)other).snd); + } + + public int hashCode() { + if (fst == null) return (snd == null) ? 0 : snd.hashCode() + 1; + else if (snd == null) return fst.hashCode() + 2; + else return fst.hashCode() * 17 + snd.hashCode(); + } + + public static PairMethodAndConstraint of(A a, B b) { + return new PairMethodAndConstraint<>(a,b); + } + + public PairMethodAndConstraint add(A fst, B snd){ + return new PairMethodAndConstraint<>(fst,snd); + } +} diff --git a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java index 77a7d997..9d7689a0 100644 --- a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java +++ b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java @@ -114,7 +114,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { assertFalse(classConstraints.isEmpty()); assertTrue(classConstraints.size() == 6); assertFalse(methodConstraints.isEmpty()); - assertTrue(methodConstraints.size() == 5); + assertTrue(methodConstraints.size() == 2); }