Statische Methoden Test
This commit is contained in:
parent
52a96d7253
commit
478a2df3dc
@ -170,7 +170,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
String methParamTypes = retType+method.name+"%%";
|
String methParamTypes = retType+method.name+"%%";
|
||||||
method.getParameterList().accept(this);
|
method.getParameterList().accept(this);
|
||||||
|
|
||||||
Iterator<FormalParameter> itr = method.getParameterList().iterator();
|
Iterator<FormalParameter> itr = method.getParameterList().iterator();
|
||||||
while(itr.hasNext()) {
|
while(itr.hasNext()) {
|
||||||
FormalParameter fp = itr.next();
|
FormalParameter fp = itr.next();
|
||||||
@ -186,7 +186,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
// Method getModifiers() ?
|
// Method getModifiers() ?
|
||||||
int acc = isInterface?Opcodes.ACC_ABSTRACT:method.modifier;
|
int acc = isInterface?Opcodes.ACC_ABSTRACT:method.modifier;
|
||||||
|
System.out.println(acc);
|
||||||
boolean hasGenInParameterList = genericsAndBounds.containsKey(resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
boolean hasGenInParameterList = genericsAndBounds.containsKey(resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
||||||
if(!hasGenInParameterList) {
|
if(!hasGenInParameterList) {
|
||||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
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)
|
//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;
|
String sig = null;
|
||||||
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
||||||
|
@ -786,7 +786,8 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
// mv.visitMethodInsn(Opcodes.INVOKESTATIC,
|
// mv.visitMethodInsn(Opcodes.INVOKESTATIC,
|
||||||
// staticClassName.getType().toString().replace(".", "/"),
|
// staticClassName.getType().toString().replace(".", "/"),
|
||||||
// staticClassName.toString(), staticClassName.getType().toString(), false);
|
// 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
|
@Override
|
||||||
@ -814,6 +815,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(DoStmt whileStmt) {
|
public void visit(DoStmt whileStmt) {
|
||||||
whileStmt.expr.accept(this);
|
whileStmt.expr.accept(this);
|
||||||
|
// TODO:
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
41
test/bytecode/StaticTest.java
Normal file
41
test/bytecode/StaticTest.java
Normal 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -32,18 +32,18 @@ public class Op {
|
|||||||
// return c;
|
// return c;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
subInt(Integer a, Integer b) {
|
// subInt(Integer a, Integer b) {
|
||||||
Integer c = a-b;
|
// Integer c = a-b;
|
||||||
return c;
|
// return c;
|
||||||
}
|
// }
|
||||||
subLong(Long a, Long b) {
|
// subLong(Long a, Long b) {
|
||||||
Long c = a-b;
|
// Long c = a-b;
|
||||||
return c;
|
// return c;
|
||||||
}
|
// }
|
||||||
subFloat(Float a, Float b) {
|
// subFloat(Float a, Float b) {
|
||||||
Float c = a-b;
|
// Float c = a-b;
|
||||||
return c;
|
// return c;
|
||||||
}
|
// }
|
||||||
// subDouble(Double a, Double b) {
|
// subDouble(Double a, Double b) {
|
||||||
// Double c = a-b;
|
// Double c = a-b;
|
||||||
// return c;
|
// return c;
|
||||||
|
10
test/bytecode/javFiles/StaticM.jav
Normal file
10
test/bytecode/javFiles/StaticM.jav
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
public class StaticM {
|
||||||
|
|
||||||
|
public static void m() {
|
||||||
|
System.out.println("Test");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void m2() {
|
||||||
|
m();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user