PyLucene 3.4.0-1 import
[pylucene.git] / jcc / _jcc / java / lang / reflect / Field.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/Field.h"
21 #ifdef _java_generics
22 #include "java/lang/reflect/Type.h"
23 #endif
24
25 namespace java {
26     namespace lang {
27         namespace reflect {
28
29             enum {
30                 mid_getModifiers,
31                 mid_getType,
32                 mid_getName,
33 #ifdef _java_generics
34                 mid_getGenericType,
35 #endif
36                 max_mid
37             };
38
39             Class *Field::class$ = NULL;
40             jmethodID *Field::_mids = NULL;
41
42             jclass Field::initializeClass()
43             {
44                 if (!class$)
45                 {
46                     jclass cls = env->findClass("java/lang/reflect/Field");
47
48                     _mids = new jmethodID[max_mid];
49                     _mids[mid_getModifiers] =
50                         env->getMethodID(cls, "getModifiers",
51                                          "()I");
52                     _mids[mid_getType] =
53                         env->getMethodID(cls, "getType",
54                                          "()Ljava/lang/Class;");
55                     _mids[mid_getName] =
56                         env->getMethodID(cls, "getName",
57                                          "()Ljava/lang/String;");
58 #ifdef _java_generics
59                     _mids[mid_getGenericType] =
60                         env->getMethodID(cls, "getGenericType",
61                                          "()Ljava/lang/reflect/Type;");
62 #endif
63
64                     class$ = (Class *) new JObject(cls);
65                 }
66
67                 return (jclass) class$->this$;
68             }
69
70             int Field::getModifiers() const
71             {
72                 return env->callIntMethod(this$, _mids[mid_getModifiers]);
73             }
74
75             Class Field::getType() const
76             {
77                 return Class(env->callObjectMethod(this$, _mids[mid_getType]));
78             }
79
80             String Field::getName() const
81             {
82                 return String(env->callObjectMethod(this$, _mids[mid_getName]));
83             }
84
85 #ifdef _java_generics
86             Type Field::getGenericType() const
87             {
88                 return Type(env->callObjectMethod(this$, _mids[mid_getGenericType]));
89             }
90 #endif
91         }
92     }
93 }
94
95
96 #include "structmember.h"
97 #include "functions.h"
98 #include "macros.h"
99
100 namespace java {
101     namespace lang {
102         namespace reflect {
103
104             static PyObject *t_Field_getModifiers(t_Field *self);
105             static PyObject *t_Field_getType(t_Field *self);
106             static PyObject *t_Field_getName(t_Field *self);
107 #ifdef _java_generics
108             static PyObject *t_Field_getGenericType(t_Field *self);
109 #endif
110
111             static PyMethodDef t_Field__methods_[] = {
112                 DECLARE_METHOD(t_Field, getModifiers, METH_NOARGS),
113                 DECLARE_METHOD(t_Field, getType, METH_NOARGS),
114                 DECLARE_METHOD(t_Field, getName, METH_NOARGS),
115 #ifdef _java_generics
116                 DECLARE_METHOD(t_Field, getGenericType, METH_NOARGS),
117 #endif
118                 { NULL, NULL, 0, NULL }
119             };
120
121             DECLARE_TYPE(Field, t_Field, Object, Field,
122                          abstract_init, 0, 0, 0, 0, 0);
123
124             static PyObject *t_Field_getModifiers(t_Field *self)
125             {
126                 jint modifiers;
127
128                 OBJ_CALL(modifiers = self->object.getModifiers());
129                 return PyInt_FromLong(modifiers);
130             }
131
132             static PyObject *t_Field_getType(t_Field *self)
133             {
134                 Class cls((jobject) NULL);
135
136                 OBJ_CALL(cls = self->object.getType());
137                 return t_Class::wrap_Object(cls);
138             }
139
140             static PyObject *t_Field_getName(t_Field *self)
141             {
142                 String name((jobject) NULL);
143
144                 OBJ_CALL(name = self->object.getName());
145                 return j2p(name);
146             }
147
148 #ifdef _java_generics
149             static PyObject *t_Field_getGenericType(t_Field *self)
150             {
151                 Type result((jobject) NULL);
152                 OBJ_CALL(result = self->object.getGenericType());
153
154                 return t_Type::wrap_Object(result);
155             }
156 #endif
157         }
158     }
159 }