-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathPyBuiltinMethod.java
More file actions
64 lines (52 loc) · 1.69 KB
/
Copy pathPyBuiltinMethod.java
File metadata and controls
64 lines (52 loc) · 1.69 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
package org.python.core;
import org.python.expose.ExposeAsSuperclass;
public abstract class PyBuiltinMethod extends PyBuiltinCallable implements ExposeAsSuperclass,
Cloneable, Traverseproc {
protected PyObject self;
protected PyBuiltinMethod(PyType type, PyObject self, Info info) {
super(type, info);
this.self = self;
}
protected PyBuiltinMethod(PyObject self, Info info) {
super(info);
this.self = self;
}
protected PyBuiltinMethod(String name) {
this(null, new DefaultInfo(name));
}
@Override
public PyBuiltinCallable bind(PyObject bindTo) {
if(self == null) {
PyBuiltinMethod bindable;
try {
bindable = (PyBuiltinMethod)clone();
} catch(CloneNotSupportedException e) {
throw new RuntimeException("Didn't expect PyBuiltinMethodto throw " +
"CloneNotSupported since it implements Cloneable", e);
}
bindable.self = bindTo;
return bindable;
}
return this;
}
public PyObject getSelf(){
return self;
}
public PyMethodDescr makeDescriptor(PyType t) {
return new PyMethodDescr(t, this);
}
@Override
public int hashCode() {
int hashCode = self == null ? 0 : self.hashCode();
return hashCode ^ getClass().hashCode();
}
/* Traverseproc implementation */
@Override
public int traverse(Visitproc visit, Object arg) {
return self != null ? visit.visit(self, arg) : 0;
}
@Override
public boolean refersDirectlyTo(PyObject ob) {
return ob != null && ob == self;
}
}