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
6 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "java/lang/Object.h"
19 #include "java/lang/Class.h"
20 #include "java/lang/String.h"
33 Class *Object::class$ = NULL;
34 jmethodID *Object::mids$ = NULL;
36 jclass Object::initializeClass()
40 jclass cls = env->findClass("java/lang/Object");
42 mids$ = new jmethodID[max_mid];
43 mids$[mid__init_] = env->getMethodID(cls, "<init>",
45 mids$[mid_toString] = env->getMethodID(cls, "toString",
46 "()Ljava/lang/String;");
47 mids$[mid_getClass] = env->getMethodID(cls, "getClass",
48 "()Ljava/lang/Class;");
49 mids$[mid_hashCode] = env->getMethodID(cls, "hashCode",
51 mids$[mid_equals] = env->getMethodID(cls, "equals",
52 "(Ljava/lang/Object;)Z");
54 class$ = (Class *) new JObject(cls);
57 return (jclass) class$->this$;
60 Object::Object() : JObject(env->newObject(initializeClass, &mids$, mid__init_)) {
63 String Object::toString() const
65 return String(env->callObjectMethod(this$, mids$[mid_toString]));
68 Class Object::getClass() const
70 return Class(env->callObjectMethod(this$, mids$[mid_getClass]));
73 int Object::hashCode() const
75 return env->callIntMethod(this$, mids$[mid_hashCode]);
78 jboolean Object::equals(const Object& a0) const
80 return env->callBooleanMethod(this$, mids$[mid_equals], a0.this$);
86 #include "structmember.h"
87 #include "functions.h"
93 static int t_Object_init(t_Object *self,
94 PyObject *args, PyObject *kwds);
95 static PyObject *t_Object_getClass(t_Object *self);
96 static PyObject *t_Object_equals(t_Object *self, PyObject *arg);
98 static PyMethodDef t_Object__methods_[] = {
99 DECLARE_METHOD(t_Object, getClass, METH_NOARGS),
100 DECLARE_METHOD(t_Object, equals, METH_O),
101 { NULL, NULL, 0, NULL }
104 DECLARE_TYPE(Object, t_Object, JObject, java::lang::Object,
105 t_Object_init, 0, 0, 0, 0, 0);
107 static int t_Object_init(t_Object *self,
108 PyObject *args, PyObject *kwds)
110 switch (PyTuple_Size(args)) {
112 INT_CALL(self->object = Object());
115 PyErr_SetString(PyExc_ValueError, "invalid args");
122 static PyObject *t_Object_getClass(t_Object *self)
124 Class cls((jobject) NULL);
126 OBJ_CALL(cls = self->object.getClass());
127 return t_Class::wrap_Object(cls);
130 static PyObject *t_Object_equals(t_Object *self, PyObject *arg)
132 Object a0((jobject) NULL);
135 if (!parseArg(arg, "o", &a0))
137 OBJ_CALL(result = self->object.equals(a0));
138 Py_RETURN_BOOL(result);
141 PyErr_SetArgsError((PyObject *) self, "equals", arg);