IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ClassFile.ConstantPoolItemMI.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;
26
27namespace IKVM.Runtime
28{
29
30 sealed partial class ClassFile
31 {
32
36 internal class ConstantPoolItemMI : ConstantPoolItemFMI
37 {
38
39 RuntimeJavaType[] argTypeWrappers;
40 RuntimeJavaType retTypeWrapper;
41 protected RuntimeJavaMethod method;
42 protected RuntimeJavaMethod invokespecialMethod;
43
50 public ConstantPoolItemMI(RuntimeContext context, ClassConstantHandle clazz, NameAndTypeConstantHandle nameAndTypeIndex) :
51 base(context, clazz, nameAndTypeIndex)
52 {
53
54 }
55
57 protected override void Validate(string name, string descriptor, int majorVersion)
58 {
59 if (!IsValidMethodDescriptor(descriptor))
60 throw new ClassFormatError("Method {0} has invalid signature {1}", name, descriptor);
61
62 if (!IsValidMethodName(name, new ClassFormatVersion((ushort)majorVersion, 0)))
63 {
64 if (!ReferenceEquals(name, StringConstants.INIT))
65 throw new ClassFormatError("Invalid method name \"{0}\"", name);
66
67 if (!descriptor.EndsWith("V"))
68 throw new ClassFormatError("Method {0} has invalid signature {1}", name, descriptor);
69 }
70 }
71
73 public override void Link(RuntimeJavaType thisType, LoadMode mode)
74 {
75 base.Link(thisType, mode);
76
77 lock (this)
78 if (argTypeWrappers != null)
79 return;
80
81 var classLoader = thisType.ClassLoader;
82 var args = classLoader.ArgJavaTypeListFromSig(this.Signature, mode);
83 var ret = classLoader.RetTypeWrapperFromSig(this.Signature, mode);
84 lock (this)
85 {
86 if (argTypeWrappers == null)
87 {
88 argTypeWrappers = args;
89 retTypeWrapper = ret;
90 }
91 }
92 }
93
94 public RuntimeJavaType[] GetArgTypes()
95 {
96 return argTypeWrappers;
97 }
98
99 public RuntimeJavaType GetRetType()
100 {
101 return retTypeWrapper;
102 }
103
104 public RuntimeJavaMethod GetMethod()
105 {
106 return method;
107 }
108
109 public RuntimeJavaMethod GetMethodForInvokespecial()
110 {
111 return invokespecialMethod ?? method;
112 }
113
115 public override RuntimeJavaMember GetMember()
116 {
117 return method;
118 }
119
120 }
121
122 }
123
124}
static bool IsValidMethodDescriptor(string descriptor)
Returns true if the specified descriptor is a valid method descriptor.
Definition ClassFile.cs:220
static bool IsValidMethodName(string name, ClassFormatVersion version)
Returns true if the given string is a valid method name given the specified class format version.
Definition ClassFile.cs:45