Bug 122 gefixt. MatrixTest und OLTest funktionieren

This commit is contained in:
Fayez Abu Alia 2018-11-14 12:11:03 +01:00
parent d27e0af57c
commit 0ceae1ebb7

View File

@ -677,7 +677,8 @@ public class BytecodeGenMethod implements StatementVisitor {
ClassLoader cLoader2;
java.lang.reflect.Method methodRefl = null;
String clazz = receiverName.replace("/", ".");
String methCallType = resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor());
String[] typesOfParams = getTypes(methodCall.arglist.getArguments());
try {
if(receiverName.contains("<")) {
clazz = clazz.substring(0, receiverName.indexOf("<"));
@ -688,15 +689,15 @@ public class BytecodeGenMethod implements StatementVisitor {
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methods);
} catch (Exception e) {
try {
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
System.out.println("Methods of " + receiverName + " ");
for(int i = 0; i<methods.length; i++) {
System.out.println(methods[i]);
}
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methods);
}catch (Exception e2) {
// try {
// cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
// java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
// System.out.println("Methods of " + receiverName + " ");
// for(int i = 0; i<methods.length; i++) {
// System.out.println(methods[i]);
// }
// methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
// }catch (Exception e2) {
String superClass = "";
// TODO: Test SubMatrix.jav
while(true) {
@ -732,9 +733,23 @@ public class BytecodeGenMethod implements StatementVisitor {
continue;
}
}
}
// }
}
if(methodRefl == null) {
try {
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
System.out.println("Methods of " + receiverName + " ");
for(int i = 0; i<methods.length; i++) {
System.out.println(methods[i]);
}
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
}catch (Exception e2) {
e2.printStackTrace();
}
}
methodCall.receiver.accept(this);
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
@ -795,9 +810,19 @@ public class BytecodeGenMethod implements StatementVisitor {
}
private String[] getTypes(List<Expression> arguments) {
String[] types = new String[arguments.size()];
for(int i = 0; i<arguments.size(); ++i) {
String t = getResolvedType(arguments.get(i).getType());
types[i] = t;
}
return types;
}
/**
* For API methods
* @param name name of a method
* @param i number of parameters
* @param i number of parameters
* @param methods all methods of a class
* @return the method in the class file which its name equals the given methode name
*/
@ -809,6 +834,38 @@ public class BytecodeGenMethod implements StatementVisitor {
}
return null;
}
/**
* @param name name of a method
* @param i number of parameters
* @param methCallType return type of method
* @param typesOfParams
* @param methods all methods of a class
* @return the method in the class file which its name equals the given methode name
*/
private java.lang.reflect.Method getMethod(String name, int i, String methCallType, String[] typesOfParams, java.lang.reflect.Method[] methods) {
// if(methCallType.equals("void")) {
// methCallType = "V";
// } else {
// methCallType = "L"+methCallType+";";
// }
for(java.lang.reflect.Method m : methods) {
if(name.equals(m.getName()) && i == m.getParameterCount() && methCallType.equals(m.getReturnType().getName().replace(".", "/"))) {
boolean typesEqual = true;
Class<?>[] pTypes = m.getParameterTypes();
for(int j = 0; j<typesOfParams.length; ++j) {
if(!typesOfParams[j].equals(pTypes[j])) {
typesEqual = false;
break;
}
}
if(typesEqual)
return m;
}
}
return null;
}
private String getMethodDesc(java.lang.reflect.Method methodRefl) {
StringBuilder sb = new StringBuilder("(");