IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
RuntimeManagedByteCodePropertyJavaField.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2014 Jeroen Frijters
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
19
20 Jeroen Frijters
21 jeroen@frijters.net
22
23*/
24
25#if IMPORTER || EXPORTER
26using IKVM.Reflection;
28
29using Type = IKVM.Reflection.Type;
30#else
31using System.Reflection;
32using System.Reflection.Emit;
33#endif
34
35namespace IKVM.Runtime
36{
37
42 {
43
44 readonly PropertyInfo property;
45
52 internal RuntimeManagedByteCodePropertyJavaField(RuntimeJavaType declaringType, PropertyInfo property, ExModifiers modifiers) :
53 base(declaringType, declaringType.Context.ClassLoaderFactory.GetJavaTypeFromType(property.PropertyType), property.Name, declaringType.Context.ClassLoaderFactory.GetJavaTypeFromType(property.PropertyType).SigName, modifiers, null)
54 {
55 this.property = property;
56 }
57
58 internal PropertyInfo GetProperty()
59 {
60 return property;
61 }
62
63#if EMITTERS
64
65 protected override void EmitGetImpl(CodeEmitter ilgen)
66 {
67 var getter = property.GetGetMethod(true);
68 if (getter == null)
69 RuntimeByteCodePropertyJavaField.EmitThrowNoSuchMethodErrorForGetter(ilgen, FieldTypeWrapper, this);
70 else if (getter.IsStatic)
71 ilgen.Emit(OpCodes.Call, getter);
72 else
73 ilgen.Emit(OpCodes.Callvirt, getter);
74 }
75
76 protected override void EmitSetImpl(CodeEmitter ilgen)
77 {
78 var setter = property.GetSetMethod(true);
79 if (setter == null)
80 {
81 if (IsFinal)
82 {
83 ilgen.Emit(OpCodes.Pop);
84 if (IsStatic == false)
85 {
86 ilgen.Emit(OpCodes.Pop);
87 }
88 }
89 else
90 {
91 RuntimeByteCodePropertyJavaField.EmitThrowNoSuchMethodErrorForSetter(ilgen, this);
92 }
93 }
94 else if (setter.IsStatic)
95 {
96 ilgen.Emit(OpCodes.Call, setter);
97 }
98 else
99 {
100 ilgen.Emit(OpCodes.Callvirt, setter);
101 }
102 }
103
104#endif
105
106#if !IMPORTER && !EXPORTER && !FIRST_PASS
107
108 internal override object GetValue(object obj)
109 {
110 var getter = property.GetGetMethod(true);
111 if (getter == null)
112 throw new java.lang.NoSuchMethodError();
113
114 return getter.Invoke(obj, new object[0]);
115 }
116
117 internal override void SetValue(object obj, object value)
118 {
119 var setter = property.GetSetMethod(true);
120 if (setter == null)
121 throw new java.lang.NoSuchMethodError();
122
123 setter.Invoke(obj, new object[] { value });
124 }
125
126#endif
127
128 }
129
130}
IKVM.Reflection.Type Type
IKVM.Reflection.PropertyInfo PropertyInfo
Represents a .NET property defined in Java with the ikvm.lang.Property annotation.
RuntimeClassLoaderFactory ClassLoaderFactory
Gets the RuntimeClassLoaderFactory associated with this instance of the runtime.
Represents a .NET property defined in Java with the 'ikvm.lang.Property' annotation.