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:
Etienne Zink 2022-03-29 17:00:06 +02:00
parent ed00aeb056
commit c65102d89a
5 changed files with 93 additions and 15 deletions

View File

@ -39,13 +39,13 @@ public class FunNGenerator implements FunNUtilities{
private final String methodName = "apply"; private final String methodName = "apply";
private final int bytecodeVersion = V1_8; private final int bytecodeVersion = V1_8;
private final String objectSuperType = Type.getInternalName(Object.class).replace('.','/'); private static final String objectSuperType = Type.getInternalName(Object.class).replace('.','/');
private final RefType objectRefType = new RefType(new JavaClassName(objectSuperType), null); private static final RefType objectRefType = new RefType(new JavaClassName(objectSuperType), null);
private final String objectSignature = applySignature(objectRefType); private static final String objectSignature = applySignature(objectRefType);
private static String applyDescriptor(RefTypeOrTPHOrWildcardOrGeneric a) { return a.acceptTV(new TypeToDescriptor(true)); } 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 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 @Override
public byte[] generateSuperBytecode(int numberArguments) { public byte[] generateSuperBytecode(int numberArguments) {

View 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"));
}
}

View File

@ -11,8 +11,7 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
* Test which only checks if the class {@code OLFun} was correctly compiled. * //ToDo Etienne: Beschreiben
* This is achived by verifying the existence of the three implementations of {@code m}.
* *
* @since Studienarbeit Type Erasure * @since Studienarbeit Type Erasure
* @author etiennezink * @author etiennezink
@ -26,10 +25,11 @@ public class OLFunTest {
private static Class<?> classFun1IntInt; private static Class<?> classFun1IntInt;
private static Class<?> classFun1DoubleDouble; private static Class<?> classFun1DoubleDouble;
private static Class<?> classFun1StringString; private static Class<?> classFun1StringString;
private static Object instanceOfClass;
private static String generatedByteCodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/"; 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 @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/OLFun.jav"; path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/OLFun.jav";
@ -38,19 +38,18 @@ public class OLFunTest {
compiler.generateBytecode(generatedByteCodeDirectory); compiler.generateBytecode(generatedByteCodeDirectory);
loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)}); loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)});
classToTest = loader.loadClass("OLFun"); classToTest = loader.loadClass("OLFun");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); classFun1IntInt = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$");
//classFun1IntInt = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$"); classFun1DoubleDouble = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Double$_$");
//classFun1DoubleDouble = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Double$_$");
classFun1StringString = loader.loadClass("Fun1$$Ljava$lang$String$_$Ljava$lang$String$_$"); classFun1StringString = loader.loadClass("Fun1$$Ljava$lang$String$_$Ljava$lang$String$_$");
} }
//@Test @Test
public void mExistsWithInteger() throws Exception{ public void mExistsWithInteger() throws Exception{
Method m = classToTest.getDeclaredMethod("m", classFun1IntInt ,Integer.class); Method m = classToTest.getDeclaredMethod("m", classFun1IntInt ,Integer.class);
assertNotNull(m); assertNotNull(m);
} }
//@Test @Test
public void mExistsWithDouble() throws Exception{ public void mExistsWithDouble() throws Exception{
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble ,Double.class); Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble ,Double.class);
assertNotNull(m); assertNotNull(m);

View File

@ -4,9 +4,6 @@ import java.lang.String;
import java.util.Vector; import java.util.Vector;
import java.lang.Boolean; import java.lang.Boolean;
public class OLFun { public class OLFun {
//f = x -> {return x + x;}; //f = x -> {return x + x;};

View 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)
}
}