Configured build for Ubuntu and added Stempel polish analyzer
[pylucene.git] / jcc / _jcc / java / lang / reflect / Modifier.cpp
1 /*
2  *   Licensed under the Apache License, Version 2.0 (the "License");
3  *   you may not use this file except in compliance with the License.
4  *   You may obtain a copy of the License at
5  *
6  *       http://www.apache.org/licenses/LICENSE-2.0
7  *
8  *   Unless required by applicable law or agreed to in writing, software
9  *   distributed under the License is distributed on an "AS IS" BASIS,
10  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  *   See the License for the specific language governing permissions and
12  *   limitations under the License.
13  */
14
15 #include <jni.h>
16 #include "JCCEnv.h"
17 #include "java/lang/Class.h"
18 #include "java/lang/Object.h"
19 #include "java/lang/String.h"
20 #include "java/lang/reflect/Modifier.h"
21
22 namespace java {
23     namespace lang {
24         namespace reflect {
25
26             enum {
27                 mid_isPublic,
28                 mid_isStatic,
29                 mid_isNative,
30                 mid_isFinal,
31                 mid_isAbstract,
32                 mid_isPrivate,
33                 mid_isProtected,
34                 max_mid
35             };
36
37             Class *Modifier::class$ = NULL;
38             jmethodID *Modifier::_mids = NULL;
39
40             jclass Modifier::initializeClass()
41             {
42                 if (!class$)
43                 {
44                     jclass cls = env->findClass("java/lang/reflect/Modifier");
45
46                     _mids = new jmethodID[max_mid];
47                     _mids[mid_isPublic] =
48                         env->getStaticMethodID(cls, "isPublic",
49                                                "(I)Z");
50                     _mids[mid_isStatic] =
51                         env->getStaticMethodID(cls, "isStatic",
52                                                "(I)Z");
53                     _mids[mid_isNative] =
54                         env->getStaticMethodID(cls, "isNative",
55                                                "(I)Z");
56                     _mids[mid_isFinal] =
57                         env->getStaticMethodID(cls, "isFinal",
58                                                "(I)Z");
59                     _mids[mid_isAbstract] =
60                         env->getStaticMethodID(cls, "isAbstract",
61                                                "(I)Z");
62                     _mids[mid_isPrivate] =
63                         env->getStaticMethodID(cls, "isPrivate",
64                                                "(I)Z");
65                     _mids[mid_isProtected] =
66                         env->getStaticMethodID(cls, "isProtected",
67                                                "(I)Z");
68
69                     class$ = (Class *) new JObject(cls);
70                 }
71                 
72                 return (jclass) class$->this$;
73             }
74
75             int Modifier::isPublic(int mod)
76             {
77                 jclass cls = initializeClass();
78                 return (int) env->callStaticBooleanMethod(cls, _mids[mid_isPublic], mod);
79             }
80
81             int Modifier::isStatic(int mod)
82             {
83                 jclass cls = initializeClass();
84                 return (int) env->callStaticBooleanMethod(cls, _mids[mid_isStatic], mod);
85             }
86
87             int Modifier::isNative(int mod)
88             {
89                 jclass cls = initializeClass();
90                 return (int) env->callStaticBooleanMethod(cls, _mids[mid_isNative], mod);
91             }
92
93             int Modifier::isFinal(int mod)
94             {
95                 jclass cls = initializeClass();
96                 return (int) env->callStaticBooleanMethod(cls, _mids[mid_isFinal], mod);
97             }
98
99             int Modifier::isAbstract(int mod)
100             {
101                 jclass cls = initializeClass();
102                 return (int) env->callStaticBooleanMethod(cls, _mids[mid_isAbstract], mod);
103             }
104
105             int Modifier::isPrivate(int mod)
106             {
107                 jclass cls = initializeClass();
108                 return (int) env->callStaticBooleanMethod(cls, _mids[mid_isPrivate], mod);
109             }
110
111             int Modifier::isProtected(int mod)
112             {
113                 jclass cls = initializeClass();
114                 return (int) env->callStaticBooleanMethod(cls, _mids[mid_isProtected], mod);
115             }
116         }
117     }
118 }
119
120
121 #include "structmember.h"
122 #include "functions.h"
123 #include "macros.h"
124
125 namespace java {
126     namespace lang {
127         namespace reflect {
128
129             static PyObject *t_Modifier_isPublic(PyTypeObject *type, PyObject *arg);
130             static PyObject *t_Modifier_isStatic(PyTypeObject *type, PyObject *arg);
131             static PyObject *t_Modifier_isNative(PyTypeObject *type, PyObject *arg);
132             static PyObject *t_Modifier_isFinal(PyTypeObject *type, PyObject *arg);
133             static PyObject *t_Modifier_isAbstract(PyTypeObject *type, PyObject *arg);
134             static PyObject *t_Modifier_isPrivate(PyTypeObject *type, PyObject *arg);
135             static PyObject *t_Modifier_isProtected(PyTypeObject *type, PyObject *arg);
136
137             static PyMethodDef t_Modifier__methods_[] = {
138                 DECLARE_METHOD(t_Modifier, isPublic, METH_O | METH_CLASS),
139                 DECLARE_METHOD(t_Modifier, isStatic, METH_O | METH_CLASS),
140                 DECLARE_METHOD(t_Modifier, isNative, METH_O | METH_CLASS),
141                 DECLARE_METHOD(t_Modifier, isFinal, METH_O | METH_CLASS),
142                 DECLARE_METHOD(t_Modifier, isAbstract, METH_O | METH_CLASS),
143                 DECLARE_METHOD(t_Modifier, isPrivate, METH_O | METH_CLASS),
144                 DECLARE_METHOD(t_Modifier, isProtected, METH_O | METH_CLASS),
145                 { NULL, NULL, 0, NULL }
146             };
147
148             DECLARE_TYPE(Modifier, t_Modifier, Object, Modifier,
149                          abstract_init, 0, 0, 0, 0, 0);
150
151             static PyObject *t_Modifier_isPublic(PyTypeObject *type, PyObject *arg)
152             {
153                 if (!PyInt_Check(arg))
154                 {
155                     PyErr_SetObject(PyExc_TypeError, arg);
156                     return NULL;
157                 }
158
159                 int mod = PyInt_AsLong(arg);
160                 int isPublic;
161
162                 OBJ_CALL(isPublic = Modifier::isPublic(mod));
163                 Py_RETURN_BOOL(isPublic);
164             }
165
166             static PyObject *t_Modifier_isStatic(PyTypeObject *type, PyObject *arg)
167             {
168                 if (!PyInt_Check(arg))
169                 {
170                     PyErr_SetObject(PyExc_TypeError, arg);
171                     return NULL;
172                 }
173
174                 int mod = PyInt_AsLong(arg);
175                 int isStatic;
176
177                 OBJ_CALL(isStatic = Modifier::isStatic(mod));
178                 Py_RETURN_BOOL(isStatic);
179             }
180
181             static PyObject *t_Modifier_isNative(PyTypeObject *type, PyObject *arg)
182             {
183                 if (!PyInt_Check(arg))
184                 {
185                     PyErr_SetObject(PyExc_TypeError, arg);
186                     return NULL;
187                 }
188
189                 int mod = PyInt_AsLong(arg);
190                 int isNative;
191
192                 OBJ_CALL(isNative = Modifier::isNative(mod));
193                 Py_RETURN_BOOL(isNative);
194             }
195
196             static PyObject *t_Modifier_isFinal(PyTypeObject *type, PyObject *arg)
197             {
198                 if (!PyInt_Check(arg))
199                 {
200                     PyErr_SetObject(PyExc_TypeError, arg);
201                     return NULL;
202                 }
203
204                 int mod = PyInt_AsLong(arg);
205                 int isFinal;
206
207                 OBJ_CALL(isFinal = Modifier::isFinal(mod));
208                 Py_RETURN_BOOL(isFinal);
209             }
210
211             static PyObject *t_Modifier_isAbstract(PyTypeObject *type, PyObject *arg)
212             {
213                 if (!PyInt_Check(arg))
214                 {
215                     PyErr_SetObject(PyExc_TypeError, arg);
216                     return NULL;
217                 }
218
219                 int mod = PyInt_AsLong(arg);
220                 int isAbstract;
221
222                 OBJ_CALL(isAbstract = Modifier::isAbstract(mod));
223                 Py_RETURN_BOOL(isAbstract);
224             }
225
226             static PyObject *t_Modifier_isPrivate(PyTypeObject *type, PyObject *arg)
227             {
228                 if (!PyInt_Check(arg))
229                 {
230                     PyErr_SetObject(PyExc_TypeError, arg);
231                     return NULL;
232                 }
233
234                 int mod = PyInt_AsLong(arg);
235                 int isPrivate;
236
237                 OBJ_CALL(isPrivate = Modifier::isPrivate(mod));
238                 Py_RETURN_BOOL(isPrivate);
239             }
240
241             static PyObject *t_Modifier_isProtected(PyTypeObject *type, PyObject *arg)
242             {
243                 if (!PyInt_Check(arg))
244                 {
245                     PyErr_SetObject(PyExc_TypeError, arg);
246                     return NULL;
247                 }
248
249                 int mod = PyInt_AsLong(arg);
250                 int isProtected;
251
252                 OBJ_CALL(isProtected = Modifier::isProtected(mod));
253                 Py_RETURN_BOOL(isProtected);
254             }
255         }
256     }
257 }