IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
RuntimeManagedJavaType.EnumValueJavaField.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2015 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 System;
25
26using IKVM.Attributes;
27
28#if IMPORTER || EXPORTER
30
31using Type = IKVM.Reflection.Type;
32#else
33using System.Reflection;
34using System.Reflection.Emit;
35#endif
36
37namespace IKVM.Runtime
38{
39
40 sealed partial class RuntimeManagedJavaType
41 {
42
43 internal sealed class EnumValueJavaField : RuntimeJavaField
44 {
45
46 readonly Type underlyingType;
47
53 internal EnumValueJavaField(RuntimeManagedJavaType tw, RuntimeJavaType fieldType) :
54 base(tw, fieldType, "Value", fieldType.SigName, new ExModifiers(Modifiers.Public | Modifiers.Final, false), null)
55 {
56 underlyingType = EnumHelper.GetUnderlyingType(tw.type);
57 }
58
59#if EMITTERS
60
61 protected override void EmitGetImpl(CodeEmitter ilgen)
62 {
63 // NOTE if the reference on the stack is null, we *want* the NullReferenceException, so we don't use TypeWrapper.EmitUnbox
64 ilgen.Emit(OpCodes.Unbox, underlyingType);
65 ilgen.Emit(OpCodes.Ldobj, underlyingType);
66 }
67
68 protected override void EmitSetImpl(CodeEmitter ilgen)
69 {
70 // NOTE even though the field is final, JNI reflection can still be used to set its value!
71 CodeEmitterLocal temp = ilgen.AllocTempLocal(underlyingType);
72 ilgen.Emit(OpCodes.Stloc, temp);
73 ilgen.Emit(OpCodes.Unbox, underlyingType);
74 ilgen.Emit(OpCodes.Ldloc, temp);
75 ilgen.Emit(OpCodes.Stobj, underlyingType);
76 ilgen.ReleaseTempLocal(temp);
77 }
78
79#endif
80
81#if !EXPORTER && !IMPORTER && !FIRST_PASS
82
83 internal override object GetValue(object obj)
84 {
85 return obj;
86 }
87
88 internal override void SetValue(object obj, object value)
89 {
90 obj.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)[0].SetValue(obj, value);
91 }
92
93#endif
94
95 }
96
97 }
98
99}
IKVM.Reflection.Type Type