Configured build for Ubuntu and added Stempel polish analyzer
[pylucene.git] / jcc / _jcc / java / lang / Throwable.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/Object.h"
18 #include "java/lang/Class.h"
19 #include "java/lang/String.h"
20 #include "java/lang/Throwable.h"
21 #include "java/io/PrintWriter.h"
22
23 namespace java {
24     namespace lang {
25
26         enum {
27             mid_printStackTrace_0,
28             mid_printStackTrace_1,
29             mid_getMessage,
30             max_mid
31         };
32
33         Class *Throwable::class$ = NULL;
34         jmethodID *Throwable::_mids = NULL;
35
36         jclass Throwable::initializeClass()
37         {
38             if (!class$)
39             {
40                 jclass cls = env->findClass("java/lang/Throwable");
41
42                 _mids = new jmethodID[max_mid];
43                 _mids[mid_printStackTrace_0] = 
44                     env->getMethodID(cls, "printStackTrace",
45                                      "()V");
46                 _mids[mid_printStackTrace_1] = 
47                     env->getMethodID(cls, "printStackTrace",
48                                      "(Ljava/io/PrintWriter;)V");
49                 _mids[mid_getMessage] = 
50                     env->getMethodID(cls, "getMessage",
51                                      "()Ljava/lang/String;");
52
53                 class$ = (Class *) new JObject(cls);
54             }
55
56             return (jclass) class$->this$;
57         }
58
59         void Throwable::printStackTrace() const
60         {
61             env->callVoidMethod(this$, _mids[mid_printStackTrace_0]);
62         }
63         
64         void Throwable::printStackTrace(java::io::PrintWriter writer) const
65         {
66             env->callVoidMethod(this$, _mids[mid_printStackTrace_1],
67                                 writer.this$);
68         }
69         
70         String Throwable::getMessage() const
71         {
72             return String(env->callObjectMethod(this$, _mids[mid_getMessage]));
73         }
74     }
75 }
76
77
78 #include "structmember.h"
79 #include "functions.h"
80 #include "macros.h"
81
82 namespace java {
83     namespace lang {
84
85         static PyObject *t_Throwable_printStackTrace(t_Throwable *self,
86                                                      PyObject *args);
87
88         static PyMethodDef t_Throwable__methods_[] = {
89             DECLARE_METHOD(t_Throwable, printStackTrace, METH_VARARGS),
90             { NULL, NULL, 0, NULL }
91         };
92
93         DECLARE_TYPE(Throwable, t_Throwable, Object, Throwable,
94                      abstract_init, 0, 0, 0, 0, 0);
95
96         static PyObject *t_Throwable_printStackTrace(t_Throwable *self,
97                                                      PyObject *args)
98         {
99             switch (PyTuple_Size(args)) {
100               case 0:
101                 OBJ_CALL(self->object.printStackTrace());
102                 Py_RETURN_NONE;
103               case 1:
104               {
105                   java::io::PrintWriter writer((jobject) NULL);
106
107                   if (!parseArgs(args, "j", java::io::PrintWriter::class$,
108                                  &writer))
109                   {
110                       OBJ_CALL(self->object.printStackTrace(writer));
111                       Py_RETURN_NONE;
112                   }
113               }
114               default:
115                 PyErr_SetString(PyExc_ValueError, "invalid args");
116                 return NULL;
117             }
118         }
119     }
120 }