Compare commits
82 Commits
bigCleanup
...
inferWildc
Author | SHA1 | Date | |
---|---|---|---|
26ae463e96 | |||
2e1e69df9a | |||
0e8012c132 | |||
68394565b5 | |||
c3b17a8f2f | |||
423cf8b9d2 | |||
87fb9e5a33 | |||
df6debec4f | |||
59177e09ad | |||
a9281a0db2 | |||
fe36b34a80 | |||
d3a18887c3 | |||
14821575bd | |||
c1519783ba | |||
53bbf3c511 | |||
41492e53ca | |||
74b9b024ee | |||
97483714e7 | |||
a7b9c2a4ee | |||
fd7628cb40 | |||
76a291ab41 | |||
c5c8ffeed1 | |||
ba9335e2f6 | |||
c098a0a1b0 | |||
cfce2f55ac | |||
4009a28333 | |||
f3dc0cbeb7 | |||
cd2f030ac6 | |||
f548548788 | |||
5cf41101bf | |||
e139f8c867 | |||
5a151a965c | |||
e5f03369cc | |||
f698c967c0 | |||
1509e21214 | |||
50c05064c7 | |||
6458a06293 | |||
a984e455e4 | |||
19c9f648a8 | |||
077bd62b92 | |||
de62df00e0 | |||
78e3b76dc3 | |||
c627f9de60 | |||
ff92807b83 | |||
1043b3f55f | |||
88440b873a | |||
4ca0e1e5f6 | |||
cb28405fe1 | |||
c7f91724a6 | |||
11b63e0a5d | |||
5f7829191c | |||
044d9a1860 | |||
6fcbca1187 | |||
572f41ffd4 | |||
e0f7f95bed | |||
78c365a7be | |||
bea072689b | |||
81697eee64 | |||
c474abd2bd | |||
6dd02a654b | |||
e5d5376ce9 | |||
0cdeee9e0d | |||
98b3ad1517 | |||
b59aabeea5 | |||
26953665c9 | |||
465f82e967 | |||
ce8b19acae | |||
7dfe546999 | |||
c96c56e882 | |||
3e57a64f9c | |||
e8539a84fd | |||
0551d25fbf | |||
cbe2d7b0f5 | |||
59b45b5f87 | |||
ad7e7ec42b | |||
9d2c85d686 | |||
63b4dbcc10 | |||
ca816fba85 | |||
54a2dbfedc | |||
07c1eeeb36 | |||
69a557f1f2 | |||
88175f8b48 |
.gitignorepom.xml
src
main
antlr4
java
de
dhbwstuttgart
bytecode
core
inferWildcards
ConstraintsGenerationUtils.javaFindInAstVisitor.javaJavaTXCompilerWildcards.javaReplaceTypeparamVisitor.javaTypePlaceholderReplaceUtils.java
parser
SyntaxTreeGenerator
syntaxtree
target
generate
tree
unify2
test
java
bytecode
general
inferWildcards
TestInferWildcardsFields.javaTestInferWildcardsMap.javaTestInferWildcardsMapNested.javaTestInferWildcardsNested.javaTestInferWildcardsParamType.javaTestInferWildcardsSingle.javaTestInferWildcardsSingleLib.java
parser
AntlrTest.javBoundedParameter.javCastTest.javExtendsTest.javFeatherWeightJava.javFieldInitializationTest.javFieldVarTest.javGeneralParserTest.javaGenericFieldVarTest.javImportTest.javImportTest2.javImportTestGeneric.javNewTest.javOpratorTest.javPackageNameTest.javStatementsTest.javStructuralTypes.javWhileTest.jav
targetast
resources
bytecode
javFiles
inferWildcards
.gitignoreTestClassWildcardsFields.javaTestClassWildcardsMap.javaTestClassWildcardsMapNested.javaTestClassWildcardsNested.javaTestClassWildcardsParamType.javaTestClassWildcardsSingle.javaTestClassWildcardsSingleLib.java
javFiles
testBytecode
manually
1
.gitignore
vendored
1
.gitignore
vendored
@ -29,3 +29,4 @@ logFiles/**
|
||||
|
||||
src/main/java/de/dhbwstuttgart/parser/antlr/
|
||||
src/main/java/de/dhbwstuttgart/sat/asp/parser/antlr/
|
||||
/pull.sh
|
||||
|
16
pom.xml
16
pom.xml
@ -118,15 +118,6 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
@ -138,11 +129,8 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<compilerArgs>
|
||||
--enable-preview
|
||||
</compilerArgs>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<tycho.version>0.23.0</tycho.version>
|
||||
<mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass>
|
||||
</properties>
|
||||
|
37
src/main/antlr4/sat/UnifyResult.g4
Normal file
37
src/main/antlr4/sat/UnifyResult.g4
Normal file
@ -0,0 +1,37 @@
|
||||
grammar UnifyResult;
|
||||
|
||||
answer : 'ANSWER' (resultSetRule '.')*;
|
||||
|
||||
resultSetRule :
|
||||
parameter
|
||||
| equals
|
||||
| smaller
|
||||
| typeVar
|
||||
| type
|
||||
| otherRule
|
||||
;
|
||||
|
||||
parameterList : '(' value (',' value)* ')';
|
||||
value : NAME
|
||||
| resultSetRule ;
|
||||
|
||||
parameter : PARAMLIST_NAME parameterList;
|
||||
equals : EQUALS_NAME parameterList;
|
||||
smaller : SMALLER_NAME parameterList;
|
||||
typeVar : TYPEVAR_NAME parameterList;
|
||||
type : TYPE_NAME parameterList;
|
||||
otherRule : NAME parameterList;
|
||||
|
||||
//TODO: Es sollte Regeln für das Result set geben, welche sich nicht mit den anderen überdecken, dann auch nur diese im Result ausgeben
|
||||
PARAMLIST_NAME : 'param';
|
||||
EQUALS_NAME : 'equals';
|
||||
SMALLER_NAME : 'smaller';
|
||||
TYPEVAR_NAME : 'typeVar';
|
||||
TYPE_NAME : 'type';
|
||||
NAME : [a-zA-Z0-9_]+;
|
||||
|
||||
WS : [ \t\r\n\u000C]+ -> skip
|
||||
;
|
||||
LINE_COMMENT
|
||||
: '%' ~[\r\n]* -> skip
|
||||
;
|
23
src/main/antlr4/sat/UnifyResult.tokens
Normal file
23
src/main/antlr4/sat/UnifyResult.tokens
Normal file
@ -0,0 +1,23 @@
|
||||
T__0=1
|
||||
T__1=2
|
||||
T__2=3
|
||||
T__3=4
|
||||
T__4=5
|
||||
PARAMLIST_NAME=6
|
||||
EQUALS_NAME=7
|
||||
SMALLER_NAME=8
|
||||
TYPEVAR_NAME=9
|
||||
TYPE_NAME=10
|
||||
NAME=11
|
||||
WS=12
|
||||
LINE_COMMENT=13
|
||||
'ANSWER'=1
|
||||
'.'=2
|
||||
'('=3
|
||||
','=4
|
||||
')'=5
|
||||
'param'=6
|
||||
'equals'=7
|
||||
'smaller'=8
|
||||
'typeVar'=9
|
||||
'type'=10
|
23
src/main/antlr4/sat/UnifyResultLexer.tokens
Normal file
23
src/main/antlr4/sat/UnifyResultLexer.tokens
Normal file
@ -0,0 +1,23 @@
|
||||
T__0=1
|
||||
T__1=2
|
||||
T__2=3
|
||||
T__3=4
|
||||
T__4=5
|
||||
PARAMLIST_NAME=6
|
||||
EQUALS_NAME=7
|
||||
SMALLER_NAME=8
|
||||
TYPEVAR_NAME=9
|
||||
TYPE_NAME=10
|
||||
NAME=11
|
||||
WS=12
|
||||
LINE_COMMENT=13
|
||||
'ANSWER'=1
|
||||
'.'=2
|
||||
'('=3
|
||||
','=4
|
||||
')'=5
|
||||
'param'=6
|
||||
'equals'=7
|
||||
'smaller'=8
|
||||
'typeVar'=9
|
||||
'type'=10
|
@ -13,10 +13,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
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.environment.DirectoryClassLoader;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
@ -592,21 +589,10 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
this.lamCounter++;
|
||||
|
||||
String typeErasure = createDescriptorWithTypeErasure(lambdaExpression);
|
||||
//ToDo Etienne: Double Check
|
||||
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);
|
||||
String lamDesc = lam.accept(new DescriptorToString(resultSet));
|
||||
// Call site, which, when invoked, returns an instance of the functional
|
||||
@ -828,20 +814,8 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
} else if(!helper.isInCurrPkg(clazz)){
|
||||
if(clazz.contains(CONSTANTS.$$)) {
|
||||
mDesc = helper.getDescriptorOfApplyMethod(methCallType);
|
||||
//ToDo Etienne: Double Check
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = resolver.resolve(methodCall.getType());
|
||||
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);
|
||||
helper.generateBCForFunN(mDesc);
|
||||
// mDesc = helper.generateBCForFunN(methCallType,typesOfParams);
|
||||
}else {
|
||||
try {
|
||||
cLoader2 = new DirectoryClassLoader(path, classLoader);
|
||||
|
@ -153,7 +153,6 @@ public class DescriptorToString implements DescriptorVisitor, CONSTANTS {
|
||||
return desc;
|
||||
}
|
||||
|
||||
//ToDo Etienne: ändern
|
||||
@Override
|
||||
public String visit(Lambda lambdaExpression) {
|
||||
String desc = "(";
|
||||
|
@ -1,24 +1,17 @@
|
||||
package de.dhbwstuttgart.bytecode.descriptor;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.funN.FunNGenerator;
|
||||
import de.dhbwstuttgart.bytecode.funN.FunNUtilities;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
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>{
|
||||
|
||||
private final boolean specializedFunN;
|
||||
|
||||
public TypeToDescriptor(){ this(true); }
|
||||
|
||||
public TypeToDescriptor(boolean specializedFunN) { this.specializedFunN = specializedFunN; }
|
||||
|
||||
@Override
|
||||
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(".", "/");
|
||||
// String t = refType.getName().toString().replace(".", "/");
|
||||
// return t.equals("Fun1")?(t+"$$"):t;
|
||||
@ -45,8 +38,6 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
||||
//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
|
||||
public String visit(GenericRefType genericRefType) {
|
||||
return genericRefType.getParsedName().replace(".", "/");
|
||||
|
@ -1,181 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -5,8 +5,6 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
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.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
@ -19,29 +17,18 @@ import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
|
||||
public class TypeToSignature implements TypeVisitor<String> {
|
||||
private List<GenericsGeneratorResult> constraints;
|
||||
|
||||
private final boolean specializedFunN;
|
||||
|
||||
public TypeToSignature() { this(new ArrayList<>(), true); }
|
||||
|
||||
public TypeToSignature(boolean specializedFunN) { this(new ArrayList<>(), specializedFunN); }
|
||||
|
||||
public TypeToSignature(List<GenericsGeneratorResult> constraints) {
|
||||
this(constraints, true);
|
||||
public TypeToSignature() {
|
||||
this.constraints = new ArrayList<>();
|
||||
}
|
||||
|
||||
public TypeToSignature(List<GenericsGeneratorResult> constraints, boolean specializedFunN){
|
||||
public TypeToSignature(List<GenericsGeneratorResult> constraints) {
|
||||
this.constraints = constraints;
|
||||
this.specializedFunN = specializedFunN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(RefType refType) {
|
||||
if(refType.getName().toString().equals("void"))
|
||||
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(".", "/");
|
||||
String params = "";
|
||||
if(refType.getParaList().size()>0){
|
||||
@ -102,20 +89,9 @@ public class TypeToSignature implements TypeVisitor<String> {
|
||||
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
|
||||
public String visit(GenericRefType genericRefType) {
|
||||
return String.format("T%s;", genericRefType.getParsedName()).replace(".", "/");
|
||||
return genericRefType.getParsedName().replace(".", "/");
|
||||
}
|
||||
|
||||
private Optional<GenericsGeneratorResult> getEqualTPHFromClassConstraints(List<GenericsGeneratorResult> listOfConstraints, String tph) {
|
||||
|
@ -25,8 +25,4 @@ public class Resolver {
|
||||
public String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric resolve(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
return resultSet.resolveType(type).resolvedType;
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,9 @@ public class JavaTXCompiler {
|
||||
this(sourceFile);
|
||||
this.log = log;
|
||||
}
|
||||
public JavaTXCompiler(File[] sourceFiles) throws IOException, ClassNotFoundException {
|
||||
this(Arrays.asList(sourceFiles), null);
|
||||
}
|
||||
public JavaTXCompiler(List<File> sourceFiles) throws IOException, ClassNotFoundException {
|
||||
this(sourceFiles, null);
|
||||
}
|
||||
@ -108,7 +111,8 @@ public class JavaTXCompiler {
|
||||
//INSTANCE = this;
|
||||
}
|
||||
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
|
||||
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
ClassOrInterface objectClass = ASTFactory.createClass(
|
||||
|
@ -0,0 +1,132 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
|
||||
/**
|
||||
* Utilities to generate the constraints for the infer wildcards algorithm.
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
public final class ConstraintsGenerationUtils
|
||||
{
|
||||
|
||||
private ConstraintsGenerationUtils () {
|
||||
throw new AssertionError("No ConstraintsGenerationUtils instance for you");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the constraints for a map of type placeholder and RefType and merge
|
||||
* these to the already provided constraints.
|
||||
*
|
||||
* @param tphMap {@link Map} of {@link TypePlaceholder} and
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @param constraints {@link ConstraintSet} over {@link Pair} to merge to
|
||||
* @return The same instance {@code constraints} provided including the merged
|
||||
* constraints
|
||||
*/
|
||||
public static ConstraintSet<Pair> generateAndMergeConstraints (
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap,
|
||||
ConstraintSet<Pair> constraints) {
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
constraints.addAll(generateConstraints);
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the constraints for a map of type placeholder and RefType.
|
||||
*
|
||||
* @param tphMap {@link Map} of {@link TypePlaceholder} and
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @return {@link ConstraintSet} of {@link Pair} containing the constraints to
|
||||
* infer the matching wildcard type.
|
||||
*/
|
||||
public static ConstraintSet<Pair> generateConstraints (
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap) {
|
||||
return tphMap.entrySet().stream().map(ConstraintsGenerationUtils::generateConstraints)
|
||||
.reduce(
|
||||
new ConstraintSet<>(),
|
||||
(cs, c) -> {
|
||||
cs.addAll(c);
|
||||
return cs;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the constraints for a single RefType type placeholder pair to infer
|
||||
* the wildcards for the generic parameter type.
|
||||
*
|
||||
* @param tphEntry {@link Entry} of {@link TypePlaceholder} and
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @return {@link ConstraintSet} of {@link Pair} generated containing the
|
||||
* constraints.
|
||||
*/
|
||||
private static ConstraintSet<Pair> generateConstraints (
|
||||
Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphEntry) {
|
||||
return generateConstraints(tphEntry.getValue(), tphEntry.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the constraints for a single RefType type placeholder pair to infer
|
||||
* the wildcards for the generic parameter type.
|
||||
*
|
||||
* @param refType {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @param tph {@link TypePlaceholder}
|
||||
* @return {@link ConstraintSet} of {@link Pair} generated containing the
|
||||
* constraints.
|
||||
*/
|
||||
public static ConstraintSet<Pair> generateConstraints (RefTypeOrTPHOrWildcardOrGeneric refType,
|
||||
TypePlaceholder tph) {
|
||||
ConstraintSet<Pair> constraintSet = new ConstraintSet<>();
|
||||
Set<Constraint<Pair>> oderConstraints = new HashSet<>();
|
||||
constraintSet.addOderConstraint(oderConstraints);
|
||||
|
||||
// single type
|
||||
ConstraintsGenerationUtils.addToOderConstraint(oderConstraints, tph, refType);
|
||||
|
||||
// extends type
|
||||
ExtendsWildcardType extendsWildcardType = new ExtendsWildcardType(refType, new NullToken());
|
||||
ConstraintsGenerationUtils.addToOderConstraint(oderConstraints, tph, extendsWildcardType);
|
||||
|
||||
// super type
|
||||
SuperWildcardType superWildcardType = new SuperWildcardType(refType, new NullToken());
|
||||
ConstraintsGenerationUtils.addToOderConstraint(oderConstraints, tph, superWildcardType);
|
||||
|
||||
return constraintSet;
|
||||
}
|
||||
|
||||
private static void addToOderConstraint (Set<Constraint<Pair>> oderConstraints, TypePlaceholder tph,
|
||||
RefTypeOrTPHOrWildcardOrGeneric refType) {
|
||||
Constraint<Pair> c = new Constraint<>();
|
||||
oderConstraints.add(c);
|
||||
|
||||
ConstraintsGenerationUtils.addToConstraint(c, tph, refType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a pair and adds it to a constraint.
|
||||
*
|
||||
* @param c {@link Constraint} of {@link Pair}
|
||||
* @param tph {@link TypePlaceholder}
|
||||
* @param type {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
*/
|
||||
private static void addToConstraint (Constraint<Pair> c, TypePlaceholder tph,
|
||||
RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
Pair pair = new Pair(tph, type, PairOperator.EQUALSDOT);
|
||||
c.add(pair);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class FindInAstVisitor
|
||||
{
|
||||
|
||||
public static boolean find (SourceFile file, TypePlaceholder tph) {
|
||||
FindInAstVisitor findInAstVisitor = new FindInAstVisitor(tph);
|
||||
return findInAstVisitor.find(file);
|
||||
}
|
||||
|
||||
private boolean find;
|
||||
private TypePlaceholder tph;
|
||||
|
||||
|
||||
public FindInAstVisitor (TypePlaceholder tph) {
|
||||
this.tph = tph;
|
||||
find = false;
|
||||
}
|
||||
|
||||
public boolean find (SourceFile file) {
|
||||
CostumASTWalker walker = new CostumASTWalker();
|
||||
walker.visit(file);
|
||||
return find;
|
||||
}
|
||||
|
||||
private class CostumASTWalker extends AbstractASTWalker{
|
||||
|
||||
@Override
|
||||
public void visit (TypePlaceholder typePlaceholder) {
|
||||
if (typePlaceholder.equals(tph))
|
||||
find = true;
|
||||
else
|
||||
super.visit(typePlaceholder);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,209 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
/**
|
||||
* Extension of the JavaTX Compiler providing the capabilities to inference
|
||||
* wildcard types.
|
||||
* <p>
|
||||
* <code>
|
||||
* <ul>
|
||||
* <li>? super Type</li>
|
||||
* <li>? extends Type</li>
|
||||
* <li>Type</li>
|
||||
* </ul>
|
||||
* </code>
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
public class JavaTXCompilerWildcards
|
||||
extends JavaTXCompiler
|
||||
{
|
||||
|
||||
/**
|
||||
* Generated Type placeholder and the implementation type represented.
|
||||
*/
|
||||
private final Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap;
|
||||
|
||||
public JavaTXCompilerWildcards (File... sourceFile) throws IOException, ClassNotFoundException {
|
||||
super(Arrays.asList(sourceFile));
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
public JavaTXCompilerWildcards (File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
|
||||
super(sourceFile, log);
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
public JavaTXCompilerWildcards (List<File> sourceFiles) throws IOException, ClassNotFoundException {
|
||||
super(sourceFiles);
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
public JavaTXCompilerWildcards (List<File> sources, List<File> contextPath)
|
||||
throws IOException, ClassNotFoundException {
|
||||
super(sources, contextPath);
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Type Placeholder generated.
|
||||
*
|
||||
* @return {@link Map} over {@link TypePlaceholder} and
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
*/
|
||||
public Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> getTphMap () {
|
||||
return tphMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintSet<Pair> getConstraints () throws ClassNotFoundException, IOException {
|
||||
ConstraintSet<Pair> constraints = super.getConstraints();
|
||||
return ConstraintsGenerationUtils.generateAndMergeConstraints(tphMap, constraints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the source code for manipulated Java Generic Types to a new .java
|
||||
* file.
|
||||
*
|
||||
* @param outputDir {@link File}
|
||||
* @throws IOException if an i/o exception during file reading and
|
||||
* writing occurs
|
||||
* @throws ClassNotFoundException see {@link #typeInference()}
|
||||
*/
|
||||
public void generateSourceCode (File outputDir) throws IOException, ClassNotFoundException {
|
||||
if (!outputDir.exists()) {
|
||||
boolean mkdirs = outputDir.mkdirs();
|
||||
if (!mkdirs)
|
||||
throw new IOException("Could not create output directory at: " + outputDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
List<ResultSet> typeInference = typeInference();
|
||||
|
||||
if (typeInference.isEmpty())
|
||||
return;
|
||||
|
||||
ResultSet resultSet = typeInference.get(0); // Use the first available result sets
|
||||
|
||||
for (Map.Entry<File, SourceFile> e : sourceFiles.entrySet()) {
|
||||
List<Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric>> list = tphMap.entrySet().stream().filter(d -> FindInAstVisitor.find(e.getValue(), d.getKey())).sorted( (c1, c2) -> Integer.compare(c1.getValue().getOffset().getStartIndex(),
|
||||
c2.getValue().getOffset().getStartIndex())).collect(Collectors.toList());
|
||||
generateSourceCode(e.getKey(), outputDir, list, resultSet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void generateSourceCode (File inputFile, File outputDir,
|
||||
List<Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric>> tphs,
|
||||
ResultSet results)
|
||||
throws IOException {
|
||||
|
||||
File outputFile = new File(outputDir, inputFile.getName());
|
||||
|
||||
Files.deleteIfExists(outputFile.toPath());
|
||||
|
||||
if(!outputFile.createNewFile())
|
||||
throw new IOException("File could not be created at: " + outputFile.getAbsolutePath());
|
||||
|
||||
try(BufferedReader reader = new BufferedReader(new FileReader(inputFile));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))){
|
||||
|
||||
|
||||
int readIdx = 0;
|
||||
|
||||
for (Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> e : tphs) {
|
||||
Token token = e.getValue().getOffset();
|
||||
|
||||
// read the characters before the token
|
||||
int startIndex = token.getStartIndex();
|
||||
char[] read = new char[startIndex - readIdx];
|
||||
|
||||
int i = reader.read(read);
|
||||
if (i != read.length)
|
||||
throw new IOException("Could not read the assumed number of character, read " + i
|
||||
+ " assumed " + read.length);
|
||||
|
||||
readIdx += read.length;
|
||||
|
||||
// Write to output file
|
||||
writer.write(read);
|
||||
|
||||
// Write the new type
|
||||
ResolvedType resolveType = results.resolveType(e.getKey());
|
||||
String string = resolveType.resolvedType.toString();
|
||||
writer.write(string);
|
||||
|
||||
// Read the replaced type and count the read counter
|
||||
int length = token.getStopIndex() - token.getStartIndex() + 1;
|
||||
reader.read(new char[length]);
|
||||
readIdx += length;
|
||||
|
||||
// Read the replaced nested type if the result was a nested type
|
||||
Pattern pattern = Pattern.compile("<.*>");
|
||||
Matcher matcher = pattern.matcher(string);
|
||||
if (matcher.find()) {
|
||||
|
||||
// Read the first and check if it will be a Java Generic Expression starting
|
||||
// with <
|
||||
char c = (char) reader.read();
|
||||
readIdx++;
|
||||
|
||||
if (c != '<')
|
||||
throw new IllegalStateException("At this position is a < expected, found " + c);
|
||||
|
||||
// Read and forget all content until a > on the same level
|
||||
int opens = 1;
|
||||
while (opens > 0) {
|
||||
c = (char) reader.read();
|
||||
readIdx++;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '<':
|
||||
opens++;
|
||||
break;
|
||||
case '>':
|
||||
opens--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read the rest of the file.
|
||||
while (true) {
|
||||
char[] tmp = new char[1024];
|
||||
int read = reader.read(tmp);
|
||||
if (read == -1)
|
||||
break;
|
||||
|
||||
writer.write(tmp, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* Visitor replace type parameter of the type RefType by Type Placeholder in a
|
||||
* AST.
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ReplaceTypeparamVisitor
|
||||
extends AbstractASTWalker
|
||||
{
|
||||
|
||||
/**
|
||||
* Containing the replaced RefType and the mapping TPH
|
||||
*/
|
||||
private final Map<TypePlaceholder, RefTypeOrTPHOrWildcardOrGeneric> tphMap;
|
||||
|
||||
/**
|
||||
* Constructor for a {@code ReplaceTypeparamVisitor}.
|
||||
*/
|
||||
public ReplaceTypeparamVisitor () {
|
||||
this.tphMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit (Field field) {
|
||||
System.out.println("Field: " + field.getName());
|
||||
|
||||
field.accept(new ReplaceRefTypeVisitor());
|
||||
|
||||
super.visit(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit (FormalParameter formalParameter) {
|
||||
System.out.println("FormalParameter: " + formalParameter.getName());
|
||||
|
||||
formalParameter.accept(new ReplaceRefTypeVisitor());
|
||||
|
||||
super.visit(formalParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit (LocalVarDecl localVarDecl) {
|
||||
System.out.println("LocalVarDecl: " + localVarDecl.getName());
|
||||
|
||||
localVarDecl.accept(new ReplaceRefTypeVisitor());
|
||||
|
||||
super.visit(localVarDecl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit (Method method) {
|
||||
System.out.println("Method: " + method.getName());
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
|
||||
if (returnType != null)
|
||||
returnType.accept(new ReplaceRefTypeVisitor());
|
||||
|
||||
super.visit(method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the mapping of the replaced {@link RefType} and the inserted
|
||||
* {@link TypePlaceholder}.
|
||||
*
|
||||
* @return {@link Map} of {@link TypePlaceholder} and {@link RefType}
|
||||
*/
|
||||
public Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> getTphMap () {
|
||||
return tphMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visitor replace each RefType occurs.
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
private class ReplaceRefTypeVisitor
|
||||
extends AbstractASTWalker
|
||||
{
|
||||
@Override
|
||||
public void visit (RefType refType) {
|
||||
|
||||
// check if RefType has Parameter Types
|
||||
if (!refType.getParaList().isEmpty()) {
|
||||
System.out.print("Visit Type: " + refType + " -> ");
|
||||
|
||||
// Iterate over all Parameter Types
|
||||
for (ListIterator<RefTypeOrTPHOrWildcardOrGeneric> listIterator = refType.getParaList()
|
||||
.listIterator(); listIterator.hasNext();) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric next = listIterator.next();
|
||||
|
||||
// If Parameter type is RefType replace with TPH
|
||||
if (next instanceof RefType) {
|
||||
RefType nextRefType = (RefType) next;
|
||||
|
||||
// Visit replaced RefType to get all nested type parameters
|
||||
// Should be done before generating parents TPH to include child TPH in the
|
||||
// parent TPH mapping
|
||||
this.visit(nextRefType);
|
||||
|
||||
generateTphAndReplaceInTree(listIterator, next);
|
||||
}
|
||||
else if (next instanceof GenericRefType) {
|
||||
|
||||
// Visit of nested type arguments not necessary as Generic Types cannot contain
|
||||
// type parameters
|
||||
|
||||
generateTphAndReplaceInTree(listIterator, next);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(refType);
|
||||
}
|
||||
|
||||
// Let the parent take care about all the other stuff
|
||||
super.visit(refType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the TPH for a {@link RefTypeOrTPHOrWildcardOrGeneric} and saves the
|
||||
* mapping.
|
||||
*
|
||||
* @param t {@link RefTypeOrTPHOrWildcardOrGeneric}
|
||||
* @return {@link TypePlaceholder} generated
|
||||
*/
|
||||
private TypePlaceholder generateTypePlaceholder (RefTypeOrTPHOrWildcardOrGeneric t) {
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(new NullToken());
|
||||
tphMap.put(tph, t);
|
||||
return tph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the TPH for a {@link RefTypeOrTPHOrWildcardOrGeneric}, saves the
|
||||
* mapping and replaces the type by the type placeholder in the tree.
|
||||
*
|
||||
* @param listIterator {@link ListIterator} over
|
||||
* {@link RefTypeOrTPHOrWildcardOrGeneric} representing the
|
||||
* tree to replace in
|
||||
* @param refType {@link RefTypeOrTPHOrWildcardOrGeneric} to generate type
|
||||
* placeholder for and replace
|
||||
*/
|
||||
private void generateTphAndReplaceInTree (ListIterator<RefTypeOrTPHOrWildcardOrGeneric> listIterator,
|
||||
RefTypeOrTPHOrWildcardOrGeneric refType) {
|
||||
// Generate TPH
|
||||
TypePlaceholder tph = generateTypePlaceholder(refType);
|
||||
|
||||
// Replace in AST
|
||||
listIterator.set(tph);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* Class providing utilities to generate the Type placeholder for parameter
|
||||
* types which shall be inferred.
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
public final class TypePlaceholderReplaceUtils
|
||||
{
|
||||
|
||||
private TypePlaceholderReplaceUtils () {
|
||||
throw new AssertionError("No TypePlaceholderReplaceUtils instance for you");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the map of the generated type placeholder for the associate parameter
|
||||
* type
|
||||
*
|
||||
* @param compiler {@link JavaTXCompiler} to get the source file from
|
||||
* @return {@link Map} over {@link TypePlaceholder} and the {@link RefType}
|
||||
* replaced
|
||||
*/
|
||||
public static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTypePlaceholder (
|
||||
JavaTXCompiler compiler) {
|
||||
Map<File, SourceFile> sourceFiles = compiler.sourceFiles;
|
||||
ReplaceTypeparamVisitor visitor = new ReplaceTypeparamVisitor();
|
||||
sourceFiles.forEach( (k, v) -> v.accept(visitor));
|
||||
return visitor.getTphMap();
|
||||
}
|
||||
|
||||
}
|
@ -272,10 +272,8 @@ public class StatementGenerator {
|
||||
whole+=".";
|
||||
}
|
||||
|
||||
if(parts.length < 2 || parts[0].contentEquals("this") ){
|
||||
if(parts.length < 2){
|
||||
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:
|
||||
String part = expression.substring(0,expression.length() - (1 + parts[parts.length-1].length()));
|
||||
receiver = generateLocalOrFieldVarOrClassName(part, offset);
|
||||
|
@ -4,8 +4,6 @@ import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
{
|
||||
private String name;
|
||||
@ -35,20 +33,12 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Studienarbeit Type Erasure
|
||||
* @author etiennezink
|
||||
*
|
||||
* @param o
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if((! (o instanceof GenericRefType))) return false;
|
||||
GenericRefType genericRefType = (GenericRefType) o;
|
||||
return getParsedName().equals(genericRefType.getParsedName()) &&
|
||||
Objects.equals(getOffset(), genericRefType.getOffset());
|
||||
}
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
|
@ -1,78 +0,0 @@
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,156 +0,0 @@
|
||||
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) {
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
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) {
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree;
|
||||
|
||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||
|
||||
public record MethodParameter(TargetType type, String name) {
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
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) {}
|
||||
|
@ -1,9 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree;
|
||||
|
||||
import de.dhbwstuttgart.target.tree.expression.TargetBlock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record TargetConstructor(List<MethodParameter> parameterTypes, TargetBlock block) {
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree;
|
||||
|
||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||
|
||||
public record TargetField(TargetType type, String name) {
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
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) {
|
||||
}
|
||||
|
@ -1,4 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree.expression;
|
||||
|
||||
public record TargetAssign(TargetExpression leftSide, TargetExpression rightSide) implements TargetExpression {
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree.expression;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record TargetBlock(List<TargetExpression> statememts) implements TargetExpression {
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree.expression;
|
||||
|
||||
import de.dhbwstuttgart.target.tree.type.*;
|
||||
|
||||
public sealed interface TargetExpression
|
||||
permits TargetBlock, TargetLambdaExpression, TargetReturn, TargetThis, TargetSuper, TargetNew, TargetAssign {
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
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 {
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
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 {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree.expression;
|
||||
|
||||
public record TargetReturn(TargetExpression expression) implements TargetExpression {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree.expression;
|
||||
|
||||
public record TargetSuper() implements TargetExpression {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree.expression;
|
||||
|
||||
public record TargetThis() implements TargetExpression {
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree.type;
|
||||
|
||||
public record TargetExtendsWildcard(TargetType innerType) implements TargetType{
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree.type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record TargetFunNType(int N, List<TargetRefType> params) implements TargetType {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree.type;
|
||||
|
||||
public record TargetGenericType(String name) implements TargetType {
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
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 {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree.type;
|
||||
|
||||
public record TargetSuperWildcard(TargetType innerType) implements TargetType {
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package de.dhbwstuttgart.target.tree.type;
|
||||
|
||||
public sealed interface TargetType
|
||||
permits TargetExtendsWildcard, TargetFunNType, TargetGenericType, TargetRefType, TargetSuperWildcard {
|
||||
}
|
17
src/main/java/de/dhbwstuttgart/unify2/model/Result.java
Normal file
17
src/main/java/de/dhbwstuttgart/unify2/model/Result.java
Normal file
@ -0,0 +1,17 @@
|
||||
package de.dhbwstuttgart.unify2.model;
|
||||
|
||||
public class Result<A> {
|
||||
private final A v;
|
||||
|
||||
private Result(A a, UnifyError e){
|
||||
this.v = a;
|
||||
}
|
||||
|
||||
public static <A> Result<A> of(A a){
|
||||
return new Result(a, null);
|
||||
}
|
||||
|
||||
public static <A> Result<A> error(UnifyError error){
|
||||
return new Result(null, error);
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package de.dhbwstuttgart.unify2.model;
|
||||
|
||||
public class UnifyError {
|
||||
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mExistsWithIntegerDouble() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1IntDouble);
|
||||
assertNotNull(m);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mExistsWithDoubleInteger() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleInt);
|
||||
assertNotNull(m);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mExistsWithDoubleDouble() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble);
|
||||
assertNotNull(m);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
TestCleanUp.cleanUpDirectory(new File(generatedByteCodeDirectory), f -> f.getName().contains(".class"));
|
||||
}
|
||||
}
|
@ -1,91 +1,52 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
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.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
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 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 {
|
||||
private static String pathToClassFile;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/OLFun.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(generatedByteCodeDirectory);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)});
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("OLFun");
|
||||
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$_$");
|
||||
classFun1StringInt = loader.loadClass("Fun1$$Ljava$lang$String$_$Ljava$lang$Integer$_$");
|
||||
classFun1StringDouble = loader.loadClass("Fun1$$Ljava$lang$String$_$Ljava$lang$Double$_$");
|
||||
/*
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
||||
Method m = classToTest.getDeclaredMethod("m");
|
||||
Class<?> lambda = m.invoke(instanceOfClass).getClass();
|
||||
Method apply = lambda.getMethod("apply", Object.class);
|
||||
|
||||
// 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"));
|
||||
}
|
||||
}
|
||||
|
@ -1,248 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
148
src/test/java/inferWildcards/TestInferWildcardsFields.java
Normal file
148
src/test/java/inferWildcards/TestInferWildcardsFields.java
Normal file
@ -0,0 +1,148 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsFields
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsFields.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
private static List<ResultSet> generateExpectedTypeInferResult (JavaTXCompilerWildcards compiler) {
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = compiler.getTphMap();
|
||||
|
||||
ArrayList<ResultSet> list = new ArrayList<>();
|
||||
|
||||
tphMap.forEach( (tph, t) -> {
|
||||
ResultPair r = new PairTPHequalRefTypeOrWildcardType(tph,
|
||||
new RefType(new JavaClassName("java.lang.String"), new NullToken()));
|
||||
HashSet<ResultPair> set = new HashSet<>();
|
||||
set.add(r);
|
||||
list.add(new ResultSet(set));
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 4", 4, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
125
src/test/java/inferWildcards/TestInferWildcardsMap.java
Normal file
125
src/test/java/inferWildcards/TestInferWildcardsMap.java
Normal file
@ -0,0 +1,125 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsMap
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsMap.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 6", 6, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
126
src/test/java/inferWildcards/TestInferWildcardsMapNested.java
Normal file
126
src/test/java/inferWildcards/TestInferWildcardsMapNested.java
Normal file
@ -0,0 +1,126 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsMapNested
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsMapNested.java";
|
||||
}
|
||||
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 9", 9, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
125
src/test/java/inferWildcards/TestInferWildcardsNested.java
Normal file
125
src/test/java/inferWildcards/TestInferWildcardsNested.java
Normal file
@ -0,0 +1,125 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsNested
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsNested.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 6", 6, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
125
src/test/java/inferWildcards/TestInferWildcardsParamType.java
Normal file
125
src/test/java/inferWildcards/TestInferWildcardsParamType.java
Normal file
@ -0,0 +1,125 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsParamType
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsParamType.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 4", 4, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
125
src/test/java/inferWildcards/TestInferWildcardsSingle.java
Normal file
125
src/test/java/inferWildcards/TestInferWildcardsSingle.java
Normal file
@ -0,0 +1,125 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsSingle
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsSingle.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 3", 3, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
125
src/test/java/inferWildcards/TestInferWildcardsSingleLib.java
Normal file
125
src/test/java/inferWildcards/TestInferWildcardsSingleLib.java
Normal file
@ -0,0 +1,125 @@
|
||||
package inferWildcards;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
|
||||
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
|
||||
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class TestInferWildcardsSingleLib
|
||||
{
|
||||
|
||||
private String resourceFilePath;
|
||||
private String resourceDirPath;
|
||||
|
||||
@Before
|
||||
public void setup () {
|
||||
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||
resourceFilePath = resourceDirPath + "/TestClassWildcardsSingleLib.java";
|
||||
}
|
||||
|
||||
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompiler(files1);
|
||||
}
|
||||
|
||||
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
|
||||
File[] files1 = { new File(resourceFilePath) };
|
||||
return new JavaTXCompilerWildcards(files1);
|
||||
}
|
||||
|
||||
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
|
||||
JavaTXCompiler javaTXCompiler) {
|
||||
System.out.println("\nReplacements:");
|
||||
|
||||
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTph () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate TPH --------------\n");
|
||||
|
||||
JavaTXCompiler javaTXCompiler = getStandardCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
|
||||
javaTXCompiler);
|
||||
|
||||
System.out.println(generateTph);
|
||||
|
||||
assertThat("Number of TPH is 2", 2, CoreMatchers.is(generateTph.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Generate Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
|
||||
.getTphMap();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
|
||||
System.out.println(generateConstraints);
|
||||
|
||||
int size = 0;
|
||||
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
|
||||
for (Constraint<Pair> c : l)
|
||||
size += c.size();
|
||||
|
||||
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
|
||||
System.out.println("\n--------- Test Combined Constraints --------------\n");
|
||||
|
||||
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
|
||||
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
|
||||
|
||||
System.out.println(constraints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeInference () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
|
||||
|
||||
System.out.println(typeInference);
|
||||
|
||||
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
|
||||
CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
|
||||
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
|
||||
|
||||
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
|
||||
|
||||
assertThat("Generation Succeeded", null, CoreMatchers.anything());
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
|
||||
class Test{
|
||||
method(){
|
||||
if(true)i++;
|
0
src/test/resources/javFiles/parser/BoundedParameter.jav → src/test/java/parser/BoundedParameter.jav
0
src/test/resources/javFiles/parser/BoundedParameter.jav → src/test/java/parser/BoundedParameter.jav
@ -20,17 +20,18 @@ import org.junit.Test;
|
||||
*
|
||||
*/
|
||||
public class GeneralParserTest{
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/test/parser/";
|
||||
|
||||
@Test
|
||||
public void run(){
|
||||
|
||||
|
||||
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("ImportTest.jav");
|
||||
filenames.add("CastTest.jav");
|
||||
filenames.add("StatementsTest.jav");
|
||||
//filenames.add("Methods.jav");
|
||||
filenames.add("ImportTestGeneric.jav");
|
||||
@ -39,14 +40,11 @@ public class GeneralParserTest{
|
||||
//filenames.add("GenericFieldVarTest.jav");
|
||||
filenames.add("FieldVarTest.jav");
|
||||
filenames.add("StructuralTypes.jav");
|
||||
filenames.add("ExtendsTest.jav");
|
||||
*/
|
||||
|
||||
//filenames.add("PackageNameTest.jav");
|
||||
// filenames.add("ExtendsTest.jav");
|
||||
filenames.add("PackageNameTest.jav");
|
||||
try{
|
||||
for(String filename : filenames){
|
||||
new JavaTXCompiler(new File(Thread.currentThread().getContextClassLoader().getResource(filename).getPath()));
|
||||
}
|
||||
new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList()));
|
||||
}catch(Exception exc){
|
||||
exc.printStackTrace();
|
||||
fail();
|
||||
|
@ -1,5 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
public class ASTToTargetTest {
|
||||
|
||||
}
|
@ -4,9 +4,14 @@ import java.lang.Double;
|
||||
import java.util.Vector;
|
||||
import java.lang.Boolean;
|
||||
|
||||
|
||||
|
||||
|
||||
public class OLFun {
|
||||
|
||||
//f = x -> {return x + x;};
|
||||
|
||||
m(f, x) {
|
||||
var y = f.apply(x + x) + 1;
|
||||
x = f.apply(x+x);
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
2
src/test/resources/inferWildcards/.gitignore
vendored
Normal file
2
src/test/resources/inferWildcards/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/generatedSC/
|
||||
/generatedBC/
|
@ -0,0 +1,31 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
|
||||
class TestClassWildcardsFields
|
||||
{
|
||||
|
||||
private List<String> field1;
|
||||
//private int counter;
|
||||
|
||||
public TestClassWildcards () {
|
||||
//field1 = new ArrayList<>();
|
||||
//counter = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Working method for Java
|
||||
* @param param1
|
||||
* @return
|
||||
*/
|
||||
public List<String> test (List<String> param1) {
|
||||
List<String> localVar = field1;
|
||||
field1 = param1;
|
||||
//counter++;
|
||||
return localVar;
|
||||
}
|
||||
|
||||
public void foo() {
|
||||
|
||||
}
|
||||
}
|
13
src/test/resources/inferWildcards/TestClassWildcardsMap.java
Normal file
13
src/test/resources/inferWildcards/TestClassWildcardsMap.java
Normal file
@ -0,0 +1,13 @@
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
import java.util.Map;
|
||||
import java.lang.Integer;
|
||||
|
||||
class TestClassWildcardsMap
|
||||
{
|
||||
|
||||
public Map<Integer, Object> test(Map<Integer, String> input){
|
||||
Map<Integer, Object> listOfObjects = input;
|
||||
return listOfObjects;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
import java.util.Map;
|
||||
import java.lang.Integer;
|
||||
|
||||
class TestClassWildcardsMapNested
|
||||
{
|
||||
|
||||
public Map<Integer, Collection<Object>> test(Map<Integer, List<String>> input){
|
||||
Map<Integer, Collection<Object>> listOfObjects = input;
|
||||
return listOfObjects;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
import java.util.Map;
|
||||
import java.lang.Integer;
|
||||
|
||||
class TestClassWildcardsNested
|
||||
{
|
||||
public List<Collection<Object>> test(List<List<String>> input){
|
||||
List<Collection<Object>> listOfObjects = input;
|
||||
return listOfObjects;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
|
||||
public final class TestClassWildcardsParamType<T1, T2> {
|
||||
public final T1 first;
|
||||
public final T2 second;
|
||||
|
||||
public TestClassWildcardsParamType(T1 first, T2 second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public static <T1, T2> TestClassWildcardsParamType<T1, T2> of(T1 first, T2 second) {
|
||||
return new TestClassWildcardsParamType<>(first, second);
|
||||
}
|
||||
|
||||
public static void main(String[] agrs) {
|
||||
TestClassWildcardsParamType<Class<?>, String> pair = TestClassWildcardsParamType.of(List.class, "hello");
|
||||
|
||||
//Output of compiler
|
||||
//TestClassWildcardsParamType<? extends Class<?>, String> pair = TestClassWildcardsParamType.of(List.class, "hello");
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
import java.util.List;
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
|
||||
class TestClassWildcardsSingle
|
||||
{
|
||||
|
||||
/**
|
||||
* Non working method in normal Java
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public List<Object> test (List<String> input) {
|
||||
List<Object> listOfObjects = input;
|
||||
Object test = listOfObjects.get(0);
|
||||
String string = "Test";
|
||||
input.add(string);
|
||||
return listOfObjects;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import java.util.List;
|
||||
|
||||
class TestClassWildcardsLib
|
||||
{
|
||||
|
||||
// public <T> List<T> merge (List<T> l1, List<T> l2) {
|
||||
// l2.forEach(s -> {if(!l1.contains(s)) l1.add(s);});
|
||||
// return l2;
|
||||
// }
|
||||
|
||||
public static <T> List<T> foo(List<T> dd){
|
||||
T t = dd.get(1);
|
||||
return dd;
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package de.test;
|
||||
|
||||
class Pair {
|
||||
fst;
|
||||
snd;
|
||||
|
||||
Pair(fst, snd) {
|
||||
this.fst = fst;
|
||||
this.snd = snd;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
public class OLFunTest{
|
||||
public static void main(String[] args){
|
||||
var olFun2 = new OLFun2();
|
||||
olFun2.m((Integer x) -> x);
|
||||
olFun2.m((Integer x) -> (Double) Double.valueOf(x));
|
||||
olFun2.m((Double x) -> x);
|
||||
olFun2.m((Double x) -> x.intValue());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user