Statische Methoden Test

This commit is contained in:
Fayez Abu Alia 2018-04-18 11:51:10 +02:00
parent 52a96d7253
commit 478a2df3dc
5 changed files with 69 additions and 16 deletions

View File

@ -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;

View File

@ -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

View File

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

View File

@ -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;

View File

@ -0,0 +1,10 @@
public class StaticM {
public static void m() {
System.out.println("Test");
}
public static void m2() {
m();
}
}