-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathJavaMaker.java
More file actions
68 lines (56 loc) · 2.24 KB
/
JavaMaker.java
File metadata and controls
68 lines (56 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) Corporation for National Research Initiatives
package org.python.compiler;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import org.python.core.PyObject;
public class JavaMaker extends ProxyMaker {
public String pythonClass, pythonModule;
PyObject methods;
public JavaMaker(Class<?> superclass,
Class<?>[] interfaces,
String pythonClass,
String pythonModule,
String myClass,
PyObject methods) {
super(myClass, superclass, interfaces);
this.pythonClass = pythonClass;
this.pythonModule = pythonModule;
this.methods = methods;
}
@Override
public void addConstructor(String name,
Class<?>[] parameters,
Class<?> ret,
String sig,
int access) throws Exception {
/* Need a fancy constructor for the Java side of things */
Code code = classfile.addMethod("<init>", sig, access);
callSuper(code, "<init>", name, parameters, Void.TYPE, false);
callInitProxy(parameters, code);
}
@Override
public void addProxy() throws Exception {
if (methods != null)
super.addProxy();
// _initProxy method
Code code = classfile.addMethod("__initProxy__", makeSig("V", $objArr), Modifier.PUBLIC);
code.visitVarInsn(ALOAD, 0);
code.visitLdcInsn(pythonModule);
code.visitLdcInsn(pythonClass);
code.visitVarInsn(ALOAD, 1);
code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "initProxy",
makeSig("V", $pyProxy, $str, $str, $objArr), false);
code.visitInsn(RETURN);
}
@Override
public void addMethod(Method method, int access) throws Exception {
if (Modifier.isAbstract(access)) {
// Maybe throw an exception here???
super.addMethod(method, access);
} else if (methods.__finditem__(method.getName().intern()) != null) {
super.addMethod(method, access);
} else if (Modifier.isProtected(method.getModifiers())) {
addSuperMethod(method, access);
}
}
}