File: SimpleExposed.java

package info (click to toggle)
jython 2.5.3-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 43,304 kB
  • sloc: python: 351,314; java: 216,338; xml: 1,547; sh: 330; perl: 124; ansic: 102; makefile: 101
file content (181 lines) | stat: -rw-r--r-- 4,621 bytes parent folder | download | duplicates (7)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package org.python.expose.generate;

import org.python.core.Py;
import org.python.core.PyInteger;
import org.python.core.PyNewWrapper;
import org.python.core.PyObject;
import org.python.core.PyType;
import org.python.core.ThreadState;
import org.python.expose.ExposedClassMethod;
import org.python.expose.ExposedDelete;
import org.python.expose.ExposedGet;
import org.python.expose.ExposedMethod;
import org.python.expose.ExposedNew;
import org.python.expose.ExposedSet;
import org.python.expose.ExposedType;
import org.python.expose.MethodType;

@ExposedType(name = "simpleexposed", isBaseType = false, doc = "Docstring")
public class SimpleExposed extends PyObject {

    public void method() {}

    public int timesCalled;

    @ExposedNew
    public static PyObject __new__(PyNewWrapper new_,
                                   boolean init,
                                   PyType subtype,
                                   PyObject[] args,
                                   String[] keywords) {
        return Py.One;
    }

    @ExposedMethod
    void invisible() {}

    @ExposedMethod
    public void simple_method() {
        timesCalled++;
    }

    @ExposedMethod
    public void simpleexposed_prefixed() {}

    @ExposedMethod
    public boolean __nonzero__() {
        return false;
    }

    @ExposedMethod(names = {"__repr__", "__str__"})
    public String toString() {
        return toStringVal;
    }

    @ExposedSet(name = "tostring")
    public void setToString(String newVal) {
        toStringVal = newVal;
    }

    @ExposedDelete(name = "tostring")
    public void deleteToString() {
        toStringVal = null;
    }

    @ExposedMethod
    public double takesArgument(PyObject arg) {
        return Py.py2double(arg);
    }

    @ExposedMethod(type = MethodType.BINARY)
    public PyObject __add__(PyObject arg) {
        if(arg == Py.False) {
            return Py.One;
        }
        return null;
    }

    @ExposedMethod(type = MethodType.CMP)
    public int __cmp__(PyObject other) {
        if(other == Py.False) {
            return 1;
        }
        return -2;
    }

    @ExposedMethod(defaults = "Py.None")
    public PyObject defaultToNone(PyObject arg) {
        return arg;
    }

    @ExposedMethod(defaults = "null")
    public PyObject defaultToNull(PyObject arg) {
        return arg;
    }

    @ExposedMethod(defaults = "1")
    public PyObject defaultToOne(int arg) {
        return new PyInteger(arg);
    }

    @ExposedMethod(defaults = {"a", "1", "2", "3"})
    public String manyPrimitives(char c, short s, double d, byte b) {
        return "" + c + s + d + b;
    }

    @ExposedMethod
    public long fullArgs(PyObject[] args, String[] kws) {
        return args.length + kws.length;
    }

    @ExposedMethod
    public short shortReturn() {
        return 12;
    }

    @ExposedMethod
    public byte byteReturn() {
        return 0;
    }

    @ExposedMethod
    public char charReturn() {
        return 'a';
    }

    @ExposedMethod
    public String stringReturnNull() {
        return null;
    }

    @ExposedClassMethod 
    public static char classmethod(PyType onType) {
        return 'a';
    }

    @ExposedClassMethod(defaults = {"null", "Py.None"})
    public static int defaultsclassmethod(PyType onType, String possiblyNull, PyObject possiblyNone) {
        if (possiblyNull == null) {
            return 0;
        } else if (possiblyNull.equals("hello")) {
            return 1;
        } else if (possiblyNone.equals(Py.None)) {
            return 2;
        } else {
            return 3;
        }
    }

    @ExposedGet(name = "tostring", doc = "tostring docs")
    public String toStringVal = TO_STRING_RETURN;

    public static final String TO_STRING_RETURN = "A simple test class";

    @ExposedMethod
    public String needsThreadState(ThreadState state, String s) {
        return needsThreadStateClass(state, null, s, null);
    }

    @ExposedMethod
    public int needsThreadStateWide(ThreadState state, PyObject[] args, String[] kws) {
        if (state == null) {
            return -1;
        }
        return args.length + kws.length;
    }

    @ExposedClassMethod(defaults = {"null"})
    public static String needsThreadStateClass(ThreadState state, PyType onType, String s,
                                               String possiblyNull) {
        if (state != null) {
            s += " got state " + state.hashCode();
        }
        if (onType != null) {
            s += " got type";
        }
        if (possiblyNull != null) {
            s += possiblyNull;
        }
        return s;
    }
}