diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 4d4a2af2..beab7c06 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -177,6 +177,7 @@ public class JavaTXCompiler { gtvs.put(tvarVarIt.next().getName(), paraIt.next()); } Iterator methodIt = superclass.getMethods().iterator(); + //TODO: PL 2020-05-06: Hier müssen ueberschriebene Methoden noch rausgefiltert werden while(methodIt.hasNext()) { Method m = methodIt.next(); ParameterList newParaList = new ParameterList( @@ -975,7 +976,7 @@ public class JavaTXCompiler { @Override public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) { - throw new DebugException("Dieser Fall darf nicht auftreten"); + return typePlaceholder; //TypePlaceholder der vererbert wird kann bei der Vererbung nicht instanziert werden. } @Override diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java index 4b8de165..8715fe55 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java @@ -41,8 +41,9 @@ public class Constraint extends HashSet { } public String toString() { - return super.toString() + " isInherited = " + isInherited + "\nextendsContraint: " + - (extendConstraint != null ? extendConstraint.toStringBase() : "null" ) + "\n" ; + return super.toString() + " isInherited = " + isInherited + //" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" ) + + "\n" ; } public String toStringBase() { diff --git a/src/test/java/bytecode/InheritTest.java b/src/test/java/bytecode/InheritTest.java index 713d82f4..7166c54e 100644 --- a/src/test/java/bytecode/InheritTest.java +++ b/src/test/java/bytecode/InheritTest.java @@ -31,18 +31,59 @@ public class InheritTest { @BeforeClass public static void setUpBeforeClass() throws Exception { - path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit.jav"; + path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/AA.jav"; fileToTest = new File(path); compiler = new JavaTXCompiler(fileToTest); - pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/"; List typeinferenceResult = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult); compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest1 = loader.loadClass("AA"); + instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance(); + + path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/BB.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/"; + typeinferenceResult = compiler.typeInference(); + simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult); + compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest1 = loader.loadClass("AA"); + instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance(); + + path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/CC.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/"; + typeinferenceResult = compiler.typeInference(); + simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult); + compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest1 = loader.loadClass("AA"); + instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance(); + + path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/DD.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/"; + typeinferenceResult = compiler.typeInference(); + simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult); + compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest1 = loader.loadClass("AA"); + instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance(); + path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + typeinferenceResult = compiler.typeInference(); + simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult); + compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass("Inherit"); instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - classToTest1 = loader.loadClass("A"); - instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance(); } @Test @@ -52,7 +93,7 @@ public class InheritTest { @Test public void testAName() { - assertEquals("A", classToTest1.getName()); + assertEquals("AA", classToTest1.getName()); } /* @Test diff --git a/src/test/resources/bytecode/javFiles/AA.jav b/src/test/resources/bytecode/javFiles/AA.jav new file mode 100644 index 00000000..aee2d5de --- /dev/null +++ b/src/test/resources/bytecode/javFiles/AA.jav @@ -0,0 +1,5 @@ +import java.lang.Integer; + +public class AA { + m(Integer i) { } +} \ No newline at end of file diff --git a/src/test/resources/bytecode/javFiles/BB.jav b/src/test/resources/bytecode/javFiles/BB.jav new file mode 100644 index 00000000..27856c42 --- /dev/null +++ b/src/test/resources/bytecode/javFiles/BB.jav @@ -0,0 +1,3 @@ +import java.lang.Integer; + +public class BB extends AA { } \ No newline at end of file diff --git a/src/test/resources/bytecode/javFiles/CC.jav b/src/test/resources/bytecode/javFiles/CC.jav new file mode 100644 index 00000000..af5a4000 --- /dev/null +++ b/src/test/resources/bytecode/javFiles/CC.jav @@ -0,0 +1,7 @@ +import java.lang.Integer; + + + +public class CC extends BB { + m(Integer i) { } +} diff --git a/src/test/resources/bytecode/javFiles/DD.jav b/src/test/resources/bytecode/javFiles/DD.jav new file mode 100644 index 00000000..6d49f4c7 --- /dev/null +++ b/src/test/resources/bytecode/javFiles/DD.jav @@ -0,0 +1,4 @@ +import java.lang.Integer; + +public class DD extends CC { } + diff --git a/src/test/resources/bytecode/javFiles/Inherit.jav b/src/test/resources/bytecode/javFiles/Inherit.jav index 271c4edd..4f13c94e 100644 --- a/src/test/resources/bytecode/javFiles/Inherit.jav +++ b/src/test/resources/bytecode/javFiles/Inherit.jav @@ -1,29 +1,17 @@ -import java.lang.Integer; import java.util.Vector; -public class A { - m(Integer i) { } -} - -public class B extends A { } - -public class C extends B { - m(Integer i) { } -} - -public class D extends C { } - +import java.lang.Integer; public class Inherit { -/* + main(d, i) { - d.m(1); + d.m(i); } -*/ - + main(v, i) { var aa = v.elementAt(0); - aa.m(1); + aa.m(i); } + } \ No newline at end of file