From 478a2df3dccc5061d5fac024eb2f7b5ac4b16406 Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Wed, 18 Apr 2018 11:51:10 +0200 Subject: [PATCH] Statische Methoden Test --- .../dhbwstuttgart/bytecode/BytecodeGen.java | 6 +-- .../bytecode/BytecodeGenMethod.java | 4 +- test/bytecode/StaticTest.java | 41 +++++++++++++++++++ test/bytecode/javFiles/Op.jav | 24 +++++------ test/bytecode/javFiles/StaticM.jav | 10 +++++ 5 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 test/bytecode/StaticTest.java create mode 100644 test/bytecode/javFiles/StaticM.jav diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java index c7fbe36db..07bb7308f 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java @@ -170,7 +170,7 @@ public class BytecodeGen implements ASTVisitor { String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor()); String methParamTypes = retType+method.name+"%%"; method.getParameterList().accept(this); - + Iterator itr = method.getParameterList().iterator(); while(itr.hasNext()) { FormalParameter fp = itr.next(); @@ -186,7 +186,7 @@ public class BytecodeGen implements ASTVisitor { // Method getModifiers() ? int acc = isInterface?Opcodes.ACC_ABSTRACT:method.modifier; - + System.out.println(acc); boolean hasGenInParameterList = genericsAndBounds.containsKey(resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())); if(!hasGenInParameterList) { for(String paramName : methodParamsAndTypes.keySet()) { @@ -199,7 +199,7 @@ public class BytecodeGen implements ASTVisitor { } //TODO: Test if the return-type or any of the parameter is a parameterized type. (VP) - //than create the descriptor with the new syntax. + //then create the descriptor with the new syntax. String sig = null; boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList; diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index e5b24320d..aa7b586eb 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -786,7 +786,8 @@ public class BytecodeGenMethod implements StatementVisitor { // mv.visitMethodInsn(Opcodes.INVOKESTATIC, // staticClassName.getType().toString().replace(".", "/"), // staticClassName.toString(), staticClassName.getType().toString(), false); - mv.visitFieldInsn(Opcodes.GETSTATIC, getResolvedType(staticClassName.getType()), fieldName, fieldDesc); + //mv.visitFieldInsn(Opcodes.GETSTATIC, getResolvedType(staticClassName.getType()), fieldName, fieldDesc); + throw new NotImplementedException("Static noch nicht implementiert!"); } @Override @@ -814,6 +815,7 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(DoStmt whileStmt) { whileStmt.expr.accept(this); + // TODO: } @Override diff --git a/test/bytecode/StaticTest.java b/test/bytecode/StaticTest.java new file mode 100644 index 000000000..f639645cf --- /dev/null +++ b/test/bytecode/StaticTest.java @@ -0,0 +1,41 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; + +import org.junit.BeforeClass; +import org.junit.Test; + +import de.dhbwstuttgart.core.JavaTXCompiler; + +public class StaticTest { + + 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; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + path = System.getProperty("user.dir")+"/test/bytecode/javFiles/StaticM.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + compiler.generateBytecode(); + pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; + loader = new URLClassLoader(new URL[] {new URL("file://" + pathToClassFile)}); + classToTest = loader.loadClass("StaticM"); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + } + + @Test + public void test() { + fail("Not yet implemented"); + } + +} diff --git a/test/bytecode/javFiles/Op.jav b/test/bytecode/javFiles/Op.jav index 76e118028..4aa039d57 100644 --- a/test/bytecode/javFiles/Op.jav +++ b/test/bytecode/javFiles/Op.jav @@ -32,18 +32,18 @@ public class Op { // return c; // } - subInt(Integer a, Integer b) { - Integer c = a-b; - return c; - } - subLong(Long a, Long b) { - Long c = a-b; - return c; - } - subFloat(Float a, Float b) { - Float c = a-b; - return c; - } +// subInt(Integer a, Integer b) { +// Integer c = a-b; +// return c; +// } +// subLong(Long a, Long b) { +// Long c = a-b; +// return c; +// } +// subFloat(Float a, Float b) { +// Float c = a-b; +// return c; +// } // subDouble(Double a, Double b) { // Double c = a-b; // return c; diff --git a/test/bytecode/javFiles/StaticM.jav b/test/bytecode/javFiles/StaticM.jav new file mode 100644 index 000000000..668900338 --- /dev/null +++ b/test/bytecode/javFiles/StaticM.jav @@ -0,0 +1,10 @@ +public class StaticM { + + public static void m() { + System.out.println("Test"); + } + + public static void m2() { + m(); + } +} \ No newline at end of file