modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java

modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/PositionFinder.java
	modified:   src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java
	modified:   src/test/java/insertGenerics/TestExample42.java
This commit is contained in:
AluAli 2020-12-04 14:25:37 +01:00
parent f7101da621
commit d06c6abb5a
5 changed files with 48 additions and 25 deletions

View File

@ -136,7 +136,6 @@ public class GeneratedGenericsFinder implements ASTVisitor {
//PL 2020-10-16: Ab hier GGenerics implementieren durch Ali
//Rueckgabe an generatedGenericsForSF
fogg = new FamilyOfGeneratedGenerics(tphExtractor);
// fogg.getClassConstraints();
tphsClass = tphExtractor.tphsClass;
simplifiedConstraints = GenericsGenerator.simplifyConstraints(tphExtractor, tphsClass);

View File

@ -12,13 +12,15 @@ import java.util.List;
public class FamilyOfGeneratedGenerics {
public List<TPHConstraint> allConstraints = new ArrayList<>();
public HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTPHs = new HashMap<>();
public List<ClassConstraint> classConstraints = new ArrayList<>();
public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor) {
this.allConstraints = tphExtractor.allCons;
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
}
public static List<ClassConstraint> getClassConstraints(List<TPHConstraint> cs, HashMap<String, PositionFinder.Position> 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
List<ClassConstraint> cs_cl = new ArrayList<>();
List<ClassConstraint> classConstraints1 = typeOfANodeOfAField(cs, posOfTphs);
for (ClassConstraint cons: classConstraints1) {
@ -41,7 +43,7 @@ public class FamilyOfGeneratedGenerics {
return cs_cl;
}
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, HashMap<String, PositionFinder.Position> posOfTphs) {
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
//TODO: Regeln
List<MethodConstraint> cs_m = new ArrayList<>();
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, cs_m, posOfTphs);
@ -58,13 +60,13 @@ public class FamilyOfGeneratedGenerics {
* Def. FGG: erste Zeile von cs_cl
* {T < .T' | T is a type variable in a type of a node of a field}
*/
public static List<ClassConstraint> typeOfANodeOfAField(List<TPHConstraint> allConstraints, HashMap<String, PositionFinder.Position> posOfTphs) {
public static List<ClassConstraint> typeOfANodeOfAField(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
//RuntimeException re = new RuntimeException("enthält EQUALS-Relation");
List<ClassConstraint> 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.FIELD) {
if(tph == allCons.getLeft() && posOfTphs.get(tph).fst == PositionFinder.Position.FIELD) {
ClassConstraint consToAdd = new ClassConstraint(tph, allCons.getRight(), allCons.getRel());
if (!checkForDuplicates(consToAdd, tempCC)) {
tempCC.add(consToAdd);
@ -105,12 +107,12 @@ public class FamilyOfGeneratedGenerics {
* {T <. Object | ((T is a type variable in a type of a node of a field
* 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) {
public static List<ClassConstraint> hasNoSupertypeForClassTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
List<ClassConstraint> tempCC= new ArrayList<>();
for(TPHConstraint allCons: allConstraints) {
for(ClassConstraint cCons: cs_cl) {
for(String tph: posOfTphs.keySet()) {
boolean tvInField = posOfTphs.get(tph) == PositionFinder.Position.FIELD;
boolean tvInField = posOfTphs.get(tph).fst == PositionFinder.Position.FIELD;
boolean hasSmallerTVInClCons = (posOfTphs.containsKey(cCons.getRight()) && cCons.getRight() == tph && cCons.getLeft() != null);
if( ((tvInField || hasSmallerTVInClCons) && cCons.getRel()==Relation.EXTENDS) &&
checkUpperBound(allConstraints, tph) && allCons.getRel()==Relation.EXTENDS) {
@ -139,13 +141,13 @@ public class FamilyOfGeneratedGenerics {
* {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(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m, HashMap<String, PositionFinder.Position> posOfTphs) { // cl_\sigma??
public static List<MethodConstraint> typeOfTheMethodInClSigma(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { // cl_\sigma??
//TODO:
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)) {
if(tph == allCons.getLeft() && (posOfTphs.get(tph).fst == PositionFinder.Position.METHOD || posOfTphs.get(tph).fst == PositionFinder.Position.CONSTRUCTOR)) {
MethodConstraint consToAdd = new MethodConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel());
if (!checkForDuplicates(consToAdd, tempCC)) {
tempCC.add(consToAdd);

View File

@ -10,6 +10,7 @@ public class PositionFinder{
static HashMap<String, PairTphMethod<Position, String>> posOfTphs = new HashMap<String, PairTphMethod<Position, String>>();
static PairTphMethod<Position, String> whichMethod; // gibt an, in welcher Methode sich TPH befindet (Position.METHOD, id_of_method)
public enum Position{
METHOD,
CONSTRUCTOR,

View File

@ -3,6 +3,7 @@ package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.*;
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import junit.framework.TestCase;
import java.util.ArrayList;
@ -11,26 +12,31 @@ import java.util.List;
public class FamilyOfGeneratedGenericsTest extends TestCase {
/*
public void testIdentityMethod(){
/*
*/
/*
Example method:
A id(B i) return i;
gives constraint: B <. A, which is a method constraint
*/
*//*
List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("B", "A", TPHConstraint.Relation.EXTENDS));
HashMap<String, PositionFinder.Position> tphPositions = new HashMap<>();
HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>();
tphPositions.put("A", PositionFinder.Position.METHOD);
tphPositions.put("B", PositionFinder.Position.METHOD);
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
assertTrue(classConstraints.isEmpty());
/*
*/
/*
MethodConstraints should be the same as the input constraint
*/
*//*
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, tphPositions);
assertTrue(methodConstraints.size() == 1);
assertTrue(methodConstraints.get(0).getLeft().equals("B"));
@ -38,7 +44,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
}
public void testClassField(){
/*
*/
/*
class Example{
A f;
B fReturn(){
@ -46,18 +53,21 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
}
}
gives constraint: A <. B, which is a class constraint
*/
*//*
List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
HashMap<String, PositionFinder.Position> tphPositions = new HashMap<>();
HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>();
tphPositions.put("A", PositionFinder.Position.FIELD);
tphPositions.put("B", PositionFinder.Position.METHOD);
/*
*/
/*
ClassConstraints should not be the same as the input constraint
*/
*//*
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
System.out.println(classConstraints);
assertTrue(classConstraints.size() == 2);
@ -66,7 +76,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
}
public void testSecondLineOfClassConstraints() {
/*
*/
/*
class Example() {
A a;
B b = a;
@ -80,7 +91,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
return e;
}
}
*/
*//*
List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
@ -89,7 +101,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
inputConstraints.add(new TPHConstraint("A", "E", TPHConstraint.Relation.EXTENDS));
inputConstraints.add(new TPHConstraint("E", "D", TPHConstraint.Relation.EXTENDS));
HashMap<String, PositionFinder.Position> tphPositions = new HashMap<>();
HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>();
tphPositions.put("A", PositionFinder.Position.FIELD);
tphPositions.put("B", PositionFinder.Position.FIELD);
tphPositions.put("C", PositionFinder.Position.METHOD);
@ -105,7 +117,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
}
public void testTPHsAndGenerics() {
/*
*/
/*
class TPHsAndGenerics {
Fun1<A,B> id = x -> x;
C id2 (D x) {
@ -119,7 +132,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
return b;
}
}
*/
*//*
List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("A","B", TPHConstraint.Relation.EXTENDS));
@ -130,7 +144,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
inputConstraints.add(new TPHConstraint("G","J", TPHConstraint.Relation.EXTENDS));
inputConstraints.add(new TPHConstraint("J","H", TPHConstraint.Relation.EXTENDS));
HashMap<String, PositionFinder.Position> tphPositions = new HashMap<>();
HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>();
tphPositions.put("A", PositionFinder.Position.FIELD);
tphPositions.put("B", PositionFinder.Position.FIELD);
tphPositions.put("C", PositionFinder.Position.METHOD);
@ -148,6 +162,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
assertFalse(classConstraints.isEmpty());
assertTrue(classConstraints.size() == 3);
}
*/
public void testPositionConverter() {
@ -155,8 +170,12 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
List<MethodAndTPH> listOfMethodsAndTphs = new ArrayList<>();
allTphsOld.put("A", true);
allTphsOld.put("B", false);
MethodAndTPH m1 = new MethodAndTPH("m1");
listOfMethodsAndTphs.add(new MethodAndTPH("bla"));
listOfMethodsAndTphs.add(new MethodAndTPH("blubb"));
listOfMethodsAndTphs.add(m1);

View File

@ -1,3 +1,4 @@
/*
package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
@ -50,3 +51,4 @@ public class TestExample42 {
List<TPHConstraint> testCons;
}
}
*/