From 3b062de61270a82007b15075d696c50e36c89d56 Mon Sep 17 00:00:00 2001 From: AluAli Date: Mon, 28 Dec 2020 15:37:45 +0100 Subject: [PATCH] modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java modified: src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java modified: src/test/java/insertGenerics/TestExample42.java modified: src/test/java/insertGenerics/TestExample42_allInOneMethod.java --- .../FamilyOfGeneratedGenerics.java | 77 ++++++++++++------- .../FamilyOfGeneratedGenericsTest.java | 2 +- .../java/insertGenerics/TestExample42.java | 2 +- .../TestExample42_allInOneMethod.java | 20 ++--- 4 files changed, 62 insertions(+), 39 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index fc30ab085..cc68e6e0f 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.bytecode.insertGenerics; +import com.ibm.icu.text.CurrencyMetaInfo; import de.dhbwstuttgart.bytecode.TPHExtractor; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; @@ -47,22 +48,33 @@ public class FamilyOfGeneratedGenerics { return cs_cl; } - public static List getMethodConstraints(List cs, HashMap> posOfTphs) { + public static List getMethodConstraints(List cs, List cs_cl, HashMap> posOfTphs) { //TODO: Regeln List cs_m = new ArrayList<>(); - List methodConstraints1 = typeOfTheMethodInClSigma(cs, cs_m, posOfTphs); + List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); for (MethodConstraint cons: methodConstraints1) { if (!checkForDuplicates(cons, cs_m)) { cs_m.add(cons); } } - List methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m, posOfTphs); + List methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m); for (MethodConstraint cons: methodConstraints2) { if (!checkForDuplicates(cons, cs_m)) { cs_m.add(cons); } } - System.out.println("sdfsdf" + methodConstraints2); + List methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m); + for (MethodConstraint cons: methodConstraints3) { + if (!checkForDuplicates(cons, cs_m)) { + cs_m.add(cons); + } + } + List methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs); + for (MethodConstraint cons: methodConstraints4) { + if (!checkForDuplicates(cons, cs_m)) { + cs_m.add(cons); + } + } return cs_m; } @@ -137,21 +149,11 @@ public class FamilyOfGeneratedGenerics { return tempCC; } - public static boolean checkUpperBound(List cs, String tph) { - for(int i=0; i typeOfTheMethodInClSigma(List allConstraints, List cs_m, HashMap> posOfTphs) { // cl_\sigma?? + public static List typeOfTheMethodInClSigma(List allConstraints, HashMap> posOfTphs) { // cl_\sigma?? //TODO: List tempCC= new ArrayList<>(); for(TPHConstraint allCons: allConstraints){ @@ -170,12 +172,11 @@ public class FamilyOfGeneratedGenerics { } -/** + /** * 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 firstTransitiveSubtypeForMethodTypes(List allConstraints, List cs_m, HashMap> posOfTphs) { //transitive closure of cs + public static List firstTransitiveSubtypeForMethodTypes(List allConstraints, List cs_m) { //transitive closure of cs //TODO: List tempCC= new ArrayList<>(); List tcOfCs = buildTransitiveClosure(allConstraints); @@ -188,7 +189,6 @@ public class FamilyOfGeneratedGenerics { MethodConstraint consToAdd = new MethodConstraint(lSide, rSide, tphC.getRel()); //create (R'<.S) if (!checkForDuplicates(consToAdd, tempCC)) { tempCC.add(consToAdd); - System.out.println(consToAdd); } } } @@ -197,12 +197,11 @@ public class FamilyOfGeneratedGenerics { return tempCC; } -/** + /** * 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 secondTransitiveSubtypeForMethodTypes(List allConstraints, List cs_cl, List cs_m, HashMap> posOfTphs) { + public static List secondTransitiveSubtypeForMethodTypes(List allConstraints, List cs_cl, List cs_m) { //TODO: List tempCC= new ArrayList<>(); List tcOfCs = buildTransitiveClosure(allConstraints); @@ -212,7 +211,11 @@ public class FamilyOfGeneratedGenerics { String leftSide = cC.getLeft(); for(TPHConstraint tphC : tcOfCs) { if(tphC.getLeft().equals(leftSide)&&tphC.getRight().equals(rightSide)) { - tempCC.add((MethodConstraint) tphC); + if (!checkForDuplicates(tphC, tempCC)) { + tempCC.add((MethodConstraint) tphC); + System.out.println(tphC); + } + } } } @@ -225,10 +228,21 @@ public class FamilyOfGeneratedGenerics { * {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 hasNoSupertypeForMethodTypes() { + public static List hasNoSupertypeForMethodTypes(List allConstraints, HashMap> posOfTphs) { //TODO: - return null; + List tempCC= new ArrayList<>(); + for(TPHConstraint allCons: allConstraints) { + for(TPHConstraint allCons2: allConstraints) { + if(posOfTphs.containsKey(allCons.getRight()) && (posOfTphs.get(allCons.getRight()).fst.equals(PositionFinder.Position.METHOD) ||posOfTphs.get(allCons.getRight()).fst.equals(PositionFinder.Position.CONSTRUCTOR)) && allCons.getRight()!=allCons2.getLeft()) { + MethodConstraint consToAdd = new MethodConstraint(allCons.getRight(), "Object", Relation.EXTENDS); + if (!checkForDuplicates(consToAdd, tempCC)) { + tempCC.add(consToAdd); + System.out.println(consToAdd); + } + } + } + } + return tempCC; } /** @@ -274,6 +288,15 @@ public class FamilyOfGeneratedGenerics { return tcList; } + public static boolean checkUpperBound(List cs, String tph) { + for(int i=0; i> positionConverter(HashMap allTphs, List listOfMethodsAndTphs) { HashMap> convertedPositions = new HashMap<>(); diff --git a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java index cb3f68403..ea7bcfd50 100644 --- a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java +++ b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java @@ -32,7 +32,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase { /* MethodConstraints should be the same as the input constraint */ - List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, tphPositions); + List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList(), tphPositions); assertTrue(methodConstraints.size() == 1); assertTrue(methodConstraints.get(0).getLeft().equals("B")); assertTrue(methodConstraints.get(0).getRight().equals("A")); diff --git a/src/test/java/insertGenerics/TestExample42.java b/src/test/java/insertGenerics/TestExample42.java index f8f059568..911c2b5ab 100644 --- a/src/test/java/insertGenerics/TestExample42.java +++ b/src/test/java/insertGenerics/TestExample42.java @@ -53,7 +53,7 @@ public class TestExample42 { public void genericTest() { List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); System.out.println("ClassConstraints: " + classConstraints); - List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),fillPosOfTphs()); + List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs()); System.out.println("MethodConstraints: " + methodConstraints); List testCons; diff --git a/src/test/java/insertGenerics/TestExample42_allInOneMethod.java b/src/test/java/insertGenerics/TestExample42_allInOneMethod.java index 6da2c0d80..d5783edae 100644 --- a/src/test/java/insertGenerics/TestExample42_allInOneMethod.java +++ b/src/test/java/insertGenerics/TestExample42_allInOneMethod.java @@ -25,15 +25,15 @@ public class TestExample42_allInOneMethod { HashMap> posOfTphs = new HashMap<>(); PairTphMethod posOfK = new PairTphMethod<>(PositionFinder.Position.FIELD, null); - PairTphMethod posOfL = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); - PairTphMethod posOfM = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); - PairTphMethod posOfN = new PairTphMethod<>(PositionFinder.Position.METHOD, "id"); - PairTphMethod posOfP = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA"); - PairTphMethod posOfQ = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA"); - PairTphMethod posOfU = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); - PairTphMethod posOfV = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); - PairTphMethod posOfW = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); - PairTphMethod posOfZ = new PairTphMethod<>(PositionFinder.Position.METHOD, "m"); + PairTphMethod posOfL = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); + PairTphMethod posOfM = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); + PairTphMethod posOfN = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); + PairTphMethod posOfP = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); + PairTphMethod posOfQ = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); + PairTphMethod posOfU = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); + PairTphMethod posOfV = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); + PairTphMethod posOfW = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); + PairTphMethod posOfZ = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod"); posOfTphs.put("K", posOfK); posOfTphs.put("L", posOfL); @@ -52,7 +52,7 @@ public class TestExample42_allInOneMethod { public void genericTest() { List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); System.out.println("ClassConstraints: " + classConstraints); - List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),fillPosOfTphs()); + List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs()); System.out.println("MethodConstraints: " + methodConstraints); List testCons;