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

Tests insertGenerics funtionieren
	modified:   src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java
reset-Funktion eingefuegt, damit bei jedem Test die Namen der TypepLaceholdert von vorne beginnen

	modified:   src/test/java/insertGenerics/TestContraVariant.java
	modified:   src/test/java/insertGenerics/TestTPHsAndGenerics.java
	modified:   src/test/java/insertGenerics/TestThreeArgs.java
This commit is contained in:
pl@gohorb.ba-horb.de 2021-04-01 16:59:14 +02:00
parent 9be64e4905
commit 0cb1f244bc
7 changed files with 45 additions and 24 deletions

View File

@ -195,7 +195,7 @@ public class TPHExtractor extends AbstractASTWalker {
public void visit(Method method) { public void visit(Method method) {
inMethod = true; inMethod = true;
String id = MethodUtility.createID(resolver,method); String id = MethodUtility.createID(resolver,method);
Predicate<Pair> filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA1 instanceof TypePlaceholder) && Predicate<Pair> filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA2 instanceof TypePlaceholder) &&
(resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) && (resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) &&
(resultSet.resolveType((TypePlaceholder)(cs.TA2)).resolvedType instanceof TypePlaceholder)); (resultSet.resolveType((TypePlaceholder)(cs.TA2)).resolvedType instanceof TypePlaceholder));

View File

@ -505,11 +505,13 @@ public class FamilyOfGeneratedGenerics {
} }
MethodConstraint mc = new MethodConstraint(ta1, ta2, r); MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
if(mc.getRel() == Relation.EXTENDS) { if(mc.getRel() == Relation.EXTENDS) {
if (!mc.getLeft().equals(mc.getRight())) { //eliminieren der Fälle wie AA<.AA
if(!checkForDuplicates(mc, tempMC)) { if(!checkForDuplicates(mc, tempMC)) {
tempMC.add(mc); tempMC.add(mc);
} }
} }
} }
}
return tempMC; return tempMC;
} }
@ -611,7 +613,7 @@ public class FamilyOfGeneratedGenerics {
if(newPair.TA1 != newPair.TA2) { //eliminieren der Fälle wie AA<.AA if(newPair.TA1 != newPair.TA2) { //eliminieren der Fälle wie AA<.AA
if (!checkForDuplicatesForSets(newPair, tempSet)) { if (!checkForDuplicatesForSets(newPair, tempSet)) {
//TODO: evtl. pairExtends hinzufuegen //TODO: evtl. pairExtends hinzufuegen
tempSet.add(newPair); //tempSet.add(newPair);
} }
} }
} }
@ -662,6 +664,7 @@ public class FamilyOfGeneratedGenerics {
while(itExtends2.hasNext()) { while(itExtends2.hasNext()) {
Pair pairExtends2 = itExtends2.next(); Pair pairExtends2 = itExtends2.next();
Iterator<Pair> itEqual2 = equalSet.iterator(); Iterator<Pair> itEqual2 = equalSet.iterator();
while (itEqual2.hasNext()) { while (itEqual2.hasNext()) {
boolean transClo = false; boolean transClo = false;
Pair pairEqual2 = itEqual2.next(); Pair pairEqual2 = itEqual2.next();
@ -693,15 +696,17 @@ public class FamilyOfGeneratedGenerics {
// break; // break;
//} //}
//} //}
if (tcOfCs.contains(newPairTPHConstraint)) { if (tcOfCs.contains(newPairTPHConstraint)|| (newPairTPHConstraint.getLeft().equals(newPairTPHConstraint.getRight()))) {
transClo = true; transClo = true;
} }
TypePlaceholder tphR = (TypePlaceholder) pairEqual2.TA2; TypePlaceholder tphR = (TypePlaceholder) pairEqual2.TA2;
Iterator<Pair> itUndCons = undCons.iterator(); Iterator<Pair> itUndCons = undCons.iterator();
boolean rEqExRtilde = false;
while (itUndCons.hasNext()) { while (itUndCons.hasNext()) {
Pair pairUndCons2 = itUndCons.next(); Pair pairUndCons2 = itUndCons.next();
boolean rEqExRtilde = (tphR == pairUndCons2.TA1); rEqExRtilde = rEqExRtilde || (tphR == pairUndCons2.TA1);
// Pair rExRtildePair = new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT); // Pair rExRtildePair = new Pair(resSet.resolveType((TypePlaceholder) (tphR)).resolvedType, resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, PairOperator.SMALLERDOT);
}
boolean isPairInTExTapostrophe = false; boolean isPairInTExTapostrophe = false;
// Constraint<Pair> allOfOr = new Constraint<Pair>(); // Constraint<Pair> allOfOr = new Constraint<Pair>();
for(Set<Constraint<Pair>> scp: orCons) { for(Set<Constraint<Pair>> scp: orCons) {
@ -716,10 +721,10 @@ public class FamilyOfGeneratedGenerics {
} }
} }
} }
} }
if (transClo && (rEqExRtilde || isPairInTExTapostrophe)) {
if ((rEqExRtilde || isPairInTExTapostrophe)) {
if (!newPair2.TA1.equals(newPair2.TA2)) { //eliminieren der Fälle wie AA<.AA if (!newPair2.TA1.equals(newPair2.TA2)) { //eliminieren der Fälle wie AA<.AA
if (transClo && !checkForDuplicatesForSets(newPair2, tempSet2)) if (transClo && !checkForDuplicatesForSets(newPair2, tempSet2))
tempSet2.add(newPair2); tempSet2.add(newPair2);
@ -728,8 +733,11 @@ public class FamilyOfGeneratedGenerics {
tempSet2.add(pairExtends2); tempSet2.add(pairExtends2);
} }
} }
String key = ((TypePlaceholder)pairExtends2.TA2).getName();
if (posOfTphs.containsKey(key)) {
if (posOfTphs.get(key).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) {
tempSet2.add(pairExtends2);
}
} }
} }
} }

View File

@ -102,6 +102,7 @@ public class JavaTXCompiler {
} }
classLoader = new DirectoryClassLoader(contextPath, ClassLoader.getSystemClassLoader()); classLoader = new DirectoryClassLoader(contextPath, ClassLoader.getSystemClassLoader());
environment = new CompilationEnvironment(sources); environment = new CompilationEnvironment(sources);
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
for (File s : sources) { for (File s : sources) {
sourceFiles.put(s, parse(s)); sourceFiles.put(s, parse(s));
} }

View File

@ -4,6 +4,16 @@ public class NameGenerator {
private static String strNextName = "A"; private static String strNextName = "A";
/**
* Setzt den zu Beginn der Typinferenz auf "A" zurueck.
* Dies ist beio den JUnit-Test noetig
* <code>TypePlaceholder</code>. <br>Author: Martin Pluemicke
* @return void
*/
public static void reset() {
strNextName = "A";
}
/** /**
* Berechnet einen neuen, eindeutigen Namen ¯Â¿Â½r eine neue * Berechnet einen neuen, eindeutigen Namen ¯Â¿Â½r eine neue
* <code>TypePlaceholder</code>. <br>Author: ¯Â¿Â½rg ¯Â¿Â½uerle * <code>TypePlaceholder</code>. <br>Author: ¯Â¿Â½rg ¯Â¿Â½uerle

View File

@ -57,8 +57,8 @@ public class TestContraVariant {
lmc.add(new MethodConstraint("O", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("O", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Rm(TPH O)", lmc); methodConstraintsWithPositionTest.put("TPH Rm(TPH O)", lmc);
lmc = new HashSet<>(); lmc = new HashSet<>();
lmc.add(new MethodConstraint("S", "O", Relation.EXTENDS)); //lmc.add(new MethodConstraint("S", "O", Relation.EXTENDS));
lmc.add(new MethodConstraint("O", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("S", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Rmain(TPH S)", lmc); methodConstraintsWithPositionTest.put("TPH Rmain(TPH S)", lmc);

View File

@ -70,9 +70,9 @@ public class TestTPHsAndGenerics {
lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS));
lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS));
lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); //lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS));
lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
lmc = new HashSet<>(); lmc = new HashSet<>();
lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS)); lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS));
@ -89,9 +89,9 @@ public class TestTPHsAndGenerics {
lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS));
lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS));
lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); //lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS));
lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
lmc = new HashSet<>(); lmc = new HashSet<>();
lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS)); lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS));
@ -108,9 +108,9 @@ public class TestTPHsAndGenerics {
lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS)); lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS));
lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS)); lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS));
lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS)); //lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS));
lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc); methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
lmc = new HashSet<>(); lmc = new HashSet<>();
lmc.add(new MethodConstraint("V", "VK", Relation.EXTENDS)); lmc.add(new MethodConstraint("V", "VK", Relation.EXTENDS));

View File

@ -59,8 +59,9 @@ public class TestThreeArgs {
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>(); HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
Set<MethodConstraint> lmc; Set<MethodConstraint> lmc;
lmc = new HashSet<>(); lmc = new HashSet<>();
lmc.add(new MethodConstraint("P", "R", Relation.EXTENDS)); lmc.add(new MethodConstraint("P", "AF", Relation.EXTENDS));
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AF", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AFid(TPH P)", lmc); methodConstraintsWithPositionTest.put("TPH AFid(TPH P)", lmc);
lmc = new HashSet<>(); lmc = new HashSet<>();
lmc.add(new MethodConstraint("AF", "W", Relation.EXTENDS)); lmc.add(new MethodConstraint("AF", "W", Relation.EXTENDS));
@ -84,7 +85,8 @@ public class TestThreeArgs {
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className); classToTest = loader.loadClass(className);
instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); //liefert Fehler, da Variable "a" nicht initialisiert ist.
//instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
return new TestResultSet(); return new TestResultSet();
} }
} }