-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathCustomMaker.java
More file actions
49 lines (43 loc) · 1.71 KB
/
CustomMaker.java
File metadata and controls
49 lines (43 loc) · 1.71 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
package org.python.compiler;
import org.python.core.BytecodeLoader;
import org.python.core.Py;
import org.python.core.PyObject;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Arrays;
public class CustomMaker extends JavaMaker {
public CustomMaker(Class<?> superclass,
Class<?>[] interfaces,
String pythonClass,
String pythonModule,
String myClass,
PyObject methods) {
super(superclass, interfaces, pythonClass, pythonModule, myClass, methods);
}
// Override to save bytes
public void saveBytes(ByteArrayOutputStream bytes) {
}
// By default makeClass will have the same behavior as MakeProxies calling JavaMaker,
// other than the debug behavior of saving the classfile (as controlled by
// Options.ProxyDebugDirectory; users of CustomMaker simply need to save it themselves).
//
// Override this method to get custom classes built from any desired source.
public Class<?> makeClass() {
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
build(bytes); // Side effect of writing to bytes
saveBytes(bytes);
List<Class<?>> secondary = new LinkedList(Arrays.asList(interfaces));
List<Class<?>> referents = null;
if (superclass != null) {
secondary.add(0, superclass);
}
referents = secondary;
return BytecodeLoader.makeClass(myClass, referents, bytes.toByteArray());
} catch (Exception exc) {
throw Py.JavaError(exc);
}
}
}