| 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 | #include "jpype.h" |
| 17 | #include "jp_field.h" |
| 18 | |
| 19 | JPField::JPField(JPJavaFrame& frame, |
| 20 | JPClass* cls, |
| 21 | const string& name, |
| 22 | jobject field, |
| 23 | jfieldID fid, |
| 24 | JPClass* fieldType, |
| 25 | jint modifiers) |
| 26 | : m_Field(frame, field) |
| 27 | { |
| 28 | m_Class = cls; |
| 29 | m_Name = name; |
| 30 | m_FieldID = fid; |
| 31 | m_Type = fieldType; |
| 32 | m_Modifiers = modifiers; |
| 33 | } |
| 34 | |
| 35 | JPField::~JPField() |
| 36 | = default; |
| 37 | |
| 38 | JPPyObject JPField::getStaticField() |
| 39 | { |
| 40 | JP_TRACE_IN("JPField::getStaticAttribute"); |
| 41 | JPJavaFrame frame = JPJavaFrame::outer(); |
| 42 | return m_Type->getStaticField(frame, m_Class->getJavaClass(), m_FieldID); |
| 43 | JP_TRACE_OUT; |
| 44 | } |
| 45 | |
| 46 | void JPField::setStaticField(PyObject *pyobj) |
| 47 | { |
| 48 | JP_TRACE_IN("JPField::setStaticAttribute"); |
| 49 | JPJavaFrame frame = JPJavaFrame::outer(); |
| 50 | m_Type->setStaticField(frame, m_Class->getJavaClass(), m_FieldID, pyobj); |
| 51 | JP_TRACE_OUT; |
| 52 | } |
| 53 | |
| 54 | JPPyObject JPField::getField(jobject inst) |
| 55 | { |
| 56 | JP_TRACE_IN("JPField::getAttribute"); |
| 57 | JPJavaFrame frame = JPJavaFrame::outer(); |
| 58 | ASSERT_NOT_NULL(m_Type); |
| 59 | JP_TRACE("field type", m_Type->getCanonicalName()); |
| 60 | return m_Type->getField(frame, inst, m_FieldID); |
| 61 | JP_TRACE_OUT; |
| 62 | } |
| 63 | |
| 64 | void JPField::setField(jobject inst, PyObject *pyobj) |
| 65 | { |
| 66 | JP_TRACE_IN("JPField::setAttribute"); |
| 67 | JPJavaFrame frame = JPJavaFrame::outer(); |
| 68 | m_Type->setField(frame, inst, m_FieldID, pyobj); |
| 69 | JP_TRACE_OUT; |
| 70 | } |