IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ClassFile.ConstantPoolItemFieldref.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*/
24
25using IKVM.ByteCode;
26using IKVM.ByteCode.Decoding;
27
28namespace IKVM.Runtime
29{
30
31 sealed partial class ClassFile
32 {
33
37 internal sealed class ConstantPoolItemFieldref : ConstantPoolItemFMI
38 {
39
40 RuntimeJavaField _field;
41 RuntimeJavaType _fieldJavaType;
42
48 public ConstantPoolItemFieldref(RuntimeContext context, FieldrefConstantData data) :
49 base(context, data.Class, data.NameAndType)
50 {
51
52 }
53
54 protected override void Validate(string name, string descriptor, int majorVersion)
55 {
56 if (!IsValidFieldDescriptor(descriptor))
57 throw new ClassFormatError("Invalid field signature \"{0}\"", descriptor);
58 if (!IsValidFieldName(name, new ClassFormatVersion((ushort)majorVersion, 0)))
59 throw new ClassFormatError("Invalid field name \"{0}\"", name);
60 }
61
63 public override void Link(RuntimeJavaType thisType, LoadMode mode)
64 {
65 base.Link(thisType, mode);
66 lock (this)
67 if (_fieldJavaType != null)
68 return;
69
70 RuntimeJavaField fw = null;
71 var wrapper = GetClassType();
72 if (wrapper == null)
73 return;
74
75 if (!wrapper.IsUnloadable)
76 {
77 fw = wrapper.GetFieldWrapper(Name, Signature);
78 if (fw != null)
79 fw.Link(mode);
80 }
81
82 var classLoader = thisType.ClassLoader;
83 var fld = classLoader.FieldTypeWrapperFromSig(this.Signature, mode);
84
85 lock (this)
86 {
87 if (_fieldJavaType == null)
88 {
89 _fieldJavaType = fld;
90 _field = fw;
91 }
92 }
93 }
94
99 public RuntimeJavaType GetFieldType()
100 {
101 return _fieldJavaType;
102 }
103
108 public RuntimeJavaField GetField()
109 {
110 return _field;
111 }
112
114 public override RuntimeJavaMember GetMember()
115 {
116 return _field;
117 }
118
119 }
120
121 }
122
123}
global::java.lang.Class Class
global::java.lang.invoke.LambdaForm.Name Name
static bool IsValidFieldName(string name, ClassFormatVersion version)
Returns true if the given string is a valid field name given the specified class format version.
Definition ClassFile.cs:84
static bool IsValidFieldDescriptor(string descriptor)
Returns true if the specified descriptor is a valid field descriptor.
Definition ClassFile.cs:152