-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathPyBuiltinMethod.java
More file actions
86 lines (72 loc) · 2.35 KB
/
PyBuiltinMethod.java
File metadata and controls
86 lines (72 loc) · 2.35 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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();
}
@Override
public int __cmp__(PyObject other) {
if (!(other instanceof PyBuiltinMethod)) {
return -2;
}
PyBuiltinMethod otherMethod = (PyBuiltinMethod)other;
if (self != otherMethod.self) {
if (self == null) {
return -1;
} else if (otherMethod.self == null) {
return 1;
}
return self._cmp(otherMethod.self);
}
if (getClass() == otherMethod.getClass()) {
return 0;
}
int compareTo = info.getName().compareTo(otherMethod.info.getName());
return compareTo < 0 ? -1 : compareTo > 0 ? 1 : 0;
}
/* 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;
}
}