IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
RuntimeManagedByteCodeAccessStubJavaField.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*/
24using IKVM.Attributes;
25
26#if IMPORTER || EXPORTER
27using IKVM.Reflection;
29
30using Type = IKVM.Reflection.Type;
31#else
32using System.Reflection;
33using System.Reflection.Emit;
34#endif
35
36namespace IKVM.Runtime
37{
38
40 {
41
42 readonly MethodInfo getter;
43 readonly MethodInfo setter;
44
45 static Modifiers GetModifiers(PropertyInfo property)
46 {
47 // NOTE we only support the subset of modifiers that is expected for "access stub" properties
48 var getter = property.GetGetMethod(true);
49 var modifiers = getter.IsPublic ? Modifiers.Public : Modifiers.Protected;
50 if (!property.CanWrite)
51 modifiers |= Modifiers.Final;
52 if (getter.IsStatic)
53 modifiers |= Modifiers.Static;
54
55 return modifiers;
56 }
57
64 internal RuntimeManagedByteCodeAccessStubJavaField(RuntimeJavaType wrapper, PropertyInfo property, RuntimeJavaType propertyType) :
65 this(wrapper, property, null, propertyType, GetModifiers(property), MemberFlags.HideFromReflection | MemberFlags.AccessStub)
66 {
67
68 }
69
77 internal RuntimeManagedByteCodeAccessStubJavaField(RuntimeJavaType wrapper, PropertyInfo property, FieldInfo field, RuntimeJavaType propertyType) :
78 this(wrapper, property, field, propertyType, wrapper.Context.AttributeHelper.GetModifiersAttribute(property).Modifiers, MemberFlags.AccessStub)
79 {
80
81 }
82
92 private RuntimeManagedByteCodeAccessStubJavaField(RuntimeJavaType wrapper, PropertyInfo property, FieldInfo field, RuntimeJavaType propertyType, Modifiers modifiers, MemberFlags flags) :
93 base(wrapper, propertyType, property.Name, propertyType.SigName, modifiers, field, flags)
94 {
95 this.getter = property.GetGetMethod(true);
96 this.setter = property.GetSetMethod(true);
97 }
98
99#if EMITTERS
100
101 protected override void EmitGetImpl(CodeEmitter ilgen)
102 {
103 ilgen.Emit(OpCodes.Call, getter);
104 }
105
106 protected override void EmitSetImpl(CodeEmitter ilgen)
107 {
108 ilgen.Emit(OpCodes.Call, setter);
109 }
110
111#endif
112
113#if !IMPORTER && !EXPORTER && !FIRST_PASS
114
115 internal override object GetValue(object obj)
116 {
117 // we can only be invoked on type 2 access stubs (because type 1 access stubs are HideFromReflection), so we know we have a field
118 return GetField().GetValue(obj);
119 }
120
121 internal override void SetValue(object obj, object value)
122 {
123 // we can only be invoked on type 2 access stubs (because type 1 access stubs are HideFromReflection), so we know we have a field
124 GetField().SetValue(obj, value);
125 }
126
127#endif
128
129 }
130
131}
IKVM.Reflection.Type Type
IKVM.Reflection.FieldInfo FieldInfo
IKVM.Reflection.PropertyInfo PropertyInfo
IKVM.Reflection.MethodInfo MethodInfo
AttributeHelper AttributeHelper
Gets the AttributeHelper associated with this instance of the runtime.
MemberFlags
Describes various options applied to a member.