modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
new file: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/PairMethodAndConstraint.java modified: src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java
This commit is contained in:
parent
2f37bb7313
commit
dce7ac8262
@ -16,13 +16,34 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
public HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTPHs = new HashMap<>();
|
public HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTPHs = new HashMap<>();
|
||||||
public List<ClassConstraint> classConstraints = new ArrayList<>();
|
public List<ClassConstraint> classConstraints = new ArrayList<>();
|
||||||
public List<MethodConstraint> methodConstraints = new ArrayList<>();
|
public List<MethodConstraint> methodConstraints = new ArrayList<>();
|
||||||
|
public HashMap<String, List<MethodConstraint>> methodConstraintsWithPosition = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor) {
|
public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor) {
|
||||||
this.allConstraints = tphExtractor.allCons;
|
this.allConstraints = tphExtractor.allCons;
|
||||||
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
|
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
|
||||||
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
|
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
|
||||||
// this.methodConstraints =
|
this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs);
|
||||||
|
for(MethodAndTPH method: tphExtractor.ListOfMethodsAndTph){
|
||||||
|
List<String> methodsAddedToHashMap = new ArrayList<>();
|
||||||
|
String currentMethod = method.getId();
|
||||||
|
boolean containsCurrentMethod = false;
|
||||||
|
if(!containsCurrentMethod) {
|
||||||
|
methodsAddedToHashMap.add(currentMethod);
|
||||||
|
containsCurrentMethod = true;
|
||||||
|
List<MethodConstraint> listOfThisMethod = new ArrayList<>();
|
||||||
|
HashMap<String, PairTphMethod<PositionFinder.Position, String>> 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<ClassConstraint> getClassConstraints(List<TPHConstraint> cs, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { //Inputparameter List<TPHConstraint> constraintsSet weg
|
public static List<ClassConstraint> getClassConstraints(List<TPHConstraint> cs, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { //Inputparameter List<TPHConstraint> constraintsSet weg
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode.insertGenerics;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/** A generic class for pairs.
|
||||||
|
*
|
||||||
|
* <p><b>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.</b>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public class PairMethodAndConstraint<A, B> {
|
||||||
|
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 <A,B> PairMethodAndConstraint<A,B> of(A a, B b) {
|
||||||
|
return new PairMethodAndConstraint<>(a,b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PairMethodAndConstraint add(A fst, B snd){
|
||||||
|
return new PairMethodAndConstraint<>(fst,snd);
|
||||||
|
}
|
||||||
|
}
|
@ -114,7 +114,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
|
|||||||
assertFalse(classConstraints.isEmpty());
|
assertFalse(classConstraints.isEmpty());
|
||||||
assertTrue(classConstraints.size() == 6);
|
assertTrue(classConstraints.size() == 6);
|
||||||
assertFalse(methodConstraints.isEmpty());
|
assertFalse(methodConstraints.isEmpty());
|
||||||
assertTrue(methodConstraints.size() == 5);
|
assertTrue(methodConstraints.size() == 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user