forked from JavaTX/JavaCompilerCore
MergeTest
This commit is contained in:
parent
0443f1e528
commit
52c445435d
@ -20,6 +20,7 @@ import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
@ -104,10 +105,13 @@ public class Signature {
|
||||
Iterator<? extends GenericTypeVar> itr = method.getGenerics().iterator();
|
||||
// visits all formal type parameter and visits their bounds <T:...;B:...;...>
|
||||
while(itr.hasNext()) {
|
||||
System.out.println("HAS GENERICS!!");
|
||||
GenericTypeVar g = itr.next();
|
||||
getBoundsOfTypeVar(g,genericsAndBoundsMethod);
|
||||
}
|
||||
|
||||
//TODO: paramtrisierte Typen mit Generics, Type Variablen müssen definiert werden.
|
||||
|
||||
// Wenn die RückgabeType eine TPH ist, wird als generic behandelt
|
||||
// z.B: Type = TPH K => wird eine Formal Type Parameter K$ erzeugt und Bound = Object
|
||||
if(!isConstructor) {
|
||||
@ -131,7 +135,9 @@ public class Signature {
|
||||
if(hasTPHs(ref)) {
|
||||
createSignatureForParameterizedType(ref);
|
||||
}
|
||||
|
||||
System.out.println("HAS WC = " + hasWC(ref));
|
||||
if(hasWC(ref))
|
||||
createSigForParamTypeWithWC(ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -170,6 +176,10 @@ public class Signature {
|
||||
RefType ref = (RefType) methodParamsAndTypes.get(paramName);
|
||||
if(hasTPHs(ref))
|
||||
createSignatureForParameterizedType(ref);
|
||||
|
||||
System.out.println("HAS WC = " + hasWC(ref));
|
||||
if(hasWC(ref))
|
||||
createSigForParamTypeWithWC(ref);
|
||||
}
|
||||
|
||||
for(GenericInsertPair p:methodPairs) {
|
||||
@ -218,6 +228,34 @@ public class Signature {
|
||||
// sw.visitEnd();
|
||||
}
|
||||
|
||||
private void createSigForParamTypeWithWC(RefType ref) {
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
||||
if(p instanceof WildcardType) {
|
||||
if(((WildcardType) p).getInnerType() instanceof GenericRefType) {
|
||||
String name = new TypeToSignature().visit((GenericRefType)((WildcardType) p).getInnerType());
|
||||
if(!genericsAndBoundsMethod.containsKey(name) && !genericsAndBounds.containsKey(name)) {
|
||||
sw.visitFormalTypeParameter(name);
|
||||
sw.visitClassBound().visitClassType(Type.getInternalName(Object.class));
|
||||
sw.visitClassBound().visitEnd();
|
||||
genericsAndBoundsMethod.put(name, Type.getInternalName(Object.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean hasWC(RefType ref) {
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
||||
System.out.println("HAS WCs: " + p.acceptTV(new TypeToString()));
|
||||
System.out.println("HAS WCs: " + p.getClass());
|
||||
if(p.acceptTV(new TypeToString()).contains("WC"))
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void createSignatureForParameterizedType(RefType ref) {
|
||||
ArrayList<GenericInsertPair> allPairs = getAllPairs(ref);
|
||||
allPairs.addAll(methodPairs);
|
||||
@ -347,7 +385,7 @@ public class Signature {
|
||||
|
||||
private boolean hasTPHs(RefType ref) {
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric p : ref.getParaList()) {
|
||||
System.out.println(p.acceptTV(new TypeToString()));
|
||||
System.out.println("HAS TPHs: " + p.acceptTV(new TypeToString()));
|
||||
if(p.acceptTV(new TypeToString()).contains("WC")){
|
||||
continue;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class TypeToSignature implements TypeVisitor<String> {
|
||||
@Override
|
||||
public String visit(SuperWildcardType superWildcardType) {
|
||||
// throw new NotImplementedException();
|
||||
return "-" + superWildcardType.getInnerType().acceptTV(new TypeToSignature());
|
||||
return "+" + superWildcardType.getInnerType().acceptTV(new TypeToSignature());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,7 +60,7 @@ public class TypeToSignature implements TypeVisitor<String> {
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
// throw new NotImplementedException();
|
||||
return "+" + extendsWildcardType.getInnerType().acceptTV(new TypeToSignature());
|
||||
return "-" + extendsWildcardType.getInnerType().acceptTV(new TypeToSignature());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
43
test/bytecode/MergeTest.java
Normal file
43
test/bytecode/MergeTest.java
Normal file
@ -0,0 +1,43 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
|
||||
public class MergeTest {
|
||||
private static String path;
|
||||
private static File fileToTest;
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static String pathToClassFile;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
// @BeforeClass
|
||||
// public static void setUpBeforeClass() throws Exception {
|
||||
// path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Merge.jav";
|
||||
// fileToTest = new File(path);
|
||||
// compiler = new JavaTXCompiler(fileToTest);
|
||||
// compiler.generateBytecode(System.getProperty("user.dir")+"/testBytecode/generatedBC/");
|
||||
// pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
// loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
// classToTest = loader.loadClass("Merge");
|
||||
// instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception{
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Merge.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/testBytecode/generatedBC/");
|
||||
}
|
||||
|
||||
}
|
17
test/bytecode/javFiles/Merge.jav
Normal file
17
test/bytecode/javFiles/Merge.jav
Normal file
@ -0,0 +1,17 @@
|
||||
import java.util.List;
|
||||
import java.lang.Integer;
|
||||
import java.util.Collection;
|
||||
|
||||
class Merge {
|
||||
|
||||
merge(a, b) {
|
||||
a.addAll(b);
|
||||
return a;
|
||||
}
|
||||
|
||||
sort(in){
|
||||
var firstHalf = in.subList(1,2);
|
||||
var secondHalf = in.subList(1,2);
|
||||
return merge(sort(firstHalf), sort(secondHalf));
|
||||
}
|
||||
}
|
5
test/bytecode/javFiles/PTGen.jav
Normal file
5
test/bytecode/javFiles/PTGen.jav
Normal file
@ -0,0 +1,5 @@
|
||||
public class PTGen {
|
||||
m(List<E> list) {
|
||||
return list;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user