diff --git a/src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java b/src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java index 49b1b4f4..d19d38dc 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/utilities/Simplify.java @@ -174,9 +174,11 @@ public class Simplify { allCons.addAll(result.keySet()); if(!allCons.isEmpty() && allCons.size()<2) { - - if(!result.containsKey(allCons.get(0))) - result.put(allCons.get(0), null); + TPHConstraint cons = allCons.get(0); + if(!result.containsKey(cons)) { + result.put(cons, null); + result.put(new ExtendsConstraint(cons.getRight(), Type.getInternalName(Object.class), Relation.EXTENDS), null); + } return result; } diff --git a/src/test/java/bytecode/IdTest.java b/src/test/java/bytecode/IdTest.java new file mode 100644 index 00000000..e60e6990 --- /dev/null +++ b/src/test/java/bytecode/IdTest.java @@ -0,0 +1,38 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Field; +import java.net.URL; +import java.net.URLClassLoader; + +import org.junit.BeforeClass; +import org.junit.Test; + +import de.dhbwstuttgart.core.JavaTXCompiler; + +public class IdTest { + + 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; + + + @Test + public void test() throws Exception { + path = System.getProperty("user.dir")+"/src/test/resources/bytecodeJavFiles/Id.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + 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("Id"); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + } + +} diff --git a/src/test/resources/bytecodeJavFiles/Id.jav b/src/test/resources/bytecodeJavFiles/Id.jav new file mode 100644 index 00000000..6cb5d4b0 --- /dev/null +++ b/src/test/resources/bytecodeJavFiles/Id.jav @@ -0,0 +1,6 @@ +public class Id { + + id(b){ + return b; + } +} \ No newline at end of file