forked from JavaTX/JavaCompilerCore
Hinzufügen von OLFun2 und Änderung der Spezialisierungen von FunN, dass diese statt des TPH im Namen Object haben.
Ansonsten werden diese nicht wieder gefunden.
This commit is contained in:
parent
ed00aeb056
commit
c65102d89a
@ -39,13 +39,13 @@ public class FunNGenerator implements FunNUtilities{
|
||||
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 static final String objectSuperType = Type.getInternalName(Object.class).replace('.','/');
|
||||
private static final RefType objectRefType = new RefType(new JavaClassName(objectSuperType), null);
|
||||
private static final String objectSignature = applySignature(objectRefType);
|
||||
|
||||
private static String applyDescriptor(RefTypeOrTPHOrWildcardOrGeneric a) { return a.acceptTV(new TypeToDescriptor(true)); }
|
||||
private static String applySignature(RefTypeOrTPHOrWildcardOrGeneric a) { return a.acceptTV(new TypeToSignature(true)); }
|
||||
private static String applyNameDescriptor(RefTypeOrTPHOrWildcardOrGeneric a){ return a instanceof TypePlaceholder ? applySignature(a)+";" : String.format("L%s;", applyDescriptor(a)); }
|
||||
private static String applyNameDescriptor(RefTypeOrTPHOrWildcardOrGeneric a){ return a instanceof TypePlaceholder ? applyNameDescriptor(objectRefType) : String.format("L%s;", applyDescriptor(a)); }
|
||||
|
||||
@Override
|
||||
public byte[] generateSuperBytecode(int numberArguments) {
|
||||
|
69
src/test/java/bytecode/OLFun2Test.java
Normal file
69
src/test/java/bytecode/OLFun2Test.java
Normal file
@ -0,0 +1,69 @@
|
||||
package bytecode;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.function.Function;
|
||||
|
||||
import general.TestCleanUp;
|
||||
import org.junit.*;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* //ToDo Etienne: Beschreiben
|
||||
*
|
||||
* @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<?> classFun1DoubleDouble;
|
||||
private static Class<?> classFun1StringString;
|
||||
|
||||
private static String generatedByteCodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||
|
||||
//ToDo Etienne: Nach Anpassung des Bytecode die Tests hinzufügen
|
||||
//ToDo Etienne: Aufruf von m testen
|
||||
@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$_$");
|
||||
classFun1DoubleDouble = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Double$_$");
|
||||
classFun1StringString = loader.loadClass("Fun1$$Ljava$lang$String$_$Ljava$lang$String$_$");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mExistsWithInteger() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1IntInt);
|
||||
assertNotNull(m);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mExistsWithDouble() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble);
|
||||
assertNotNull(m);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mExistsWithString() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1StringString);
|
||||
assertNotNull(m);
|
||||
}
|
||||
|
||||
//@AfterClass
|
||||
public static void cleanUp(){
|
||||
TestCleanUp.cleanUpDirectory(new File(generatedByteCodeDirectory), f -> f.getName().contains(".class"));
|
||||
}
|
||||
}
|
@ -11,8 +11,7 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test which only checks if the class {@code OLFun} was correctly compiled.
|
||||
* This is achived by verifying the existence of the three implementations of {@code m}.
|
||||
* //ToDo Etienne: Beschreiben
|
||||
*
|
||||
* @since Studienarbeit Type Erasure
|
||||
* @author etiennezink
|
||||
@ -26,10 +25,11 @@ public class OLFunTest {
|
||||
private static Class<?> classFun1IntInt;
|
||||
private static Class<?> classFun1DoubleDouble;
|
||||
private static Class<?> classFun1StringString;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
private static String generatedByteCodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||
|
||||
//ToDo Etienne: Nach Anpassung des Bytecode die Tests hinzufügen
|
||||
//ToDo Etienne: Aufruf von m testen
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/OLFun.jav";
|
||||
@ -38,19 +38,18 @@ public class OLFunTest {
|
||||
compiler.generateBytecode(generatedByteCodeDirectory);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)});
|
||||
classToTest = loader.loadClass("OLFun");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
//classFun1IntInt = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$");
|
||||
//classFun1DoubleDouble = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Double$_$");
|
||||
classFun1IntInt = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$");
|
||||
classFun1DoubleDouble = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Double$_$");
|
||||
classFun1StringString = loader.loadClass("Fun1$$Ljava$lang$String$_$Ljava$lang$String$_$");
|
||||
}
|
||||
|
||||
//@Test
|
||||
@Test
|
||||
public void mExistsWithInteger() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1IntInt ,Integer.class);
|
||||
assertNotNull(m);
|
||||
}
|
||||
|
||||
//@Test
|
||||
@Test
|
||||
public void mExistsWithDouble() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble ,Double.class);
|
||||
assertNotNull(m);
|
||||
|
@ -4,9 +4,6 @@ import java.lang.String;
|
||||
import java.util.Vector;
|
||||
import java.lang.Boolean;
|
||||
|
||||
|
||||
|
||||
|
||||
public class OLFun {
|
||||
|
||||
//f = x -> {return x + x;};
|
||||
|
13
src/test/resources/bytecode/javFiles/OLFun2.jav
Normal file
13
src/test/resources/bytecode/javFiles/OLFun2.jav
Normal file
@ -0,0 +1,13 @@
|
||||
import java.lang.String;
|
||||
//import java.lang.Integer;
|
||||
//import java.lang.Double;
|
||||
import java.util.Vector;
|
||||
import java.lang.Boolean;
|
||||
|
||||
public class OLFun2 {
|
||||
|
||||
x;
|
||||
m(f){
|
||||
x = f.apply(x + x)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user