forked from JavaTX/JavaCompilerCore
Improve genericcs tests
This commit is contained in:
parent
7aa7f94110
commit
d9bb0037b8
7
resources/bytecode/javFiles/Generics3.jav
Normal file
7
resources/bytecode/javFiles/Generics3.jav
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
class Generics3<B extends String & List<Integer>> {
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package targetast;
|
package targetast;
|
||||||
|
|
||||||
|
import com.google.common.reflect.TypeToken;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
@ -9,12 +10,14 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|||||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||||
import de.dhbwstuttgart.target.tree.TargetClass;
|
import de.dhbwstuttgart.target.tree.TargetClass;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@ -86,6 +89,21 @@ public class ASTToTypedTargetAST {
|
|||||||
var infimum = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
var infimum = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void gen() throws Exception {
|
||||||
|
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Gen.jav").toFile();
|
||||||
|
var compiler = new JavaTXCompiler(file);
|
||||||
|
var resultSet = compiler.typeInference();
|
||||||
|
var converter = new ASTToTargetAST(resultSet);
|
||||||
|
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||||
|
|
||||||
|
var generics = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
||||||
|
var m = generics.getDeclaredMethod("m", Vector.class);
|
||||||
|
var mReturnType = m.getGenericReturnType();
|
||||||
|
assertEquals(mReturnType, m.getParameters()[0].getParameterizedType());
|
||||||
|
assertEquals(mReturnType, new TypeToken<Vector<Integer>>(){}.getType());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void definedGenerics() throws Exception {
|
public void definedGenerics() throws Exception {
|
||||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics.jav").toFile();
|
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics.jav").toFile();
|
||||||
@ -95,6 +113,13 @@ public class ASTToTypedTargetAST {
|
|||||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||||
|
|
||||||
var generics = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
var generics = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
||||||
|
var B = generics.getTypeParameters()[0];
|
||||||
|
var mt1 = generics.getDeclaredMethod("mt1", Object.class);
|
||||||
|
var constructor = generics.getDeclaredConstructor(Object.class);
|
||||||
|
|
||||||
|
assertEquals(B, mt1.getGenericReturnType());
|
||||||
|
assertEquals(B, mt1.getParameters()[0].getParameterizedType());
|
||||||
|
assertEquals(B, constructor.getParameters()[0].getParameterizedType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -106,5 +131,21 @@ public class ASTToTypedTargetAST {
|
|||||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||||
|
|
||||||
var generics2 = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
var generics2 = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
||||||
|
assertEquals(generics2.getTypeParameters()[0].getBounds()[0], String.class);
|
||||||
|
var m = generics2.getDeclaredMethod("m1", Object.class);
|
||||||
|
assertEquals(m.getTypeParameters()[0].getBounds()[0], Integer.class);
|
||||||
|
var param = m.getTypeParameters()[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore("Not implemented")
|
||||||
|
public void definedGenerics3() throws Exception {
|
||||||
|
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics3.jav").toFile();
|
||||||
|
var compiler = new JavaTXCompiler(file);
|
||||||
|
var resultSet = compiler.typeInference();
|
||||||
|
var converter = new ASTToTargetAST(resultSet);
|
||||||
|
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||||
|
|
||||||
|
var generics3 = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ public class TestCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("The lambda class is not generated because we don'T call ASTToTargetAST")
|
@Ignore("The lambda class is not generated because we don't call ASTToTargetAST")
|
||||||
public void testLambda() throws Exception {
|
public void testLambda() throws Exception {
|
||||||
var classLoader = new ByteArrayClassLoader();
|
var classLoader = new ByteArrayClassLoader();
|
||||||
//var fun = classLoader.loadClass(Path.of(System.getProperty("user.dir"), "src/test/java/targetast/Fun1$$.class"));
|
//var fun = classLoader.loadClass(Path.of(System.getProperty("user.dir"), "src/test/java/targetast/Fun1$$.class"));
|
||||||
|
Loading…
Reference in New Issue
Block a user