Compare commits
97
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
669c778af8 | ||
|
|
5071406b3f | ||
|
|
9d2d076215 | ||
|
|
6262c9434c | ||
|
|
59c5e48201 | ||
|
|
1cf1c99e72 | ||
|
|
5c60918c47 | ||
|
|
a0367d5464 | ||
|
|
722d897d4b | ||
|
|
e2d76d314a | ||
|
|
cd5fbac987 | ||
|
|
67df9aa262 | ||
|
|
5b970f9359 | ||
|
|
1b5eacf921 | ||
|
|
a35e69f878 | ||
|
|
643f7c0220 | ||
|
|
24f1b507c4 | ||
|
|
a4cc4cc357 | ||
|
|
e80e2db26c | ||
|
|
4c0fb34c00 | ||
|
|
8e80cc2985 | ||
|
|
f03d3f5e64 | ||
|
|
dfd12422a6 | ||
|
|
eebb07ec8b | ||
|
|
c65102d89a | ||
|
|
ed00aeb056 | ||
|
|
7012010462 | ||
|
|
9444ee38d6 | ||
|
|
4ed30f11f7 | ||
|
|
fcedec60e7 | ||
|
|
d8bdcf854c | ||
|
|
0e363cfae3 | ||
|
|
fedf33a006 | ||
|
|
4522aeff36 | ||
|
|
bcf56e6bdd | ||
|
|
15c05e5cba | ||
|
|
dc9a54be3b | ||
|
|
21adeb7f26 | ||
|
|
6381d09174 | ||
|
|
918a2cc04d | ||
|
|
ac1e0340c3 | ||
|
|
0d84e8361f | ||
|
|
0207c7d1b0 | ||
|
|
f1f028f0b9 | ||
|
|
8b58259fe0 | ||
|
|
55a75b04a0 | ||
|
|
06b27dabd2 | ||
|
|
9baf89acc2 | ||
|
|
be307e95a6 | ||
|
|
df4faebd92 | ||
|
|
36ef1e124a | ||
|
|
2706c31beb | ||
|
|
c32a0cc222 | ||
|
|
eaec7f613a | ||
|
|
c681396061 | ||
|
|
3d19d8d729 | ||
|
|
f457e7e4d0 | ||
|
|
c22d12f6b0 | ||
|
|
0aab2d9f53 | ||
|
|
33d6adf899 | ||
|
|
00add07132 | ||
|
|
48964d57ad | ||
|
|
18d9edfeea | ||
|
|
1b9e824b86 | ||
|
|
b40cb49b9f | ||
|
|
be9ee49878 | ||
|
|
3363037854 | ||
|
|
c8d4301e5e | ||
|
|
b46415e45a | ||
|
|
bbfd8aa203 | ||
|
|
0cb1f244bc | ||
|
|
9be64e4905 | ||
|
|
d1ad6e218a | ||
|
|
bf8d4fe647 | ||
|
|
e229093017 | ||
|
|
66a25a56c0 | ||
|
|
af223a4d8a | ||
|
|
14cb2c8909 | ||
|
|
080eb2f6f3 | ||
|
|
d8876457db | ||
|
|
32e9ce92a6 | ||
|
|
3ad9007336 | ||
|
|
da2a17c794 | ||
|
|
345b03b775 | ||
|
|
ff93b0967e | ||
|
|
db149eb588 | ||
|
|
f5f639c0f7 | ||
|
|
a4c38b2bb0 | ||
|
|
e3625cb306 | ||
|
|
86603ae343 | ||
|
|
d276c7c044 | ||
|
|
91c075829b | ||
|
|
d08e598649 | ||
|
|
ba8df8b376 | ||
|
|
b147430fb6 | ||
|
|
661fa53937 | ||
|
|
13144d0ac9 |
No files matched your search
@@ -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
|
||||||
|
|
||||||
@@ -118,6 +118,14 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
</descriptorRefs>
|
</descriptorRefs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>17</source>
|
||||||
|
<target>17</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<repositories>
|
<repositories>
|
||||||
@@ -129,8 +137,11 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<compilerArgs>
|
||||||
|
--enable-preview
|
||||||
|
</compilerArgs>
|
||||||
<tycho.version>0.23.0</tycho.version>
|
<tycho.version>0.23.0</tycho.version>
|
||||||
<mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass>
|
<mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass>
|
||||||
</properties>
|
</properties>
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.funN.FunNGenerator;
|
||||||
|
import de.dhbwstuttgart.bytecode.funN.FunNUtilities;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.*;
|
import de.dhbwstuttgart.bytecode.utilities.*;
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
@@ -589,10 +592,20 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
this.lamCounter++;
|
this.lamCounter++;
|
||||||
|
|
||||||
String typeErasure = createDescriptorWithTypeErasure(lambdaExpression);
|
String typeErasure = createDescriptorWithTypeErasure(lambdaExpression);
|
||||||
|
RefTypeOrTPHOrWildcardOrGeneric returnType = resolver.resolve(lambdaExpression.getReturnType());
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes = lambdaExpression
|
||||||
|
.params
|
||||||
|
.getFormalparalist()
|
||||||
|
.stream()
|
||||||
|
.map(FormalParameter::getType)
|
||||||
|
.map(resolver::resolve)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
FunNUtilities funNUtilities = FunNGenerator.getInstance();
|
||||||
|
FunNUtilities.writeClassFile(funNUtilities.getSuperClassName(argumentTypes.size()),
|
||||||
|
funNUtilities.generateSuperBytecode(argumentTypes.size()), path);
|
||||||
|
FunNUtilities.writeClassFile(funNUtilities.getSpecializedClassName(argumentTypes, returnType),
|
||||||
|
funNUtilities.generateSpecializedBytecode(argumentTypes, returnType), path);
|
||||||
|
|
||||||
ByteCodeForFunNGenerator.generateBCForFunN(lambdaExpression, typeErasure,path);
|
|
||||||
|
|
||||||
|
|
||||||
Lambda lam = new Lambda(lambdaExpression);
|
Lambda lam = new Lambda(lambdaExpression);
|
||||||
String lamDesc = lam.accept(new DescriptorToString(resultSet));
|
String lamDesc = lam.accept(new DescriptorToString(resultSet));
|
||||||
// Call site, which, when invoked, returns an instance of the functional
|
// Call site, which, when invoked, returns an instance of the functional
|
||||||
@@ -814,8 +827,19 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
} else if(!helper.isInCurrPkg(clazz)){
|
} else if(!helper.isInCurrPkg(clazz)){
|
||||||
if(clazz.contains(CONSTANTS.$$)) {
|
if(clazz.contains(CONSTANTS.$$)) {
|
||||||
mDesc = helper.getDescriptorOfApplyMethod(methCallType);
|
mDesc = helper.getDescriptorOfApplyMethod(methCallType);
|
||||||
helper.generateBCForFunN(mDesc);
|
RefTypeOrTPHOrWildcardOrGeneric returnType = resolver.resolve(methodCall.getType());
|
||||||
// mDesc = helper.generateBCForFunN(methCallType,typesOfParams);
|
List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes = methodCall
|
||||||
|
.arglist
|
||||||
|
.getArguments()
|
||||||
|
.stream()
|
||||||
|
.map(TypableStatement::getType)
|
||||||
|
.map(resolver::resolve)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
FunNUtilities funNUtilities = FunNGenerator.getInstance();
|
||||||
|
FunNUtilities.writeClassFile(funNUtilities.getSuperClassName(argumentTypes.size()),
|
||||||
|
funNUtilities.generateSuperBytecode(argumentTypes.size()), path);
|
||||||
|
FunNUtilities.writeClassFile(funNUtilities.getSpecializedClassName(argumentTypes, returnType),
|
||||||
|
funNUtilities.generateSpecializedBytecode(argumentTypes, returnType), path);
|
||||||
}else {
|
}else {
|
||||||
try {
|
try {
|
||||||
cLoader2 = new DirectoryClassLoader(path, classLoader);
|
cLoader2 = new DirectoryClassLoader(path, classLoader);
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
if (inMethod && !tphsClass.contains(tphName)) {
|
if (inMethod && !tphsClass.contains(tphName)) {
|
||||||
ArrayList<String> tphs = null;
|
ArrayList<String> tphs = null;
|
||||||
if (!(tphs = methodAndTph.getTphs()).contains(tphName)) {
|
if (!(tphs = methodAndTph.getTphs()).contains(tphName)) {
|
||||||
tphs.add(tphName);
|
methodAndTph.addTph(tphName);
|
||||||
}
|
}
|
||||||
if (inLocalOrParamOrReturn) {
|
if (inLocalOrParamOrReturn) {
|
||||||
if (!(tphs = methodAndTph.getLocalTphs()).contains(tphName)) {
|
if (!(tphs = methodAndTph.getLocalTphs()).contains(tphName)) {
|
||||||
@@ -173,7 +173,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
public void visit(GenericRefType genericRefType) {
|
public void visit(GenericRefType genericRefType) {
|
||||||
String name = genericRefType.getParsedName();
|
String name = genericRefType.getParsedName();
|
||||||
if (inMethod) {
|
if (inMethod) {
|
||||||
methodAndTph.getTphs().add(name);
|
methodAndTph.addTph(name);
|
||||||
if (inLocalOrParamOrReturn)
|
if (inLocalOrParamOrReturn)
|
||||||
methodAndTph.getLocalTphs().add(name);
|
methodAndTph.getLocalTphs().add(name);
|
||||||
}else {
|
}else {
|
||||||
@@ -195,7 +195,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
public void visit(Method method) {
|
public void visit(Method method) {
|
||||||
inMethod = true;
|
inMethod = true;
|
||||||
String id = MethodUtility.createID(resolver,method);
|
String id = MethodUtility.createID(resolver,method);
|
||||||
Predicate<Pair> filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA1 instanceof TypePlaceholder) &&
|
Predicate<Pair> filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA2 instanceof TypePlaceholder) &&
|
||||||
(resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) &&
|
(resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) &&
|
||||||
(resultSet.resolveType((TypePlaceholder)(cs.TA2)).resolvedType instanceof TypePlaceholder));
|
(resultSet.resolveType((TypePlaceholder)(cs.TA2)).resolvedType instanceof TypePlaceholder));
|
||||||
|
|
||||||
@@ -209,10 +209,12 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
|
|
||||||
csS.getOderConstraints()
|
csS.getOderConstraints()
|
||||||
.forEach(oConSSet -> { Set<Constraint<Pair>> setCons = new HashSet<>();
|
.forEach(oConSSet -> { Set<Constraint<Pair>> setCons = new HashSet<>();
|
||||||
oConSSet.forEach(OConS -> { setCons.add(
|
oConSSet.forEach(OConS -> { Constraint<Pair> newConsPair = new Constraint<Pair>();
|
||||||
|
newConsPair.isStatement = OConS.isStatement;
|
||||||
|
setCons.add(
|
||||||
OConS.stream()
|
OConS.stream()
|
||||||
.filter(filterUndConstraints)
|
.filter(filterUndConstraints)
|
||||||
.collect(Collectors.toCollection(Constraint<Pair>::new)) );
|
.collect(Collectors.toCollection(() -> newConsPair)) );
|
||||||
} );
|
} );
|
||||||
ret.addOderConstraint(setCons);} );
|
ret.addOderConstraint(setCons);} );
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
package de.dhbwstuttgart.bytecode.constraint;
|
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 {
|
public class TPHConstraint {
|
||||||
protected String left;
|
protected String left;
|
||||||
protected String right;
|
protected String right;
|
||||||
@@ -9,6 +14,12 @@ public class TPHConstraint {
|
|||||||
EXTENDS, EQUAL
|
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) {
|
public TPHConstraint(String left, String right, Relation rel) {
|
||||||
this.left = left;
|
this.left = left;
|
||||||
this.right = right;
|
this.right = right;
|
||||||
@@ -58,14 +69,16 @@ public class TPHConstraint {
|
|||||||
public boolean equals (Object o) {
|
public boolean equals (Object o) {
|
||||||
if (o instanceof TPHConstraint) {
|
if (o instanceof TPHConstraint) {
|
||||||
TPHConstraint o_tphcons = (TPHConstraint)o;
|
TPHConstraint o_tphcons = (TPHConstraint)o;
|
||||||
return (left+right).equals(o_tphcons.getLeft()+o_tphcons.getRight());
|
return (this.left.equals(o_tphcons.getLeft())
|
||||||
|
&& this.right.equals(o_tphcons.getRight())
|
||||||
|
&& this.rel.equals(o_tphcons.rel));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if(rel == Relation.EXTENDS) {
|
if(rel == Relation.EXTENDS) {
|
||||||
@@ -74,13 +87,4 @@ public class TPHConstraint {
|
|||||||
return left + " = " + right;
|
return left + " = " + right;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
public String toString() {
|
|
||||||
if(rel == Relation.EXTENDS) {
|
|
||||||
return "new TPHConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return "new TPHConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,24 @@
|
|||||||
package de.dhbwstuttgart.bytecode.descriptor;
|
package de.dhbwstuttgart.bytecode.descriptor;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.bytecode.funN.FunNGenerator;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
import de.dhbwstuttgart.bytecode.funN.FunNUtilities;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
|
|
||||||
|
|
||||||
public class TypeToDescriptor implements TypeVisitor<String>{
|
public class TypeToDescriptor implements TypeVisitor<String>{
|
||||||
|
|
||||||
|
private final boolean specializedFunN;
|
||||||
|
|
||||||
|
public TypeToDescriptor(){ this(true); }
|
||||||
|
|
||||||
|
public TypeToDescriptor(boolean specializedFunN) { this.specializedFunN = specializedFunN; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(RefType refType) {
|
public String visit(RefType refType) {
|
||||||
|
if (refType.getName().toString().matches("Fun\\d+\\$\\$") && specializedFunN) {
|
||||||
|
FunNUtilities funNUtilities = FunNGenerator.getInstance();
|
||||||
|
return funNUtilities.getSpecializedDescriptor(funNUtilities.getArguments(refType.getParaList()), funNUtilities.getReturnType(refType.getParaList()));
|
||||||
|
}
|
||||||
|
|
||||||
return refType.getName().toString().replace(".", "/");
|
return refType.getName().toString().replace(".", "/");
|
||||||
// String t = refType.getName().toString().replace(".", "/");
|
// String t = refType.getName().toString().replace(".", "/");
|
||||||
// return t.equals("Fun1")?(t+"$$"):t;
|
// return t.equals("Fun1")?(t+"$$"):t;
|
||||||
@@ -38,6 +45,8 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
|||||||
//throw new NotImplementedException();
|
//throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ToDo Etienne: bin der Meinung hier müsste immer der Descriptor der extends-Schranke sein, z.b. <T> => Ljava/lang/Object; oder <T extends String> => Ljava/lang/String;
|
||||||
|
//Tests sind aber damit grün?! => Fehler in Tests schon vorher aufgefallen und gut möglich!
|
||||||
@Override
|
@Override
|
||||||
public String visit(GenericRefType genericRefType) {
|
public String visit(GenericRefType genericRefType) {
|
||||||
return genericRefType.getParsedName().replace(".", "/");
|
return genericRefType.getParsedName().replace(".", "/");
|
||||||
|
|||||||
@@ -0,0 +1,181 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode.funN;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
|
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.CONSTANTS;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
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 org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static org.objectweb.asm.Opcodes.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a Singleton-Service implementation for the {@link FunNUtilities} interface.
|
||||||
|
*
|
||||||
|
* @since Studienarbeit Type Erasure
|
||||||
|
* @author etiennezink
|
||||||
|
*/
|
||||||
|
public final class FunNGenerator implements FunNUtilities{
|
||||||
|
|
||||||
|
private static final FunNGenerator funNGenerator = new FunNGenerator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the Singleton instance for {@link FunNGenerator}
|
||||||
|
*/
|
||||||
|
public static FunNUtilities getInstance(){ return funNGenerator; }
|
||||||
|
|
||||||
|
private final String argumentGenericBase = "T";
|
||||||
|
private final String returnGeneric = "R";
|
||||||
|
private final String methodName = "apply";
|
||||||
|
private final int bytecodeVersion = V1_8;
|
||||||
|
|
||||||
|
private final String objectSuperType = Type.getInternalName(Object.class).replace('.','/');
|
||||||
|
private final RefType objectRefType = new RefType(new JavaClassName(objectSuperType), null);
|
||||||
|
private final String objectSignature = applySignature(objectRefType);
|
||||||
|
|
||||||
|
private FunNGenerator(){}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] generateSuperBytecode(int numberArguments) {
|
||||||
|
StringBuilder superFunNClassSignature = new StringBuilder("<");
|
||||||
|
StringBuilder superFunNMethodSignature = new StringBuilder("(");
|
||||||
|
StringBuilder superFunNMethodDescriptor = new StringBuilder("(");
|
||||||
|
|
||||||
|
for (int currentParameter = 1; currentParameter <= numberArguments; currentParameter++){
|
||||||
|
superFunNClassSignature.append(String.format("%s%d:%s",argumentGenericBase, currentParameter, objectSignature));
|
||||||
|
superFunNMethodSignature.append(applySignature( new GenericRefType(argumentGenericBase + currentParameter, null)));
|
||||||
|
superFunNMethodDescriptor.append(objectSignature);
|
||||||
|
}
|
||||||
|
superFunNClassSignature.append(String.format("%s:%s>%s", returnGeneric, objectSignature, objectSignature));
|
||||||
|
superFunNMethodSignature.append(String.format(")%s", applySignature(new GenericRefType(returnGeneric, null))));
|
||||||
|
superFunNMethodDescriptor.append(String.format(")%s", objectSignature));
|
||||||
|
|
||||||
|
ClassWriter classWriter = new ClassWriter(0);
|
||||||
|
MethodVisitor methodVisitor;
|
||||||
|
classWriter.visit(bytecodeVersion, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, getSuperClassName(numberArguments), superFunNClassSignature.toString(), objectSuperType, null);
|
||||||
|
methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, methodName, superFunNMethodDescriptor.toString(), superFunNMethodSignature.toString(), null);
|
||||||
|
methodVisitor.visitEnd();
|
||||||
|
classWriter.visitEnd();
|
||||||
|
return classWriter.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSuperClassName(int numberArguments) {
|
||||||
|
return String.format("Fun%d$$", numberArguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] generateSpecializedBytecode(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType) {
|
||||||
|
Objects.requireNonNull(argumentTypes);
|
||||||
|
Objects.requireNonNull(returnType);
|
||||||
|
//generates a list of all params and substitutes the TPH
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> parameters = Stream
|
||||||
|
.concat(argumentTypes.stream(), Stream.of(returnType))
|
||||||
|
.map(this::substituteTPH)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
RefType superFunN = new RefType(new JavaClassName(getSuperClassName(argumentTypes.size())), parameters , null);
|
||||||
|
StringBuilder funNClassSignature = new StringBuilder(objectSignature + (superFunN.acceptTV(new TypeToSignature(false))));
|
||||||
|
boolean containsGeneric = false;
|
||||||
|
|
||||||
|
String genericSignature = "<";
|
||||||
|
for (RefTypeOrTPHOrWildcardOrGeneric typeArgument : parameters) {
|
||||||
|
if (typeArgument instanceof GenericRefType){
|
||||||
|
GenericRefType generic = (GenericRefType) typeArgument;
|
||||||
|
String signatureOfArgument = generic.getParsedName();
|
||||||
|
if(genericSignature.contains(signatureOfArgument)) continue;
|
||||||
|
genericSignature += String.format("%s:%s", signatureOfArgument, objectSignature);
|
||||||
|
containsGeneric = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
genericSignature += ">";
|
||||||
|
if (containsGeneric) funNClassSignature.insert(0, genericSignature);
|
||||||
|
|
||||||
|
ClassWriter classWriter = new ClassWriter(0);
|
||||||
|
classWriter.visit(bytecodeVersion, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, getSpecializedClassName(argumentTypes, returnType), funNClassSignature.toString(), objectSuperType, new String[]{getSuperClassName(argumentTypes.size())});
|
||||||
|
classWriter.visitEnd();
|
||||||
|
return classWriter.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSpecializedClassName(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType) {
|
||||||
|
Objects.requireNonNull(argumentTypes);
|
||||||
|
Objects.requireNonNull(returnType);
|
||||||
|
return String.format("Fun%d$$$_$%s%s",
|
||||||
|
argumentTypes.size(),
|
||||||
|
argumentTypes
|
||||||
|
.stream()
|
||||||
|
.map(this::applyNameDescriptor)
|
||||||
|
.collect(Collectors.joining()),
|
||||||
|
applyNameDescriptor(returnType))
|
||||||
|
.replace('/', '$')
|
||||||
|
.replace(";", "$_$");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSpecializedDescriptor(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType) {
|
||||||
|
Objects.requireNonNull(argumentTypes);
|
||||||
|
Objects.requireNonNull(returnType);
|
||||||
|
return applyDescriptor(getSpecializedFunNRefType(argumentTypes, returnType));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSpecializedSignature(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType) {
|
||||||
|
Objects.requireNonNull(argumentTypes);
|
||||||
|
Objects.requireNonNull(returnType);
|
||||||
|
return applySignature(getSpecializedFunNRefType(argumentTypes, returnType));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RefTypeOrTPHOrWildcardOrGeneric> getArguments(List<RefTypeOrTPHOrWildcardOrGeneric> list) {
|
||||||
|
Objects.requireNonNull(list);
|
||||||
|
return list
|
||||||
|
.stream()
|
||||||
|
.limit(Math.max(0, list.size() - 1))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric getReturnType(List<RefTypeOrTPHOrWildcardOrGeneric> list) {
|
||||||
|
Objects.requireNonNull(list);
|
||||||
|
if(list.size() == 0) return null;
|
||||||
|
return list.get(list.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String applyDescriptor(RefTypeOrTPHOrWildcardOrGeneric a) { return a.acceptTV(new TypeToDescriptor(true)); }
|
||||||
|
private String applySignature(RefTypeOrTPHOrWildcardOrGeneric a) { return a.acceptTV(new TypeToSignature(true)); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param a
|
||||||
|
* @return the name for the type {@code a} which should be used in the specialized name for FunN.
|
||||||
|
*/
|
||||||
|
private String applyNameDescriptor(RefTypeOrTPHOrWildcardOrGeneric a){ return a instanceof TypePlaceholder ? "LTPH;" : String.format("L%s;", applyDescriptor(a)); }
|
||||||
|
|
||||||
|
private RefTypeOrTPHOrWildcardOrGeneric substituteTPH(RefTypeOrTPHOrWildcardOrGeneric t) {
|
||||||
|
if (t instanceof TypePlaceholder) {
|
||||||
|
TypePlaceholder tph = (TypePlaceholder) t;
|
||||||
|
return new GenericRefType(tph.getName()+"$", t.getOffset());
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
private RefType getSpecializedFunNRefType(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType){
|
||||||
|
return new RefType(new JavaClassName(getSpecializedClassName(argumentTypes, returnType)),
|
||||||
|
Stream
|
||||||
|
.concat(argumentTypes.stream(), Stream.of(returnType))
|
||||||
|
.filter(t -> t instanceof GenericRefType ||
|
||||||
|
t instanceof TypePlaceholder)
|
||||||
|
.collect(Collectors.toList()),null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode.funN;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.CONSTANTS;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface which represents the functionality for specifying and generating the specified functional types (FunN).
|
||||||
|
*
|
||||||
|
* @since Studienarbeit Type Erasure
|
||||||
|
* @author etiennezink
|
||||||
|
*/
|
||||||
|
public interface FunNUtilities {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param numberArguments (excluding the return type!)
|
||||||
|
* @return the bytecode for the super FunN-interface
|
||||||
|
*/
|
||||||
|
byte[] generateSuperBytecode(int numberArguments);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param numberArguments (excluding the return type!)
|
||||||
|
* @return the name for the super FunN-interface
|
||||||
|
*/
|
||||||
|
String getSuperClassName(int numberArguments);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param argumentTypes (excluding the return type!)
|
||||||
|
* @param returnType
|
||||||
|
* @return the bytecode for the specialized FunN-interface
|
||||||
|
*/
|
||||||
|
byte[] generateSpecializedBytecode(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param argumentTypes (excluding the return type!)
|
||||||
|
* @param returnType
|
||||||
|
* @return the name for the specialized FunN-interface
|
||||||
|
*/
|
||||||
|
String getSpecializedClassName(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param argumentTypes (excluding the return type!)
|
||||||
|
* @param returnType
|
||||||
|
* @return the descriptor for a specialized FunN-interface.
|
||||||
|
*/
|
||||||
|
String getSpecializedDescriptor(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param argumentTypes (excluding the return type!)
|
||||||
|
* @param returnType
|
||||||
|
* @return the signature for a specialized FunN-interface.
|
||||||
|
*/
|
||||||
|
String getSpecializedSignature(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list containing type arguments and the return type.
|
||||||
|
* @return a {@link List} containing only the arguments of the specialized FunN-interface.
|
||||||
|
*/
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> getArguments(List<RefTypeOrTPHOrWildcardOrGeneric> list);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list containing type arguments and the return type.
|
||||||
|
* @return the return type of the {@code list} (last member)
|
||||||
|
*/
|
||||||
|
RefTypeOrTPHOrWildcardOrGeneric getReturnType(List<RefTypeOrTPHOrWildcardOrGeneric> list);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be refactored into a central API.
|
||||||
|
*
|
||||||
|
* @param className
|
||||||
|
* @param bytecode
|
||||||
|
* @param directory
|
||||||
|
* @return {@code true} iff the file could be generated and {@code false} if not
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
static boolean writeClassFile(String className, byte[] bytecode, File directory) {
|
||||||
|
try (FileOutputStream output = new FileOutputStream(new File(directory , className + CONSTANTS.EXTENSIONCLASS))){
|
||||||
|
output.write(bytecode);
|
||||||
|
output.flush();
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -29,5 +29,13 @@ public class GenericGeneratorResultsForAllMethods {
|
|||||||
public List<MethodAndConstraints> getMethodsAndConstraints() {
|
public List<MethodAndConstraints> getMethodsAndConstraints() {
|
||||||
return methodsAndConstraints;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+4
@@ -52,4 +52,8 @@ public class GenericsGeneratorResult {
|
|||||||
this.equalsTPHs = equalsTPHs;
|
this.equalsTPHs = equalsTPHs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return constraint.toString() + " EqualsTPS: " + equalsTPHs.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+8
@@ -73,4 +73,12 @@ public class GenericsGeneratorResultForClass {
|
|||||||
return Collections.emptyList();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+10
@@ -33,4 +33,14 @@ public class MethodAndConstraints {
|
|||||||
return constraints;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -13,12 +13,4 @@ public class ClassConstraint extends TPHConstraint {
|
|||||||
/*public ClassConstraint(TPHConstraint constraint) {
|
/*public ClassConstraint(TPHConstraint constraint) {
|
||||||
this.constraint = constraint;
|
this.constraint = constraint;
|
||||||
}*/
|
}*/
|
||||||
public String toString() {
|
|
||||||
if(rel == Relation.EXTENDS) {
|
|
||||||
return "new ClassConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return "new ClassConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+187
-91
@@ -8,6 +8,7 @@ import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
@@ -21,6 +22,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
// HashMap speichert ob TPH in einer Methode oder in der Klasse ist; und wenn es in der Methode ist, in welcher Methode
|
// 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 HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTPHs = new HashMap<>();
|
||||||
public List<ClassConstraint> classConstraints = new ArrayList<>();
|
public List<ClassConstraint> classConstraints = new ArrayList<>();
|
||||||
|
private HashMap<String, MethodAndTPH> mapMethodsAndTph = new HashMap<>();
|
||||||
public List<MethodConstraint> methodConstraints = new ArrayList<>();
|
public List<MethodConstraint> methodConstraints = new ArrayList<>();
|
||||||
public HashMap<String, List<MethodConstraint>> methodConstraintsWithPosition = new HashMap<>();
|
public HashMap<String, List<MethodConstraint>> methodConstraintsWithPosition = new HashMap<>();
|
||||||
public ResultSet resSet;
|
public ResultSet resSet;
|
||||||
@@ -34,6 +36,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
this.allConstraints = tphExtractor.allCons;
|
this.allConstraints = tphExtractor.allCons;
|
||||||
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
|
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
|
||||||
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
|
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
|
||||||
|
tphExtractor.ListOfMethodsAndTph.forEach(matph -> this.mapMethodsAndTph.put(matph.getId(), matph));
|
||||||
this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph);
|
this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph);
|
||||||
this.methodConstraintsWithPosition = getMethodConstraintsWithPositionNew(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph, resSet, oldCons);
|
this.methodConstraintsWithPosition = getMethodConstraintsWithPositionNew(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph, resSet, oldCons);
|
||||||
}
|
}
|
||||||
@@ -60,7 +63,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
}
|
}
|
||||||
} while (addedToConstraintsListForCC2);
|
} while (addedToConstraintsListForCC2);
|
||||||
|
|
||||||
List<ClassConstraint> classConstraints3 = hasNoSupertypeForClassTypes(cs, cs_cl, posOfTphs);
|
List<ClassConstraint> classConstraints3 = hasNoSupertypeForClassTypes(cs_cl, posOfTphs);
|
||||||
for (ClassConstraint cons: classConstraints3) {
|
for (ClassConstraint cons: classConstraints3) {
|
||||||
if (!checkForDuplicates(cons, cs_cl)) {
|
if (!checkForDuplicates(cons, cs_cl)) {
|
||||||
cs_cl.add(cons);
|
cs_cl.add(cons);
|
||||||
@@ -69,7 +72,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
return cs_cl;
|
return cs_cl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph) {
|
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> cs_m = new ArrayList<>();
|
||||||
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
||||||
for (MethodConstraint cons: methodConstraints1) {
|
for (MethodConstraint cons: methodConstraints1) {
|
||||||
@@ -114,7 +117,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
return cs_m;
|
return cs_m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static 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) {
|
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<>();
|
HashMap<String, List<MethodConstraint>> tempMethodConstraintsWithPosition = new HashMap<>();
|
||||||
for(MethodAndTPH method: listOfMethodsAndTph){
|
for(MethodAndTPH method: listOfMethodsAndTph){
|
||||||
List<String> methodsAddedToHashMap = new ArrayList<>();
|
List<String> methodsAddedToHashMap = new ArrayList<>();
|
||||||
@@ -224,28 +227,34 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
* {T <. Object | ((T is a type variable in a type of a node of a field
|
* {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)}
|
* or (\exists T~: (T~ <. T) \in cs_cl)) and (\existsnot T': T <. T') \in cs)}
|
||||||
*/
|
*/
|
||||||
public static List<ClassConstraint> hasNoSupertypeForClassTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) {
|
public static List<ClassConstraint> hasNoSupertypeForClassTypes(List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) {
|
||||||
List<ClassConstraint> tempCC= new ArrayList<>();
|
List<ClassConstraint> tempCC= new ArrayList<>();
|
||||||
for(TPHConstraint allCons: allConstraints) {
|
List<TPHConstraint> clCons = new ArrayList<>(cs_cl);
|
||||||
for(ClassConstraint cCons: cs_cl) {
|
for(String tph: posOfTphs.keySet()) {
|
||||||
for(String tph: posOfTphs.keySet()) {
|
for(PairTphMethod pair: posOfTphs.get(tph)) {
|
||||||
for(PairTphMethod pair: posOfTphs.get(tph)) {
|
boolean tvInField = pair.fst == PositionFinder.Position.FIELD;
|
||||||
boolean tvInField = pair.fst == PositionFinder.Position.FIELD;
|
boolean hasSmallerTVInClCons = hasSmallerTVInClCons(tph, cs_cl);
|
||||||
boolean hasSmallerTVInClCons = (posOfTphs.containsKey(cCons.getRight()) && cCons.getRight() == tph && cCons.getLeft() != null);
|
if ((tvInField || hasSmallerTVInClCons) &&
|
||||||
if( ((tvInField || hasSmallerTVInClCons) && cCons.getRel()==Relation.EXTENDS) &&
|
!checkUpperBound(clCons, tph)) {
|
||||||
!checkUpperBound(allConstraints, tph) && allCons.getRel()==Relation.EXTENDS) {
|
ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS);
|
||||||
ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS);
|
if (!checkForDuplicates(consToAdd, tempCC)) {
|
||||||
if (!checkForDuplicates(consToAdd, tempCC)){
|
tempCC.add(consToAdd);
|
||||||
tempCC.add(consToAdd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return tempCC;
|
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
|
* 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}
|
* {T < .T' | T is a type variable in a type of the method/constructor m in cl_\sigma, (T <. T') \in cs}
|
||||||
@@ -275,7 +284,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
* Def. FGG: zweite Zeile von cs_m
|
* 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}
|
* {R' <. S | (R <. R'), (S <. S') \in cs_m and (R',S) is in the transitive closure of cs}
|
||||||
*/
|
*/
|
||||||
public static List<MethodConstraint> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m) { //transitive closure of cs
|
public List<MethodConstraint> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m) { //transitive closure of cs
|
||||||
//TODO:
|
//TODO:
|
||||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
List<MethodConstraint> tempMC= new ArrayList<>();
|
||||||
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
||||||
@@ -300,7 +309,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
* Def. FGG: dritte Zeile von cs_m
|
* 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}
|
* {R' <. S | (R <. R') \in cs_m, (S <. S') \in cs_cl and (R',S) is in the transitive closure of cs}
|
||||||
*/
|
*/
|
||||||
public static List<MethodConstraint> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
|
public List<MethodConstraint> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
|
||||||
//TODO:
|
//TODO:
|
||||||
List<MethodConstraint> tempMC= new ArrayList<>();
|
List<MethodConstraint> tempMC= new ArrayList<>();
|
||||||
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
||||||
@@ -363,7 +372,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
/**
|
/**
|
||||||
* nimm die Menge cs_cl aus cs_m raus
|
* nimm die Menge cs_cl aus cs_m raus
|
||||||
*/
|
*/
|
||||||
public static List<MethodConstraint> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
|
public List<MethodConstraint> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
|
||||||
// erstelle Kopie der Liste cs_cl
|
// erstelle Kopie der Liste cs_cl
|
||||||
List<TPHConstraint> tempCC = new ArrayList<>();
|
List<TPHConstraint> tempCC = new ArrayList<>();
|
||||||
for(ClassConstraint cc: cs_cl) {
|
for(ClassConstraint cc: cs_cl) {
|
||||||
@@ -409,7 +418,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<TPHConstraint> buildTransitiveClosure(List list) {
|
public List<TPHConstraint> buildTransitiveClosure(List list) {
|
||||||
List<TPHConstraint> iterList = new ArrayList<>(list);
|
List<TPHConstraint> iterList = new ArrayList<>(list);
|
||||||
List<TPHConstraint> runList = new ArrayList<>(list);
|
List<TPHConstraint> runList = new ArrayList<>(list);
|
||||||
List<TPHConstraint> tcList = new ArrayList<>(list);
|
List<TPHConstraint> tcList = new ArrayList<>(list);
|
||||||
@@ -496,27 +505,32 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
r = Relation.EQUAL;
|
r = Relation.EQUAL;
|
||||||
}
|
}
|
||||||
MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
|
MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
|
||||||
if(mc.getRel() != Relation.EQUAL) {
|
if(mc.getRel() == Relation.EXTENDS) {
|
||||||
if(!checkForDuplicates(mc, tempMC)) {
|
if (!mc.getLeft().equals(mc.getRight())) { //eliminieren der Fälle wie AA<.AA
|
||||||
tempMC.add(mc);
|
if(!checkForDuplicates(mc, tempMC)) {
|
||||||
}
|
tempMC.add(mc);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tempMC;
|
return tempMC;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<MethodConstraint> secondLineMethodDefinition(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set<Pair> oldCons) {
|
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<>();
|
List<MethodConstraint> tempMC = new ArrayList<>(); //für Ergebnisse basierend auf der neuen Datenstruktur (Ali)
|
||||||
Set<Pair> tempSet = new HashSet<>();
|
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);
|
Set<Pair> tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet);
|
||||||
|
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
|
||||||
MethodAndTPH methAndTphs = methodAndTPH;
|
MethodAndTPH methAndTphs = methodAndTPH;
|
||||||
|
Set<Pair> undCons = methAndTphs.constraints.getUndConstraints();
|
||||||
List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints();
|
List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints();
|
||||||
List<List<Constraint<Pair>>> orConsList = new ArrayList<>();
|
|
||||||
List<HashMap<Relation, List<TPHConstraint>>> orConsListConverted = new ArrayList<>();
|
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++) {
|
for(int i=0; i<orCons.size(); i++) {
|
||||||
HashMap<Relation, List<TPHConstraint>> orConsInternal = new HashMap<>();
|
|
||||||
List<TPHConstraint> orConsWithEQUAL = new ArrayList();
|
List<TPHConstraint> orConsWithEQUAL = new ArrayList();
|
||||||
List<TPHConstraint> orConsWithEXTENDS = new ArrayList();
|
List<TPHConstraint> orConsWithEXTENDS = new ArrayList();
|
||||||
|
HashMap<Relation, List<TPHConstraint>> orConsInternal = new HashMap<>();
|
||||||
for(Constraint con: orCons.get(i)) {
|
for(Constraint con: orCons.get(i)) {
|
||||||
Iterator<Pair> it = con.iterator();
|
Iterator<Pair> it = con.iterator();
|
||||||
while(it.hasNext()) {
|
while(it.hasNext()) {
|
||||||
@@ -525,10 +539,10 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
if(p.GetOperator() == PairOperator.SMALLERDOT) {
|
if(p.GetOperator() == PairOperator.SMALLERDOT) {
|
||||||
r = Relation.EXTENDS;
|
r = Relation.EXTENDS;
|
||||||
orConsWithEXTENDS.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r));
|
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);
|
/*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)) {
|
if(!checkForDuplicates(mc, tempMC)) {
|
||||||
tempMC.add(mc);
|
tempMC.add(mc);
|
||||||
}
|
}*/
|
||||||
} else if(p.GetOperator() == PairOperator.EQUALSDOT) {
|
} else if(p.GetOperator() == PairOperator.EQUALSDOT) {
|
||||||
r = Relation.EQUAL;
|
r = Relation.EQUAL;
|
||||||
orConsWithEQUAL.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r));
|
orConsWithEQUAL.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r));
|
||||||
@@ -544,6 +558,8 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
orConsListConverted.add(orConsInternal);
|
orConsListConverted.add(orConsInternal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// oldCons sind alle Und- und Oder-Constraints
|
||||||
|
// zunächst in meine Datenstruktur(Ali) konvertieren
|
||||||
List<Pair> oldConsList = new ArrayList<>(oldCons);
|
List<Pair> oldConsList = new ArrayList<>(oldCons);
|
||||||
List<TPHConstraint> oldConsListConverted = new ArrayList<>();
|
List<TPHConstraint> oldConsListConverted = new ArrayList<>();
|
||||||
for(Pair pair: oldConsList) {
|
for(Pair pair: oldConsList) {
|
||||||
@@ -555,54 +571,106 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
}
|
}
|
||||||
oldConsListConverted.add(new TPHConstraint(((TypePlaceholder) pair.TA1).getName(), ((TypePlaceholder) pair.TA2).getName(), r));
|
oldConsListConverted.add(new TPHConstraint(((TypePlaceholder) pair.TA1).getName(), ((TypePlaceholder) pair.TA2).getName(), r));
|
||||||
}
|
}
|
||||||
// List<TPHConstraint> tcOfoldCons = buildTransitiveClosure(oldConsListConverted);
|
|
||||||
// Set<Pair> tcOfoldConsSet = buildTransitiveClosureForCP(oldCons);
|
|
||||||
|
|
||||||
// for(int i=0; i<orConsListConverted.size(); i++) {
|
|
||||||
|
// Berechnung des zweiten Teils der Bedingung der Regel
|
||||||
for(int i=0; i<orCons.size(); i++) {
|
for(int i=0; i<orCons.size(); i++) {
|
||||||
Constraint<Pair> extendsSet = new Constraint<Pair>();
|
Constraint<Pair> extendsSet = new Constraint<Pair>();
|
||||||
Constraint<Pair> equalSet = new Constraint<Pair>();
|
Constraint<Pair> equalSet = new Constraint<Pair>();
|
||||||
for(Constraint con: orCons.get(i)) {
|
//für jede einzelne OrConstraint-Menge gehe durch
|
||||||
|
for (Constraint con : orCons.get(i)) {
|
||||||
Iterator<Pair> it = con.iterator();
|
Iterator<Pair> it = con.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Pair p = it.next();
|
Pair p = it.next();
|
||||||
// List<TPHConstraint> extendsList = orConsListConverted.get(i).get(Relation.EXTENDS);
|
|
||||||
// List<TPHConstraint> equalList = orConsListConverted.get(i).get(Relation.EQUAL);
|
|
||||||
if (p.OperatorSmallerDot()) {
|
if (p.OperatorSmallerDot()) {
|
||||||
extendsSet.add(p);
|
extendsSet.add(p);
|
||||||
} else if (p.OperatorEqual()) {
|
} else if (p.OperatorEqual()) {
|
||||||
equalSet.add(p);
|
equalSet.add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for (TPHConstraint ex : extendsList) {
|
Iterator<Pair> itExtends2 = extendsSet.iterator();
|
||||||
Iterator<Pair> itExtends = extendsSet.iterator();
|
while(itExtends2.hasNext()) {
|
||||||
while(itExtends.hasNext()) {
|
Pair pairExtends2 = itExtends2.next();
|
||||||
Pair pairExtends = itExtends.next();
|
Set<String> containedVars = new HashSet<>(methodAndTPH.getTphs());
|
||||||
// for (TPHConstraint eq : equalList) {
|
String pairExtends2RHSName = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName();
|
||||||
Iterator<Pair> itEqual = equalSet.iterator();
|
Iterator<Pair> itEqual2 = equalSet.iterator();
|
||||||
while(itEqual.hasNext()) {
|
while (itEqual2.hasNext()) {
|
||||||
Pair pairEqual = itEqual.next();
|
boolean transClo = false;
|
||||||
// MethodConstraint mc = new MethodConstraint(ex.getRight(), eq.getLeft(), Relation.EXTENDS);
|
Pair pairEqual2 = itEqual2.next();
|
||||||
Pair newPair = new Pair(resSet.resolveType((TypePlaceholder)(pairExtends.TA2)).resolvedType, resSet.resolveType((TypePlaceholder)(pairEqual.TA1)).resolvedType, PairOperator.SMALLERDOT);
|
//TODO: Auf trans.FamilyOfGeneratedGenerics Huelle pruefen
|
||||||
// for (TPHConstraint tc : tcOfoldCons) {
|
Pair newPairOld = new Pair(pairExtends2.TA2, pairEqual2.TA1);
|
||||||
Iterator<Pair> itTC = tcOfoldConsSet.iterator();
|
Pair newPair2 = new Pair(resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, resSet.resolveType((TypePlaceholder) (pairEqual2.TA1)).resolvedType, PairOperator.SMALLERDOT);
|
||||||
while(itTC.hasNext()) {
|
TPHConstraint newPairTPHConstraint = new TPHConstraint(newPair2);
|
||||||
Pair pairTC = itTC.next();
|
if (tcOfCs.contains(newPairTPHConstraint)|| (newPairTPHConstraint.getLeft().equals(newPairTPHConstraint.getRight()))) {
|
||||||
// if (tc.getLeft() == mc.getLeft() && tc.getRight() == mc.getRight() && tc.getRel() == mc.getRel()) {
|
transClo = true;
|
||||||
if(resSet.resolveType((TypePlaceholder)(pairTC.TA1)).resolvedType == newPair.TA1 && resSet.resolveType((TypePlaceholder)(pairTC.TA2)).resolvedType == newPair.TA2 && pairTC.OperatorSmallerDot() && newPair.OperatorSmallerDot()) { //hier bei pairTC resolvedType, damit Pairs aus oldCons in der Methode zur Berechnung von der transitiven Hülle nicht in eine Endlosschleife kommen (Cycles!)
|
}
|
||||||
// if (!checkForDuplicates(mc, tempMC)) {
|
TypePlaceholder tphR = (TypePlaceholder) pairEqual2.TA2;
|
||||||
if(newPair.TA1 != newPair.TA2) {
|
Iterator<Pair> itUndCons = undCons.iterator();
|
||||||
if (!checkForDuplicatesForSets(newPair, tempSet)) {
|
boolean rEqExRtilde = false;
|
||||||
tempSet.add(newPair);
|
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();
|
Iterator<Pair> itTemp = tempSet.iterator();
|
||||||
while(itTemp.hasNext()) {
|
while(itTemp.hasNext()) {
|
||||||
Pair p = itTemp.next();
|
Pair p = itTemp.next();
|
||||||
@@ -615,13 +683,35 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
r = Relation.EQUAL;
|
r = Relation.EQUAL;
|
||||||
}
|
}
|
||||||
MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
|
MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
|
||||||
if(mc.getRel() != Relation.EQUAL) {
|
if(mc.getRel() == Relation.EXTENDS) {
|
||||||
if(!checkForDuplicates(mc, tempMC)) {
|
if(!checkForDuplicates(mc, tempMC)) {
|
||||||
tempMC.add(mc);
|
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;
|
return tempMC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,27 +768,43 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<MethodConstraint> hasNoSupertypeForMethodTypesNew(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH) {
|
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<MethodConstraint> tempMC = new ArrayList<>();
|
||||||
List<TPHConstraint> allCons = allConstraints;
|
List<TPHConstraint> methCons = new ArrayList<>(cs_m);
|
||||||
MethodAndTPH methAndTphs = methodAndTPH;
|
MethodAndTPH methAndTphs = methodAndTPH;
|
||||||
for(String tph: posOfTphs.keySet()) {
|
for(String tph: posOfTphs.keySet()) {
|
||||||
for(int i=0; i<posOfTphs.get(tph).size(); i++)
|
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()) {
|
if(posOfTphs.get(tph).get(i).fst == PositionFinder.Position.METHOD && posOfTphs.get(tph).get(i).snd == methAndTphs.getId() && !checkUpperBound(methCons,tph)) {
|
||||||
for(TPHConstraint ac: allCons) {
|
MethodConstraint mc2 = new MethodConstraint(tph, objectType, Relation.EXTENDS);
|
||||||
if(tph==ac.getRight() && !checkUpperBound(allCons,tph)) {
|
if (!checkForDuplicates(mc2, tempMC)) {
|
||||||
MethodConstraint mc2 = new MethodConstraint(tph, objectType, Relation.EXTENDS);
|
tempMC.add(mc2);
|
||||||
if(!checkForDuplicates(mc2, tempMC)) {
|
|
||||||
tempMC.add(mc2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tempMC;
|
return tempMC;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static 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) {
|
|
||||||
|
|
||||||
|
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<>();
|
HashMap<String, List<MethodConstraint>> tempMethodConstraintsWithPosition = new HashMap<>();
|
||||||
List<MethodConstraint> newMCList = new ArrayList<>();
|
List<MethodConstraint> newMCList = new ArrayList<>();
|
||||||
List<MethodConstraint> newMCList2 = new ArrayList<>();
|
List<MethodConstraint> newMCList2 = new ArrayList<>();
|
||||||
@@ -736,14 +842,23 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
tempMethodConstraintsWithPosition.put(currentMethod, newMCList2);
|
tempMethodConstraintsWithPosition.put(currentMethod, newMCList2);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
hasNoSupType = hasNoSupertypeForMethodTypesNew(cs,posOfTphs,method);
|
hasNoSupType = hasNoSupertypeForMethodTypesNew(posOfTphs,method,listToAdd);
|
||||||
for (MethodConstraint cons: hasNoSupType) {
|
for (MethodConstraint cons: hasNoSupType) {
|
||||||
if (!checkForDuplicates(cons, listToAdd)) {
|
if (!checkForDuplicates(cons, listToAdd)) {
|
||||||
listToAdd.add(cons);
|
listToAdd.add(cons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mcWithoutCc = methodTypesWithoutClassTypes(cs_cl, listToAdd);
|
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);
|
tempMethodConstraintsWithPosition.put(currentMethod, mcWithoutCc);
|
||||||
}
|
}
|
||||||
@@ -760,25 +875,6 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
|
|
||||||
return tempMethodConstraintsWithPosition;
|
return tempMethodConstraintsWithPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
String ret =
|
|
||||||
"List<ClassConstraint> classConstraintsTest = new ArrayList<>();\n";
|
|
||||||
for(ClassConstraint cC: classConstraints) {
|
|
||||||
ret = ret + "classConstraintsTest.add(" + cC.toString() + ");\n";
|
|
||||||
}
|
|
||||||
ret = ret + "HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();\n";
|
|
||||||
ret = ret + "List<MethodConstraint> lmc;\n";
|
|
||||||
for (String methName : methodConstraintsWithPosition.keySet()) {
|
|
||||||
String consSet = "";
|
|
||||||
ret = ret + "lmc = new ArrayList<>();\n";
|
|
||||||
for (MethodConstraint methConstrs : methodConstraintsWithPosition.get(methName)) {
|
|
||||||
consSet = consSet + "lmc.add(" + methConstrs + ");\n";
|
|
||||||
}
|
|
||||||
ret = ret + consSet + "methodConstraintsWithPositionTest.put(\""+ methName + "\", lmc);\n";
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,13 +7,4 @@ public class MethodConstraint extends TPHConstraint {
|
|||||||
public MethodConstraint(String left, String right, Relation rel) {
|
public MethodConstraint(String left, String right, Relation rel) {
|
||||||
super(left, right, rel);
|
super(left, right, rel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
if(rel == Relation.EXTENDS) {
|
|
||||||
return "new MethodConstraint(\"" + left + "\", \"" + right + "\", Relation.EXTENDS)";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return "new MethodConstraint(\"" + left + "\", \"" + right + "\", Relation.EQUAL)";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,8 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.funN.FunNGenerator;
|
||||||
|
import de.dhbwstuttgart.bytecode.funN.FunNUtilities;
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
@@ -17,18 +19,29 @@ import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
|
|||||||
public class TypeToSignature implements TypeVisitor<String> {
|
public class TypeToSignature implements TypeVisitor<String> {
|
||||||
private List<GenericsGeneratorResult> constraints;
|
private List<GenericsGeneratorResult> constraints;
|
||||||
|
|
||||||
public TypeToSignature() {
|
private final boolean specializedFunN;
|
||||||
this.constraints = new ArrayList<>();
|
|
||||||
}
|
public TypeToSignature() { this(new ArrayList<>(), true); }
|
||||||
|
|
||||||
|
public TypeToSignature(boolean specializedFunN) { this(new ArrayList<>(), specializedFunN); }
|
||||||
|
|
||||||
public TypeToSignature(List<GenericsGeneratorResult> constraints) {
|
public TypeToSignature(List<GenericsGeneratorResult> constraints) {
|
||||||
|
this(constraints, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TypeToSignature(List<GenericsGeneratorResult> constraints, boolean specializedFunN){
|
||||||
this.constraints = constraints;
|
this.constraints = constraints;
|
||||||
|
this.specializedFunN = specializedFunN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(RefType refType) {
|
public String visit(RefType refType) {
|
||||||
if(refType.getName().toString().equals("void"))
|
if(refType.getName().toString().equals("void"))
|
||||||
return "V";
|
return "V";
|
||||||
|
if (refType.getName().toString().matches("Fun\\d+\\$\\$") && specializedFunN){
|
||||||
|
FunNUtilities funNUtilities = FunNGenerator.getInstance();
|
||||||
|
return funNUtilities.getSpecializedSignature(funNUtilities.getArguments(refType.getParaList()), funNUtilities.getReturnType(refType.getParaList()));
|
||||||
|
}
|
||||||
// return refType.toString().replace(".", "/");
|
// return refType.toString().replace(".", "/");
|
||||||
String params = "";
|
String params = "";
|
||||||
if(refType.getParaList().size()>0){
|
if(refType.getParaList().size()>0){
|
||||||
@@ -89,9 +102,20 @@ public class TypeToSignature implements TypeVisitor<String> {
|
|||||||
return sig;
|
return sig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changed that the correct signature is returned:
|
||||||
|
* returns now T...; expect of only ...
|
||||||
|
* where ... is {@code genericRefType.getParsedName()}
|
||||||
|
*
|
||||||
|
* @since Studienarbeit Type Erasure
|
||||||
|
* @author etiennezink
|
||||||
|
*
|
||||||
|
* @param genericRefType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String visit(GenericRefType genericRefType) {
|
public String visit(GenericRefType genericRefType) {
|
||||||
return genericRefType.getParsedName().replace(".", "/");
|
return String.format("T%s;", genericRefType.getParsedName()).replace(".", "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<GenericsGeneratorResult> getEqualTPHFromClassConstraints(List<GenericsGeneratorResult> listOfConstraints, String tph) {
|
private Optional<GenericsGeneratorResult> getEqualTPHFromClassConstraints(List<GenericsGeneratorResult> listOfConstraints, String tph) {
|
||||||
|
|||||||
@@ -27,7 +27,11 @@ public class MethodAndTPH {
|
|||||||
this.id = name;
|
this.id = name;
|
||||||
this.constraints = constraints;
|
this.constraints = constraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addTph(String tph) {
|
||||||
|
tphs.add(tph);
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<String> getTphs() {
|
public ArrayList<String> getTphs() {
|
||||||
return tphs;
|
return tphs;
|
||||||
}
|
}
|
||||||
@@ -47,4 +51,9 @@ public class MethodAndTPH {
|
|||||||
return localTphs;
|
return localTphs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -25,4 +25,8 @@ public class Resolver {
|
|||||||
public String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
public String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||||
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric resolve(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||||
|
return resultSet.resolveType(type).resolvedType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -216,6 +216,7 @@ public class StatementGenerator {
|
|||||||
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()),
|
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()),
|
||||||
getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()),
|
getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()),
|
||||||
argTypes, methodInvocationContext.getStart());
|
argTypes, methodInvocationContext.getStart());
|
||||||
|
ret.setStatement();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,8 +272,10 @@ public class StatementGenerator {
|
|||||||
whole+=".";
|
whole+=".";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parts.length < 2){
|
if(parts.length < 2 || parts[0].contentEquals("this") ){
|
||||||
receiver = new This(offset);
|
receiver = new This(offset);
|
||||||
|
} else if (parts[0].contentEquals("super")) {
|
||||||
|
receiver = new Super(offset);
|
||||||
}else if(receiver == null){ //Handelt es sich um keinen Statischen Klassennamen:
|
}else if(receiver == null){ //Handelt es sich um keinen Statischen Klassennamen:
|
||||||
String part = expression.substring(0,expression.length() - (1 + parts[parts.length-1].length()));
|
String part = expression.substring(0,expression.length() - (1 + parts[parts.length-1].length()));
|
||||||
receiver = generateLocalOrFieldVarOrClassName(part, offset);
|
receiver = generateLocalOrFieldVarOrClassName(part, offset);
|
||||||
@@ -302,33 +305,45 @@ public class StatementGenerator {
|
|||||||
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream()
|
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream()
|
||||||
.map(x -> TypePlaceholder.fresh(newExpression.getStart()))
|
.map(x -> TypePlaceholder.fresh(newExpression.getStart()))
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.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) {
|
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
|
||||||
Expression argument = convert(stmt.unaryExpression());
|
Expression argument = convert(stmt.unaryExpression());
|
||||||
Token offset = stmt.getStart();
|
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) {
|
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());
|
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
|
||||||
|
ret.setStatement();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) {
|
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());
|
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
|
||||||
|
ret.setStatement();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) {
|
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());
|
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
|
||||||
|
ret.setStatement();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java8Parser.AssignmentContext stmt) {
|
private Statement convert(Java8Parser.AssignmentContext stmt) {
|
||||||
AssignLeftSide leftHandSide = convert(stmt.leftHandSide());
|
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) {
|
private AssignLeftSide convert(Java8Parser.LeftHandSideContext leftHandSide) {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class ASTFactory {
|
|||||||
List<Method> methoden = new ArrayList<>();
|
List<Method> methoden = new ArrayList<>();
|
||||||
List<de.dhbwstuttgart.syntaxtree.Constructor> konstruktoren = new ArrayList<>();
|
List<de.dhbwstuttgart.syntaxtree.Constructor> konstruktoren = new ArrayList<>();
|
||||||
for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){
|
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> allMethods = new HashSet<>(Arrays.asList(jreClass.getMethods()));
|
||||||
Set<java.lang.reflect.Method> allDeclaredMethods = new HashSet<>(Arrays.asList(jreClass.getDeclaredMethods()));
|
Set<java.lang.reflect.Method> allDeclaredMethods = new HashSet<>(Arrays.asList(jreClass.getDeclaredMethods()));
|
||||||
@@ -87,7 +87,7 @@ public class ASTFactory {
|
|||||||
// return createClass(classType).getType();
|
// 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();
|
String name = constructor.getName();
|
||||||
RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass);
|
RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass);
|
||||||
Parameter[] jreParams = constructor.getParameters();
|
Parameter[] jreParams = constructor.getParameters();
|
||||||
@@ -106,10 +106,10 @@ public class ASTFactory {
|
|||||||
int modifier = constructor.getModifiers();
|
int modifier = constructor.getModifiers();
|
||||||
|
|
||||||
if(inClass.equals(java.lang.Object.class)){
|
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){
|
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";
|
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
|
* Berechnet einen neuen, eindeutigen Namen f�r eine neue
|
||||||
* <code>TypePlaceholder</code>. <br>Author: J�rg B�uerle
|
* <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.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.PairNoResult;
|
||||||
import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
|
import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
|
||||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||||
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
|
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
|
||||||
@@ -208,6 +209,7 @@ public class UnifyTypeFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ResultPair convert(UnifyPair mp, Map<String,TypePlaceholder> tphs) {
|
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 tl = UnifyTypeFactory.convert(mp.getLhsType(), tphs);
|
||||||
RefTypeOrTPHOrWildcardOrGeneric tr = UnifyTypeFactory.convert(mp.getRhsType(), tphs);
|
RefTypeOrTPHOrWildcardOrGeneric tr = UnifyTypeFactory.convert(mp.getRhsType(), tphs);
|
||||||
if(tl instanceof TypePlaceholder){
|
if(tl instanceof TypePlaceholder){
|
||||||
@@ -218,7 +220,7 @@ public class UnifyTypeFactory {
|
|||||||
//Einfach ignorieren TODO: Das hier muss ausgebessert werden:
|
//Einfach ignorieren TODO: Das hier muss ausgebessert werden:
|
||||||
//return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, ASTFactory.createObjectType());
|
//return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, ASTFactory.createObjectType());
|
||||||
}else{
|
}else{
|
||||||
return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr);
|
return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr, convert(mp.getBasePair(), tphs));
|
||||||
}
|
}
|
||||||
}else if(tr instanceof RefType){
|
}else if(tr instanceof RefType){
|
||||||
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (RefType) tr);
|
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (RefType) tr);
|
||||||
@@ -227,7 +229,7 @@ public class UnifyTypeFactory {
|
|||||||
}else if(tr instanceof GenericRefType){
|
}else if(tr instanceof GenericRefType){
|
||||||
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (GenericRefType) tr);
|
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (GenericRefType) tr);
|
||||||
}else throw new NotImplementedException();
|
}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) {
|
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {
|
||||||
|
|||||||
@@ -24,13 +24,9 @@ public class MethodCall extends Statement
|
|||||||
|
|
||||||
public final ArgumentList arglist;
|
public final ArgumentList arglist;
|
||||||
|
|
||||||
/*
|
|
||||||
* noetig fuer Bytecodegenerierung
|
|
||||||
*/
|
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
public RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
||||||
public final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes;
|
public final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes;
|
||||||
|
|
||||||
|
|
||||||
public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList,
|
public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList,
|
||||||
RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
|
RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
|
||||||
super(retType,offset);
|
super(retType,offset);
|
||||||
@@ -40,6 +36,7 @@ public class MethodCall extends Statement
|
|||||||
this.receiverType = receiverType;
|
this.receiverType = receiverType;
|
||||||
this.argTypes = argTypes;
|
this.argTypes = argTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(StatementVisitor visitor) {
|
public void accept(StatementVisitor visitor) {
|
||||||
|
|||||||
@@ -6,11 +6,20 @@ import org.antlr.v4.runtime.Token;
|
|||||||
|
|
||||||
public abstract class Statement extends Expression
|
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)
|
public Statement(RefTypeOrTPHOrWildcardOrGeneric type, Token offset)
|
||||||
{
|
{
|
||||||
super(type, offset);
|
super(type, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStatement() {
|
||||||
|
isStatement=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getStatement() {
|
||||||
|
return isStatement;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,8 @@ import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
|||||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||||
{
|
{
|
||||||
private String name;
|
private String name;
|
||||||
@@ -33,10 +35,25 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
|||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since Studienarbeit Type Erasure
|
||||||
|
* @author etiennezink
|
||||||
|
*
|
||||||
|
* @param o
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
// TODO Auto-generated method stub
|
if((! (o instanceof GenericRefType))) return false;
|
||||||
return false;
|
GenericRefType genericRefType = (GenericRefType) o;
|
||||||
|
return getParsedName().equals(genericRefType.getParsedName()) &&
|
||||||
|
Objects.equals(getOffset(), genericRefType.getOffset());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "GTV " + this.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package de.dhbwstuttgart.target.generate;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
|
import de.dhbwstuttgart.target.tree.*;
|
||||||
|
import de.dhbwstuttgart.target.tree.expression.TargetBlock;
|
||||||
|
import de.dhbwstuttgart.target.tree.type.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class ASTToTargetAST {
|
||||||
|
|
||||||
|
public TargetClass convert(ClassOrInterface input, Map<TypePlaceholder, TargetType> sigma){
|
||||||
|
List<TargetConstructor> targetConstructors = new ArrayList<>();
|
||||||
|
//TODO constructor conversion -> also reduce syntactic sugar
|
||||||
|
return new TargetClass(input.getModifiers(),input.getClassName().toString(), null,
|
||||||
|
sigma.get(input.getSuperClass()),
|
||||||
|
input.getSuperInterfaces().stream().map(it -> sigma.get(it)).collect(Collectors.toList()),
|
||||||
|
targetConstructors,
|
||||||
|
input.getFieldDecl().stream().map(it -> convert(it, sigma)).collect(Collectors.toList()),
|
||||||
|
input.getMethods().stream().map(it -> convert(it, sigma)).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private TargetMethod convert(Method input, Map<TypePlaceholder, TargetType> sigma) {
|
||||||
|
List<MethodParameter> params = input.getParameterList().getFormalparalist().stream()
|
||||||
|
.map(param -> new MethodParameter(convert(param.getType(), sigma), param.getName())).collect(Collectors.toList());
|
||||||
|
return new TargetMethod(input.name, params, convert(input.block));
|
||||||
|
}
|
||||||
|
|
||||||
|
private TargetBlock convert(Block block) {
|
||||||
|
return new TargetBlock(block.statements.stream().map(e -> {
|
||||||
|
StatementToTargetExpression converter = new StatementToTargetExpression();
|
||||||
|
e.accept(converter);
|
||||||
|
return converter.result;
|
||||||
|
}).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private TargetField convert(Field input, Map<TypePlaceholder, TargetType> sigma) {
|
||||||
|
return new TargetField(convert(input.getType(), sigma), input.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input, Map<TypePlaceholder, TargetType> sigma) {
|
||||||
|
return input.acceptTV(new TypeVisitor<>() {
|
||||||
|
@Override
|
||||||
|
public TargetType visit(RefType refType) {
|
||||||
|
return new TargetRefType(refType.getName().toString(),
|
||||||
|
refType.getParaList().stream().map((it) -> convert(it, sigma)).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetType visit(SuperWildcardType superWildcardType) {
|
||||||
|
return new TargetSuperWildcard(convert(superWildcardType.getInnerType(), sigma));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetType visit(TypePlaceholder typePlaceholder) {
|
||||||
|
return sigma.get(typePlaceholder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetType visit(ExtendsWildcardType extendsWildcardType) {
|
||||||
|
return new TargetExtendsWildcard(convert(extendsWildcardType.getInnerType(), sigma));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetType visit(GenericRefType genericRefType) {
|
||||||
|
return new TargetGenericType(genericRefType.getParsedName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
package de.dhbwstuttgart.target.generate;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
|
import de.dhbwstuttgart.target.tree.expression.TargetExpression;
|
||||||
|
|
||||||
|
public class StatementToTargetExpression implements StatementVisitor {
|
||||||
|
public TargetExpression result;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(ArgumentList argumentList) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(LambdaExpression lambdaExpression) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Assign assign) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(BinaryExpr binary) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Block block) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(CastExpr castExpr) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(EmptyStmt emptyStmt) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(FieldVar fieldVar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(ForStmt forStmt) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(IfStmt ifStmt) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(InstanceOf instanceOf) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(LocalVar localVar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(LocalVarDecl localVarDecl) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(MethodCall methodCall) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(NewClass methodCall) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(NewArray newArray) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Return aReturn) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(ReturnVoid aReturn) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(StaticClassName staticClassName) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Super aSuper) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(This aThis) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(WhileStmt whileStmt) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(DoStmt whileStmt) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(AssignToField assignLeftSide) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(AssignToLocal assignLeftSide) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(SuperCall superCall) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(ExpressionReceiver expressionReceiver) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(UnaryExpr unaryExpr) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Literal literal) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
|
|
||||||
|
public record GenericDeclaration(GenericRefType generic, TargetType bound) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
|
|
||||||
|
public record MethodParameter(TargetType type, String name) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.target.tree.type.TargetRefType;
|
||||||
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record TargetClass(int modifiers, String qualifiedName, List<GenericDeclaration> generics, TargetType superType,
|
||||||
|
List<TargetType> implementingInterfaces,
|
||||||
|
List<TargetConstructor> constructors, List<TargetField> fields, List<TargetMethod> methods) {}
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.target.tree.expression.TargetBlock;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record TargetConstructor(List<MethodParameter> parameterTypes, TargetBlock block) {
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
|
|
||||||
|
public record TargetField(TargetType type, String name) {
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.target.tree.expression.TargetBlock;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record TargetMethod(String name, List<MethodParameter> parameterTypes, TargetBlock block) {
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.expression;
|
||||||
|
|
||||||
|
public record TargetAssign(TargetExpression leftSide, TargetExpression rightSide) implements TargetExpression {
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.expression;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record TargetBlock(List<TargetExpression> statememts) implements TargetExpression {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.expression;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.target.tree.type.*;
|
||||||
|
|
||||||
|
public sealed interface TargetExpression
|
||||||
|
permits TargetBlock, TargetLambdaExpression, TargetReturn, TargetThis, TargetSuper, TargetNew, TargetAssign {
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.expression;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.target.tree.MethodParameter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record TargetLambdaExpression(List<MethodParameter> params, TargetExpression block) implements TargetExpression {
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.expression;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record TargetNew(TargetType instantiatedType, List<TargetExpression> params) implements TargetExpression {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.expression;
|
||||||
|
|
||||||
|
public record TargetReturn(TargetExpression expression) implements TargetExpression {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.expression;
|
||||||
|
|
||||||
|
public record TargetSuper() implements TargetExpression {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.expression;
|
||||||
|
|
||||||
|
public record TargetThis() implements TargetExpression {
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.type;
|
||||||
|
|
||||||
|
public record TargetExtendsWildcard(TargetType innerType) implements TargetType{
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.type;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record TargetFunNType(int N, List<TargetRefType> params) implements TargetType {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.type;
|
||||||
|
|
||||||
|
public record TargetGenericType(String name) implements TargetType {
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.type;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record TargetRefType(String name, List<TargetType> params) implements TargetType {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.type;
|
||||||
|
|
||||||
|
public record TargetSuperWildcard(TargetType innerType) implements TargetType {
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.type;
|
||||||
|
|
||||||
|
public sealed interface TargetType
|
||||||
|
permits TargetExtendsWildcard, TargetFunNType, TargetGenericType, TargetRefType, TargetSuperWildcard {
|
||||||
|
}
|
||||||
@@ -9,6 +9,12 @@ import java.util.Set;
|
|||||||
public class Constraint<A> extends HashSet<A> {
|
public class Constraint<A> extends HashSet<A> {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt
|
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;
|
private Constraint<A> extendConstraint = null;
|
||||||
|
|
||||||
public Constraint() {
|
public Constraint() {
|
||||||
@@ -41,7 +47,7 @@ public class Constraint<A> extends HashSet<A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString() + " isInherited = " + isInherited
|
return super.toString() + "\nisInherited = " + isInherited + "\nisStatement = " + isStatement
|
||||||
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
|
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
|
||||||
+ "\n" ;
|
+ "\n" ;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 class PairTPHsmallerTPH extends ResultPair{
|
||||||
public final TypePlaceholder left;
|
public final TypePlaceholder left;
|
||||||
public final TypePlaceholder right;
|
public final TypePlaceholder right;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* urspruengliches Paar aus diesem dieses Resultpair erzeugt wurde
|
||||||
|
* wichtig fuer generated Generics
|
||||||
|
*/
|
||||||
|
ResultPair origPair;
|
||||||
|
|
||||||
public PairTPHsmallerTPH(TypePlaceholder left, TypePlaceholder right){
|
public PairTPHsmallerTPH(TypePlaceholder left, TypePlaceholder right){
|
||||||
super(left, right);
|
super(left, right);
|
||||||
@@ -16,6 +22,11 @@ public class PairTPHsmallerTPH extends ResultPair{
|
|||||||
this.right = right;
|
this.right = right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PairTPHsmallerTPH(TypePlaceholder left, TypePlaceholder right, ResultPair origPair){
|
||||||
|
this(left, right);
|
||||||
|
this.origPair = origPair;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ResultPairVisitor visitor) {
|
public void accept(ResultPairVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
|
|||||||
@@ -4,4 +4,7 @@ public interface ResultPairVisitor {
|
|||||||
void visit(PairTPHsmallerTPH p);
|
void visit(PairTPHsmallerTPH p);
|
||||||
void visit(PairTPHequalRefTypeOrWildcardType p);
|
void visit(PairTPHequalRefTypeOrWildcardType p);
|
||||||
void visit(PairTPHEqualTPH p);
|
void visit(PairTPHEqualTPH p);
|
||||||
|
|
||||||
|
//bisher nicht umgesetzt
|
||||||
|
//void visit(PairNoResult p);
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
|||||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.FunNClass;
|
import de.dhbwstuttgart.typeinference.assumptions.FunNClass;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
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)
|
? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT)
|
||||||
: x)
|
: x)
|
||||||
.collect(Collectors.toCollection(() -> new Constraint<Pair>(oneMethodConstraint.isInherited())));
|
.collect(Collectors.toCollection(() -> new Constraint<Pair>(oneMethodConstraint.isInherited())));
|
||||||
|
extendsOneMethodConstraint.isStatement = oneMethodConstraint.isStatement;
|
||||||
oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint);
|
oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint);
|
||||||
extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint);
|
extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint);
|
||||||
methodConstraints.add(extendsOneMethodConstraint);
|
methodConstraints.add(extendsOneMethodConstraint);
|
||||||
@@ -594,9 +596,11 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
//methodConstraint.add(new Pair(forMethod.receiverType, retType,
|
//methodConstraint.add(new Pair(forMethod.receiverType, retType,
|
||||||
// PairOperator.EQUALSDOT));
|
// PairOperator.EQUALSDOT));
|
||||||
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
||||||
|
|
||||||
|
|
||||||
|
methodConstraint.isStatement = forMethod.getStatement();
|
||||||
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
|
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
|
||||||
PairOperator.EQUALSDOT));
|
PairOperator.EQUALSDOT));
|
||||||
methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));
|
methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));
|
||||||
return methodConstraint;
|
return methodConstraint;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,6 +269,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
System.err.println("no log-File");
|
System.err.println("no log-File");
|
||||||
}
|
}
|
||||||
if (isUndefinedPairSetSet(res)) {
|
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<>();
|
throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -2181,6 +2184,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
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;
|
boolean allGen = thetaPrime.getTypeParams().size() > 0;
|
||||||
for(UnifyType t : thetaPrime.getTypeParams())
|
for(UnifyType t : thetaPrime.getTypeParams())
|
||||||
if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) {
|
if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) {
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import general.TestCleanUp;
|
||||||
|
import org.junit.*;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for the file {@code OLFun2.jav}.
|
||||||
|
* Tests if the expected overloading for the method {@code m} exists.
|
||||||
|
*
|
||||||
|
* @since Studienarbeit Type Erasure
|
||||||
|
* @author etiennezink
|
||||||
|
*/
|
||||||
|
public class OLFun2Test {
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static Class<?> classFun1IntInt;
|
||||||
|
private static Class<?> classFun1IntDouble;
|
||||||
|
private static Class<?> classFun1DoubleDouble;
|
||||||
|
private static Class<?> classFun1DoubleInt;
|
||||||
|
|
||||||
|
private static String generatedByteCodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUp() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/OLFun2.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode(generatedByteCodeDirectory);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)});
|
||||||
|
classToTest = loader.loadClass("OLFun2");
|
||||||
|
classFun1IntInt = loader.loadClass("Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$");
|
||||||
|
classFun1IntDouble = loader.loadClass("Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Double$_$");
|
||||||
|
classFun1DoubleDouble = loader.loadClass("Fun1$$$_$Ljava$lang$Double$_$Ljava$lang$Double$_$");
|
||||||
|
classFun1DoubleInt = loader.loadClass("Fun1$$$_$Ljava$lang$Double$_$Ljava$lang$Integer$_$");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mExistsWithIntegerInteger() throws Exception{
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", classFun1IntInt);
|
||||||
|
assertNotNull(m);
|
||||||
|
assertEquals(Integer.class, m.getReturnType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mExistsWithIntegerDouble() throws Exception{
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", classFun1IntDouble);
|
||||||
|
assertNotNull(m);
|
||||||
|
assertEquals(Double.class, m.getReturnType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mExistsWithDoubleInteger() throws Exception{
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleInt);
|
||||||
|
assertNotNull(m);
|
||||||
|
assertEquals(Integer.class, m.getReturnType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mExistsWithDoubleDouble() throws Exception{
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble);
|
||||||
|
assertNotNull(m);
|
||||||
|
assertEquals(Double.class, m.getReturnType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUp() {
|
||||||
|
TestCleanUp.cleanUpDirectory(new File(generatedByteCodeDirectory), f -> f.getName().contains(".class"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,52 +1,91 @@
|
|||||||
package bytecode;
|
package bytecode;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
import org.junit.Test;
|
import general.TestCleanUp;
|
||||||
|
import org.junit.*;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for the file {@code OLFun.jav}.
|
||||||
|
* Tests if the expected overloading for the method {@code m} exists.
|
||||||
|
*
|
||||||
|
* @since Studienarbeit Type Erasure
|
||||||
|
* @author etiennezink
|
||||||
|
*/
|
||||||
public class OLFunTest {
|
public class OLFunTest {
|
||||||
private static String path;
|
private static String path;
|
||||||
private static File fileToTest;
|
private static File fileToTest;
|
||||||
private static JavaTXCompiler compiler;
|
private static JavaTXCompiler compiler;
|
||||||
private static ClassLoader loader;
|
private static ClassLoader loader;
|
||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static String pathToClassFile;
|
private static Class<?> classFun1IntInt;
|
||||||
private static Object instanceOfClass;
|
private static Class<?> classFun1IntDouble;
|
||||||
|
private static Class<?> classFun1DoubleDouble;
|
||||||
@Test
|
private static Class<?> classFun1DoubleInt;
|
||||||
public void generateBC() throws Exception {
|
private static Class<?> classFun1StringInt;
|
||||||
|
private static Class<?> classFun1StringDouble;
|
||||||
|
|
||||||
|
private static String generatedByteCodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUp() throws Exception {
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/OLFun.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/OLFun.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
compiler.generateBytecode(generatedByteCodeDirectory);
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)});
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
|
||||||
classToTest = loader.loadClass("OLFun");
|
classToTest = loader.loadClass("OLFun");
|
||||||
/*
|
classFun1IntInt = loader.loadClass("Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
classFun1IntDouble = loader.loadClass("Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Double$_$");
|
||||||
|
classFun1DoubleDouble = loader.loadClass("Fun1$$$_$Ljava$lang$Double$_$Ljava$lang$Double$_$");
|
||||||
Method m = classToTest.getDeclaredMethod("m");
|
classFun1DoubleInt = loader.loadClass("Fun1$$$_$Ljava$lang$Double$_$Ljava$lang$Integer$_$");
|
||||||
Class<?> lambda = m.invoke(instanceOfClass).getClass();
|
classFun1StringInt = loader.loadClass("Fun1$$$_$Ljava$lang$String$_$Ljava$lang$Integer$_$");
|
||||||
Method apply = lambda.getMethod("apply", Object.class);
|
classFun1StringDouble = loader.loadClass("Fun1$$$_$Ljava$lang$String$_$Ljava$lang$Double$_$");
|
||||||
|
|
||||||
// Damit man auf die Methode zugreifen kann
|
|
||||||
apply.setAccessible(true);
|
|
||||||
|
|
||||||
Integer i = 77;
|
|
||||||
|
|
||||||
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
|
|
||||||
|
|
||||||
assertEquals(77, result);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mExistsWithIntegerInteger() throws Exception{
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", classFun1IntInt, Integer.class);
|
||||||
|
assertNotNull(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mExistsWithIntegerDouble() throws Exception{
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", classFun1IntDouble, Integer.class);
|
||||||
|
assertNotNull(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mExistsWithDoubleInteger() throws Exception{
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleInt, Double.class);
|
||||||
|
assertNotNull(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mExistsWithDoubleDouble() throws Exception{
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble, Double.class);
|
||||||
|
assertNotNull(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mExistsWithStringInteger() throws Exception{
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", classFun1StringInt, String.class);
|
||||||
|
assertNotNull(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mExistsWithStringDouble() throws Exception{
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", classFun1StringDouble, String.class);
|
||||||
|
assertNotNull(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUp(){
|
||||||
|
TestCleanUp.cleanUpDirectory(new File(generatedByteCodeDirectory), f -> f.getName().contains(".class"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,248 @@
|
|||||||
|
package bytecode.funN;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.funN.FunNGenerator;
|
||||||
|
import de.dhbwstuttgart.bytecode.funN.FunNUtilities;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.objectweb.asm.Opcodes.*;
|
||||||
|
|
||||||
|
public class FunNGeneratorTest {
|
||||||
|
|
||||||
|
static FunNUtilities funNGenerator;
|
||||||
|
static RefType voidType;
|
||||||
|
static RefType integerType;
|
||||||
|
static GenericRefType genericT;
|
||||||
|
static TypePlaceholder tph;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUp(){
|
||||||
|
|
||||||
|
funNGenerator = FunNGenerator.getInstance();
|
||||||
|
voidType = new RefType(new JavaClassName(Type.getInternalName(Void.class)), null);
|
||||||
|
integerType = new RefType(new JavaClassName(Type.getInternalName(Integer.class)), null);
|
||||||
|
genericT = new GenericRefType("T", null);
|
||||||
|
tph = TypePlaceholder.fresh(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void superClassName_0(){
|
||||||
|
var superClassName = funNGenerator.getSuperClassName(0);
|
||||||
|
assertEquals("Fun0$$", superClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void superClassName_1(){
|
||||||
|
var superClassName = funNGenerator.getSuperClassName(1);
|
||||||
|
assertEquals("Fun1$$", superClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void specializedClassName_VoidVoid(){
|
||||||
|
var specializedClassName = funNGenerator.getSpecializedClassName(Arrays.asList(), voidType);
|
||||||
|
assertEquals("Fun0$$$_$Ljava$lang$Void$_$", specializedClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void specializedClassName_VoidInt(){
|
||||||
|
var specializedClassName = funNGenerator.getSpecializedClassName(Arrays.asList(), integerType);
|
||||||
|
assertEquals("Fun0$$$_$Ljava$lang$Integer$_$", specializedClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void specializedClassName_IntInt(){
|
||||||
|
var specializedClassName = funNGenerator.getSpecializedClassName(Arrays.asList(integerType), integerType);
|
||||||
|
assertEquals("Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$", specializedClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void specializedClassName_IntT(){
|
||||||
|
var specializedClassName = funNGenerator.getSpecializedClassName(Arrays.asList(integerType), genericT);
|
||||||
|
assertEquals("Fun1$$$_$Ljava$lang$Integer$_$LT$_$", specializedClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void specializedClassName_IntTPH(){
|
||||||
|
var specializedClassName = funNGenerator.getSpecializedClassName(Arrays.asList(integerType), TypePlaceholder.fresh(null));
|
||||||
|
assertEquals("Fun1$$$_$Ljava$lang$Integer$_$LTPH$_$", specializedClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void signature_IntInt(){
|
||||||
|
var classSignature = funNGenerator.getSpecializedSignature(Arrays.asList(integerType), integerType);
|
||||||
|
assertEquals("LFun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$;", classSignature);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void signature_IntT(){
|
||||||
|
var classSignature = funNGenerator.getSpecializedSignature(Arrays.asList(integerType), genericT);
|
||||||
|
assertEquals("LFun1$$$_$Ljava$lang$Integer$_$LT$_$<TT;>;", classSignature);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void signature_TPHTPH(){
|
||||||
|
var classSignature = funNGenerator.getSpecializedSignature(Arrays.asList(tph), tph);
|
||||||
|
assertEquals(String.format("LFun1$$$_$LTPH$_$LTPH$_$<T%s$;T%s$;>;",tph.getName(), tph.getName()), classSignature);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void descriptor_IntInt(){
|
||||||
|
var classDescriptor = funNGenerator.getSpecializedDescriptor(Arrays.asList(integerType), integerType);
|
||||||
|
//does not have to contain L and ; because TypeToDescriptor returns the descriptor without these characters as well
|
||||||
|
assertEquals("Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$", classDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void descriptor_IntT(){
|
||||||
|
var classDescriptor = funNGenerator.getSpecializedDescriptor(Arrays.asList(integerType), genericT);
|
||||||
|
//does not have to contain L and ; because TypeToDescriptor returns the descriptor without these characters as well
|
||||||
|
assertEquals("Fun1$$$_$Ljava$lang$Integer$_$LT$_$", classDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void descriptor_TPHTPH(){
|
||||||
|
var classDescriptor = funNGenerator.getSpecializedDescriptor(Arrays.asList(tph), tph);
|
||||||
|
//does not have to contain L and ; because TypeToDescriptor returns the descriptor without these characters as well
|
||||||
|
assertEquals("Fun1$$$_$LTPH$_$LTPH$_$", classDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getArguments_Empty(){
|
||||||
|
var arguments = funNGenerator.getArguments(Arrays.asList());
|
||||||
|
assertTrue(arguments.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getArguments_Int(){
|
||||||
|
var arguments = funNGenerator.getArguments(Arrays.asList(integerType));
|
||||||
|
assertTrue(arguments.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getArguments_IntT(){
|
||||||
|
var arguments = funNGenerator.getArguments(Arrays.asList(integerType, genericT));
|
||||||
|
assertTrue(arguments.size() == 1);
|
||||||
|
assertTrue(arguments.contains(integerType));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getArguments_IntTInt(){
|
||||||
|
var arguments = funNGenerator.getArguments(Arrays.asList(integerType, genericT, integerType));
|
||||||
|
assertTrue(arguments.size() == 2);
|
||||||
|
assertTrue(arguments.contains(integerType));
|
||||||
|
assertTrue(arguments.contains(genericT));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getReturnType_Empty(){
|
||||||
|
var returnType = funNGenerator.getReturnType(Arrays.asList());
|
||||||
|
assertNull(returnType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getReturnType_Int(){
|
||||||
|
var returnType = funNGenerator.getReturnType(Arrays.asList(integerType));
|
||||||
|
assertEquals(integerType, returnType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getReturnType_IntT(){
|
||||||
|
var returnType = funNGenerator.getReturnType(Arrays.asList(integerType, genericT));
|
||||||
|
assertEquals(genericT, returnType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void superBytecode_0(){
|
||||||
|
var superBytecode = funNGenerator.generateSuperBytecode(0);
|
||||||
|
assertArrayEquals(superBytecodeReference_0(), superBytecode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void superBytecode_1(){
|
||||||
|
var superBytecode = funNGenerator.generateSuperBytecode(1);
|
||||||
|
assertArrayEquals(superBytecodeReference_1(), superBytecode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void superBytecode_2(){
|
||||||
|
var superBytecode = funNGenerator.generateSuperBytecode(2);
|
||||||
|
assertArrayEquals(superBytecodeReference_2(), superBytecode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void specializedBytecode_VoidInt(){
|
||||||
|
var specializedBytecode = funNGenerator.generateSpecializedBytecode(Arrays.asList(), integerType);
|
||||||
|
assertArrayEquals(specializedBytecodeReference_VoidInt(), specializedBytecode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void specializedBytecode_IntInt(){
|
||||||
|
var specializedBytecode = funNGenerator.generateSpecializedBytecode(Arrays.asList(integerType), integerType);
|
||||||
|
assertArrayEquals(specializedBytecodeReference_IntInt(), specializedBytecode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void specializedBytecode_TIntInt(){
|
||||||
|
var specializedBytecode = funNGenerator.generateSpecializedBytecode(Arrays.asList(genericT, integerType), integerType);
|
||||||
|
assertArrayEquals(specializedBytecodeReference_TIntInt(), specializedBytecode);
|
||||||
|
}
|
||||||
|
|
||||||
|
//super bytecode reference methods
|
||||||
|
private static byte[] superBytecodeReference_0() {
|
||||||
|
var classWriter = new ClassWriter(0);
|
||||||
|
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun0$$", "<R:Ljava/lang/Object;>Ljava/lang/Object;", "java/lang/Object", null);
|
||||||
|
var methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, "apply", "()Ljava/lang/Object;", "()TR;", null);
|
||||||
|
methodVisitor.visitEnd();
|
||||||
|
classWriter.visitEnd();
|
||||||
|
return classWriter.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] superBytecodeReference_1() {
|
||||||
|
var classWriter = new ClassWriter(0);
|
||||||
|
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun1$$", "<T1:Ljava/lang/Object;R:Ljava/lang/Object;>Ljava/lang/Object;", "java/lang/Object", null);
|
||||||
|
var methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, "apply", "(Ljava/lang/Object;)Ljava/lang/Object;", "(TT1;)TR;", null);
|
||||||
|
methodVisitor.visitEnd();
|
||||||
|
classWriter.visitEnd();
|
||||||
|
return classWriter.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] superBytecodeReference_2() {
|
||||||
|
ClassWriter classWriter = new ClassWriter(0);
|
||||||
|
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun2$$", "<T1:Ljava/lang/Object;T2:Ljava/lang/Object;R:Ljava/lang/Object;>Ljava/lang/Object;", "java/lang/Object", null);
|
||||||
|
var methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, "apply", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", "(TT1;TT2;)TR;", null);
|
||||||
|
methodVisitor.visitEnd();
|
||||||
|
classWriter.visitEnd();
|
||||||
|
return classWriter.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
//specialized bytecode reference methods
|
||||||
|
private static byte[] specializedBytecodeReference_VoidInt() {
|
||||||
|
ClassWriter classWriter = new ClassWriter(0);
|
||||||
|
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun0$$$_$Ljava$lang$Integer$_$", "Ljava/lang/Object;LFun0$$<Ljava/lang/Integer;>;", "java/lang/Object", new String[]{"Fun0$$"});
|
||||||
|
classWriter.visitEnd();
|
||||||
|
return classWriter.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] specializedBytecodeReference_IntInt() {
|
||||||
|
ClassWriter classWriter = new ClassWriter(0);
|
||||||
|
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$", "Ljava/lang/Object;LFun1$$<Ljava/lang/Integer;Ljava/lang/Integer;>;", "java/lang/Object", new String[]{"Fun1$$"});
|
||||||
|
classWriter.visitEnd();
|
||||||
|
return classWriter.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] specializedBytecodeReference_TIntInt() {
|
||||||
|
ClassWriter classWriter = new ClassWriter(0);
|
||||||
|
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun2$$$_$LT$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$", "<T:Ljava/lang/Object;>Ljava/lang/Object;LFun2$$<TT;Ljava/lang/Integer;Ljava/lang/Integer;>;", "java/lang/Object", new String[]{"Fun2$$"});
|
||||||
|
classWriter.visitEnd();
|
||||||
|
return classWriter.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package general;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
|
|
||||||
|
public class TestCleanUp {
|
||||||
|
|
||||||
|
public static void cleanUpDirectory(File directory, FileFilter fileFilter){
|
||||||
|
if(!directory.isDirectory()) throw new RuntimeException("Directory for bytecode generation is wrong!");
|
||||||
|
for (File file: directory.listFiles(fileFilter)) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -32,6 +34,11 @@ public class TestAny {
|
|||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
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
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"TestAny.jav"));
|
execute(new File(rootDirectory+"TestAny.jav"));
|
||||||
@@ -54,12 +61,12 @@ public class TestAny {
|
|||||||
classConstraintsTest.add(new ClassConstraint("N", "U", Relation.EXTENDS));
|
classConstraintsTest.add(new ClassConstraint("N", "U", Relation.EXTENDS));
|
||||||
classConstraintsTest.add(new ClassConstraint("U", "O", Relation.EXTENDS));
|
classConstraintsTest.add(new ClassConstraint("U", "O", Relation.EXTENDS));
|
||||||
classConstraintsTest.add(new ClassConstraint("O", "java/lang/Object", Relation.EXTENDS));
|
classConstraintsTest.add(new ClassConstraint("O", "java/lang/Object", Relation.EXTENDS));
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||||
List<MethodConstraint> lmc;
|
Set<MethodConstraint> lmc;
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH RanyMethod()", lmc);
|
methodConstraintsWithPositionTest.put("TPH RanyMethod()", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
methodConstraintsWithPositionTest.put("TPH UotherMethod(TPH U)", lmc);
|
methodConstraintsWithPositionTest.put("TPH UotherMethod(TPH U)", lmc);
|
||||||
|
|
||||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||||
@@ -67,8 +74,11 @@ public class TestAny {
|
|||||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||||
|
|
||||||
assertEquals(expectedClassCons, computedClassCons);
|
assertEquals(expectedClassCons, computedClassCons);
|
||||||
|
|
||||||
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||||
|
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||||
|
|
||||||
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
|
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||||
|
|
||||||
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
|
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
|
||||||
for(File f : compiler.sourceFiles.keySet()){
|
for(File f : compiler.sourceFiles.keySet()){
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -24,6 +26,11 @@ public class TestClassField {
|
|||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
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
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"TestClassField.jav"));
|
execute(new File(rootDirectory+"TestClassField.jav"));
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -39,7 +41,12 @@ public class TestGGFinder {
|
|||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
private static String className = "TestGGFinder";
|
private static String className = "TestGGFinder";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void resetNamesOfTypePlaceholder() {
|
||||||
|
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
execute(new File(rootDirectory+className+".jav"));
|
execute(new File(rootDirectory+className+".jav"));
|
||||||
@@ -56,16 +63,16 @@ public class TestGGFinder {
|
|||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||||
classConstraintsTest.add(new ClassConstraint("S", "java/lang/Object", Relation.EXTENDS));
|
classConstraintsTest.add(new ClassConstraint("S", "java/lang/Object", Relation.EXTENDS));
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||||
List<MethodConstraint> lmc;
|
Set<MethodConstraint> lmc;
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AC", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AC", "java/lang/Object", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH ACid(TPH P)", lmc);
|
methodConstraintsWithPositionTest.put("TPH ACid(TPH P)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("T", "S", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("T", "S", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH SsetA(TPH T)", lmc);
|
methodConstraintsWithPositionTest.put("TPH SsetA(TPH T)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("AC", "Y", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AC", "Y", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS));
|
||||||
@@ -78,7 +85,10 @@ public class TestGGFinder {
|
|||||||
|
|
||||||
assertEquals(expectedClassCons, computedClassCons);
|
assertEquals(expectedClassCons, computedClassCons);
|
||||||
|
|
||||||
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
|
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);
|
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -39,7 +41,12 @@ public class TestLocalVarLambda {
|
|||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
private static String className = "TestLocalVarLambda";
|
private static String className = "TestLocalVarLambda";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void resetNamesOfTypePlaceholder() {
|
||||||
|
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
execute(new File(rootDirectory+className+".jav"));
|
execute(new File(rootDirectory+className+".jav"));
|
||||||
@@ -55,31 +62,46 @@ public class TestLocalVarLambda {
|
|||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||||
|
|
||||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||||
|
|
||||||
List<MethodConstraint> lmc;
|
Set<MethodConstraint> lmc;
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
|
|
||||||
if (fogg.allConstraints.contains((new MethodConstraint("O", "ALU", Relation.EXTENDS)))) {
|
if (fogg.allConstraints.contains((new MethodConstraint("O", "ALU", Relation.EXTENDS)))) {
|
||||||
lmc.add(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("DIU", "java/lang/Object", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("ALU", "DIU", 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 {
|
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("O", "DIU", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("DIU", "N", 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);
|
||||||
}
|
}
|
||||||
methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc);
|
|
||||||
|
|
||||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||||
|
|
||||||
assertEquals(expectedClassCons, computedClassCons);
|
assertEquals(expectedClassCons, computedClassCons);
|
||||||
|
|
||||||
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
|
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);
|
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -39,7 +41,12 @@ public class TestMutualRecursion {
|
|||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
private static String className;
|
private static String className;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void resetNamesOfTypePlaceholder() {
|
||||||
|
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestMutualRecursion1() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
public void TestMutualRecursion1() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
className = "TestMutualRecursion";
|
className = "TestMutualRecursion";
|
||||||
@@ -49,18 +56,19 @@ public class TestMutualRecursion {
|
|||||||
|
|
||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
||||||
List<MethodConstraint> lmc;
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||||
lmc = new ArrayList<>();
|
Set<MethodConstraint> lmc;
|
||||||
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("P", "Q", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("P", "Q", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc);
|
methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("Z", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("Z", "java/lang/Object", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH ALm(TPH ALTPH Z)", lmc);
|
methodConstraintsWithPositionTest.put("TPH ALm(TPH ALTPH Z)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AH", "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));
|
lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS));
|
||||||
@@ -71,8 +79,11 @@ public class TestMutualRecursion {
|
|||||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||||
|
|
||||||
assertEquals(expectedClassCons, computedClassCons);
|
assertEquals(expectedClassCons, computedClassCons);
|
||||||
|
|
||||||
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||||
|
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||||
|
|
||||||
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
|
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||||
|
|
||||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -24,6 +26,11 @@ public class TestReturnVar {
|
|||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
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
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"TestReturnVar.jav"));
|
execute(new File(rootDirectory+"TestReturnVar.jav"));
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -24,6 +26,11 @@ public class TestSecondLineOfClassConstraints {
|
|||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
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
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"TestSecondLineOfClassConstraints.jav"));
|
execute(new File(rootDirectory+"TestSecondLineOfClassConstraints.jav"));
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
import org.junit.Test;
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@@ -40,7 +42,12 @@ public class TestTPHsAndGenerics {
|
|||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
private static String className = "TestTPHsAndGenerics";
|
private static String className = "TestTPHsAndGenerics";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void resetNamesOfTypePlaceholder() {
|
||||||
|
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
execute(new File(rootDirectory+className+".jav"));
|
execute(new File(rootDirectory+className+".jav"));
|
||||||
@@ -56,12 +63,12 @@ public class TestTPHsAndGenerics {
|
|||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||||
|
|
||||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||||
|
|
||||||
List<MethodConstraint> lmc;
|
Set<MethodConstraint> lmc;
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
|
|
||||||
if (fogg.allConstraints.contains((new MethodConstraint("DZP", "ETW", Relation.EXTENDS)))) {
|
if (fogg.allConstraints.contains((new MethodConstraint("DZP", "ETW", Relation.EXTENDS)))) {
|
||||||
classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS));
|
classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS));
|
||||||
@@ -70,42 +77,70 @@ public class TestTPHsAndGenerics {
|
|||||||
|
|
||||||
lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS));
|
//lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
|
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc);
|
methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS));
|
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);
|
methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc);
|
||||||
}
|
} else {
|
||||||
else {
|
if (fogg.allConstraints.contains((new MethodConstraint("DZP", "U", Relation.EXTENDS)))) {
|
||||||
classConstraintsTest.add(new ClassConstraint("ETW", "DZP", Relation.EXTENDS));
|
classConstraintsTest.add(new ClassConstraint("ETW", "DZP", Relation.EXTENDS));
|
||||||
classConstraintsTest.add(new ClassConstraint("DZP", "U", Relation.EXTENDS));
|
classConstraintsTest.add(new ClassConstraint("DZP", "U", Relation.EXTENDS));
|
||||||
classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS));
|
classConstraintsTest.add(new ClassConstraint("U", "java/lang/Object", Relation.EXTENDS));
|
||||||
|
|
||||||
lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS));
|
//lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
|
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc);
|
methodConstraintsWithPositionTest.put("TPH Uid2(TPH V)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS));
|
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);
|
methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||||
|
|
||||||
assertEquals(expectedClassCons, computedClassCons);
|
assertEquals(expectedClassCons, computedClassCons);
|
||||||
|
|
||||||
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
|
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);
|
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -24,6 +26,11 @@ public class TestTPHsAndGenerics2 {
|
|||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
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
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"TestTPHSAndGenerics2.jav"));
|
execute(new File(rootDirectory+"TestTPHSAndGenerics2.jav"));
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,8 +21,8 @@ public class TestTransitiveClosure {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void genericTest() {
|
public void genericTest() {
|
||||||
List<TPHConstraint> testCons = FamilyOfGeneratedGenerics.buildTransitiveClosure(fillList());
|
//List<TPHConstraint> testCons = FamilyOfGeneratedGenerics.buildTransitiveClosure(fillList());
|
||||||
System.out.println(testCons);
|
//System.out.println(testCons);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -40,7 +42,12 @@ public class TestTwoArgs {
|
|||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
private static String className = "TestTwoArgs";
|
private static String className = "TestTwoArgs";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void resetNamesOfTypePlaceholder() {
|
||||||
|
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
execute(new File(rootDirectory+className+".jav"));
|
execute(new File(rootDirectory+className+".jav"));
|
||||||
@@ -61,32 +68,39 @@ public class TestTwoArgs {
|
|||||||
classConstraintsTest.add(new ClassConstraint("P", "AL", Relation.EXTENDS));
|
classConstraintsTest.add(new ClassConstraint("P", "AL", Relation.EXTENDS));
|
||||||
classConstraintsTest.add(new ClassConstraint("AL", "AF", Relation.EXTENDS));
|
classConstraintsTest.add(new ClassConstraint("AL", "AF", Relation.EXTENDS));
|
||||||
classConstraintsTest.add(new ClassConstraint("AF", "java/lang/Object", Relation.EXTENDS));
|
classConstraintsTest.add(new ClassConstraint("AF", "java/lang/Object", Relation.EXTENDS));
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||||
List<MethodConstraint> lmc;
|
Set<MethodConstraint> lmc;
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS));
|
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);
|
methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("P", "AL", 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);
|
methodConstraintsWithPositionTest.put("TPH AFm(TPH AFTPH Z)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH APsetA(TPH T)", lmc);
|
methodConstraintsWithPositionTest.put("TPH APsetA(TPH T)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("AG", "P", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AG", "P", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AH", "T", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AH", "T", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("T", "AP", 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);
|
methodConstraintsWithPositionTest.put("TPH AFmain(TPH AGTPH AH)", lmc);
|
||||||
|
|
||||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||||
|
|
||||||
assertEquals(expectedClassCons, computedClassCons);
|
assertEquals(expectedClassCons, computedClassCons);
|
||||||
|
|
||||||
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||||
|
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||||
|
|
||||||
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
|
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||||
|
|
||||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -39,7 +41,12 @@ public class TestTwoArgs2 {
|
|||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
private static String className = "TestTwoArgs2";
|
private static String className = "TestTwoArgs2";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void resetNamesOfTypePlaceholder() {
|
||||||
|
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
execute(new File(rootDirectory+className+".jav"));
|
execute(new File(rootDirectory+className+".jav"));
|
||||||
@@ -56,15 +63,15 @@ public class TestTwoArgs2 {
|
|||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||||
classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||||
List<MethodConstraint> lmc;
|
Set<MethodConstraint> lmc;
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("U", "P", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("U", "P", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AA", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AA", "java/lang/Object", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH AAm(TPH AATPH U)", lmc);
|
methodConstraintsWithPositionTest.put("TPH AAm(TPH AATPH U)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("AB", "P", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AB", "P", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AC", "U", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AC", "U", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AB", "AA", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AB", "AA", Relation.EXTENDS));
|
||||||
@@ -73,7 +80,7 @@ public class TestTwoArgs2 {
|
|||||||
lmc.add(new MethodConstraint("U", "AA", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("U", "AA", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH AAmain(TPH ABTPH AC)", lmc);
|
methodConstraintsWithPositionTest.put("TPH AAmain(TPH ABTPH AC)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH AGid(TPH P)", lmc);
|
methodConstraintsWithPositionTest.put("TPH AGid(TPH P)", lmc);
|
||||||
@@ -84,7 +91,10 @@ public class TestTwoArgs2 {
|
|||||||
|
|
||||||
assertEquals(expectedClassCons, computedClassCons);
|
assertEquals(expectedClassCons, computedClassCons);
|
||||||
|
|
||||||
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
|
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);
|
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -39,7 +41,12 @@ public class TestTwoCalls {
|
|||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
private static String className = "TestTwoCalls";
|
private static String className = "TestTwoCalls";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void resetNamesOfTypePlaceholder() {
|
||||||
|
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
execute(new File(rootDirectory+className+".jav"));
|
execute(new File(rootDirectory+className+".jav"));
|
||||||
@@ -55,16 +62,17 @@ public class TestTwoCalls {
|
|||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||||
List<MethodConstraint> lmc;
|
Set<MethodConstraint> lmc;
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH Rid(TPH O)", lmc);
|
methodConstraintsWithPositionTest.put("TPH Rid(TPH O)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("T", "O", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("T", "O", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("R", "java/lang/Object", 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);
|
methodConstraintsWithPositionTest.put("TPH Rmain(TPH STPH T)", lmc);
|
||||||
|
|
||||||
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
FamilyOfGeneratedGenerics fogg = compiler.fogg;
|
||||||
@@ -72,8 +80,12 @@ public class TestTwoCalls {
|
|||||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||||
|
|
||||||
assertEquals(expectedClassCons, computedClassCons);
|
assertEquals(expectedClassCons, computedClassCons);
|
||||||
|
|
||||||
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||||
|
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||||
|
|
||||||
|
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||||
|
|
||||||
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
|
|
||||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass(className);
|
classToTest = loader.loadClass(className);
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -39,7 +41,12 @@ public class TestVector {
|
|||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
private static String className = "TestVector";
|
private static String className = "TestVector";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void resetNamesOfTypePlaceholder() {
|
||||||
|
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
execute(new File(rootDirectory+className+".jav"));
|
execute(new File(rootDirectory+className+".jav"));
|
||||||
@@ -55,14 +62,14 @@ public class TestVector {
|
|||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||||
|
|
||||||
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
|
||||||
HashMap<String, List<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
|
||||||
List<MethodConstraint> lmc;
|
Set<MethodConstraint> lmc;
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("T", "W", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("T", "W", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("W", "ZU", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("W", "ZU", Relation.EXTENDS));
|
||||||
lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc);
|
methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc);
|
||||||
lmc = new ArrayList<>();
|
lmc = new HashSet<>();
|
||||||
lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS));
|
lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS));
|
||||||
methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc);
|
methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc);
|
||||||
|
|
||||||
@@ -70,9 +77,12 @@ public class TestVector {
|
|||||||
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
|
||||||
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
|
||||||
|
|
||||||
assertEquals(expectedClassCons, computedClassCons);
|
assertEquals(expectedClassCons, computedClassCons);
|
||||||
|
|
||||||
|
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
|
||||||
|
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
|
||||||
|
|
||||||
assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition);
|
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
|
||||||
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass(className);
|
classToTest = loader.loadClass(className);
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -24,6 +26,11 @@ public class TestVoidMeth {
|
|||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
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
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"TestVoidMeth.jav"));
|
execute(new File(rootDirectory+"TestVoidMeth.jav"));
|
||||||
|
|||||||
@@ -20,18 +20,17 @@ import org.junit.Test;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GeneralParserTest{
|
public class GeneralParserTest{
|
||||||
private static final String rootDirectory = System.getProperty("user.dir")+"/test/parser/";
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void run(){
|
public void run(){
|
||||||
|
|
||||||
|
|
||||||
List<String> filenames = new ArrayList<String>();
|
List<String> filenames = new ArrayList<String>();
|
||||||
|
|
||||||
|
filenames.add("javFiles/parser/NewTest.jav");
|
||||||
|
//filenames.add("CastTest.jav");
|
||||||
/*
|
/*
|
||||||
filenames.add("NewTest.jav");
|
|
||||||
filenames.add("FieldInitializationTest.jav");
|
filenames.add("FieldInitializationTest.jav");
|
||||||
filenames.add("ImportTest.jav");
|
filenames.add("ImportTest.jav");
|
||||||
filenames.add("CastTest.jav");
|
|
||||||
filenames.add("StatementsTest.jav");
|
filenames.add("StatementsTest.jav");
|
||||||
//filenames.add("Methods.jav");
|
//filenames.add("Methods.jav");
|
||||||
filenames.add("ImportTestGeneric.jav");
|
filenames.add("ImportTestGeneric.jav");
|
||||||
@@ -40,11 +39,14 @@ public class GeneralParserTest{
|
|||||||
//filenames.add("GenericFieldVarTest.jav");
|
//filenames.add("GenericFieldVarTest.jav");
|
||||||
filenames.add("FieldVarTest.jav");
|
filenames.add("FieldVarTest.jav");
|
||||||
filenames.add("StructuralTypes.jav");
|
filenames.add("StructuralTypes.jav");
|
||||||
|
filenames.add("ExtendsTest.jav");
|
||||||
*/
|
*/
|
||||||
// filenames.add("ExtendsTest.jav");
|
|
||||||
filenames.add("PackageNameTest.jav");
|
//filenames.add("PackageNameTest.jav");
|
||||||
try{
|
try{
|
||||||
new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList()));
|
for(String filename : filenames){
|
||||||
|
new JavaTXCompiler(new File(Thread.currentThread().getContextClassLoader().getResource(filename).getPath()));
|
||||||
|
}
|
||||||
}catch(Exception exc){
|
}catch(Exception exc){
|
||||||
exc.printStackTrace();
|
exc.printStackTrace();
|
||||||
fail();
|
fail();
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package targetast;
|
||||||
|
|
||||||
|
public class ASTToTargetTest {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ import java.lang.Integer;
|
|||||||
|
|
||||||
public class Fac {
|
public class Fac {
|
||||||
|
|
||||||
getFac(java.lang.Integer n){
|
getFac(n){
|
||||||
var res = 1;
|
var res = 1;
|
||||||
var i = 1;
|
var i = 1;
|
||||||
while(i<=n) {
|
while(i<=n) {
|
||||||
|
|||||||
@@ -4,14 +4,9 @@ import java.lang.Double;
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.lang.Boolean;
|
import java.lang.Boolean;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class OLFun {
|
public class OLFun {
|
||||||
|
|
||||||
//f = x -> {return x + x;};
|
|
||||||
|
|
||||||
m(f, x) {
|
m(f, x) {
|
||||||
x = f.apply(x+x);
|
var y = f.apply(x + x) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Double;
|
||||||
|
import java.util.Vector;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
|
||||||
|
public class OLFun2 {
|
||||||
|
|
||||||
|
m(f){
|
||||||
|
var x = 1;
|
||||||
|
var y = f.apply(x + x) + 1;
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
public class TestContraVariant {
|
||||||
|
|
||||||
|
m(x) {
|
||||||
|
var y;
|
||||||
|
x = y;
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
main(x) {
|
||||||
|
return m(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
public class TestVectorArg {
|
||||||
|
|
||||||
|
add(v, e) {
|
||||||
|
v.addElement(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
main(v, e) {
|
||||||
|
add(v, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import de.test.Pair;
|
||||||
|
|
||||||
|
class Pairs {
|
||||||
|
setfst(fst) {
|
||||||
|
return new Pair<>(snd, fst);
|
||||||
|
}
|
||||||
|
|
||||||
|
swap () {
|
||||||
|
return new Pair<> (snd, fst); }
|
||||||
|
|
||||||
|
polyrec(p) {
|
||||||
|
return polyrec (p.swap());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package de.test;
|
||||||
|
|
||||||
|
class Pair {
|
||||||
|
fst;
|
||||||
|
snd;
|
||||||
|
|
||||||
|
Pair(fst, snd) {
|
||||||
|
this.fst = fst;
|
||||||
|
this.snd = snd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
class Test{
|
class Test{
|
||||||
method(){
|
method(){
|
||||||
if(true)i++;
|
if(true)i++;
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loaded 100 of 104 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user