Compare commits
239 Commits
bigRefacto
...
inferWildc
Author | SHA1 | Date | |
---|---|---|---|
26ae463e96 | |||
2e1e69df9a | |||
0e8012c132 | |||
68394565b5 | |||
c3b17a8f2f | |||
423cf8b9d2 | |||
87fb9e5a33 | |||
df6debec4f | |||
59177e09ad | |||
a9281a0db2 | |||
fe36b34a80 | |||
d3a18887c3 | |||
14821575bd | |||
c1519783ba | |||
53bbf3c511 | |||
48964d57ad | |||
41492e53ca | |||
18d9edfeea | |||
74b9b024ee | |||
97483714e7 | |||
a7b9c2a4ee | |||
fd7628cb40 | |||
76a291ab41 | |||
c5c8ffeed1 | |||
ba9335e2f6 | |||
c098a0a1b0 | |||
cfce2f55ac | |||
4009a28333 | |||
1b9e824b86 | |||
b40cb49b9f | |||
f3dc0cbeb7 | |||
cd2f030ac6 | |||
f548548788 | |||
5cf41101bf | |||
e139f8c867 | |||
5a151a965c | |||
be9ee49878 | |||
e5f03369cc | |||
f698c967c0 | |||
1509e21214 | |||
50c05064c7 | |||
6458a06293 | |||
a984e455e4 | |||
19c9f648a8 | |||
077bd62b92 | |||
de62df00e0 | |||
78e3b76dc3 | |||
c627f9de60 | |||
ff92807b83 | |||
1043b3f55f | |||
88440b873a | |||
4ca0e1e5f6 | |||
cb28405fe1 | |||
3363037854 | |||
c7f91724a6 | |||
11b63e0a5d | |||
5f7829191c | |||
044d9a1860 | |||
6fcbca1187 | |||
572f41ffd4 | |||
e0f7f95bed | |||
78c365a7be | |||
bea072689b | |||
81697eee64 | |||
c474abd2bd | |||
6dd02a654b | |||
e5d5376ce9 | |||
0cdeee9e0d | |||
c8d4301e5e | |||
98b3ad1517 | |||
b59aabeea5 | |||
26953665c9 | |||
465f82e967 | |||
ce8b19acae | |||
7dfe546999 | |||
c96c56e882 | |||
3e57a64f9c | |||
e8539a84fd | |||
0551d25fbf | |||
b46415e45a | |||
bbfd8aa203 | |||
0cb1f244bc | |||
9be64e4905 | |||
d1ad6e218a | |||
bf8d4fe647 | |||
e229093017 | |||
cbe2d7b0f5 | |||
59b45b5f87 | |||
ad7e7ec42b | |||
9d2c85d686 | |||
63b4dbcc10 | |||
ca816fba85 | |||
66a25a56c0 | |||
af223a4d8a | |||
14cb2c8909 | |||
080eb2f6f3 | |||
d8876457db | |||
32e9ce92a6 | |||
3ad9007336 | |||
da2a17c794 | |||
345b03b775 | |||
ff93b0967e | |||
db149eb588 | |||
f5f639c0f7 | |||
a4c38b2bb0 | |||
e3625cb306 | |||
86603ae343 | |||
d276c7c044 | |||
91c075829b | |||
705d0b6a73 | |||
bc378f2fe9 | |||
e5816bac22 | |||
8c6027645f | |||
e147a8ce85 | |||
54a2dbfedc | |||
07c1eeeb36 | |||
d08e598649 | |||
ba8df8b376 | |||
b147430fb6 | |||
661fa53937 | |||
13144d0ac9 | |||
539cacef86 | |||
69a557f1f2 | |||
6e0e575524 | |||
55e44d62de | |||
54de28c3f0 | |||
8e89c9b5e8 | |||
bb5692da8e | |||
f69554c6a1 | |||
fbb7d82ef4 | |||
4f1aadef60 | |||
4acb820202 | |||
6862c91b73 | |||
55ee8ab61a | |||
af9943be28 | |||
f208432c54 | |||
2ca4aad07d | |||
b99c022b50 | |||
d1a796f37b | |||
31d7856afa | |||
b711dc72e0 | |||
d14f1d92c9 | |||
ebb0803a38 | |||
60f2e3def4 | |||
7e35e09c47 | |||
ab99889c3c | |||
bbdf220324 | |||
f2d6dae4c7 | |||
905dfd8a27 | |||
5fb2d57d3b | |||
5b7fec660d | |||
5980f1c7b8 | |||
f270686b3c | |||
92bc3d626c | |||
ef723e4103 | |||
9f06118138 | |||
a0c92c2d9d | |||
c6d896fa3b | |||
b942e508fc | |||
f33002e998 | |||
2dc4331afb | |||
ebf6f0bbe3 | |||
dc62b72f7f | |||
42bb787195 | |||
cd135c3962 | |||
59adfd6c59 | |||
604300a07e | |||
0bc0e4c722 | |||
ebfc3dedbe | |||
e07e5e9b42 | |||
8fb7a23279 | |||
8706882388 | |||
918d0db799 | |||
4b99b38b47 | |||
1236ca2953 | |||
1348a7a4b6 | |||
3f4aa7bbd5 | |||
bb900af6bf | |||
cfacc6235c | |||
1a135ebe5c | |||
c15953bbac | |||
404bbbf746 | |||
a8f04a25cd | |||
1242252cde | |||
5e9e774d1e | |||
bd6d74c74d | |||
3d8275c676 | |||
3ef15d814d | |||
842b85cfd7 | |||
fc8f11ebb1 | |||
eb97dd810f | |||
ab850edae8 | |||
3f5f51df5b | |||
dce7ac8262 | |||
88175f8b48 | |||
2f37bb7313 | |||
a04316f629 | |||
3b062de612 | |||
c32ef1e31f | |||
5ed6a4617a | |||
7139a1709e | |||
e9bcea4b9e | |||
d671e74fcf | |||
c2f0368d2e | |||
d06c6abb5a | |||
f7101da621 | |||
c0c24eed3b | |||
af36b43786 | |||
997d3b9bea | |||
ed7cc55139 | |||
29a7f2e7fb | |||
4ac67120a4 | |||
f0db6cb901 | |||
2e5581ab6e | |||
e8ac8e3c5a | |||
a4bc49f5c4 | |||
9cf7cec37b | |||
531b1ccd22 | |||
7ced6338cb | |||
0550f73ef7 | |||
b91aadf24a | |||
70b6c35731 | |||
e617a0911a | |||
7cf46b02b7 | |||
8cf57ba35b | |||
486d7d9011 | |||
8402d18f83 | |||
8d25920a87 | |||
ab9e9e16bd | |||
b45964ed5f | |||
0ecd3916f8 | |||
c86fe95da5 | |||
d677d053d6 | |||
5060cca6db | |||
7900449897 | |||
f6154b8f2c | |||
1d7c894f39 | |||
61f35f8f8b | |||
1e7c25805e |
.gitignoreREADME_aktuelle_Branches
src
main
java
de
dhbwstuttgart
bytecode
TPHExtractor.java
constraint
genericsGenerator
genericsGeneratorTypes
GenericGeneratorResultsForAllMethods.javaGenericsGeneratorResult.javaGenericsGeneratorResultForClass.javaMethodAndConstraints.java
insertGenerics
ClassConstraint.javaFamilyOfGeneratedGenerics.javaGGenerics.javaMethodConstraint.javaPairMethodAndConstraint.javaPairTphMethod.javaPositionFinder.javapreGGenerics.java
utilities
core
inferWildcards
ConstraintsGenerationUtils.javaFindInAstVisitor.javaJavaTXCompilerWildcards.javaReplaceTypeparamVisitor.javaTypePlaceholderReplaceUtils.java
parser
syntaxtree
typeinference
constraints
result
typeAlgo
unify
unify2
test
java
constraintSimplify
inferWildcards
TestInferWildcardsFields.javaTestInferWildcardsMap.javaTestInferWildcardsMapNested.javaTestInferWildcardsNested.javaTestInferWildcardsParamType.javaTestInferWildcardsSingle.javaTestInferWildcardsSingleLib.java
insertGenerics
FamilyOfGeneratedGenericsTest.javaTestAny.javaTestClassField.javaTestContraVariant.javaTestExample42.javaTestExample42_allInOneMethod.javaTestGGFinder.javaTestLocalVarLambda.javaTestMutualRecursion.javaTestReturnVar.javaTestSecondLineOfClassConstraints.javaTestTPHsAndGenerics.javaTestTPHsAndGenerics2.javaTestThreeArgs.javaTestTransitiveClosure.javaTestTwoArgs.javaTestTwoArgs2.javaTestTwoCalls.javaTestVector.javaTestVectorArg.javaTestVoidMeth.java
resources
bytecode
javFiles
inferWildcards
.gitignoreTestClassWildcardsFields.javaTestClassWildcardsMap.javaTestClassWildcardsMapNested.javaTestClassWildcardsNested.javaTestClassWildcardsParamType.javaTestClassWildcardsSingle.javaTestClassWildcardsSingleLib.java
insertGenericsJav
TestAny.javTestClassField.javTestContraVariant.javTestGGFinder.javTestLocalVarLambda.javTestMutualRecursion.javTestMutualRecursionWithField.javTestMutualRecursionWithField2.javTestMutualRecursionWithField3.javTestReturnVar.javTestSecondLineOfClassConstraints.javTestTPHsAndGenerics.javTestTPHsAndGenerics2.javTestThreeArgs.javTestTwoArgs.javTestTwoArgs2.javTestTwoCalls.javTestVector.javTestVectorArg.javTestVoidMeth.jav
1
.gitignore
vendored
1
.gitignore
vendored
@ -29,3 +29,4 @@ logFiles/**
|
||||
|
||||
src/main/java/de/dhbwstuttgart/parser/antlr/
|
||||
src/main/java/de/dhbwstuttgart/sat/asp/parser/antlr/
|
||||
/pull.sh
|
||||
|
10
README_aktuelle_Branches
Normal file
10
README_aktuelle_Branches
Normal file
@ -0,0 +1,10 @@
|
||||
Stand: 24.5.21
|
||||
bigRefactoring: Master-Brach
|
||||
bigRefactoringUnifyComment: Dokumentation Unify, Martin
|
||||
bytecodeGenericsSecond: Generated Generics, Ali, Martin
|
||||
inferWildcards, Wildcards, Till
|
||||
master, derzeit nicht genutzt
|
||||
plugin, eigemntlicher Branch fuer Plugin-Basis, derzeit nicht aktuelle (aktuelle Version in simplifyRes
|
||||
simplifyRes, Basis fuer Plugin, sollte auf Plugin gemerged werden, noch keine Packages, Michael
|
||||
strucTypesNew, Struturelle Typen, alte Basis, arbeite derzeit niemand
|
||||
|
@ -10,6 +10,9 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
@ -30,6 +33,9 @@ import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
@ -49,6 +55,10 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
boolean inLocalOrParamOrReturn = false;
|
||||
|
||||
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
||||
|
||||
// Alle Constraints in einer Menge (Und- & Oder-Constraints)
|
||||
public Set<Pair> oldConstraints = new HashSet<>();
|
||||
|
||||
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();
|
||||
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
||||
private ResultSet resultSet;
|
||||
@ -78,15 +88,25 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
public void visit(TypePlaceholder tph) {
|
||||
if (resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) {
|
||||
TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType;
|
||||
if (inMethod) {
|
||||
methodAndTph.getTphs().add(resolvedTPH.getName());
|
||||
if (inLocalOrParamOrReturn)
|
||||
methodAndTph.getLocalTphs().add(resolvedTPH.getName());
|
||||
}else {
|
||||
tphsClass.add(resolvedTPH.getName());
|
||||
String tphName = resolvedTPH.getName();
|
||||
if (inMethod && !tphsClass.contains(tphName)) {
|
||||
ArrayList<String> tphs = null;
|
||||
if (!(tphs = methodAndTph.getTphs()).contains(tphName)) {
|
||||
methodAndTph.addTph(tphName);
|
||||
}
|
||||
if (inLocalOrParamOrReturn) {
|
||||
if (!(tphs = methodAndTph.getLocalTphs()).contains(tphName)) {
|
||||
tphs.add(tphName);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!tphsClass.contains(tphName)) {
|
||||
tphsClass.add(tphName);
|
||||
}
|
||||
}
|
||||
if (!allTPHS.containsKey(tphName)) {
|
||||
allTPHS.put(tphName, inMethod);
|
||||
}
|
||||
|
||||
allTPHS.put(resolvedTPH.getName(), inMethod);
|
||||
// final List<TPHConstraint> cons = new ArrayList<>();
|
||||
// resultSet.resolveType(tph).additionalGenerics.forEach(ag -> {
|
||||
// TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
||||
@ -153,7 +173,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
public void visit(GenericRefType genericRefType) {
|
||||
String name = genericRefType.getParsedName();
|
||||
if (inMethod) {
|
||||
methodAndTph.getTphs().add(name);
|
||||
methodAndTph.addTph(name);
|
||||
if (inLocalOrParamOrReturn)
|
||||
methodAndTph.getLocalTphs().add(name);
|
||||
}else {
|
||||
@ -175,7 +195,33 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
public void visit(Method method) {
|
||||
inMethod = true;
|
||||
String id = MethodUtility.createID(resolver,method);
|
||||
methodAndTph = new MethodAndTPH(id);
|
||||
Predicate<Pair> filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA2 instanceof TypePlaceholder) &&
|
||||
(resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) &&
|
||||
(resultSet.resolveType((TypePlaceholder)(cs.TA2)).resolvedType instanceof TypePlaceholder));
|
||||
|
||||
Function<ConstraintSet<Pair>, ConstraintSet<Pair>> filterConstrRemainingTVar =
|
||||
csS -> {
|
||||
ConstraintSet<Pair> ret = new ConstraintSet<>();
|
||||
ret.addAllUndConstraint(
|
||||
csS.getUndConstraints()
|
||||
.stream().filter(filterUndConstraints)
|
||||
.collect(Collectors.toCollection(Constraint<Pair>::new)));
|
||||
|
||||
csS.getOderConstraints()
|
||||
.forEach(oConSSet -> { Set<Constraint<Pair>> setCons = new HashSet<>();
|
||||
oConSSet.forEach(OConS -> { Constraint<Pair> newConsPair = new Constraint<Pair>();
|
||||
newConsPair.isStatement = OConS.isStatement;
|
||||
setCons.add(
|
||||
OConS.stream()
|
||||
.filter(filterUndConstraints)
|
||||
.collect(Collectors.toCollection(() -> newConsPair)) );
|
||||
} );
|
||||
ret.addOderConstraint(setCons);} );
|
||||
return ret;
|
||||
};
|
||||
ConstraintSet<Pair> filteredConstraints = filterConstrRemainingTVar.apply(method.getConstraints());
|
||||
methodAndTph = new MethodAndTPH(id, filteredConstraints);
|
||||
oldConstraints.addAll(filteredConstraints.getAll());
|
||||
|
||||
inLocalOrParamOrReturn = true;
|
||||
method.getReturnType().accept(this);
|
||||
@ -184,7 +230,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
|
||||
if(method.block != null)
|
||||
method.block.accept(this);
|
||||
|
||||
|
||||
inMethod = false;
|
||||
ListOfMethodsAndTph.add(methodAndTph);
|
||||
}
|
||||
|
@ -1,13 +1,25 @@
|
||||
package de.dhbwstuttgart.bytecode.constraint;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class TPHConstraint {
|
||||
protected String left;
|
||||
protected String right;
|
||||
protected Relation rel;
|
||||
protected int variance; //noch nicht benutzt
|
||||
public enum Relation{
|
||||
EXTENDS, EQUAL
|
||||
}
|
||||
|
||||
public TPHConstraint(Pair p) {
|
||||
this.left = ((TypePlaceholder)p.TA1).getName();
|
||||
this.right = ((TypePlaceholder)p.TA2).getName();
|
||||
this.rel = p.GetOperator().equals(PairOperator.SMALLERDOT) ? Relation.EXTENDS : Relation.EQUAL;
|
||||
}
|
||||
|
||||
public TPHConstraint(String left, String right, Relation rel) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
@ -48,6 +60,25 @@ public class TPHConstraint {
|
||||
return rel == constraint.getRel() && left.equals(constraint.getLeft()) && right.equals(constraint.getRight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (left+right).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals (Object o) {
|
||||
if (o instanceof TPHConstraint) {
|
||||
TPHConstraint o_tphcons = (TPHConstraint)o;
|
||||
return (this.left.equals(o_tphcons.getLeft())
|
||||
&& this.right.equals(o_tphcons.getRight())
|
||||
&& this.rel.equals(o_tphcons.rel));
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(rel == Relation.EXTENDS) {
|
||||
|
@ -3,15 +3,14 @@
|
||||
*/
|
||||
package de.dhbwstuttgart.bytecode.genericsGenerator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.MethodAndConstraints;
|
||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.*;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
||||
@ -74,11 +73,13 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
||||
private GenericGenratorResultForSourceFile generatedGenericsForSF;//Ergebnis des GGenerics
|
||||
private ResultSet resultSet;
|
||||
private final List<String> methodNameAndParamsT = new ArrayList<>();
|
||||
private FamilyOfGeneratedGenerics fogg;
|
||||
|
||||
private String pkgName;
|
||||
private JavaClassName className;
|
||||
private Resolver resolver;
|
||||
|
||||
|
||||
/**
|
||||
* @param sf
|
||||
* @param listOfResultSets
|
||||
@ -93,6 +94,14 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
||||
return generatedGenericsForSF;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the family of Generated Generics
|
||||
* insbesondere fuer Testzwecke
|
||||
*/
|
||||
public FamilyOfGeneratedGenerics getFogg() {
|
||||
return fogg;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
@ -125,13 +134,28 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
||||
|
||||
ConstraintsSimplierResult simplifiedConstraints = null;
|
||||
GenericsGeneratorResultForClass ggResult = null;
|
||||
GenericsGeneratorResultForClass ggResultAlternative = null;
|
||||
|
||||
for (int i = 0; i < listOfResultSetsList.size(); i++) {
|
||||
resultSet = listOfResultSetsList.get(i);
|
||||
tphExtractor.setResultSet(resultSet);
|
||||
resolver = new Resolver(resultSet);
|
||||
classOrInterface.accept(tphExtractor);
|
||||
//PL 2020-10-16: Ab hier GGenerics implementieren durch Ali
|
||||
//Rueckgabe an generatedGenericsForSF
|
||||
fogg = new FamilyOfGeneratedGenerics(tphExtractor, resultSet);
|
||||
|
||||
System.out.println("fogg.allConstraints: "+ fogg.allConstraints);
|
||||
System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs);
|
||||
System.out.println("fogg.classConstraints: "+ fogg.classConstraints);
|
||||
System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition);
|
||||
System.out.println(fogg);
|
||||
|
||||
///*
|
||||
//Fayez Ansatz Anfang
|
||||
tphsClass = tphExtractor.tphsClass;
|
||||
//PL 2020-01-15
|
||||
//Es muss ggResult aus fogg gebildet werden
|
||||
simplifiedConstraints = GenericsGenerator.simplifyConstraints(tphExtractor, tphsClass);
|
||||
if(!isVisited) {
|
||||
ggResult = GenericsGenerator.generateConstraints(className, tphExtractor, tphsClass,simplifiedConstraints);
|
||||
@ -140,13 +164,46 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
||||
|
||||
for(Method m : classOrInterface.getMethods()) {
|
||||
addMethodConstraints(simplifiedConstraints, ggResult, m);
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(ggResult != null)
|
||||
|
||||
if(ggResult != null) { //Hinzufuegen von Fayez ggResult
|
||||
generatedGenericsForSF.addGenericGeneratorResultClass(ggResult);
|
||||
}
|
||||
// Fayez Ansatz Ende
|
||||
//*/
|
||||
|
||||
|
||||
//Ali Ansatz Anfang
|
||||
List<GenericsGeneratorResult> listOfClassCons = new ArrayList<>();
|
||||
for(TPHConstraint clCons: fogg.classConstraints) {
|
||||
// ExtendsConstraint ec = new ExtendsConstraint(clCons.getLeft(), clCons.getRight());
|
||||
GenericsGeneratorResult ggR = new GenericsGeneratorResult(clCons, new HashSet<>());
|
||||
listOfClassCons.add(ggR);
|
||||
}
|
||||
|
||||
GenericGeneratorResultsForAllMethods ggRfaM = null;
|
||||
List<MethodAndConstraints> listOfMethAndCons = new ArrayList<>();
|
||||
for(String methID: fogg.methodConstraintsWithPosition.keySet()) {
|
||||
List<GenericsGeneratorResult> listOfGGR = new ArrayList<>();
|
||||
for(TPHConstraint methCons: fogg.methodConstraintsWithPosition.get(methID)) {
|
||||
// ExtendsConstraint ec = new ExtendsConstraint(methCons.getLeft(),methCons.getRight());
|
||||
GenericsGeneratorResult ggR = new GenericsGeneratorResult(methCons, new HashSet<>());
|
||||
listOfGGR.add(ggR);
|
||||
}
|
||||
MethodAndConstraints mac = new MethodAndConstraints(methID, listOfGGR);
|
||||
listOfMethAndCons.add(mac);
|
||||
}
|
||||
ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons);
|
||||
ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM);
|
||||
|
||||
if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult
|
||||
//generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative);
|
||||
System.out.println(generatedGenericsForSF);
|
||||
}
|
||||
System.out.println(ggResultAlternative);
|
||||
//Ali Ansatz Ende
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,5 +29,13 @@ public class GenericGeneratorResultsForAllMethods {
|
||||
public List<MethodAndConstraints> getMethodsAndConstraints() {
|
||||
return methodsAndConstraints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String ret = "";
|
||||
ret = ret + methodsAndConstraints.stream().reduce("", (x,y) -> x + y.toString(), (x,y) -> x + y);
|
||||
//ret = ret + "\n";
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,4 +52,8 @@ public class GenericsGeneratorResult {
|
||||
this.equalsTPHs = equalsTPHs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return constraint.toString() + " EqualsTPS: " + equalsTPHs.toString();
|
||||
}
|
||||
}
|
||||
|
8
src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResultForClass.java
8
src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/GenericsGeneratorResultForClass.java
@ -73,4 +73,12 @@ public class GenericsGeneratorResultForClass {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String ret = "Classconstraints: ";
|
||||
ret = ret + classConstraints.stream().reduce("", (x,y) -> x + y.toString(), (x,y) -> x + y);
|
||||
ret = ret + "\n" + methodsAndTheirConstraints.toString();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,14 @@ public class MethodAndConstraints {
|
||||
return constraints;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String ret = methodID + ": ";
|
||||
ret = ret + constraints.stream().reduce("",
|
||||
(x,y) -> x + y.toString(),
|
||||
(x,y) -> x + y);
|
||||
ret = ret + "\n";
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package de.dhbwstuttgart.bytecode.insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
|
||||
public class ClassConstraint extends TPHConstraint {
|
||||
//private TPHConstraint constraint;
|
||||
|
||||
public ClassConstraint(String left, String right, Relation rel) {
|
||||
super(left, right, rel);
|
||||
}
|
||||
//besser?
|
||||
/*public ClassConstraint(TPHConstraint constraint) {
|
||||
this.constraint = constraint;
|
||||
}*/
|
||||
}
|
880
src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
Normal file
880
src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
Normal file
@ -0,0 +1,880 @@
|
||||
package de.dhbwstuttgart.bytecode.insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
public class FamilyOfGeneratedGenerics {
|
||||
public List<TPHConstraint> allConstraints = new ArrayList<>();
|
||||
// HashMap speichert ob TPH in einer Methode oder in der Klasse ist; und wenn es in der Methode ist, in welcher Methode
|
||||
public HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTPHs = new HashMap<>();
|
||||
public List<ClassConstraint> classConstraints = new ArrayList<>();
|
||||
private HashMap<String, MethodAndTPH> mapMethodsAndTph = new HashMap<>();
|
||||
public List<MethodConstraint> methodConstraints = new ArrayList<>();
|
||||
public HashMap<String, List<MethodConstraint>> methodConstraintsWithPosition = new HashMap<>();
|
||||
public ResultSet resSet;
|
||||
public Set<Pair> oldCons = new HashSet<>();
|
||||
|
||||
private static final String objectType = Type.getInternalName(Object.class);
|
||||
|
||||
public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor, ResultSet resultSet) {
|
||||
this.resSet = resultSet;
|
||||
this.oldCons = tphExtractor.oldConstraints;
|
||||
this.allConstraints = tphExtractor.allCons;
|
||||
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
|
||||
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
|
||||
tphExtractor.ListOfMethodsAndTph.forEach(matph -> this.mapMethodsAndTph.put(matph.getId(), matph));
|
||||
this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph);
|
||||
this.methodConstraintsWithPosition = getMethodConstraintsWithPositionNew(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph, resSet, oldCons);
|
||||
}
|
||||
|
||||
public static List<ClassConstraint> getClassConstraints(List<TPHConstraint> cs, HashMap<String, List<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) {
|
||||
if (!checkForDuplicates(cons, cs_cl)) {
|
||||
cs_cl.add(cons);
|
||||
}
|
||||
}
|
||||
|
||||
// if sth new is added to cs_cl, then do same step again
|
||||
boolean addedToConstraintsListForCC2 = false;
|
||||
do {
|
||||
addedToConstraintsListForCC2 = false;
|
||||
List<ClassConstraint> classConstraints2 = transitiveSubtypeForClassTypes(cs, cs_cl); // in Klammer classConstraints1 oder constraintsSet? beides eher
|
||||
for (ClassConstraint cons: classConstraints2) {
|
||||
if (!checkForDuplicates(cons, cs_cl)) {
|
||||
cs_cl.add(cons);
|
||||
addedToConstraintsListForCC2 = true;
|
||||
}
|
||||
}
|
||||
} while (addedToConstraintsListForCC2);
|
||||
|
||||
List<ClassConstraint> classConstraints3 = hasNoSupertypeForClassTypes(cs_cl, posOfTphs);
|
||||
for (ClassConstraint cons: classConstraints3) {
|
||||
if (!checkForDuplicates(cons, cs_cl)) {
|
||||
cs_cl.add(cons);
|
||||
}
|
||||
}
|
||||
return cs_cl;
|
||||
}
|
||||
|
||||
public List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph) {
|
||||
List<MethodConstraint> cs_m = new ArrayList<>();
|
||||
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
||||
for (MethodConstraint cons: methodConstraints1) {
|
||||
if (!checkForDuplicates(cons, cs_m)) {
|
||||
cs_m.add(cons);
|
||||
}
|
||||
}
|
||||
|
||||
// if sth new is added to cs_cl, then do same step again
|
||||
boolean addedToConstraintsListForMC2 = false;
|
||||
do {
|
||||
addedToConstraintsListForMC2 = false;
|
||||
List<MethodConstraint> methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m);
|
||||
for (MethodConstraint cons : methodConstraints2) {
|
||||
if (!checkForDuplicates(cons, cs_m)) {
|
||||
cs_m.add(cons);
|
||||
addedToConstraintsListForMC2 = true;
|
||||
}
|
||||
}
|
||||
} while (addedToConstraintsListForMC2);
|
||||
|
||||
// if sth new is added to cs_cl, then do same step again
|
||||
boolean addedToConstraintsListForMC3 = false;
|
||||
do {
|
||||
addedToConstraintsListForMC3 = false;
|
||||
List<MethodConstraint> methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m);
|
||||
for (MethodConstraint cons : methodConstraints3) {
|
||||
if (!checkForDuplicates(cons, cs_m)) {
|
||||
cs_m.add(cons);
|
||||
addedToConstraintsListForMC3 = true;
|
||||
}
|
||||
}
|
||||
} while (addedToConstraintsListForMC3);
|
||||
List<MethodConstraint> methodConstraints4 = hasNoSupertypeForMethodTypes(cs, cs_m, posOfTphs, listOfMethodsAndTph);
|
||||
for (MethodConstraint cons: methodConstraints4) {
|
||||
if (!checkForDuplicates(cons, cs_m)) {
|
||||
cs_m.add(cons);
|
||||
}
|
||||
}
|
||||
List<MethodConstraint> methodConstraints5 = methodTypesWithoutClassTypes(cs_cl, cs_m);
|
||||
cs_m = methodConstraints5;
|
||||
return cs_m;
|
||||
}
|
||||
|
||||
public HashMap<String, List<MethodConstraint>> getMethodConstraintsWithPosition(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph, ResultSet resSet, Set<Pair> oldCons) {
|
||||
HashMap<String, List<MethodConstraint>> tempMethodConstraintsWithPosition = new HashMap<>();
|
||||
for(MethodAndTPH method: 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, List<PairTphMethod<PositionFinder.Position, String>>> posOfTPHsForThisMethod = new HashMap<>();
|
||||
for(String s: posOfTphs.keySet()) {
|
||||
for(PairTphMethod pair: posOfTphs.get(s)) {
|
||||
if(pair.snd == currentMethod && pair.snd != null) {
|
||||
posOfTPHsForThisMethod.put(s,posOfTphs.get(s));
|
||||
}
|
||||
}
|
||||
}
|
||||
listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod,listOfMethodsAndTph);
|
||||
tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod);
|
||||
|
||||
List<MethodConstraint> newMCList = firstLineMethodDefinition(cs, posOfTphs, method, resSet);
|
||||
List<MethodConstraint> newMCList2 = secondLineMethodDefinition(cs, posOfTphs, method, resSet, oldCons);
|
||||
System.out.println(newMCList);
|
||||
System.out.println(newMCList2);
|
||||
}
|
||||
}
|
||||
|
||||
for(String curMeth: tempMethodConstraintsWithPosition.keySet()){
|
||||
for(int i=0; i<tempMethodConstraintsWithPosition.get(curMeth).size(); i++) {
|
||||
MethodConstraint currentMC = tempMethodConstraintsWithPosition.get(curMeth).get(i);
|
||||
if(currentMC.getRight()!= objectType && !compareTphsOfConstraints(currentMC.getRight(), cs_cl) && !compareTphsOfConstraints(currentMC.getRight(), tempMethodConstraintsWithPosition.get(curMeth))) {
|
||||
MethodConstraint mc = new MethodConstraint(currentMC.getRight(), objectType, Relation.EXTENDS);
|
||||
tempMethodConstraintsWithPosition.get(curMeth).add(mc);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tempMethodConstraintsWithPosition;
|
||||
}
|
||||
|
||||
// Hilfsmethode um TPHs in den Methoden zu finden, die <. Object sein müssen
|
||||
private static boolean compareTphsOfConstraints(String tph, List list) {
|
||||
List<TPHConstraint> tempList = new ArrayList<>(list);
|
||||
for(TPHConstraint tphC: tempList) {
|
||||
if(tph == tphC.getLeft()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, List<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()) {
|
||||
for(PairTphMethod pair: posOfTphs.get(tph)) {
|
||||
if(tph == allCons.getLeft() && pair.fst == PositionFinder.Position.FIELD) {
|
||||
ClassConstraint consToAdd = new ClassConstraint(tph, allCons.getRight(), allCons.getRel());
|
||||
if (!checkForDuplicates(consToAdd, tempCC)) {
|
||||
tempCC.add(consToAdd);
|
||||
}
|
||||
/*}else if(pair.fst == PositionFinder.Position.FIELD){
|
||||
ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS);
|
||||
if (!checkForDuplicates(consToAdd, tempCC)) {
|
||||
tempCC.add(consToAdd);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*else if (allCons.getRel() != Relation.EXTENDS) {
|
||||
throw re;
|
||||
}*/
|
||||
}
|
||||
return tempCC;
|
||||
}
|
||||
|
||||
/**
|
||||
* Def. FGG: zweite Zeile von cs_cl
|
||||
* {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) {
|
||||
List<ClassConstraint> tempCC = new ArrayList<>();
|
||||
ClassConstraint consToAdd;
|
||||
for(ClassConstraint cCons: cs_cl) {
|
||||
if(cCons.getLeft() != null && cCons.getRel()==Relation.EXTENDS) {
|
||||
for(TPHConstraint allCons: allConstraints) {
|
||||
if(cCons.getRight() == allCons.getLeft() && allCons.getRight() != null && allCons.getRel()==Relation.EXTENDS){
|
||||
consToAdd = new ClassConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel());
|
||||
if (!checkForDuplicates(consToAdd, tempCC)) {
|
||||
tempCC.add(consToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return tempCC;
|
||||
}
|
||||
|
||||
/**
|
||||
* Def. FGG: dritte Zeile von cs_cl
|
||||
* {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<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) {
|
||||
List<ClassConstraint> tempCC= new ArrayList<>();
|
||||
List<TPHConstraint> clCons = new ArrayList<>(cs_cl);
|
||||
for(String tph: posOfTphs.keySet()) {
|
||||
for(PairTphMethod pair: posOfTphs.get(tph)) {
|
||||
boolean tvInField = pair.fst == PositionFinder.Position.FIELD;
|
||||
boolean hasSmallerTVInClCons = hasSmallerTVInClCons(tph, cs_cl);
|
||||
if ((tvInField || hasSmallerTVInClCons) &&
|
||||
!checkUpperBound(clCons, tph)) {
|
||||
ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS);
|
||||
if (!checkForDuplicates(consToAdd, tempCC)) {
|
||||
tempCC.add(consToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return tempCC;
|
||||
}
|
||||
|
||||
public static boolean hasSmallerTVInClCons(String tph, List<ClassConstraint> cs_cl) {
|
||||
for(ClassConstraint cC: cs_cl) {
|
||||
if(tph == cC.getRight() && cC.getRel() == Relation.EXTENDS) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) { // cl_\sigma??
|
||||
//TODO:
|
||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
||||
for(TPHConstraint allCons: allConstraints){
|
||||
if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) {
|
||||
for(String tph: posOfTphs.keySet()) {
|
||||
for(PairTphMethod pair: posOfTphs.get(tph)) {
|
||||
if(tph == allCons.getLeft() && (pair.fst == PositionFinder.Position.METHOD || pair.fst == PositionFinder.Position.CONSTRUCTOR)) {
|
||||
MethodConstraint consToAdd = new MethodConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel());
|
||||
if (!checkForDuplicates(consToAdd, tempMC)) {
|
||||
tempMC.add(consToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return tempMC;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 List<MethodConstraint> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m) { //transitive closure of cs
|
||||
//TODO:
|
||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
||||
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
||||
for(MethodConstraint mC1 : cs_m) { //(R <. R')
|
||||
for(MethodConstraint mC2 : cs_m) { //(S <. S')
|
||||
String lSide = mC1.getRight(); //R'
|
||||
String rSide = mC2.getLeft(); //S
|
||||
for(TPHConstraint tphC : tcOfCs) {
|
||||
if(tphC.getLeft().equals(lSide)&&tphC.getRight().equals(rSide)) { //is it (R',S)
|
||||
MethodConstraint consToAdd = new MethodConstraint(lSide, rSide, tphC.getRel()); //create (R'<.S)
|
||||
if (!checkForDuplicates(consToAdd, tempMC)) {
|
||||
tempMC.add(consToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return tempMC;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 List<MethodConstraint> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
|
||||
//TODO:
|
||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
||||
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
||||
for(ClassConstraint cC : cs_cl) {
|
||||
for(MethodConstraint mC : cs_m) {
|
||||
String leftSide = mC.getRight();
|
||||
String rightSide = cC.getLeft();
|
||||
for(TPHConstraint tphC : tcOfCs) {
|
||||
if(tphC.getLeft().equals(leftSide)&&tphC.getRight().equals(rightSide)) {
|
||||
MethodConstraint consToAdd = new MethodConstraint(tphC.getLeft(), tphC.getRight(), tphC.getRel());
|
||||
if (!checkForDuplicates(consToAdd, tempMC)) {
|
||||
tempMC.add(consToAdd);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return tempMC;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph) {
|
||||
//TODO:
|
||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
||||
for(String tph: posOfTphs.keySet()) {
|
||||
for(PairTphMethod pair: posOfTphs.get(tph)) {
|
||||
for(TPHConstraint allCons: allConstraints) {
|
||||
if((pair.fst.equals(PositionFinder.Position.METHOD) || pair.fst.equals(PositionFinder.Position.CONSTRUCTOR)) && !checkUpperBound(allConstraints,tph)) {
|
||||
MethodConstraint consToAdd = new MethodConstraint(tph, objectType, Relation.EXTENDS);
|
||||
if (!checkForDuplicates(consToAdd, tempMC)) {
|
||||
tempMC.add(consToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<TPHConstraint> tempMCObject1 = new ArrayList<>(cs_m);
|
||||
String currentMethod = "";
|
||||
for(MethodAndTPH mat: listOfMethodsAndTph) {
|
||||
if(mat.getId().equals(pair.snd)) {
|
||||
currentMethod = mat.getId();
|
||||
}
|
||||
for(TPHConstraint mc1: tempMCObject1) {
|
||||
if(tph==mc1.getRight() && !checkUpperBound(tempMCObject1,tph)) {
|
||||
MethodConstraint consToAdd = new MethodConstraint(tph, objectType, Relation.EXTENDS);
|
||||
if (!checkForDuplicates(consToAdd, tempMC)) {
|
||||
tempMC.add(consToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return tempMC;
|
||||
}
|
||||
|
||||
/**
|
||||
* nimm die Menge cs_cl aus cs_m raus
|
||||
*/
|
||||
public List<MethodConstraint> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
|
||||
// erstelle Kopie der Liste cs_cl
|
||||
List<TPHConstraint> tempCC = new ArrayList<>();
|
||||
for(ClassConstraint cc: cs_cl) {
|
||||
TPHConstraint tphC = new TPHConstraint(cc.getLeft(), cc.getRight(), cc.getRel());
|
||||
tempCC.add(tphC);
|
||||
}
|
||||
// Transitive Hülle von cs_cl
|
||||
List<TPHConstraint> tcOfCsCl = buildTransitiveClosure(tempCC);
|
||||
|
||||
List<TPHConstraint> tempMC = new ArrayList<>();
|
||||
for(MethodConstraint mc: cs_m) {
|
||||
TPHConstraint tphC = new TPHConstraint(mc.getLeft(), mc.getRight(), mc.getRel());
|
||||
tempMC.add(tphC);
|
||||
}
|
||||
List<TPHConstraint> tempMC2 = new ArrayList<>();
|
||||
tempMC2.addAll(tempMC);
|
||||
List<MethodConstraint> tempMCToReturn = new ArrayList<>();
|
||||
|
||||
for(TPHConstraint cc: tcOfCsCl) {
|
||||
for(TPHConstraint mc: tempMC) {
|
||||
if(cc.getLeft().equals(mc.getLeft()) && cc.getRight().equals(mc.getRight())) {
|
||||
tempMC2.remove(mc);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(TPHConstraint tphC: tempMC2) {
|
||||
MethodConstraint mCons = new MethodConstraint(tphC.getLeft(), tphC.getRight(), tphC.getRel());
|
||||
tempMCToReturn.add(mCons);
|
||||
}
|
||||
return tempMCToReturn;
|
||||
}
|
||||
|
||||
public static boolean checkForDuplicates(TPHConstraint constraint, List list) {
|
||||
List<TPHConstraint> tempList = list;
|
||||
boolean hasSame = false;
|
||||
for (TPHConstraint tphC: tempList) {
|
||||
hasSame = constraint.getLeft() == tphC.getLeft() &&
|
||||
constraint.getRight() == tphC.getRight() &&
|
||||
constraint.getRel() == tphC.getRel(); //constraint already in ArrayList if true
|
||||
if (hasSame)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<TPHConstraint> buildTransitiveClosure(List list) {
|
||||
List<TPHConstraint> iterList = new ArrayList<>(list);
|
||||
List<TPHConstraint> runList = new ArrayList<>(list);
|
||||
List<TPHConstraint> tcList = new ArrayList<>(list);
|
||||
boolean addedConToList = false;
|
||||
for (TPHConstraint cons: iterList) {
|
||||
for (TPHConstraint cons2: runList) {
|
||||
if(cons.getRight() == cons2.getLeft()) {
|
||||
TPHConstraint consToAdd = new TPHConstraint(cons.getLeft(), cons2.getRight(), Relation.EXTENDS);
|
||||
if (!checkForDuplicates(consToAdd,tcList)) {
|
||||
tcList.add(consToAdd);
|
||||
addedConToList = true;
|
||||
if (addedConToList) {
|
||||
return buildTransitiveClosure(tcList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return tcList;
|
||||
}
|
||||
|
||||
public static boolean checkUpperBound(List<TPHConstraint> cs, String tph) {
|
||||
for(int i=0; i<cs.size(); i++) {
|
||||
if(cs.get(i).getLeft() == tph) {
|
||||
//has upper bound
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> positionConverter(HashMap<String, Boolean> allTphs, List<MethodAndTPH> listOfMethodsAndTphs) {
|
||||
HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> convertedPositions = new HashMap<>();
|
||||
for(String tph: allTphs.keySet()) {
|
||||
List<PairTphMethod<PositionFinder.Position, String>> currMeth = new ArrayList<>();
|
||||
if(allTphs.get(tph)) { //if true, then tph is a method-TPH
|
||||
for(MethodAndTPH methTph: listOfMethodsAndTphs) {
|
||||
if (methTph.getTphs().contains(tph)) {
|
||||
currMeth.add(new PairTphMethod<>(PositionFinder.Position.METHOD, methTph.getId()));
|
||||
}
|
||||
}
|
||||
} else { // else it is in the class-TPH
|
||||
currMeth.add(new PairTphMethod<>(PositionFinder.Position.FIELD, null));
|
||||
}
|
||||
convertedPositions.put(tph, currMeth);
|
||||
}
|
||||
return convertedPositions;
|
||||
}
|
||||
|
||||
/* public PositionFinder.Position positionConverter(TPHExtractor tphExtractor) {
|
||||
if(tphExtractor.allTPHS.keySet())
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* GeneratedGenericsFinder genGenFinder;
|
||||
ConstraintsSimplierResult simplifiedConstraints = null;
|
||||
GenericsGeneratorResultForClass ggResult = null;
|
||||
Method m;
|
||||
|
||||
public void addMethodConstraints(List<MethodConstraint> cs_m) {
|
||||
genGenFinder.addMethodConstraints(simplifiedConstraints, ggResult, m);
|
||||
cs_m.add();
|
||||
}
|
||||
*/
|
||||
|
||||
public static List<MethodConstraint> firstLineMethodDefinition(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet) {
|
||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
||||
MethodAndTPH methAndTphs = methodAndTPH;
|
||||
Set<Pair> undCons = methAndTphs.constraints.getUndConstraints();
|
||||
List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints();
|
||||
Iterator<Pair> it = undCons.iterator();
|
||||
while(it.hasNext()) {
|
||||
Pair p = it.next();
|
||||
String ta1 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName();
|
||||
String ta2 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName();
|
||||
Relation r = null;
|
||||
if(p.GetOperator() == PairOperator.SMALLERDOT) {
|
||||
r = Relation.EXTENDS;
|
||||
} else if(p.GetOperator() == PairOperator.EQUALSDOT) {
|
||||
r = Relation.EQUAL;
|
||||
}
|
||||
MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
|
||||
if(mc.getRel() == Relation.EXTENDS) {
|
||||
if (!mc.getLeft().equals(mc.getRight())) { //eliminieren der Fälle wie AA<.AA
|
||||
if(!checkForDuplicates(mc, tempMC)) {
|
||||
tempMC.add(mc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return tempMC;
|
||||
}
|
||||
|
||||
public List<MethodConstraint> secondLineMethodDefinition(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set<Pair> oldCons) {
|
||||
List<MethodConstraint> tempMC = new ArrayList<>(); //für Ergebnisse basierend auf der neuen Datenstruktur (Ali)
|
||||
Set<Pair> tempSet = new HashSet<>(); //für Ergebnisse des ersten Teils der Bedinung basierend auf der alten Datenstruktur
|
||||
Set<Pair> tempSet2 = new HashSet<>(); //für Ergebnisse des zweiten Teils der Bedingung basierend auf der alten Datenstruktur
|
||||
Set<Pair> tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet);
|
||||
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
||||
MethodAndTPH methAndTphs = methodAndTPH;
|
||||
Set<Pair> undCons = methAndTphs.constraints.getUndConstraints();
|
||||
List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints();
|
||||
List<HashMap<Relation, List<TPHConstraint>>> orConsListConverted = new ArrayList<>();
|
||||
//gehe die OrConstraints der aktuellen Methode durch und teile nach Operator auf (
|
||||
for(int i=0; i<orCons.size(); i++) {
|
||||
List<TPHConstraint> orConsWithEQUAL = new ArrayList();
|
||||
List<TPHConstraint> orConsWithEXTENDS = new ArrayList();
|
||||
HashMap<Relation, List<TPHConstraint>> orConsInternal = new HashMap<>();
|
||||
for(Constraint con: orCons.get(i)) {
|
||||
Iterator<Pair> it = con.iterator();
|
||||
while(it.hasNext()) {
|
||||
Pair p = it.next();
|
||||
Relation r = null;
|
||||
if(p.GetOperator() == PairOperator.SMALLERDOT) {
|
||||
r = Relation.EXTENDS;
|
||||
orConsWithEXTENDS.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r));
|
||||
/*MethodConstraint mc = new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r);
|
||||
if(!checkForDuplicates(mc, tempMC)) {
|
||||
tempMC.add(mc);
|
||||
}*/
|
||||
} else if(p.GetOperator() == PairOperator.EQUALSDOT) {
|
||||
r = Relation.EQUAL;
|
||||
orConsWithEQUAL.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r));
|
||||
/*MethodConstraint mc = new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r);
|
||||
if(!checkForDuplicates(mc, tempMC)) {
|
||||
tempMC.add(mc);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
orConsInternal.put(Relation.EXTENDS, orConsWithEXTENDS);
|
||||
orConsInternal.put(Relation.EQUAL, orConsWithEQUAL);
|
||||
orConsListConverted.add(orConsInternal);
|
||||
}
|
||||
|
||||
// oldCons sind alle Und- und Oder-Constraints
|
||||
// zunächst in meine Datenstruktur(Ali) konvertieren
|
||||
List<Pair> oldConsList = new ArrayList<>(oldCons);
|
||||
List<TPHConstraint> oldConsListConverted = new ArrayList<>();
|
||||
for(Pair pair: oldConsList) {
|
||||
Relation r = null;
|
||||
if(pair.GetOperator() == PairOperator.SMALLERDOT) {
|
||||
r = Relation.EXTENDS;
|
||||
} else if(pair.GetOperator() == PairOperator.EQUALSDOT) {
|
||||
r = Relation.EQUAL;
|
||||
}
|
||||
oldConsListConverted.add(new TPHConstraint(((TypePlaceholder) pair.TA1).getName(), ((TypePlaceholder) pair.TA2).getName(), r));
|
||||
}
|
||||
|
||||
|
||||
// Berechnung des zweiten Teils der Bedingung der Regel
|
||||
for(int i=0; i<orCons.size(); i++) {
|
||||
Constraint<Pair> extendsSet = new Constraint<Pair>();
|
||||
Constraint<Pair> equalSet = new Constraint<Pair>();
|
||||
//für jede einzelne OrConstraint-Menge gehe durch
|
||||
for (Constraint con : orCons.get(i)) {
|
||||
Iterator<Pair> it = con.iterator();
|
||||
while (it.hasNext()) {
|
||||
Pair p = it.next();
|
||||
if (p.OperatorSmallerDot()) {
|
||||
extendsSet.add(p);
|
||||
} else if (p.OperatorEqual()) {
|
||||
equalSet.add(p);
|
||||
}
|
||||
}
|
||||
Iterator<Pair> itExtends2 = extendsSet.iterator();
|
||||
while(itExtends2.hasNext()) {
|
||||
Pair pairExtends2 = itExtends2.next();
|
||||
Set<String> containedVars = new HashSet<>(methodAndTPH.getTphs());
|
||||
String pairExtends2RHSName = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName();
|
||||
Iterator<Pair> itEqual2 = equalSet.iterator();
|
||||
while (itEqual2.hasNext()) {
|
||||
boolean transClo = false;
|
||||
Pair pairEqual2 = itEqual2.next();
|
||||
//TODO: Auf trans.FamilyOfGeneratedGenerics Huelle pruefen
|
||||
Pair newPairOld = new Pair(pairExtends2.TA2, pairEqual2.TA1);
|
||||
Pair newPair2 = new Pair(resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, resSet.resolveType((TypePlaceholder) (pairEqual2.TA1)).resolvedType, PairOperator.SMALLERDOT);
|
||||
TPHConstraint newPairTPHConstraint = new TPHConstraint(newPair2);
|
||||
if (tcOfCs.contains(newPairTPHConstraint)|| (newPairTPHConstraint.getLeft().equals(newPairTPHConstraint.getRight()))) {
|
||||
transClo = true;
|
||||
}
|
||||
TypePlaceholder tphR = (TypePlaceholder) pairEqual2.TA2;
|
||||
Iterator<Pair> itUndCons = undCons.iterator();
|
||||
boolean rEqExRtilde = false;
|
||||
while (itUndCons.hasNext()) {
|
||||
Pair pairUndCons2 = itUndCons.next();
|
||||
rEqExRtilde = rEqExRtilde || (tphR == pairUndCons2.TA1);
|
||||
}
|
||||
boolean isPairInTExTapostrophe = false;
|
||||
for(Set<Constraint<Pair>> scp: orCons) {
|
||||
Iterator<Constraint<Pair>> itSCP = scp.iterator();
|
||||
while(itSCP.hasNext()) {
|
||||
Constraint<Pair> cp = itSCP.next();
|
||||
Iterator<Pair> itCP = cp.iterator();
|
||||
while(itCP.hasNext()) {
|
||||
Pair p = itCP.next();
|
||||
if(p.OperatorSmallerDot()) {
|
||||
isPairInTExTapostrophe = isPairInTExTapostrophe || tphR.equals(p.TA1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (transClo && (rEqExRtilde || isPairInTExTapostrophe)) {
|
||||
if (!newPair2.TA1.equals(newPair2.TA2)) { //eliminieren der Fälle wie AA<.AA
|
||||
if (!checkForDuplicatesForSets(newPair2, tempSet2)) {
|
||||
tempSet2.add(newPair2);
|
||||
}
|
||||
}
|
||||
if (!checkForDuplicatesForSets(pairExtends2, tempSet2)) {
|
||||
tempSet2.add(pairExtends2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//containedVars.remove(((TypePlaceholder)newPair2.TA2).getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//String key = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName();
|
||||
//TODO: containedVars stimmt noch nicht. Ueberpruefen, ob ggf. mit den containedVars möglicherweise auch die anderen Faelle
|
||||
// rEqExRtilde isPairInTExTapostrophe abgedeckt sind => ggf. integrieren
|
||||
/*
|
||||
posOfTphs.forEach((x,y) -> {
|
||||
if (y.contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) {
|
||||
containedVars.add(x);
|
||||
};
|
||||
}
|
||||
);
|
||||
*/
|
||||
//Referenzbeispiel Put.jav
|
||||
if (containedVars.stream().filter(v -> tcOfCs.contains(new TPHConstraint(pairExtends2RHSName, v, Relation.EXTENDS)))
|
||||
.count() > 0) {
|
||||
System.out.println();
|
||||
//tempSet2.add(pairExtends2);
|
||||
}
|
||||
if (posOfTphs.containsKey(pairExtends2RHSName)) {//Refrenzbeispiel TestVector.jav
|
||||
if (posOfTphs.get(pairExtends2RHSName).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) {
|
||||
tempSet2.add(pairExtends2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// aus der alten Datenstruktur in die neue Datenstruktur (von Ali) für ersten Teil
|
||||
Iterator<Pair> itTemp = tempSet.iterator();
|
||||
while(itTemp.hasNext()) {
|
||||
Pair p = itTemp.next();
|
||||
String ta1 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName();
|
||||
String ta2 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName();
|
||||
Relation r = null;
|
||||
if(p.GetOperator() == PairOperator.SMALLERDOT) {
|
||||
r = Relation.EXTENDS;
|
||||
} else if(p.GetOperator() == PairOperator.EQUALSDOT) {
|
||||
r = Relation.EQUAL;
|
||||
}
|
||||
MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
|
||||
if(mc.getRel() == Relation.EXTENDS) {
|
||||
if(!checkForDuplicates(mc, tempMC)) {
|
||||
tempMC.add(mc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// aus der alten Datenstruktur in die neue Datenstruktur (von Ali) für zweiten Teil
|
||||
Iterator<Pair> itTemp2 = tempSet2.iterator();
|
||||
while(itTemp2.hasNext()) {
|
||||
Pair p = itTemp2.next();
|
||||
String ta1 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName();
|
||||
String ta2 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName();
|
||||
Relation r = null;
|
||||
if (p.GetOperator() == PairOperator.SMALLERDOT) {
|
||||
r = Relation.EXTENDS;
|
||||
} else if (p.GetOperator() == PairOperator.EQUALSDOT) {
|
||||
r = Relation.EQUAL;
|
||||
}
|
||||
for(TPHConstraint tphCons: tcOfCs) {//TODO: hier werden Elemente der Trans. clo herausgenommen, aber die dazugehoerigen OrCons nicht.
|
||||
if(ta1 == tphCons.getLeft() && ta2 == tphCons.getRight() && r==Relation.EXTENDS) {
|
||||
MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
|
||||
if(!checkForDuplicates(mc, tempMC)) {
|
||||
tempMC.add(mc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tempMC;
|
||||
}
|
||||
|
||||
|
||||
public static Set<Pair> buildTransitiveClosureForCP(Set constraint, ResultSet resSet) {
|
||||
Set<Pair> iterSet = new HashSet<>(constraint);
|
||||
Set<Pair> runSet = new HashSet<>(constraint);
|
||||
Set<Pair> tcSet = new HashSet<>(constraint);
|
||||
boolean addedConToList = false;
|
||||
// for (TPHConstraint cons: iterList) {
|
||||
Iterator<Pair> itIterSet = iterSet.iterator();
|
||||
while(itIterSet.hasNext()) {
|
||||
Pair pairIterSet = itIterSet.next();
|
||||
// for (TPHConstraint cons2: runList) {
|
||||
Iterator<Pair> itRunSet = runSet.iterator();
|
||||
while (itRunSet.hasNext()) {
|
||||
Pair pairRunSet = itRunSet.next();
|
||||
// if(cons.getRight() == cons2.getLeft()) {
|
||||
if(pairIterSet.TA2 == pairRunSet.TA1 && pairIterSet.OperatorSmallerDot() && pairRunSet.OperatorSmallerDot()) {
|
||||
// TPHConstraint consToAdd = new TPHConstraint(cons.getLeft(), cons2.getRight(), Relation.EXTENDS);
|
||||
Pair p = new Pair(resSet.resolveType((TypePlaceholder)(pairIterSet.TA1)).resolvedType, resSet.resolveType((TypePlaceholder)(pairRunSet.TA2)).resolvedType, PairOperator.SMALLERDOT);
|
||||
// if (!checkForDuplicates(consToAdd,tcList)) {
|
||||
if(!checkForDuplicatesForSets(p, tcSet)) {
|
||||
// tcList.add(consToAdd);
|
||||
tcSet.add(p);
|
||||
addedConToList = true;
|
||||
if (addedConToList) {
|
||||
return buildTransitiveClosureForCP(tcSet, resSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("tcSet: " + tcSet);
|
||||
return tcSet;
|
||||
}
|
||||
|
||||
public static boolean checkForDuplicatesForSets(Pair pair, Set set) {
|
||||
Set<Pair> tempSet = set;
|
||||
boolean hasSame = false;
|
||||
// for (TPHConstraint tphC: tempList) {
|
||||
Iterator<Pair> it = tempSet.iterator();
|
||||
while (it.hasNext()) {
|
||||
Pair p = it.next();
|
||||
// hasSame = constraint.getLeft() == tphC.getLeft() &&
|
||||
// constraint.getRight() == tphC.getRight() &&
|
||||
// constraint.getRel() == tphC.getRel(); //constraint already in ArrayList if true
|
||||
hasSame = pair.TA1 == p.TA1 &&
|
||||
pair.TA2 == p.TA2 &&
|
||||
pair.OperatorSmallerDot() && p.OperatorSmallerDot(); //constraint already in Set if true
|
||||
if (hasSame)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<MethodConstraint> hasNoSupertypeForMethodTypesNew(HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH, List<MethodConstraint> cs_m) {
|
||||
List<MethodConstraint> tempMC = new ArrayList<>();
|
||||
List<TPHConstraint> methCons = new ArrayList<>(cs_m);
|
||||
MethodAndTPH methAndTphs = methodAndTPH;
|
||||
for(String tph: posOfTphs.keySet()) {
|
||||
for(int i=0; i<posOfTphs.get(tph).size(); i++)
|
||||
if(posOfTphs.get(tph).get(i).fst == PositionFinder.Position.METHOD && posOfTphs.get(tph).get(i).snd == methAndTphs.getId() && !checkUpperBound(methCons,tph)) {
|
||||
MethodConstraint mc2 = new MethodConstraint(tph, objectType, Relation.EXTENDS);
|
||||
if (!checkForDuplicates(mc2, tempMC)) {
|
||||
tempMC.add(mc2);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tempMC;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List<MethodConstraint> methodTypesWithoutClassTypesNEW(List<String> tphsToCompute, List<MethodConstraint> cs_m) {
|
||||
List<MethodConstraint> tempMC = new ArrayList<>(cs_m);
|
||||
List<MethodConstraint> tempMC2 = new ArrayList<>(cs_m);
|
||||
List<String> toRemove = new ArrayList<>();
|
||||
for(String tph: tphsToCompute) {
|
||||
for(TPHConstraint tphCons: tempMC) {
|
||||
if(tphCons.getLeft() == tph) {
|
||||
toRemove.add(tphCons.getRight());
|
||||
tempMC2.remove(tphCons);
|
||||
tempMC2 = methodTypesWithoutClassTypesNEW(toRemove,tempMC2);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tempMC2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public HashMap<String, List<MethodConstraint>> getMethodConstraintsWithPositionNew(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph, ResultSet resSet, Set<Pair> oldCons) {
|
||||
HashMap<String, List<MethodConstraint>> tempMethodConstraintsWithPosition = new HashMap<>();
|
||||
List<MethodConstraint> newMCList = new ArrayList<>();
|
||||
List<MethodConstraint> newMCList2 = new ArrayList<>();
|
||||
List<MethodConstraint> hasNoSupType = new ArrayList<>();
|
||||
List<MethodConstraint> mcWithoutCc = new ArrayList<>();
|
||||
|
||||
List<String> methodsAddedToHashMap = new ArrayList<>();
|
||||
for(MethodAndTPH method: listOfMethodsAndTph){
|
||||
String currentMethod = method.getId();
|
||||
boolean containsCurrentMethod = false;
|
||||
if(!containsCurrentMethod) {
|
||||
methodsAddedToHashMap.add(currentMethod);
|
||||
containsCurrentMethod = true;
|
||||
List<MethodConstraint> listToAdd = new ArrayList<>();
|
||||
HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTPHsForThisMethod = new HashMap<>();
|
||||
for(String s: posOfTphs.keySet()) {
|
||||
for(PairTphMethod pair: posOfTphs.get(s)) {
|
||||
if(pair.snd == currentMethod && pair.snd != null) {
|
||||
posOfTPHsForThisMethod.put(s,posOfTphs.get(s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newMCList = firstLineMethodDefinition(cs, posOfTphs, method, resSet);
|
||||
for(int i=0; i<newMCList.size(); i++) {
|
||||
listToAdd.add(newMCList.get(i));
|
||||
}
|
||||
newMCList2 = secondLineMethodDefinition(cs, posOfTphs, method, resSet, oldCons);
|
||||
for(int i=0; i<newMCList2.size(); i++) {
|
||||
listToAdd.add(newMCList2.get(i));
|
||||
}
|
||||
|
||||
/*if(!methodsAddedToHashMap.contains(currentMethod)) {
|
||||
tempMethodConstraintsWithPosition.put(currentMethod, newMCList);
|
||||
tempMethodConstraintsWithPosition.put(currentMethod, newMCList2);
|
||||
}*/
|
||||
|
||||
hasNoSupType = hasNoSupertypeForMethodTypesNew(posOfTphs,method,listToAdd);
|
||||
for (MethodConstraint cons: hasNoSupType) {
|
||||
if (!checkForDuplicates(cons, listToAdd)) {
|
||||
listToAdd.add(cons);
|
||||
}
|
||||
}
|
||||
|
||||
mcWithoutCc = listToAdd;
|
||||
List<String> tphs = new ArrayList<>();
|
||||
for(String tph: posOfTphs.keySet()) {
|
||||
for (PairTphMethod p : posOfTphs.get(tph)) {
|
||||
if(p.fst == PositionFinder.Position.FIELD) {
|
||||
tphs.add(tph);
|
||||
mcWithoutCc = methodTypesWithoutClassTypesNEW(tphs, listToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tempMethodConstraintsWithPosition.put(currentMethod, mcWithoutCc);
|
||||
}
|
||||
for(String curMeth: tempMethodConstraintsWithPosition.keySet()){
|
||||
for(int i=0; i<tempMethodConstraintsWithPosition.get(curMeth).size(); i++) {
|
||||
MethodConstraint currentMC = tempMethodConstraintsWithPosition.get(curMeth).get(i);
|
||||
if(currentMC.getRight()!= objectType && !compareTphsOfConstraints(currentMC.getRight(), cs_cl) && !compareTphsOfConstraints(currentMC.getRight(), tempMethodConstraintsWithPosition.get(curMeth))) {
|
||||
MethodConstraint mc = new MethodConstraint(currentMC.getRight(), objectType, Relation.EXTENDS);
|
||||
tempMethodConstraintsWithPosition.get(curMeth).add(mc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tempMethodConstraintsWithPosition;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
package de.dhbwstuttgart.bytecode.gGenericsAli;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
*/
|
||||
/**
|
||||
* gets set of typed variable constraints with substitutions and the set of typed classes
|
||||
* and returns the set of families of generated generics and the set of families of type variable mappings
|
||||
*//*
|
||||
|
||||
public class GGenerics implements preGGenerics {
|
||||
private TVarConstraints tVarCons;
|
||||
private Substitutions subst;
|
||||
private TClass typedClass;
|
||||
|
||||
|
||||
public GGenerics(TVarConstraints tVarCons, Substitutions subst, TClass typedClass) throws IOException, ClassNotFoundException {
|
||||
this.tVarCons = tVarCons;
|
||||
this.subst = subst;
|
||||
this.typedClass = typedClass;
|
||||
}
|
||||
|
||||
List<File> input = new ArrayList<>();
|
||||
List<File> classpath = new ArrayList<>();
|
||||
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(input, classpath);
|
||||
compiler.typeInference();
|
||||
|
||||
public List<ResultSet> getResultOfTypeInference() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
*/
|
@ -0,0 +1,10 @@
|
||||
package de.dhbwstuttgart.bytecode.insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
|
||||
public class MethodConstraint extends TPHConstraint {
|
||||
public MethodConstraint(String left, String right, Relation rel) {
|
||||
super(left, right, rel);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
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 PairTphMethod<A, B> {
|
||||
public final A fst;
|
||||
public final B snd;
|
||||
|
||||
public PairTphMethod(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 PairTphMethod<?,?> &&
|
||||
Objects.equals(fst, ((PairTphMethod<?,?>)other).fst) &&
|
||||
Objects.equals(snd, ((PairTphMethod<?,?>)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> PairTphMethod<A,B> of(A a, B b) {
|
||||
return new PairTphMethod<>(a,b);
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package de.dhbwstuttgart.bytecode.insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
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,
|
||||
FIELD
|
||||
}
|
||||
|
||||
public static HashMap<String, PairTphMethod<Position, String>> getPositionOfTPH(SourceFile sf, Set<String> tphs) {
|
||||
|
||||
new Walker().visit(sf);
|
||||
for (String tph: posOfTphs.keySet()) {
|
||||
System.out.println(tph + " " + posOfTphs.get(tph));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public static void putPositionInMethod(String tph, String methodId) {
|
||||
posOfTphs.put(tph, new PairTphMethod<>(Position.METHOD, methodId));
|
||||
}
|
||||
|
||||
public static void putPositionInField(String tph) {
|
||||
posOfTphs.put(tph, new PairTphMethod<>(Position.FIELD, null));
|
||||
}
|
||||
|
||||
public static void putPositionInConstructor(String tph, String id) {
|
||||
posOfTphs.put(tph, new PairTphMethod<>(Position.CONSTRUCTOR, id));
|
||||
}
|
||||
|
||||
|
||||
|
||||
static class Walker extends AbstractASTWalker{
|
||||
Boolean inMethod = false;
|
||||
Boolean inConstructor = false;
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder tph) {
|
||||
if (inMethod) {
|
||||
if (inConstructor) {
|
||||
// System.out.println(tph);
|
||||
// putPositionInConstructor(tph.getName(),);
|
||||
}
|
||||
// System.out.println(tph);
|
||||
// putPositionInMethod(tph.getName(),);
|
||||
} else {
|
||||
putPositionInField(tph.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Field field) {
|
||||
super.visit(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
inMethod = true;
|
||||
super.visit(method);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Constructor cons) {
|
||||
inConstructor = true;
|
||||
super.visit(cons);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package de.dhbwstuttgart.bytecode.insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
interface preGGenerics {
|
||||
public List<ResultSet> getResultOfTypeInference();
|
||||
}
|
@ -4,6 +4,8 @@ import java.util.ArrayList;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
|
||||
@ -15,11 +17,21 @@ public class MethodAndTPH {
|
||||
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
|
||||
// tphs of local variables and parameters
|
||||
private final ArrayList<String> localTphs = new ArrayList<>();
|
||||
/*
|
||||
* its Constraints
|
||||
* eingefuegt PL 2021-02-15
|
||||
*/
|
||||
public final ConstraintSet constraints;
|
||||
|
||||
public MethodAndTPH(String name) {
|
||||
public MethodAndTPH(String name, ConstraintSet<Pair> constraints) {
|
||||
this.id = name;
|
||||
this.constraints = constraints;
|
||||
}
|
||||
|
||||
|
||||
public void addTph(String tph) {
|
||||
tphs.add(tph);
|
||||
}
|
||||
|
||||
public ArrayList<String> getTphs() {
|
||||
return tphs;
|
||||
}
|
||||
@ -39,4 +51,9 @@ public class MethodAndTPH {
|
||||
return localTphs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import de.dhbwstuttgart.bytecode.BytecodeGen;
|
||||
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
||||
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
@ -78,7 +79,12 @@ public class JavaTXCompiler {
|
||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll?
|
||||
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
//nur fuer Testzwecke of Generated Generics
|
||||
//wieder loeschen PL 2021-03-22
|
||||
public FamilyOfGeneratedGenerics fogg;
|
||||
|
||||
|
||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||
this(Arrays.asList(sourceFile), null);
|
||||
}
|
||||
@ -86,6 +92,9 @@ public class JavaTXCompiler {
|
||||
this(sourceFile);
|
||||
this.log = log;
|
||||
}
|
||||
public JavaTXCompiler(File[] sourceFiles) throws IOException, ClassNotFoundException {
|
||||
this(Arrays.asList(sourceFiles), null);
|
||||
}
|
||||
public JavaTXCompiler(List<File> sourceFiles) throws IOException, ClassNotFoundException {
|
||||
this(sourceFiles, null);
|
||||
}
|
||||
@ -102,7 +111,8 @@ public class JavaTXCompiler {
|
||||
//INSTANCE = this;
|
||||
}
|
||||
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
|
||||
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
ClassOrInterface objectClass = ASTFactory.createClass(
|
||||
@ -872,6 +882,7 @@ public class JavaTXCompiler {
|
||||
SourceFile sf = sourceFiles.get(f);
|
||||
GeneratedGenericsFinder sResFinder = new GeneratedGenericsFinder(sf, typeinferenceResult);
|
||||
GenericGenratorResultForSourceFile simplifyResOfSF = sResFinder.findGeneratedGenerics();
|
||||
this.fogg = sResFinder.getFogg();
|
||||
result.add(simplifyResOfSF);
|
||||
}
|
||||
return result;
|
||||
|
@ -0,0 +1,132 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
|
||||
/**
|
||||
* Utilities to generate the constraints for the infer wildcards algorithm.
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
public final class ConstraintsGenerationUtils
|
||||
{
|
||||
|
||||
private ConstraintsGenerationUtils () {
|
||||
throw new AssertionError("No ConstraintsGenerationUtils instance for you");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the constraints for a map of type placeholder and RefType and merge
|
||||
* these to the already provided constraints.
|
||||
*
|
||||
* @param tphMap {@link Map} of {@link TypePlaceholder} and
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @param constraints {@link ConstraintSet} over {@link Pair} to merge to
|
||||
* @return The same instance {@code constraints} provided including the merged
|
||||
* constraints
|
||||
*/
|
||||
public static ConstraintSet<Pair> generateAndMergeConstraints (
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap,
|
||||
ConstraintSet<Pair> constraints) {
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
constraints.addAll(generateConstraints);
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the constraints for a map of type placeholder and RefType.
|
||||
*
|
||||
* @param tphMap {@link Map} of {@link TypePlaceholder} and
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @return {@link ConstraintSet} of {@link Pair} containing the constraints to
|
||||
* infer the matching wildcard type.
|
||||
*/
|
||||
public static ConstraintSet<Pair> generateConstraints (
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap) {
|
||||
return tphMap.entrySet().stream().map(ConstraintsGenerationUtils::generateConstraints)
|
||||
.reduce(
|
||||
new ConstraintSet<>(),
|
||||
(cs, c) -> {
|
||||
cs.addAll(c);
|
||||
return cs;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the constraints for a single RefType type placeholder pair to infer
|
||||
* the wildcards for the generic parameter type.
|
||||
*
|
||||
* @param tphEntry {@link Entry} of {@link TypePlaceholder} and
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @return {@link ConstraintSet} of {@link Pair} generated containing the
|
||||
* constraints.
|
||||
*/
|
||||
private static ConstraintSet<Pair> generateConstraints (
|
||||
Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphEntry) {
|
||||
return generateConstraints(tphEntry.getValue(), tphEntry.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the constraints for a single RefType type placeholder pair to infer
|
||||
* the wildcards for the generic parameter type.
|
||||
*
|
||||
* @param refType {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @param tph {@link TypePlaceholder}
|
||||
* @return {@link ConstraintSet} of {@link Pair} generated containing the
|
||||
* constraints.
|
||||
*/
|
||||
public static ConstraintSet<Pair> generateConstraints (RefTypeOrTPHOrWildcardOrGeneric refType,
|
||||
TypePlaceholder tph) {
|
||||
ConstraintSet<Pair> constraintSet = new ConstraintSet<>();
|
||||
Set<Constraint<Pair>> oderConstraints = new HashSet<>();
|
||||
constraintSet.addOderConstraint(oderConstraints);
|
||||
|
||||
// single type
|
||||
ConstraintsGenerationUtils.addToOderConstraint(oderConstraints, tph, refType);
|
||||
|
||||
// extends type
|
||||
ExtendsWildcardType extendsWildcardType = new ExtendsWildcardType(refType, new NullToken());
|
||||
ConstraintsGenerationUtils.addToOderConstraint(oderConstraints, tph, extendsWildcardType);
|
||||
|
||||
// super type
|
||||
SuperWildcardType superWildcardType = new SuperWildcardType(refType, new NullToken());
|
||||
ConstraintsGenerationUtils.addToOderConstraint(oderConstraints, tph, superWildcardType);
|
||||
|
||||
return constraintSet;
|
||||
}
|
||||
|
||||
private static void addToOderConstraint (Set<Constraint<Pair>> oderConstraints, TypePlaceholder tph,
|
||||
RefTypeOrTPHOrWildcardOrGeneric refType) {
|
||||
Constraint<Pair> c = new Constraint<>();
|
||||
oderConstraints.add(c);
|
||||
|
||||
ConstraintsGenerationUtils.addToConstraint(c, tph, refType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a pair and adds it to a constraint.
|
||||
*
|
||||
* @param c {@link Constraint} of {@link Pair}
|
||||
* @param tph {@link TypePlaceholder}
|
||||
* @param type {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
*/
|
||||
private static void addToConstraint (Constraint<Pair> c, TypePlaceholder tph,
|
||||
RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
Pair pair = new Pair(tph, type, PairOperator.EQUALSDOT);
|
||||
c.add(pair);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class FindInAstVisitor
|
||||
{
|
||||
|
||||
public static boolean find (SourceFile file, TypePlaceholder tph) {
|
||||
FindInAstVisitor findInAstVisitor = new FindInAstVisitor(tph);
|
||||
return findInAstVisitor.find(file);
|
||||
}
|
||||
|
||||
private boolean find;
|
||||
private TypePlaceholder tph;
|
||||
|
||||
|
||||
public FindInAstVisitor (TypePlaceholder tph) {
|
||||
this.tph = tph;
|
||||
find = false;
|
||||
}
|
||||
|
||||
public boolean find (SourceFile file) {
|
||||
CostumASTWalker walker = new CostumASTWalker();
|
||||
walker.visit(file);
|
||||
return find;
|
||||
}
|
||||
|
||||
private class CostumASTWalker extends AbstractASTWalker{
|
||||
|
||||
@Override
|
||||
public void visit (TypePlaceholder typePlaceholder) {
|
||||
if (typePlaceholder.equals(tph))
|
||||
find = true;
|
||||
else
|
||||
super.visit(typePlaceholder);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,209 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
/**
|
||||
* Extension of the JavaTX Compiler providing the capabilities to inference
|
||||
* wildcard types.
|
||||
* <p>
|
||||
* <code>
|
||||
* <ul>
|
||||
* <li>? super Type</li>
|
||||
* <li>? extends Type</li>
|
||||
* <li>Type</li>
|
||||
* </ul>
|
||||
* </code>
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
public class JavaTXCompilerWildcards
|
||||
extends JavaTXCompiler
|
||||
{
|
||||
|
||||
/**
|
||||
* Generated Type placeholder and the implementation type represented.
|
||||
*/
|
||||
private final Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap;
|
||||
|
||||
public JavaTXCompilerWildcards (File... sourceFile) throws IOException, ClassNotFoundException {
|
||||
super(Arrays.asList(sourceFile));
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
public JavaTXCompilerWildcards (File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
|
||||
super(sourceFile, log);
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
public JavaTXCompilerWildcards (List<File> sourceFiles) throws IOException, ClassNotFoundException {
|
||||
super(sourceFiles);
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
public JavaTXCompilerWildcards (List<File> sources, List<File> contextPath)
|
||||
throws IOException, ClassNotFoundException {
|
||||
super(sources, contextPath);
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Type Placeholder generated.
|
||||
*
|
||||
* @return {@link Map} over {@link TypePlaceholder} and
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
*/
|
||||
public Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> getTphMap () {
|
||||
return tphMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintSet<Pair> getConstraints () throws ClassNotFoundException, IOException {
|
||||
ConstraintSet<Pair> constraints = super.getConstraints();
|
||||
return ConstraintsGenerationUtils.generateAndMergeConstraints(tphMap, constraints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the source code for manipulated Java Generic Types to a new .java
|
||||
* file.
|
||||
*
|
||||
* @param outputDir {@link File}
|
||||
* @throws IOException if an i/o exception during file reading and
|
||||
* writing occurs
|
||||
* @throws ClassNotFoundException see {@link #typeInference()}
|
||||
*/
|
||||
public void generateSourceCode (File outputDir) throws IOException, ClassNotFoundException {
|
||||
if (!outputDir.exists()) {
|
||||
boolean mkdirs = outputDir.mkdirs();
|
||||
if (!mkdirs)
|
||||
throw new IOException("Could not create output directory at: " + outputDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
List<ResultSet> typeInference = typeInference();
|
||||
|
||||
if (typeInference.isEmpty())
|
||||
return;
|
||||
|
||||
ResultSet resultSet = typeInference.get(0); // Use the first available result sets
|
||||
|
||||
for (Map.Entry<File, SourceFile> e : sourceFiles.entrySet()) {
|
||||
List<Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric>> list = tphMap.entrySet().stream().filter(d -> FindInAstVisitor.find(e.getValue(), d.getKey())).sorted( (c1, c2) -> Integer.compare(c1.getValue().getOffset().getStartIndex(),
|
||||
c2.getValue().getOffset().getStartIndex())).collect(Collectors.toList());
|
||||
generateSourceCode(e.getKey(), outputDir, list, resultSet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void generateSourceCode (File inputFile, File outputDir,
|
||||
List<Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric>> tphs,
|
||||
ResultSet results)
|
||||
throws IOException {
|
||||
|
||||
File outputFile = new File(outputDir, inputFile.getName());
|
||||
|
||||
Files.deleteIfExists(outputFile.toPath());
|
||||
|
||||
if(!outputFile.createNewFile())
|
||||
throw new IOException("File could not be created at: " + outputFile.getAbsolutePath());
|
||||
|
||||
try(BufferedReader reader = new BufferedReader(new FileReader(inputFile));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))){
|
||||
|
||||
|
||||
int readIdx = 0;
|
||||
|
||||
for (Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> e : tphs) {
|
||||
Token token = e.getValue().getOffset();
|
||||
|
||||
// read the characters before the token
|
||||
int startIndex = token.getStartIndex();
|
||||
char[] read = new char[startIndex - readIdx];
|
||||
|
||||
int i = reader.read(read);
|
||||
if (i != read.length)
|
||||
throw new IOException("Could not read the assumed number of character, read " + i
|
||||
+ " assumed " + read.length);
|
||||
|
||||
readIdx += read.length;
|
||||
|
||||
// Write to output file
|
||||
writer.write(read);
|
||||
|
||||
// Write the new type
|
||||
ResolvedType resolveType = results.resolveType(e.getKey());
|
||||
String string = resolveType.resolvedType.toString();
|
||||
writer.write(string);
|
||||
|
||||
// Read the replaced type and count the read counter
|
||||
int length = token.getStopIndex() - token.getStartIndex() + 1;
|
||||
reader.read(new char[length]);
|
||||
readIdx += length;
|
||||
|
||||
// Read the replaced nested type if the result was a nested type
|
||||
Pattern pattern = Pattern.compile("<.*>");
|
||||
Matcher matcher = pattern.matcher(string);
|
||||
if (matcher.find()) {
|
||||
|
||||
// Read the first and check if it will be a Java Generic Expression starting
|
||||
// with <
|
||||
char c = (char) reader.read();
|
||||
readIdx++;
|
||||
|
||||
if (c != '<')
|
||||
throw new IllegalStateException("At this position is a < expected, found " + c);
|
||||
|
||||
// Read and forget all content until a > on the same level
|
||||
int opens = 1;
|
||||
while (opens > 0) {
|
||||
c = (char) reader.read();
|
||||
readIdx++;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '<':
|
||||
opens++;
|
||||
break;
|
||||
case '>':
|
||||
opens--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read the rest of the file.
|
||||
while (true) {
|
||||
char[] tmp = new char[1024];
|
||||
int read = reader.read(tmp);
|
||||
if (read == -1)
|
||||
break;
|
||||
|
||||
writer.write(tmp, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* Visitor replace type parameter of the type RefType by Type Placeholder in a
|
||||
* AST.
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ReplaceTypeparamVisitor
|
||||
extends AbstractASTWalker
|
||||
{
|
||||
|
||||
/**
|
||||
* Containing the replaced RefType and the mapping TPH
|
||||
*/
|
||||
private final Map<TypePlaceholder, RefTypeOrTPHOrWildcardOrGeneric> tphMap;
|
||||
|
||||
/**
|
||||
* Constructor for a {@code ReplaceTypeparamVisitor}.
|
||||
*/
|
||||
public ReplaceTypeparamVisitor () {
|
||||
this.tphMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit (Field field) {
|
||||
System.out.println("Field: " + field.getName());
|
||||
|
||||
field.accept(new ReplaceRefTypeVisitor());
|
||||
|
||||
super.visit(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit (FormalParameter formalParameter) {
|
||||
System.out.println("FormalParameter: " + formalParameter.getName());
|
||||
|
||||
formalParameter.accept(new ReplaceRefTypeVisitor());
|
||||
|
||||
super.visit(formalParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit (LocalVarDecl localVarDecl) {
|
||||
System.out.println("LocalVarDecl: " + localVarDecl.getName());
|
||||
|
||||
localVarDecl.accept(new ReplaceRefTypeVisitor());
|
||||
|
||||
super.visit(localVarDecl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit (Method method) {
|
||||
System.out.println("Method: " + method.getName());
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
|
||||
if (returnType != null)
|
||||
returnType.accept(new ReplaceRefTypeVisitor());
|
||||
|
||||
super.visit(method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the mapping of the replaced {@link RefType} and the inserted
|
||||
* {@link TypePlaceholder}.
|
||||
*
|
||||
* @return {@link Map} of {@link TypePlaceholder} and {@link RefType}
|
||||
*/
|
||||
public Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> getTphMap () {
|
||||
return tphMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visitor replace each RefType occurs.
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
private class ReplaceRefTypeVisitor
|
||||
extends AbstractASTWalker
|
||||
{
|
||||
@Override
|
||||
public void visit (RefType refType) {
|
||||
|
||||
// check if RefType has Parameter Types
|
||||
if (!refType.getParaList().isEmpty()) {
|
||||
System.out.print("Visit Type: " + refType + " -> ");
|
||||
|
||||
// Iterate over all Parameter Types
|
||||
for (ListIterator<RefTypeOrTPHOrWildcardOrGeneric> listIterator = refType.getParaList()
|
||||
.listIterator(); listIterator.hasNext();) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric next = listIterator.next();
|
||||
|
||||
// If Parameter type is RefType replace with TPH
|
||||
if (next instanceof RefType) {
|
||||
RefType nextRefType = (RefType) next;
|
||||
|
||||
// Visit replaced RefType to get all nested type parameters
|
||||
// Should be done before generating parents TPH to include child TPH in the
|
||||
// parent TPH mapping
|
||||
this.visit(nextRefType);
|
||||
|
||||
generateTphAndReplaceInTree(listIterator, next);
|
||||
}
|
||||
else if (next instanceof GenericRefType) {
|
||||
|
||||
// Visit of nested type arguments not necessary as Generic Types cannot contain
|
||||
// type parameters
|
||||
|
||||
generateTphAndReplaceInTree(listIterator, next);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(refType);
|
||||
}
|
||||
|
||||
// Let the parent take care about all the other stuff
|
||||
super.visit(refType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the TPH for a {@link RefTypeOrTPHOrWildcardOrGeneric} and saves the
|
||||
* mapping.
|
||||
*
|
||||
* @param t {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @return {@link TypePlaceholder} generated
|
||||
*/
|
||||
private TypePlaceholder generateTypePlaceholder (RefTypeOrTPHOrWildcardOrGeneric t) {
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(new NullToken());
|
||||
tphMap.put(tph, t);
|
||||
return tph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the TPH for a {@link RefTypeOrTPHOrWildcardOrGeneric}, saves the
|
||||
* mapping and replaces the type by the type placeholder in the tree.
|
||||
*
|
||||
* @param listIterator {@link ListIterator} over
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric} representing the
|
||||
* tree to replace in
|
||||
* @param refType {@link RefTypeOrTPHOrWildcardOrGeneric} to generate type
|
||||
* placeholder for and replace
|
||||
*/
|
||||
private void generateTphAndReplaceInTree (ListIterator<RefTypeOrTPHOrWildcardOrGeneric> listIterator,
|
||||
RefTypeOrTPHOrWildcardOrGeneric refType) {
|
||||
// Generate TPH
|
||||
TypePlaceholder tph = generateTypePlaceholder(refType);
|
||||
|
||||
// Replace in AST
|
||||
listIterator.set(tph);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* Class providing utilities to generate the Type placeholder for parameter
|
||||
* types which shall be inferred.
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
public final class TypePlaceholderReplaceUtils
|
||||
{
|
||||
|
||||
private TypePlaceholderReplaceUtils () {
|
||||
throw new AssertionError("No TypePlaceholderReplaceUtils instance for you");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the map of the generated type placeholder for the associate parameter
|
||||
* type
|
||||
*
|
||||
* @param compiler {@link JavaTXCompiler} to get the source file from
|
||||
* @return {@link Map} over {@link TypePlaceholder} and the {@link RefType}
|
||||
* replaced
|
||||
*/
|
||||
public static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTypePlaceholder (
|
||||
JavaTXCompiler compiler) {
|
||||
Map<File, SourceFile> sourceFiles = compiler.sourceFiles;
|
||||
ReplaceTypeparamVisitor visitor = new ReplaceTypeparamVisitor();
|
||||
sourceFiles.forEach( (k, v) -> v.accept(visitor));
|
||||
return visitor.getTphMap();
|
||||
}
|
||||
|
||||
}
|
@ -216,6 +216,7 @@ public class StatementGenerator {
|
||||
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()),
|
||||
getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()),
|
||||
argTypes, methodInvocationContext.getStart());
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -302,33 +303,45 @@ public class StatementGenerator {
|
||||
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream()
|
||||
.map(x -> TypePlaceholder.fresh(newExpression.getStart()))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
return new NewClass(newClass, args, null, argTypes, newExpression.getStart());
|
||||
Statement ret = new NewClass(newClass, args, null, argTypes, newExpression.getStart());
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
|
||||
Expression argument = convert(stmt.unaryExpression());
|
||||
Token offset = stmt.getStart();
|
||||
return new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset), offset);
|
||||
}
|
||||
Statement ret = new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset), offset);
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) {
|
||||
return new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()),
|
||||
Statement ret = new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()),
|
||||
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) {
|
||||
return new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()),
|
||||
Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()),
|
||||
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) {
|
||||
return new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()),
|
||||
Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()),
|
||||
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.AssignmentContext stmt) {
|
||||
AssignLeftSide leftHandSide = convert(stmt.leftHandSide());
|
||||
return new Assign(leftHandSide, convert(stmt.expression()), stmt.getStart());
|
||||
Statement ret = new Assign(leftHandSide, convert(stmt.expression()), stmt.getStart());
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private AssignLeftSide convert(Java8Parser.LeftHandSideContext leftHandSide) {
|
||||
|
@ -43,7 +43,7 @@ public class GatherNames {
|
||||
}
|
||||
else{
|
||||
if(typeDecl.classDeclaration().normalClassDeclaration() != null){
|
||||
if(pkgName != ""){
|
||||
if(!pkgName.isEmpty()){
|
||||
nameString = pkgName + "." + typeDecl.classDeclaration().normalClassDeclaration().Identifier().toString();
|
||||
}
|
||||
else{
|
||||
|
@ -126,6 +126,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
||||
public void visit(Assign assign) {
|
||||
assign.lefSide.accept(this);
|
||||
assign.rightSide.accept(this);
|
||||
assign.rightSide.getType().accept((ASTVisitor) this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -186,8 +187,10 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
||||
public void visit(MethodCall methodCall) {
|
||||
methodCall.receiver.accept(this);
|
||||
methodCall.getArgumentList().accept(this);
|
||||
methodCall.getArgumentList().getArguments().forEach(a -> a.getType().accept((ASTVisitor) this));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(NewClass methodCall) {
|
||||
visit((MethodCall) methodCall);
|
||||
@ -211,6 +214,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
||||
@Override
|
||||
public void visit(Return aReturn) {
|
||||
aReturn.retexpr.accept(this);
|
||||
aReturn.getType().accept((ASTVisitor) this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,8 +31,14 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
private ExceptionList exceptionlist;
|
||||
private GenericDeclarationList generics;
|
||||
private final RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||
public final Boolean isInherited;
|
||||
|
||||
public final Boolean isInherited;
|
||||
|
||||
/*
|
||||
* its Constraints
|
||||
* eingefuegt PL 2021-02-15
|
||||
*/
|
||||
public final ConstraintSet constraints = new ConstraintSet();
|
||||
|
||||
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
|
||||
GenericDeclarationList gtvDeclarations, Token offset) {
|
||||
super(offset);
|
||||
@ -70,6 +76,10 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
return this.returnType;
|
||||
}
|
||||
|
||||
public ConstraintSet getConstraints() {
|
||||
return this.constraints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
|
@ -45,6 +45,12 @@ public class SourceFile extends SyntaxTreeNode{
|
||||
public List<ClassOrInterface> getClasses() {
|
||||
return KlassenVektor;
|
||||
}
|
||||
|
||||
public List<Method> getAllMethods() {
|
||||
List<Method> ret = new ArrayList<>();
|
||||
getClasses().forEach(cl -> ret.addAll(cl.getMethods()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ASTVisitor visitor) {
|
||||
|
@ -36,7 +36,7 @@ public class ASTFactory {
|
||||
List<Method> methoden = new ArrayList<>();
|
||||
List<de.dhbwstuttgart.syntaxtree.Constructor> konstruktoren = new ArrayList<>();
|
||||
for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){
|
||||
konstruktoren.add(createConstructor(constructor, jreClass));
|
||||
createConstructor(constructor, jreClass).map(c -> konstruktoren.add(c));
|
||||
}
|
||||
Set<java.lang.reflect.Method> allMethods = new HashSet<>(Arrays.asList(jreClass.getMethods()));
|
||||
Set<java.lang.reflect.Method> allDeclaredMethods = new HashSet<>(Arrays.asList(jreClass.getDeclaredMethods()));
|
||||
@ -87,7 +87,7 @@ public class ASTFactory {
|
||||
// return createClass(classType).getType();
|
||||
//}
|
||||
|
||||
private static de.dhbwstuttgart.syntaxtree.Constructor createConstructor(Constructor constructor, Class inClass) {
|
||||
private static Optional<de.dhbwstuttgart.syntaxtree.Constructor> createConstructor(Constructor constructor, Class inClass) {
|
||||
String name = constructor.getName();
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass);
|
||||
Parameter[] jreParams = constructor.getParameters();
|
||||
@ -106,10 +106,10 @@ public class ASTFactory {
|
||||
int modifier = constructor.getModifiers();
|
||||
|
||||
if(inClass.equals(java.lang.Object.class)){
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */);
|
||||
return Optional.of(new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */));
|
||||
}
|
||||
|
||||
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass, Boolean isInherited){
|
||||
|
@ -4,6 +4,16 @@ public class NameGenerator {
|
||||
|
||||
private static String strNextName = "A";
|
||||
|
||||
/**
|
||||
* Setzt den zu Beginn der Typinferenz auf "A" zurueck.
|
||||
* Dies ist bei JUnit-Test noetig
|
||||
* <code>TypePlaceholder</code>. <br>Author: Martin Pluemicke
|
||||
* @return void
|
||||
*/
|
||||
public static void reset() {
|
||||
strNextName = "A";
|
||||
}
|
||||
|
||||
/**
|
||||
* Berechnet einen neuen, eindeutigen Namen f�r eine neue
|
||||
* <code>TypePlaceholder</code>. <br>Author: J�rg B�uerle
|
||||
|
@ -18,6 +18,7 @@ import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.PairNoResult;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
|
||||
@ -208,6 +209,7 @@ public class UnifyTypeFactory {
|
||||
}
|
||||
|
||||
public static ResultPair convert(UnifyPair mp, Map<String,TypePlaceholder> tphs) {
|
||||
if (mp == null) { return null;} //kann bei basePairs passieren
|
||||
RefTypeOrTPHOrWildcardOrGeneric tl = UnifyTypeFactory.convert(mp.getLhsType(), tphs);
|
||||
RefTypeOrTPHOrWildcardOrGeneric tr = UnifyTypeFactory.convert(mp.getRhsType(), tphs);
|
||||
if(tl instanceof TypePlaceholder){
|
||||
@ -218,7 +220,7 @@ public class UnifyTypeFactory {
|
||||
//Einfach ignorieren TODO: Das hier muss ausgebessert werden:
|
||||
//return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, ASTFactory.createObjectType());
|
||||
}else{
|
||||
return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr);
|
||||
return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr, convert(mp.getBasePair(), tphs));
|
||||
}
|
||||
}else if(tr instanceof RefType){
|
||||
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (RefType) tr);
|
||||
@ -227,7 +229,7 @@ public class UnifyTypeFactory {
|
||||
}else if(tr instanceof GenericRefType){
|
||||
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (GenericRefType) tr);
|
||||
}else throw new NotImplementedException();
|
||||
}else throw new NotImplementedException();
|
||||
}else return new PairNoResult(tl, tr);//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {
|
||||
@ -258,6 +260,7 @@ public class UnifyTypeFactory {
|
||||
ret = TypePlaceholder.fresh(new NullToken());
|
||||
tphs.put(t.getName(), ret);
|
||||
}
|
||||
ret.setVariance(t.getVariance());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -24,13 +24,9 @@ public class MethodCall extends Statement
|
||||
|
||||
public final ArgumentList arglist;
|
||||
|
||||
/*
|
||||
* noetig fuer Bytecodegenerierung
|
||||
*/
|
||||
public RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
||||
public final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes;
|
||||
|
||||
|
||||
public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList,
|
||||
RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
|
||||
super(retType,offset);
|
||||
@ -40,6 +36,7 @@ public class MethodCall extends Statement
|
||||
this.receiverType = receiverType;
|
||||
this.argTypes = argTypes;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(StatementVisitor visitor) {
|
||||
|
@ -6,11 +6,20 @@ import org.antlr.v4.runtime.Token;
|
||||
|
||||
public abstract class Statement extends Expression
|
||||
{
|
||||
|
||||
/* zeigt an, dass eine StatementExpression als Statement benutzt wird
|
||||
*/
|
||||
private boolean isStatement = false;
|
||||
|
||||
public Statement(RefTypeOrTPHOrWildcardOrGeneric type, Token offset)
|
||||
{
|
||||
super(type, offset);
|
||||
}
|
||||
|
||||
public void setStatement() {
|
||||
isStatement=true;
|
||||
}
|
||||
|
||||
public boolean getStatement() {
|
||||
return isStatement;
|
||||
}
|
||||
}
|
@ -53,4 +53,10 @@ public class ExtendsWildcardType extends WildcardType{
|
||||
public void accept(ResultSetVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -32,5 +32,18 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
public void accept(ResultSetVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "GTV " + this.name;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,8 +77,8 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
if(obj instanceof RefType){
|
||||
boolean ret = true;
|
||||
|
||||
if(!super.equals(obj))
|
||||
return false;
|
||||
//if(!(super.equals(obj))) PL 2020-03-12 muss vll. einkommentiert werden
|
||||
// return false;
|
||||
|
||||
if(parameter==null || parameter.size()==0){
|
||||
ret &= (((RefType)obj).getParaList()==null || ((RefType)obj).getParaList().size()==0);
|
||||
|
@ -16,4 +16,7 @@ public abstract class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{
|
||||
public abstract <A> A acceptTV(TypeVisitor<A> visitor);
|
||||
public abstract void accept(ResultSetVisitor visitor);
|
||||
|
||||
@Override
|
||||
public abstract boolean equals(Object o);
|
||||
|
||||
}
|
||||
|
@ -64,4 +64,10 @@ public class SuperWildcardType extends WildcardType{
|
||||
public void accept(ResultSetVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,9 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* wird bisher nicht genutzt
|
||||
* setVariance muss ggf. auskommentiert werden.
|
||||
* wird im Generate Generics Teil nach der Rueckumwandlung nach dem Unify genutzt
|
||||
*/
|
||||
int variance = 0;
|
||||
private int variance = 0;
|
||||
|
||||
|
||||
/**
|
||||
@ -64,6 +63,10 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.getName().hashCode();
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
@ -74,11 +77,9 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
return name;
|
||||
}
|
||||
|
||||
/* wird bisher nicht genutzt
|
||||
public void setVariance(int variance) {
|
||||
this.variance= variance;
|
||||
}
|
||||
*/
|
||||
|
||||
public int getVariance() {
|
||||
return this.variance;
|
||||
|
@ -9,6 +9,12 @@ import java.util.Set;
|
||||
public class Constraint<A> extends HashSet<A> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt
|
||||
|
||||
/* es darf kein Constraint für den Return-Type erstellt werden, sonst gibt
|
||||
* es Probleme beim Generated Generics
|
||||
*/
|
||||
public boolean isStatement = false;
|
||||
|
||||
private Constraint<A> extendConstraint = null;
|
||||
|
||||
public Constraint() {
|
||||
@ -41,7 +47,7 @@ public class Constraint<A> extends HashSet<A> {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + " isInherited = " + isInherited
|
||||
return super.toString() + "\nisInherited = " + isInherited + "\nisStatement = " + isStatement
|
||||
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
|
||||
+ "\n" ;
|
||||
}
|
||||
|
@ -23,9 +23,17 @@ public class ConstraintSet<A> {
|
||||
oderConstraints.add(methodConstraints);
|
||||
}
|
||||
|
||||
public void addAllUndConstraint(Constraint<A> allUndConstraints){
|
||||
undConstraints.addAll(allUndConstraints);
|
||||
}
|
||||
|
||||
public void addAllOderConstraint(List<Set<Constraint<A>>> allOderConstraints){
|
||||
this.oderConstraints.addAll(allOderConstraints);
|
||||
}
|
||||
|
||||
public void addAll(ConstraintSet constraints) {
|
||||
this.undConstraints.addAll(constraints.undConstraints);
|
||||
this.oderConstraints.addAll(constraints.oderConstraints);
|
||||
this.addAllUndConstraint(constraints.undConstraints);
|
||||
this.addAllOderConstraint(constraints.oderConstraints);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,32 @@
|
||||
package de.dhbwstuttgart.typeinference.result;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* enthaelt alle Paare, die in einem Ergebnis nicht vorkommen koennen
|
||||
* sie sind noetig fuer origPairs in PairTPHsmallerTPH, da hier auch
|
||||
* Paare vorkommen koennen die keine Result sind (z.B. bei FunN$$)
|
||||
*/
|
||||
public class PairNoResult extends ResultPair<RefTypeOrTPHOrWildcardOrGeneric, RefTypeOrTPHOrWildcardOrGeneric>{
|
||||
//public final TypePlaceholder left;
|
||||
//public final TypePlaceholder right;
|
||||
|
||||
/*
|
||||
* urspruengliches Paar aus diesem dieses Resultpair erzeugt wurde
|
||||
* wichtig fuer generated Generics
|
||||
*/
|
||||
ResultPair origPair;
|
||||
|
||||
public PairNoResult(RefTypeOrTPHOrWildcardOrGeneric left, RefTypeOrTPHOrWildcardOrGeneric right){
|
||||
super(left, right);
|
||||
}
|
||||
|
||||
/* noch nicht implementiert. */
|
||||
@Override
|
||||
public void accept(ResultPairVisitor visitor) {
|
||||
throw new NotImplementedException();
|
||||
//visitor.visit(this);
|
||||
}
|
||||
}
|
@ -9,6 +9,12 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
public class PairTPHsmallerTPH extends ResultPair{
|
||||
public final TypePlaceholder left;
|
||||
public final TypePlaceholder right;
|
||||
|
||||
/*
|
||||
* urspruengliches Paar aus diesem dieses Resultpair erzeugt wurde
|
||||
* wichtig fuer generated Generics
|
||||
*/
|
||||
ResultPair origPair;
|
||||
|
||||
public PairTPHsmallerTPH(TypePlaceholder left, TypePlaceholder right){
|
||||
super(left, right);
|
||||
@ -16,6 +22,11 @@ public class PairTPHsmallerTPH extends ResultPair{
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public PairTPHsmallerTPH(TypePlaceholder left, TypePlaceholder right, ResultPair origPair){
|
||||
this(left, right);
|
||||
this.origPair = origPair;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ResultPairVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
|
@ -4,4 +4,7 @@ public interface ResultPairVisitor {
|
||||
void visit(PairTPHsmallerTPH p);
|
||||
void visit(PairTPHequalRefTypeOrWildcardType p);
|
||||
void visit(PairTPHEqualTPH p);
|
||||
|
||||
//bisher nicht umgesetzt
|
||||
//void visit(PairNoResult p);
|
||||
}
|
||||
|
@ -32,8 +32,10 @@ public class TYPE {
|
||||
|
||||
private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
|
||||
ConstraintSet ret = new ConstraintSet();
|
||||
ConstraintSet methConstrains;
|
||||
for(Method m : cl.getMethods()){
|
||||
ret.addAll(getConstraintsMethod(m,info, cl));
|
||||
ret.addAll(methConstrains = getConstraintsMethod(m,info, cl));
|
||||
m.constraints.addAll(methConstrains);
|
||||
}
|
||||
for(Constructor m : cl.getConstructors()){
|
||||
ret.addAll(getConstraintsConstructor(m,info, cl));
|
||||
|
@ -11,6 +11,7 @@ import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.FunNClass;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||
@ -180,6 +181,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT)
|
||||
: x)
|
||||
.collect(Collectors.toCollection(() -> new Constraint<Pair>(oneMethodConstraint.isInherited())));
|
||||
extendsOneMethodConstraint.isStatement = oneMethodConstraint.isStatement;
|
||||
oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint);
|
||||
extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint);
|
||||
methodConstraints.add(extendsOneMethodConstraint);
|
||||
@ -490,7 +492,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
@Override
|
||||
public void visit(Return returnExpr) {
|
||||
returnExpr.retexpr.accept(this);
|
||||
constraintsSet.addUndConstraint(new Pair(returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.SMALLERDOT));
|
||||
constraintsSet.addUndConstraint(new Pair(returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.EQUALSDOT));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -594,9 +596,11 @@ public class TYPEStmt implements StatementVisitor{
|
||||
//methodConstraint.add(new Pair(forMethod.receiverType, retType,
|
||||
// PairOperator.EQUALSDOT));
|
||||
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
||||
|
||||
|
||||
|
||||
methodConstraint.isStatement = forMethod.getStatement();
|
||||
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
|
||||
PairOperator.EQUALSDOT));
|
||||
PairOperator.EQUALSDOT));
|
||||
methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));
|
||||
return methodConstraint;
|
||||
}
|
||||
|
@ -269,6 +269,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
System.err.println("no log-File");
|
||||
}
|
||||
if (isUndefinedPairSetSet(res)) {
|
||||
//fuer debug-Zwecke
|
||||
ArrayList al = res.stream().map(x -> x.stream().collect(Collectors.toCollection(ArrayList::new)))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>();
|
||||
}
|
||||
else {
|
||||
@ -2181,6 +2184,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
|
||||
if (thetaPrime instanceof ReferenceType && ((ReferenceType)thetaPrime).isGenTypeVar()) {
|
||||
Set<UnifyPair> resultOne = new HashSet<>();
|
||||
resultOne.add(new UnifyPair (a, thetaPrime, PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
||||
result.add(resultOne);
|
||||
}
|
||||
|
||||
boolean allGen = thetaPrime.getTypeParams().size() > 0;
|
||||
for(UnifyType t : thetaPrime.getTypeParams())
|
||||
if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) {
|
||||
|
@ -114,6 +114,7 @@ public abstract class UnifyType {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == null)return false;
|
||||
return this.toString().equals(obj.toString());
|
||||
}
|
||||
}
|
17
src/main/java/de/dhbwstuttgart/unify2/model/Result.java
Normal file
17
src/main/java/de/dhbwstuttgart/unify2/model/Result.java
Normal file
@ -0,0 +1,17 @@
|
||||
package de.dhbwstuttgart.unify2.model;
|
||||
|
||||
public class Result<A> {
|
||||
private final A v;
|
||||
|
||||
private Result(A a, UnifyError e){
|
||||
this.v = a;
|
||||
}
|
||||
|
||||
public static <A> Result<A> of(A a){
|
||||
return new Result(a, null);
|
||||
}
|
||||
|
||||
public static <A> Result<A> error(UnifyError error){
|
||||
return new Result(null, error);
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package de.dhbwstuttgart.unify2.model;
|
||||
|
||||
public class UnifyError {
|
||||
|
||||
}
|
68
src/test/java/constraintSimplify/FamilyOfGenerics.java
Normal file
68
src/test/java/constraintSimplify/FamilyOfGenerics.java
Normal file
@ -0,0 +1,68 @@
|
||||
package constraintSimplify;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.PositionFinder;
|
||||
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FamilyOfGenerics {
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
SourceFile sf = generateAST();
|
||||
PositionFinder.getPositionOfTPH(sf, null);
|
||||
TPHExtractor tphExtractor = new TPHExtractor();
|
||||
List<ResultSet> results = new ArrayList<ResultSet>();
|
||||
GeneratedGenericsFinder generatedGenericsFinder = new GeneratedGenericsFinder(sf, results);
|
||||
}
|
||||
|
||||
public static SourceFile generateAST(){
|
||||
ArrayList<ClassOrInterface> classes = new ArrayList<>();
|
||||
ArrayList<Field> fields = new ArrayList<>();
|
||||
ArrayList<Method> methods = new ArrayList<>();
|
||||
|
||||
fields.add(generateField("fld1"));
|
||||
String[] paramNames = {"a"};
|
||||
methods.add(generateMethod("testMethode", paramNames));
|
||||
|
||||
classes.add(new ClassOrInterface(Modifier.PUBLIC, new JavaClassName("Test"), fields, Optional.empty(), methods,
|
||||
new ArrayList<>(), generateEmptyGenericDeclList(),
|
||||
new RefType(new JavaClassName("java.lang.Object"), new NullToken()),
|
||||
false, new ArrayList<>(), new NullToken()));
|
||||
|
||||
return new SourceFile("Test.jav", classes, new HashSet<>());
|
||||
}
|
||||
|
||||
public static Method generateMethod(String methodName, String[] paramNames){
|
||||
ArrayList<FormalParameter> parameters = new ArrayList<>();
|
||||
for(String str: paramNames) {
|
||||
FormalParameter fp = new FormalParameter(str, TypePlaceholder.fresh(new NullToken()), new NullToken());
|
||||
parameters.add(fp);
|
||||
|
||||
}
|
||||
ParameterList parameterList = new ParameterList(parameters, new NullToken());
|
||||
return new Method(Modifier.PUBLIC, methodName, TypePlaceholder.fresh(new NullToken()), parameterList,
|
||||
new Block(new ArrayList<>(), new NullToken()), generateEmptyGenericDeclList(), new NullToken());
|
||||
}
|
||||
|
||||
public static GenericDeclarationList generateEmptyGenericDeclList(){
|
||||
return new GenericDeclarationList(new ArrayList<>(), new NullToken());
|
||||
}
|
||||
|
||||
public static Field generateField(String fieldName) {
|
||||
return new Field(fieldName, TypePlaceholder.fresh(new NullToken()), Modifier.PUBLIC, new NullToken());
|
||||
}
|
||||
}
|
148
src/test/java/inferWildcards/TestInferWildcardsFields.java
Normal file
148
src/test/java/inferWildcards/TestInferWildcardsFields.java
Normal file
@ -0,0 +1,148 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsFields
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsFields.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
private static List<ResultSet> generateExpectedTypeInferResult (JavaTXCompilerWildcards compiler) {
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = compiler.getTphMap();
|
||||
|
||||
ArrayList<ResultSet> list = new ArrayList<>();
|
||||
|
||||
tphMap.forEach( (tph, t) -> {
|
||||
ResultPair r = new PairTPHequalRefTypeOrWildcardType(tph,
|
||||
new RefType(new JavaClassName("java.lang.String"), new NullToken()));
|
||||
HashSet<ResultPair> set = new HashSet<>();
|
||||
set.add(r);
|
||||
list.add(new ResultSet(set));
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 4", 4, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
125
src/test/java/inferWildcards/TestInferWildcardsMap.java
Normal file
125
src/test/java/inferWildcards/TestInferWildcardsMap.java
Normal file
@ -0,0 +1,125 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsMap
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsMap.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 6", 6, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
126
src/test/java/inferWildcards/TestInferWildcardsMapNested.java
Normal file
126
src/test/java/inferWildcards/TestInferWildcardsMapNested.java
Normal file
@ -0,0 +1,126 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsMapNested
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsMapNested.java";
|
||||
}
|
||||
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 9", 9, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
125
src/test/java/inferWildcards/TestInferWildcardsNested.java
Normal file
125
src/test/java/inferWildcards/TestInferWildcardsNested.java
Normal file
@ -0,0 +1,125 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsNested
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsNested.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 6", 6, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
125
src/test/java/inferWildcards/TestInferWildcardsParamType.java
Normal file
125
src/test/java/inferWildcards/TestInferWildcardsParamType.java
Normal file
@ -0,0 +1,125 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsParamType
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsParamType.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 4", 4, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
125
src/test/java/inferWildcards/TestInferWildcardsSingle.java
Normal file
125
src/test/java/inferWildcards/TestInferWildcardsSingle.java
Normal file
@ -0,0 +1,125 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsSingle
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsSingle.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 3", 3, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
125
src/test/java/inferWildcards/TestInferWildcardsSingleLib.java
Normal file
125
src/test/java/inferWildcards/TestInferWildcardsSingleLib.java
Normal file
@ -0,0 +1,125 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsSingleLib
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsSingleLib.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 2", 2, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
228
src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java
Normal file
228
src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java
Normal file
@ -0,0 +1,228 @@
|
||||
/*
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.*;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class FamilyOfGeneratedGenericsTest extends TestCase {
|
||||
|
||||
public void testIdentityMethod(){
|
||||
*/
|
||||
/*
|
||||
Example method:
|
||||
A id(B i) return i;
|
||||
gives constraint: B <. A and A <. Object, which are method constraints
|
||||
*//*
|
||||
|
||||
|
||||
List<TPHConstraint> inputConstraints = new ArrayList<>();
|
||||
inputConstraints.add(new TPHConstraint("B", "A", TPHConstraint.Relation.EXTENDS));
|
||||
|
||||
HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>();
|
||||
PairTphMethod<PositionFinder.Position, String> meth1 = new PairTphMethod<PositionFinder.Position, String>(PositionFinder.Position.METHOD, "m1");
|
||||
tphPositions.put("A", meth1);
|
||||
tphPositions.put("B", meth1);
|
||||
|
||||
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, new ArrayList<ClassConstraint>(), tphPositions);
|
||||
// assertTrue(methodConstraints.size() == 2);
|
||||
// assertTrue(methodConstraints.get(0).getLeft().equals("B"));
|
||||
// assertTrue(methodConstraints.get(0).getRight().equals("A"));
|
||||
}
|
||||
|
||||
public void testClassField(){
|
||||
*/
|
||||
/*
|
||||
class Example{
|
||||
A f;
|
||||
B fReturn(){
|
||||
return f;
|
||||
}
|
||||
}
|
||||
gives constraint: A <. B and B <. Object which are class constraints
|
||||
*//*
|
||||
|
||||
|
||||
List<TPHConstraint> inputConstraints = new ArrayList<>();
|
||||
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
|
||||
|
||||
HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>();
|
||||
PairTphMethod<PositionFinder.Position, String> posOfA = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
|
||||
tphPositions.put("A", posOfA);
|
||||
PairTphMethod<PositionFinder.Position, String> posOfB = new PairTphMethod<>(PositionFinder.Position.METHOD, "fReturn");
|
||||
tphPositions.put("B", posOfB);
|
||||
|
||||
*/
|
||||
/*
|
||||
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);
|
||||
//assertTrue(classConstraints.get(0).getLeft().equals("A"));
|
||||
//assertTrue(classConstraints.get(0).getRight().equals("B"));
|
||||
// HashMap<String, List<MethodConstraint>> methodConstraintsWithPosition = FamilyOfGeneratedGenerics.getMethodConstraintsWithPosition(inputConstraints,classConstraints,tphPositions,)
|
||||
}
|
||||
|
||||
public void testSecondLineOfClassConstraints() {
|
||||
*/
|
||||
/*
|
||||
class Example() {
|
||||
A a;
|
||||
B b = a;
|
||||
C anyMethod() {
|
||||
F f;
|
||||
return f;
|
||||
}
|
||||
D otherMethod(E e) {
|
||||
this.b = e;
|
||||
e = this.a;
|
||||
return e;
|
||||
}
|
||||
}
|
||||
*//*
|
||||
|
||||
|
||||
List<TPHConstraint> inputConstraints = new ArrayList<>();
|
||||
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
|
||||
inputConstraints.add(new TPHConstraint("F", "C", TPHConstraint.Relation.EXTENDS));
|
||||
inputConstraints.add(new TPHConstraint("E", "B", TPHConstraint.Relation.EXTENDS));
|
||||
inputConstraints.add(new TPHConstraint("A", "E", TPHConstraint.Relation.EXTENDS));
|
||||
inputConstraints.add(new TPHConstraint("E", "D", TPHConstraint.Relation.EXTENDS));
|
||||
|
||||
HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>();
|
||||
PairTphMethod<PositionFinder.Position, String> posOfA = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
|
||||
PairTphMethod<PositionFinder.Position, String> posOfB = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
|
||||
PairTphMethod<PositionFinder.Position, String> posOfC = new PairTphMethod<>(PositionFinder.Position.METHOD, "anyMethod");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfD = new PairTphMethod<>(PositionFinder.Position.METHOD, "otherMethod");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfE = new PairTphMethod<>(PositionFinder.Position.METHOD, "otherMethod");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfF = new PairTphMethod<>(PositionFinder.Position.METHOD, "anyMethod");
|
||||
|
||||
tphPositions.put("A", posOfA);
|
||||
tphPositions.put("B", posOfB);
|
||||
tphPositions.put("C", posOfC);
|
||||
tphPositions.put("F", posOfF);
|
||||
tphPositions.put("D", posOfD);
|
||||
tphPositions.put("E", posOfE);
|
||||
|
||||
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
||||
System.out.println(classConstraints);
|
||||
// List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions);
|
||||
// System.out.println(methodConstraints);
|
||||
assertFalse(classConstraints.isEmpty());
|
||||
assertTrue(classConstraints.size() == 6);
|
||||
// assertFalse(methodConstraints.isEmpty());
|
||||
// assertTrue(methodConstraints.size() == 2);
|
||||
|
||||
}
|
||||
|
||||
public void testTPHsAndGenerics() {
|
||||
*/
|
||||
/*
|
||||
class TPHsAndGenerics {
|
||||
Fun1<A,B> id = x -> x;
|
||||
C id2 (D x) {
|
||||
return id.apply(x);
|
||||
}
|
||||
E m(F a, G b){
|
||||
var c = m2(a,b);
|
||||
return a;
|
||||
}
|
||||
H m2(I a, J b){
|
||||
return b;
|
||||
}
|
||||
}
|
||||
*//*
|
||||
|
||||
|
||||
List<TPHConstraint> inputConstraints = new ArrayList<>();
|
||||
inputConstraints.add(new TPHConstraint("A","B", TPHConstraint.Relation.EXTENDS));
|
||||
inputConstraints.add(new TPHConstraint("B","C", TPHConstraint.Relation.EXTENDS));
|
||||
inputConstraints.add(new TPHConstraint("D","A", TPHConstraint.Relation.EXTENDS));
|
||||
inputConstraints.add(new TPHConstraint("F","E", TPHConstraint.Relation.EXTENDS));
|
||||
inputConstraints.add(new TPHConstraint("F","I", TPHConstraint.Relation.EXTENDS));
|
||||
inputConstraints.add(new TPHConstraint("G","J", TPHConstraint.Relation.EXTENDS));
|
||||
inputConstraints.add(new TPHConstraint("J","H", TPHConstraint.Relation.EXTENDS));
|
||||
|
||||
HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>();
|
||||
PairTphMethod<PositionFinder.Position, String> posOfA = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
|
||||
PairTphMethod<PositionFinder.Position, String> posOfB = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
|
||||
PairTphMethod<PositionFinder.Position, String> posOfC = new PairTphMethod<>(PositionFinder.Position.METHOD, "id2");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfD = new PairTphMethod<>(PositionFinder.Position.METHOD, "id2");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfE = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfF = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfG = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfH = new PairTphMethod<>(PositionFinder.Position.METHOD, "m2");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfI = new PairTphMethod<>(PositionFinder.Position.METHOD, "m2");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfJ = new PairTphMethod<>(PositionFinder.Position.METHOD, "m2");
|
||||
|
||||
tphPositions.put("A", posOfA);
|
||||
tphPositions.put("B", posOfB);
|
||||
tphPositions.put("C", posOfC);
|
||||
tphPositions.put("D", posOfD);
|
||||
tphPositions.put("E", posOfE);
|
||||
tphPositions.put("F", posOfF);
|
||||
tphPositions.put("G", posOfG);
|
||||
tphPositions.put("H", posOfH);
|
||||
tphPositions.put("I", posOfI);
|
||||
tphPositions.put("J", posOfJ);
|
||||
|
||||
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
||||
System.out.println(classConstraints);
|
||||
// List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions);
|
||||
// System.out.println(methodConstraints);
|
||||
|
||||
assertFalse(classConstraints.isEmpty());
|
||||
assertTrue(classConstraints.size() == 3);
|
||||
// assertFalse(methodConstraints.isEmpty());
|
||||
// assertTrue(methodConstraints.size()==9);
|
||||
}
|
||||
|
||||
|
||||
public void testPositionConverter() {
|
||||
HashMap<String, Boolean> allTphsOld = new HashMap<>();
|
||||
List<MethodAndTPH> listOfMethodsAndTphs = new ArrayList<>();
|
||||
allTphsOld.put("A", true);
|
||||
allTphsOld.put("B", false);
|
||||
MethodAndTPH m1 = new MethodAndTPH("m1");
|
||||
m1.getTphs().add("A");
|
||||
MethodAndTPH bla = new MethodAndTPH("bla");
|
||||
MethodAndTPH blubb = new MethodAndTPH("blubb");
|
||||
// blubb.getTphs().add("A");
|
||||
listOfMethodsAndTphs.add(bla);
|
||||
listOfMethodsAndTphs.add(blubb);
|
||||
listOfMethodsAndTphs.add(m1);
|
||||
|
||||
|
||||
|
||||
HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> allTphsNew = FamilyOfGeneratedGenerics.positionConverter(allTphsOld, listOfMethodsAndTphs);
|
||||
System.out.println(allTphsNew);
|
||||
//was tun wenn zwei (oder mehr) Methoden gleiches TPH enthalten?
|
||||
//ist dies möglich oder werden die TPHs immer verschieden initialisiert und dann erst am Ende gemappt?
|
||||
//überarbeiten oder lassen?
|
||||
|
||||
|
||||
assertTrue(allTphsNew.get("A").fst.equals(PositionFinder.Position.METHOD));
|
||||
assertTrue(allTphsNew.get("B").fst.equals(PositionFinder.Position.FIELD));
|
||||
}
|
||||
|
||||
|
||||
public void testFirstTransitiveSubtypeForMethodTypes(){
|
||||
|
||||
}
|
||||
|
||||
}*/
|
112
src/test/java/insertGenerics/TestAny.java
Normal file
112
src/test/java/insertGenerics/TestAny.java
Normal file
@ -0,0 +1,112 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestAny {
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory+"TestAny.jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
}
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
|
||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||
classConstraintsTest.add(new ClassConstraint("N", "O", Relation.EXTENDS));
|
||||
classConstraintsTest.add(new ClassConstraint("N", "U", Relation.EXTENDS));
|
||||
classConstraintsTest.add(new ClassConstraint("U", "O", Relation.EXTENDS));
|
||||
classConstraintsTest.add(new ClassConstraint("O", "java/lang/Object", Relation.EXTENDS));
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||
Set<MethodConstraint> lmc;
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH RanyMethod()", lmc);
|
||||
lmc = new HashSet<>();
|
||||
methodConstraintsWithPositionTest.put("TPH UotherMethod(TPH U)", lmc);
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
assertEquals(expectedClassCons, computedClassCons);
|
||||
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||
|
||||
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||
|
||||
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
System.out.println(ASTTypePrinter.print(sf));
|
||||
System.out.println(ASTPrinter.print(sf));
|
||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||
assert results.size()>0;
|
||||
Set<String> insertedTypes = new HashSet<>();
|
||||
for(ResultSet resultSet : results){
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
|
||||
assert result.size()>0;
|
||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||
for(TypeInsert tip : result){
|
||||
insertedTypes.add(tip.insert(content));
|
||||
}
|
||||
}
|
||||
for(String s : insertedTypes){
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
return new TestResultSet();
|
||||
}
|
||||
|
||||
static String readFile(String path, Charset encoding)
|
||||
throws IOException
|
||||
{
|
||||
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||
return new String(encoded, encoding);
|
||||
}
|
||||
}
|
79
src/test/java/insertGenerics/TestClassField.java
Normal file
79
src/test/java/insertGenerics/TestClassField.java
Normal file
@ -0,0 +1,79 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestClassField {
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory+"TestClassField.jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
}
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
System.out.println(ASTTypePrinter.print(sf));
|
||||
System.out.println(ASTPrinter.print(sf));
|
||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||
assert results.size()>0;
|
||||
Set<String> insertedTypes = new HashSet<>();
|
||||
for(ResultSet resultSet : results){
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
|
||||
assert result.size()>0;
|
||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||
for(TypeInsert tip : result){
|
||||
insertedTypes.add(tip.insert(content));
|
||||
}
|
||||
}
|
||||
for(String s : insertedTypes){
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
return new TestResultSet();
|
||||
}
|
||||
|
||||
static String readFile(String path, Charset encoding)
|
||||
throws IOException
|
||||
{
|
||||
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||
return new String(encoded, encoding);
|
||||
}
|
||||
}
|
112
src/test/java/insertGenerics/TestContraVariant.java
Normal file
112
src/test/java/insertGenerics/TestContraVariant.java
Normal file
@ -0,0 +1,112 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestContraVariant {
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory+"TestContraVariant.jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
}
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
|
||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||
Set<MethodConstraint> lmc;
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("R", "O", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("O", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Rm(TPH O)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
//lmc.add(new MethodConstraint("S", "O", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("S", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Rmain(TPH S)", lmc);
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
assertEquals(expectedClassCons, computedClassCons);
|
||||
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||
|
||||
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||
|
||||
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
System.out.println(ASTTypePrinter.print(sf));
|
||||
System.out.println(ASTPrinter.print(sf));
|
||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||
assert results.size()>0;
|
||||
Set<String> insertedTypes = new HashSet<>();
|
||||
for(ResultSet resultSet : results){
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
|
||||
assert result.size()>0;
|
||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||
for(TypeInsert tip : result){
|
||||
insertedTypes.add(tip.insert(content));
|
||||
}
|
||||
}
|
||||
for(String s : insertedTypes){
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
return new TestResultSet();
|
||||
}
|
||||
|
||||
static String readFile(String path, Charset encoding)
|
||||
throws IOException
|
||||
{
|
||||
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||
return new String(encoded, encoding);
|
||||
}
|
||||
}
|
62
src/test/java/insertGenerics/TestExample42.java
Normal file
62
src/test/java/insertGenerics/TestExample42.java
Normal file
@ -0,0 +1,62 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.*;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class TestExample42 {
|
||||
public List<TPHConstraint> fillConstraintsList() {
|
||||
List<TPHConstraint> cs = new ArrayList<>();
|
||||
cs.add(new TPHConstraint("M", "N", Relation.EXTENDS));
|
||||
cs.add(new TPHConstraint("N", "Z", Relation.EXTENDS));
|
||||
cs.add(new TPHConstraint("Q", "K", Relation.EXTENDS));
|
||||
cs.add(new TPHConstraint("K", "P", Relation.EXTENDS));
|
||||
cs.add(new TPHConstraint("W", "M", Relation.EXTENDS));
|
||||
cs.add(new TPHConstraint("Z", "V", Relation.EXTENDS));
|
||||
return cs;
|
||||
}
|
||||
|
||||
public HashMap<String, PairTphMethod<PositionFinder.Position, String>> fillPosOfTphs() {
|
||||
HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs = new HashMap<>();
|
||||
|
||||
// TPHs "U" und "L" auskommentiert, da nach Vorgaben L zu Z umbenannt und U als void interpretiert wird
|
||||
PairTphMethod<PositionFinder.Position, String> posOfK = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
|
||||
// PairTphMethod<PositionFinder.Position, String> posOfL = new PairTphMethod<>(PositionFinder.Position.METHOD, "id");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfM = new PairTphMethod<>(PositionFinder.Position.METHOD, "id");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfN = new PairTphMethod<>(PositionFinder.Position.METHOD, "id");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfP = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfQ = new PairTphMethod<>(PositionFinder.Position.METHOD, "setA");
|
||||
// PairTphMethod<PositionFinder.Position, String> posOfU = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfV = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfW = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfZ = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
|
||||
|
||||
posOfTphs.put("K", posOfK);
|
||||
// posOfTphs.put("L", posOfL);
|
||||
posOfTphs.put("M", posOfM);
|
||||
posOfTphs.put("N", posOfN);
|
||||
posOfTphs.put("P", posOfP);
|
||||
posOfTphs.put("Q", posOfQ);
|
||||
// posOfTphs.put("U", posOfU);
|
||||
posOfTphs.put("V", posOfV);
|
||||
posOfTphs.put("W", posOfW);
|
||||
posOfTphs.put("Z", posOfZ);
|
||||
return posOfTphs;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void genericTest() {
|
||||
// List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
|
||||
// System.out.println("ClassConstraints: " + classConstraints);
|
||||
// List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs());
|
||||
// System.out.println("MethodConstraints: " + methodConstraints);
|
||||
|
||||
List<TPHConstraint> testCons;
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class TestExample42_allInOneMethod {
|
||||
public List<TPHConstraint> fillConstraintsList() {
|
||||
List<TPHConstraint> cs = new ArrayList<>();
|
||||
cs.add(new TPHConstraint("M", "N", Relation.EXTENDS));
|
||||
cs.add(new TPHConstraint("N", "Z", Relation.EXTENDS));
|
||||
cs.add(new TPHConstraint("Q", "K", Relation.EXTENDS));
|
||||
cs.add(new TPHConstraint("K", "P", Relation.EXTENDS));
|
||||
cs.add(new TPHConstraint("W", "M", Relation.EXTENDS));
|
||||
cs.add(new TPHConstraint("Z", "V", Relation.EXTENDS));
|
||||
return cs;
|
||||
}
|
||||
|
||||
public HashMap<String, PairTphMethod<PositionFinder.Position, String>> fillPosOfTphs() {
|
||||
HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs = new HashMap<>();
|
||||
|
||||
// TPHs "U" und "L" auskommentiert, da nach Vorgaben L zu Z umbenannt und U als void interpretiert wird
|
||||
PairTphMethod<PositionFinder.Position, String> posOfK = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
|
||||
// PairTphMethod<PositionFinder.Position, String> posOfL = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfM = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfN = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfP = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfQ = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
|
||||
// PairTphMethod<PositionFinder.Position, String> posOfU = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfV = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfW = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
|
||||
PairTphMethod<PositionFinder.Position, String> posOfZ = new PairTphMethod<>(PositionFinder.Position.METHOD, "sameMethod");
|
||||
|
||||
posOfTphs.put("K", posOfK);
|
||||
// posOfTphs.put("L", posOfL);
|
||||
posOfTphs.put("M", posOfM);
|
||||
posOfTphs.put("N", posOfN);
|
||||
posOfTphs.put("P", posOfP);
|
||||
posOfTphs.put("Q", posOfQ);
|
||||
// posOfTphs.put("U", posOfU);
|
||||
posOfTphs.put("V", posOfV);
|
||||
posOfTphs.put("W", posOfW);
|
||||
posOfTphs.put("Z", posOfZ);
|
||||
return posOfTphs;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void genericTest() {
|
||||
// List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
|
||||
// System.out.println("ClassConstraints: " + classConstraints);
|
||||
// List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs(),);
|
||||
// System.out.println("MethodConstraints: " + methodConstraints);
|
||||
|
||||
List<TPHConstraint> testCons;
|
||||
}
|
||||
}
|
99
src/test/java/insertGenerics/TestGGFinder.java
Normal file
99
src/test/java/insertGenerics/TestGGFinder.java
Normal file
@ -0,0 +1,99 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestGGFinder {
|
||||
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
private static String className = "TestGGFinder";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
execute(new File(rootDirectory+className+".jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
|
||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||
classConstraintsTest.add(new ClassConstraint("S", "java/lang/Object", Relation.EXTENDS));
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||
Set<MethodConstraint> lmc;
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AC", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH ACid(TPH P)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("T", "S", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH SsetA(TPH T)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("AC", "Y", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("Y", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("voidm(TPH YTPH Z)", lmc);
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
assertEquals(expectedClassCons, computedClassCons);
|
||||
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||
|
||||
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
return new TestResultSet();
|
||||
}
|
||||
}
|
112
src/test/java/insertGenerics/TestLocalVarLambda.java
Normal file
112
src/test/java/insertGenerics/TestLocalVarLambda.java
Normal file
@ -0,0 +1,112 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestLocalVarLambda {
|
||||
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
private static String className = "TestLocalVarLambda";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
execute(new File(rootDirectory+className+".jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
|
||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
|
||||
Set<MethodConstraint> lmc;
|
||||
lmc = new HashSet<>();
|
||||
|
||||
if (fogg.allConstraints.contains((new MethodConstraint("O", "ALU", Relation.EXTENDS)))) {
|
||||
lmc.add(new MethodConstraint("O", "ALU", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("DIU", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("ALU", "DIU", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc);
|
||||
}
|
||||
else if (fogg.allConstraints.contains((new MethodConstraint("O", "DIV", Relation.EXTENDS)))) {
|
||||
lmc.add(new MethodConstraint("O", "DIV", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("DIV", "N", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Nm(TPH O)", lmc);
|
||||
}
|
||||
else
|
||||
{
|
||||
lmc.add(new MethodConstraint("O", "DIU", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("DIU", "N", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Nm(TPH O)", lmc);
|
||||
}
|
||||
|
||||
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
assertEquals(expectedClassCons, computedClassCons);
|
||||
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||
|
||||
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
return new TestResultSet();
|
||||
}
|
||||
}
|
126
src/test/java/insertGenerics/TestMutualRecursion.java
Normal file
126
src/test/java/insertGenerics/TestMutualRecursion.java
Normal file
@ -0,0 +1,126 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestMutualRecursion {
|
||||
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
private static String className;
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutualRecursion1() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
className = "TestMutualRecursion";
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+className+".jav"));
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
|
||||
|
||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||
classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||
Set<MethodConstraint> lmc;
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("P", "Q", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("Z", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH ALm(TPH ALTPH Z)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AH", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH ALmain(TPH AGTPH AH)", lmc);
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
assertEquals(expectedClassCons, computedClassCons);
|
||||
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||
|
||||
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutualRecursionWithField() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
className = "TestMutualRecursionWithField";
|
||||
execute(new File(rootDirectory+className+".jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutualRecursionWithField2() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
className = "TestMutualRecursionWithField2";
|
||||
execute(new File(rootDirectory+className+".jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutualRecursionWithField3() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
className = "TestMutualRecursionWithField3";
|
||||
execute(new File(rootDirectory+className+".jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
return new TestResultSet();
|
||||
}
|
||||
}
|
79
src/test/java/insertGenerics/TestReturnVar.java
Normal file
79
src/test/java/insertGenerics/TestReturnVar.java
Normal file
@ -0,0 +1,79 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestReturnVar {
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory+"TestReturnVar.jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
}
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
System.out.println(ASTTypePrinter.print(sf));
|
||||
System.out.println(ASTPrinter.print(sf));
|
||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||
assert results.size()>0;
|
||||
Set<String> insertedTypes = new HashSet<>();
|
||||
for(ResultSet resultSet : results){
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
|
||||
assert result.size()>0;
|
||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||
for(TypeInsert tip : result){
|
||||
insertedTypes.add(tip.insert(content));
|
||||
}
|
||||
}
|
||||
for(String s : insertedTypes){
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
return new TestResultSet();
|
||||
}
|
||||
|
||||
static String readFile(String path, Charset encoding)
|
||||
throws IOException
|
||||
{
|
||||
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||
return new String(encoded, encoding);
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestSecondLineOfClassConstraints {
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory+"TestSecondLineOfClassConstraints.jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
}
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
System.out.println(ASTTypePrinter.print(sf));
|
||||
System.out.println(ASTPrinter.print(sf));
|
||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||
assert results.size()>0;
|
||||
Set<String> insertedTypes = new HashSet<>();
|
||||
for(ResultSet resultSet : results){
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
|
||||
assert result.size()>0;
|
||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||
for(TypeInsert tip : result){
|
||||
insertedTypes.add(tip.insert(content));
|
||||
}
|
||||
}
|
||||
for(String s : insertedTypes){
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
return new TestResultSet();
|
||||
}
|
||||
|
||||
static String readFile(String path, Charset encoding)
|
||||
throws IOException
|
||||
{
|
||||
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||
return new String(encoded, encoding);
|
||||
}
|
||||
}
|
154
src/test/java/insertGenerics/TestTPHsAndGenerics.java
Normal file
154
src/test/java/insertGenerics/TestTPHsAndGenerics.java
Normal file
@ -0,0 +1,154 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class TestTPHsAndGenerics {
|
||||
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
private static String className = "TestTPHsAndGenerics";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
execute(new File(rootDirectory+className+".jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
|
||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
|
||||
Set<MethodConstraint> lmc;
|
||||
lmc = new HashSet<>();
|
||||
|
||||
if (fogg.allConstraints.contains((new MethodConstraint("DZP", "ETW", Relation.EXTENDS)))) {
|
||||
classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS));
|
||||
classConstraintsTest.add(new ClassConstraint("DZP", "ETW", Relation.EXTENDS));
|
||||
classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS));
|
||||
|
||||
lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS));
|
||||
//lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AI", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc);
|
||||
} else {
|
||||
if (fogg.allConstraints.contains((new MethodConstraint("DZP", "U", Relation.EXTENDS)))) {
|
||||
classConstraintsTest.add(new ClassConstraint("ETW", "DZP", Relation.EXTENDS));
|
||||
classConstraintsTest.add(new ClassConstraint("DZP", "U", Relation.EXTENDS));
|
||||
classConstraintsTest.add(new ClassConstraint("U", "java/lang/Object", Relation.EXTENDS));
|
||||
|
||||
lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS));
|
||||
//lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Uid2(TPH V)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AI", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc);
|
||||
} else {
|
||||
if (fogg.allConstraints.contains((new MethodConstraint("EIM", "FEA", Relation.EXTENDS)))) {
|
||||
classConstraintsTest.add(new ClassConstraint("VK", "EIM", Relation.EXTENDS));
|
||||
classConstraintsTest.add(new ClassConstraint("EIM", "FEA", Relation.EXTENDS));
|
||||
classConstraintsTest.add(new ClassConstraint("FEA", "java/lang/Object", Relation.EXTENDS));
|
||||
|
||||
lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS));
|
||||
//lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("V", "VK", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH FEAid2(TPH V)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AI", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
assertEquals(expectedClassCons, computedClassCons);
|
||||
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||
|
||||
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||
|
||||
/*
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
*/
|
||||
return new TestResultSet();
|
||||
|
||||
}
|
||||
}
|
79
src/test/java/insertGenerics/TestTPHsAndGenerics2.java
Normal file
79
src/test/java/insertGenerics/TestTPHsAndGenerics2.java
Normal file
@ -0,0 +1,79 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestTPHsAndGenerics2 {
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory+"TestTPHSAndGenerics2.jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
}
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
System.out.println(ASTTypePrinter.print(sf));
|
||||
System.out.println(ASTPrinter.print(sf));
|
||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||
assert results.size()>0;
|
||||
Set<String> insertedTypes = new HashSet<>();
|
||||
for(ResultSet resultSet : results){
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
|
||||
assert result.size()>0;
|
||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||
for(TypeInsert tip : result){
|
||||
insertedTypes.add(tip.insert(content));
|
||||
}
|
||||
}
|
||||
for(String s : insertedTypes){
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
return new TestResultSet();
|
||||
}
|
||||
|
||||
static String readFile(String path, Charset encoding)
|
||||
throws IOException
|
||||
{
|
||||
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||
return new String(encoded, encoding);
|
||||
}
|
||||
}
|
99
src/test/java/insertGenerics/TestThreeArgs.java
Normal file
99
src/test/java/insertGenerics/TestThreeArgs.java
Normal file
@ -0,0 +1,99 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestThreeArgs {
|
||||
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
private static String className = "TestThreeArgs";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
execute(new File(rootDirectory+className+".jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
|
||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||
classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||
Set<MethodConstraint> lmc;
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("P", "AF", 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);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("AF", "W", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AB", "P", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("P", "AF", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AC", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Wm(TPH WTPH ABTPH AC)", lmc);
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
assertEquals(expectedClassCons, computedClassCons);
|
||||
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||
|
||||
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
//liefert Fehler, da Variable "a" nicht initialisiert ist.
|
||||
//instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
return new TestResultSet();
|
||||
}
|
||||
}
|
28
src/test/java/insertGenerics/TestTransitiveClosure.java
Normal file
28
src/test/java/insertGenerics/TestTransitiveClosure.java
Normal file
@ -0,0 +1,28 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
111
src/test/java/insertGenerics/TestTwoArgs.java
Normal file
111
src/test/java/insertGenerics/TestTwoArgs.java
Normal file
@ -0,0 +1,111 @@
|
||||
package insertGenerics;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestTwoArgs {
|
||||
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
private static String className = "TestTwoArgs";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
execute(new File(rootDirectory+className+".jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
|
||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||
classConstraintsTest.add(new ClassConstraint("AP", "Z", Relation.EXTENDS));
|
||||
classConstraintsTest.add(new ClassConstraint("Z", "P", Relation.EXTENDS));
|
||||
classConstraintsTest.add(new ClassConstraint("P", "AL", Relation.EXTENDS));
|
||||
classConstraintsTest.add(new ClassConstraint("AL", "AF", Relation.EXTENDS));
|
||||
classConstraintsTest.add(new ClassConstraint("AF", "java/lang/Object", Relation.EXTENDS));
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||
Set<MethodConstraint> lmc;
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AF", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH AFm(TPH AFTPH Z)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH APsetA(TPH T)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("AG", "P", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AH", "T", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH AFmain(TPH AGTPH AH)", lmc);
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
assertEquals(expectedClassCons, computedClassCons);
|
||||
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||
|
||||
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
return new TestResultSet();
|
||||
}
|
||||
}
|
105
src/test/java/insertGenerics/TestTwoArgs2.java
Normal file
105
src/test/java/insertGenerics/TestTwoArgs2.java
Normal file
@ -0,0 +1,105 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestTwoArgs2 {
|
||||
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
private static String className = "TestTwoArgs2";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
execute(new File(rootDirectory+className+".jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
|
||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||
classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||
Set<MethodConstraint> lmc;
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("U", "P", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AA", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH AAm(TPH AATPH U)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("AB", "P", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AC", "U", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AB", "AA", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AA", "U", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("U", "AA", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH AAmain(TPH ABTPH AC)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH AGid(TPH P)", lmc);
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
assertEquals(expectedClassCons, computedClassCons);
|
||||
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||
|
||||
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
return new TestResultSet();
|
||||
}
|
||||
}
|
95
src/test/java/insertGenerics/TestTwoCalls.java
Normal file
95
src/test/java/insertGenerics/TestTwoCalls.java
Normal file
@ -0,0 +1,95 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestTwoCalls {
|
||||
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
private static String className = "TestTwoCalls";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
execute(new File(rootDirectory+className+".jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
|
||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||
Set<MethodConstraint> lmc;
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Rid(TPH O)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("T", "O", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("S", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Rmain(TPH STPH T)", lmc);
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
assertEquals(expectedClassCons, computedClassCons);
|
||||
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||
|
||||
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
return new TestResultSet();
|
||||
}
|
||||
}
|
92
src/test/java/insertGenerics/TestVector.java
Normal file
92
src/test/java/insertGenerics/TestVector.java
Normal file
@ -0,0 +1,92 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestVector {
|
||||
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
private static String className = "TestVector";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
execute(new File(rootDirectory+className+".jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
|
||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||
Set<MethodConstraint> lmc;
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("T", "W", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("W", "ZU", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc);
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
assertEquals(expectedClassCons, computedClassCons);
|
||||
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||
|
||||
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
return new TestResultSet();
|
||||
}
|
||||
}
|
92
src/test/java/insertGenerics/TestVectorArg.java
Normal file
92
src/test/java/insertGenerics/TestVectorArg.java
Normal file
@ -0,0 +1,92 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestVectorArg {
|
||||
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
private static String className = "TestVectorArg";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
execute(new File(rootDirectory+className+".jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
|
||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||
Set<MethodConstraint> lmc;
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("T", "W", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("W", "ZU", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc);
|
||||
lmc = new HashSet<>();
|
||||
lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc);
|
||||
|
||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||
|
||||
//assertEquals(expectedClassCons, computedClassCons);
|
||||
|
||||
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||
|
||||
//assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
return new TestResultSet();
|
||||
}
|
||||
}
|
79
src/test/java/insertGenerics/TestVoidMeth.java
Normal file
79
src/test/java/insertGenerics/TestVoidMeth.java
Normal file
@ -0,0 +1,79 @@
|
||||
package insertGenerics;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestVoidMeth {
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||
|
||||
@BeforeClass
|
||||
public static void resetNamesOfTypePlaceholder() {
|
||||
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory+"TestVoidMeth.jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet{
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
}
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
System.out.println(ASTTypePrinter.print(sf));
|
||||
System.out.println(ASTPrinter.print(sf));
|
||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||
assert results.size()>0;
|
||||
Set<String> insertedTypes = new HashSet<>();
|
||||
for(ResultSet resultSet : results){
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
|
||||
assert result.size()>0;
|
||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||
for(TypeInsert tip : result){
|
||||
insertedTypes.add(tip.insert(content));
|
||||
}
|
||||
}
|
||||
for(String s : insertedTypes){
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
return new TestResultSet();
|
||||
}
|
||||
|
||||
static String readFile(String path, Charset encoding)
|
||||
throws IOException
|
||||
{
|
||||
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||
return new String(encoded, encoding);
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ import java.lang.Integer;
|
||||
|
||||
public class Fac {
|
||||
|
||||
getFac(java.lang.Integer n){
|
||||
getFac(n){
|
||||
var res = 1;
|
||||
var i = 1;
|
||||
while(i<=n) {
|
||||
|
2
src/test/resources/inferWildcards/.gitignore
vendored
Normal file
2
src/test/resources/inferWildcards/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/generatedSC/
|
||||
/generatedBC/
|
@ -0,0 +1,31 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
|
||||
class TestClassWildcardsFields
|
||||
{
|
||||
|
||||
private List<String> field1;
|
||||
//private int counter;
|
||||
|
||||
public TestClassWildcards () {
|
||||
//field1 = new ArrayList<>();
|
||||
//counter = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Working method for Java
|
||||
* @param param1
|
||||
* @return
|
||||
*/
|
||||
public List<String> test (List<String> param1) {
|
||||
List<String> localVar = field1;
|
||||
field1 = param1;
|
||||
//counter++;
|
||||
return localVar;
|
||||
}
|
||||
|
||||
public void foo() {
|
||||
|
||||
}
|
||||
}
|
13
src/test/resources/inferWildcards/TestClassWildcardsMap.java
Normal file
13
src/test/resources/inferWildcards/TestClassWildcardsMap.java
Normal file
@ -0,0 +1,13 @@
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
import java.util.Map;
|
||||
import java.lang.Integer;
|
||||
|
||||
class TestClassWildcardsMap
|
||||
{
|
||||
|
||||
public Map<Integer, Object> test(Map<Integer, String> input){
|
||||
Map<Integer, Object> listOfObjects = input;
|
||||
return listOfObjects;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
import java.util.Map;
|
||||
import java.lang.Integer;
|
||||
|
||||
class TestClassWildcardsMapNested
|
||||
{
|
||||
|
||||
public Map<Integer, Collection<Object>> test(Map<Integer, List<String>> input){
|
||||
Map<Integer, Collection<Object>> listOfObjects = input;
|
||||
return listOfObjects;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
import java.util.Map;
|
||||
import java.lang.Integer;
|
||||
|
||||
class TestClassWildcardsNested
|
||||
{
|
||||
public List<Collection<Object>> test(List<List<String>> input){
|
||||
List<Collection<Object>> listOfObjects = input;
|
||||
return listOfObjects;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
|
||||
public final class TestClassWildcardsParamType<T1, T2> {
|
||||
public final T1 first;
|
||||
public final T2 second;
|
||||
|
||||
public TestClassWildcardsParamType(T1 first, T2 second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public static <T1, T2> TestClassWildcardsParamType<T1, T2> of(T1 first, T2 second) {
|
||||
return new TestClassWildcardsParamType<>(first, second);
|
||||
}
|
||||
|
||||
public static void main(String[] agrs) {
|
||||
TestClassWildcardsParamType<Class<?>, String> pair = TestClassWildcardsParamType.of(List.class, "hello");
|
||||
|
||||
//Output of compiler
|
||||
//TestClassWildcardsParamType<? extends Class<?>, String> pair = TestClassWildcardsParamType.of(List.class, "hello");
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
|
||||
class TestClassWildcardsSingle
|
||||
{
|
||||
|
||||
/**
|
||||
* Non working method in normal Java
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public List<Object> test (List<String> input) {
|
||||
List<Object> listOfObjects = input;
|
||||
Object test = listOfObjects.get(0);
|
||||
String string = "Test";
|
||||
input.add(string);
|
||||
return listOfObjects;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import java.util.List;
|
||||
|
||||
class TestClassWildcardsLib
|
||||
{
|
||||
|
||||
// public <T> List<T> merge (List<T> l1, List<T> l2) {
|
||||
// l2.forEach(s -> {if(!l1.contains(s)) l1.add(s);});
|
||||
// return l2;
|
||||
// }
|
||||
|
||||
public static <T> List<T> foo(List<T> dd){
|
||||
T t = dd.get(1);
|
||||
return dd;
|
||||
}
|
||||
}
|
13
src/test/resources/insertGenericsJav/TestAny.jav
Normal file
13
src/test/resources/insertGenericsJav/TestAny.jav
Normal file
@ -0,0 +1,13 @@
|
||||
class TestAny {
|
||||
a;
|
||||
b = a;
|
||||
anyMethod() {
|
||||
var f;
|
||||
return f;
|
||||
}
|
||||
otherMethod(e) {
|
||||
b = e;
|
||||
e = a;
|
||||
return e;
|
||||
}
|
||||
}
|
6
src/test/resources/insertGenericsJav/TestClassField.jav
Normal file
6
src/test/resources/insertGenericsJav/TestClassField.jav
Normal file
@ -0,0 +1,6 @@
|
||||
class Example{
|
||||
f;
|
||||
fReturn(){
|
||||
return f;
|
||||
}
|
||||
}
|
12
src/test/resources/insertGenericsJav/TestContraVariant.jav
Normal file
12
src/test/resources/insertGenericsJav/TestContraVariant.jav
Normal file
@ -0,0 +1,12 @@
|
||||
public class TestContraVariant {
|
||||
|
||||
m(x) {
|
||||
var y;
|
||||
x = y;
|
||||
return y;
|
||||
}
|
||||
|
||||
main(x) {
|
||||
return m(x);
|
||||
}
|
||||
}
|
17
src/test/resources/insertGenericsJav/TestGGFinder.jav
Normal file
17
src/test/resources/insertGenericsJav/TestGGFinder.jav
Normal file
@ -0,0 +1,17 @@
|
||||
public class TestGGFinder {
|
||||
a;
|
||||
|
||||
id(b) {
|
||||
var c = b;
|
||||
return c;
|
||||
}
|
||||
|
||||
setA(x) {
|
||||
a = x;
|
||||
return a;
|
||||
}
|
||||
|
||||
m(x,y) {
|
||||
x = id(y);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
public class TestLocalVarLambda {
|
||||
|
||||
m(x) {
|
||||
var id = z -> z;
|
||||
return id.apply(x);
|
||||
}
|
||||
}
|
17
src/test/resources/insertGenericsJav/TestMutualRecursion.jav
Normal file
17
src/test/resources/insertGenericsJav/TestMutualRecursion.jav
Normal file
@ -0,0 +1,17 @@
|
||||
public class TestMutualRecursion {
|
||||
a;
|
||||
|
||||
id(b) {
|
||||
var c = b;
|
||||
return main(b,c);
|
||||
}
|
||||
|
||||
m(x,y) {
|
||||
x = id(y);
|
||||
return x;
|
||||
}
|
||||
|
||||
main(x,y) {
|
||||
return m(id(x),y);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
public class TestMutualRecursionWithField {
|
||||
a;
|
||||
|
||||
id(b) {
|
||||
var c = b;
|
||||
return main(b,c);
|
||||
}
|
||||
|
||||
setA(x) {
|
||||
a = x;
|
||||
return a;
|
||||
}
|
||||
|
||||
m(x,y) {
|
||||
x = id(y);
|
||||
return x;
|
||||
}
|
||||
|
||||
main(x,y) {
|
||||
return m(id(x),setA(y));
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
public class TestMutualRecursionWithField2 {
|
||||
a;
|
||||
|
||||
id(b) {
|
||||
var c = b;
|
||||
return main(b,c);
|
||||
}
|
||||
|
||||
setA(x) {
|
||||
a = x;
|
||||
return a;
|
||||
}
|
||||
|
||||
m(x,y) {
|
||||
x = id(y);
|
||||
return x;
|
||||
}
|
||||
|
||||
main(x,y) {
|
||||
return m(setA(x),id(y));
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
public class TestMutualRecursionWithField3 {
|
||||
a;
|
||||
|
||||
id(b) {
|
||||
var c = b;
|
||||
return main(b,c);
|
||||
}
|
||||
|
||||
setA(x) {
|
||||
a = x;
|
||||
return a;
|
||||
}
|
||||
|
||||
m(x,y) {
|
||||
x = id(y);
|
||||
return x;
|
||||
}
|
||||
|
||||
main(x,y) {
|
||||
var z = m(setA(x),id(y));
|
||||
return z;
|
||||
}
|
||||
}
|
6
src/test/resources/insertGenericsJav/TestReturnVar.jav
Normal file
6
src/test/resources/insertGenericsJav/TestReturnVar.jav
Normal file
@ -0,0 +1,6 @@
|
||||
class VarReturn {
|
||||
anyMethod() {
|
||||
var f;
|
||||
return f;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
class Example {
|
||||
a;
|
||||
b = a;
|
||||
anyMethod() {
|
||||
var f;
|
||||
return f;
|
||||
}
|
||||
otherMethod(e) {
|
||||
e = a;
|
||||
return e;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user