Debian Codegraph @

native/common/include/jp_class.h

raw symbols SCIP
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 See NOTICE file for details.
15 *****************************************************************************/
16 #ifndef _JP_CLASS_H_
17 #define _JP_CLASS_H_
18
19 #include "jp_modifier.h"
20
21 class JPClass : public JPResource
22 {
23 public:
24 // Special entry point for JVM independent entities
25 JPClass(const string& name, jint modifiers);
26 JPClass(JPJavaFrame& context,
27 jclass clss,
28 const string& name,
29 JPClass* super,
30 const JPClassList& interfaces,
31 jint modifiers);
32 ~JPClass() override;
33
34 void setHost(PyObject* host);
35
36 PyTypeObject* getHost()
37 {
38 return (PyTypeObject*) m_Host.get();
39 }
40
41 void setHints(PyObject* host);
42
43 PyObject* getHints();
44
45 public:
46 void ensureMembers(JPJavaFrame& frame);
47
48 jclass getJavaClass() const;
49
50 void assignMembers(JPMethodDispatch* ctor,
51 JPMethodDispatchList& methods,
52 JPFieldList& fields);
53
54 string toString() const;
55
56 string getCanonicalName() const
57 {
58 return m_CanonicalName;
59 }
60
61 string getName() const;
62
63 bool isAbstract() const
64 {
65 return JPModifier::isAbstract(m_Modifiers);
66 }
67
68 bool isFinal() const
69 {
70 return JPModifier::isFinal(m_Modifiers);
71 }
72
73 bool isThrowable() const
74 {
75 return JPModifier::isThrowable(m_Modifiers);
76 }
77
78 bool isInterface() const
79 {
80 return JPModifier::isInterface(m_Modifiers);
81 }
82
83 virtual bool isArray() const
84 {
85 return false;
86 }
87
88 jlong getModifiers()
89 {
90 return m_Modifiers;
91 }
92
93 virtual bool isPrimitive() const
94 {
95 return false;
96 }
97
98 virtual bool isPrimitiveArray() const
99 {
100 return JPModifier::isPrimitiveArray(m_Modifiers);
101 }
102
103 JPMethodDispatch* getCtor()
104 {
105 return m_Constructors;
106 }
107
108 const JPMethodDispatchList& getMethods()
109 {
110 return m_Methods;
111 }
112
113 const JPFieldList& getFields()
114 {
115 return m_Fields;
116 }
117
118 /**
119 * Determine if a Python object will convert to this java type.
120 *
121 * This is used to determine which overload is the best match.
122 *
123 * @param pyobj is the Python object.
124 * @return the quality of the match
125 */
126 virtual JPMatch::Type findJavaConversion(JPMatch& match);
127
128 virtual void getConversionInfo(JPConversionInfo &info);
129
130 /** Create a new Python object to wrap a Java value.
131 *
132 * Some conversion convert to a Python type such as Java boolean and char.
133 * Null pointers match to Python None. Objects convert automatically to
134 * the most derived type. To disable this behavior the cast option can be
135 * specified.
136 *
137 * @param cast force the wrapper to be the defined type.
138 * @return a new Python object.
139 */
140 virtual JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast);
141
142 /**
143 * Get the Java value representing as an object.
144 *
145 * This will unbox if the type is a primitive.
146 *
147 * @return a java value with class.
148 */
149 virtual JPValue getValueFromObject(JPJavaFrame& frame, const JPValue& obj);
150
151 /**
152 * Call a static method that returns this type of object.
153 */
154 virtual JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*);
155
156 /**
157 * Call a method that returns this type of object.
158 */
159 virtual JPPyObject invoke(JPJavaFrame& frame, jobject, jclass clazz, jmethodID, jvalue*);
160
161 /**
162 * Get a static field that returns this type.
163 *
164 * @param frame is the frame to hold the local reference.
165 * @param cls is the class holding the static field.
166 * @param fid is the field id.
167 * @return
168 */
169 virtual JPPyObject getStaticField(JPJavaFrame& frame, jclass cls, jfieldID fid);
170 virtual void setStaticField(JPJavaFrame& frame, jclass cls, jfieldID fid, PyObject* val);
171
172 virtual JPPyObject getField(JPJavaFrame& frame, jobject obj, jfieldID fid);
173 virtual void setField(JPJavaFrame& frame, jobject obj, jfieldID fid, PyObject* val);
174
175 JPClass* newArrayType(JPJavaFrame &frame, long d);
176 virtual jarray newArrayOf(JPJavaFrame& frame, jsize size);
177 virtual void setArrayRange(JPJavaFrame& frame, jarray,
178 jsize start, jsize length, jsize step, PyObject* vals);
179 virtual JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx);
180 virtual void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val);
181
182 /**
183 * Expose IsAssignableFrom to python.
184 */
185 virtual bool isAssignableFrom(JPJavaFrame& frame, JPClass* o);
186
187 // Object properties
188
189 JPClass* getSuperClass()
190 {
191 return m_SuperClass;
192 }
193
194 virtual JPValue newInstance(JPJavaFrame& frame, JPPyObjectVector& args);
195
196 const JPClassList& getInterfaces()
197 {
198 return m_Interfaces;
199 }
200
201 protected:
202 JPClassRef m_Class;
203 JPClass* m_SuperClass;
204 JPClassList m_Interfaces;
205 JPMethodDispatch* m_Constructors;
206 JPMethodDispatchList m_Methods;
207 JPFieldList m_Fields;
208 string m_CanonicalName;
209 jint m_Modifiers;
210 JPPyObject m_Host;
211 JPPyObject m_Hints;
212 } ;
213
214 #endif // _JPPOBJECTTYPE_H_