modified: src/main/java/de/dhbwstuttgart/bytecode/gGenericsAli/FamilyOfGeneratedGenerics.java

modified:   src/test/java/insertGenerics/TestExample42.java
	new file:   src/test/java/insertGenerics/TestTransitiveClosure.java
This commit is contained in:
AluAli 2020-11-06 15:22:36 +01:00
parent e617a0911a
commit 70b6c35731
3 changed files with 97 additions and 25 deletions

View File

@ -36,14 +36,17 @@ public class FamilyOfGeneratedGenerics {
return cs_cl;
}
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> constraintsSet) {
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, HashMap<String, PositionFinder.Position> posOfTphs) {
//TODO: Regeln
List<MethodConstraint> cs_m = new ArrayList<>();
// for(TPHConstraint cons: constraintsSet){
//
// cs_m =
// }
return null;
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, cs_m, posOfTphs);
for (MethodConstraint cons: methodConstraints1) {
if (!checkForDuplicates(cons, cs_m)) {
cs_m.add(cons);
}
}
List<MethodConstraint> methodConstraints2 = firstTransitiveSubtypeForMethodTypes();
return cs_m;
}
/**
@ -72,7 +75,6 @@ public class FamilyOfGeneratedGenerics {
* {T' <. T'' | \exists T: (T <. T') \in cs_cl, (T' <. T'') \in cs }
*/
public static List<ClassConstraint> transitiveSubtypeForClassTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl) {
//TODO:
List<ClassConstraint> tempCC= new ArrayList<>();
for(ClassConstraint cCons: cs_cl) {
if(cCons.getLeft() != null && cCons.getRel()==Relation.EXTENDS) {
@ -95,7 +97,6 @@ public class FamilyOfGeneratedGenerics {
* or (\exists T~: (T~ <. T) \in cs_cl)) and (\existsnot T': T <. T') \in cs)}
*/
public static List<ClassConstraint> hasNoSupertypeForClassTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, HashMap<String, PositionFinder.Position> posOfTphs) {
//TODO:
List<ClassConstraint> tempCC= new ArrayList<>();
for(TPHConstraint allCons: allConstraints) {
for(ClassConstraint cCons: cs_cl) {
@ -122,57 +123,65 @@ public class FamilyOfGeneratedGenerics {
/**
* Def. FGG: erste Zeile von cs_m
* {T < .T' | T is a type variable in a type of the method/constructor m in cl_\sigma, (T <. T') \in cs}
*//*
*/
public static List<MethodConstraint> typeOfTheMethodInClSigma() { // cl_\sigma??
public static List<MethodConstraint> typeOfTheMethodInClSigma(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m, HashMap<String, PositionFinder.Position> posOfTphs) { // cl_\sigma??
//TODO:
return cs_m;
List<MethodConstraint> tempCC= new ArrayList<>();
for(TPHConstraint allCons: allConstraints){
if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) {
for(String tph: posOfTphs.keySet()) {
if(tph == allCons.getLeft() && (posOfTphs.get(tph) == PositionFinder.Position.METHOD || posOfTphs.get(tph) == PositionFinder.Position.CONSTRUCTOR)) {
MethodConstraint consToAdd = new MethodConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel());
if (!checkForDuplicates(consToAdd, tempCC)) {
tempCC.add(consToAdd);
}
}
}
}
}
return tempCC;
}
*/
/**
* Def. FGG: zweite Zeile von cs_m
* {R' <. S | (R <. R'), (S <. S') \in cs_m and (R',S) is in the transitive closure of cs}
*//*
*/
public static List<MethodConstraint> firstTransitiveSubtypeForMethodTypes() { //transitive closure of cs
//TODO:
return cs_m;
return null;
}
*/
/**
* Def. FGG: dritte Zeile von cs_m
* {R' <. S | (R <. R') \in cs_m, (S <. S') \in cs_cl and (R',S) is in the transitive closure of cs}
*//*
*/
public static List<MethodConstraint> secondTransitiveSubtypeForMethodTypes() {
//TODO:
return cs_m;
return null;
}
*/
/**
* Def. FGG: vierte Zeile von cs_m
* {T <. Object | (T is a type variable in a type of a node of the method/constructor m in cl_\sigma),
* (\existsnot T': T <. T') \in cs)}
*//*
*/
public static List<MethodConstraint> hasNoSupertypeForMethodTypes() {
//TODO:
return cs_m;
return null;
}
*/
/**
* nimm die Menge cs_cl aus cs_m raus
*/
/*
public static List<MethodConstraint> methodTypesWithoutClassTypes() {
//TODO:
return cs_m;
return null;
}
*/
public static boolean checkForDuplicates(TPHConstraint constraint, List list) {
List<TPHConstraint> tempList = list;
@ -184,6 +193,32 @@ public class FamilyOfGeneratedGenerics {
return false;
}
public static List<TPHConstraint> buildTransitiveClosure(List list) {
List<TPHConstraint> iterList = list;
List<TPHConstraint> runList = list;
List<TPHConstraint> tcList = new ArrayList<>();
boolean addedConToList = false;
for (TPHConstraint cons: iterList) {
for (TPHConstraint cons2: runList) {
if(cons.getRight() == cons2.getLeft()) {
for (TPHConstraint tcCons: tcList) {
if (!checkForDuplicates(tcCons,tcList)) {
tcList.add(new TPHConstraint(cons.getLeft(), cons2.getRight(), Relation.EXTENDS)); //Duplikate? dürfte nicht sein -> checken
addedConToList = true;
if (addedConToList) {
list.add(new TPHConstraint(cons.getLeft(), cons2.getRight(), Relation.EXTENDS));
buildTransitiveClosure(list);
}
}
//TODO: über aktualisierte Liste laufen wegen Updates -> Rekursion?
}
}
}
}
return tcList;
}

View File

@ -4,6 +4,7 @@ import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.gGenericsAli.ClassConstraint;
import de.dhbwstuttgart.bytecode.gGenericsAli.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.gGenericsAli.MethodConstraint;
import de.dhbwstuttgart.bytecode.gGenericsAli.PositionFinder;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@ -42,6 +43,10 @@ public class TestExample42 {
@Test
public void genericTest() {
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
System.out.println(classConstraints);
System.out.println("ClassConstraints: " + classConstraints);
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),fillPosOfTphs());
System.out.println("MethodConstraints: " + methodConstraints);
List<TPHConstraint> testCons;
}
}

View File

@ -0,0 +1,32 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.gGenericsAli.ClassConstraint;
import de.dhbwstuttgart.bytecode.gGenericsAli.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.gGenericsAli.MethodConstraint;
import de.dhbwstuttgart.bytecode.gGenericsAli.PositionFinder;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class TestTransitiveClosure {
public List<TPHConstraint> fillList() {
List<TPHConstraint> list = new ArrayList<>();
list.add(new TPHConstraint("A", "B", Relation.EXTENDS));
list.add(new TPHConstraint("B", "C", Relation.EXTENDS));
list.add(new TPHConstraint("C", "D", Relation.EXTENDS));
return list;
}
@Test
public void genericTest() {
List<TPHConstraint> testCons = FamilyOfGeneratedGenerics.buildTransitiveClosure(fillList());
System.out.println(testCons);
}
}