IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
RuntimeUnloadableJavaType.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
26#if IMPORTER || EXPORTER
27using IKVM.Reflection;
29
30using Type = IKVM.Reflection.Type;
31#else
32#endif
33
34#if IMPORTER
36#endif
37
38namespace IKVM.Runtime
39{
40
41 sealed class RuntimeUnloadableJavaType : RuntimeJavaType
42 {
43
44 internal const string ContainerTypeName = "__<Unloadable>";
45
46 readonly Type missingType;
47 Type customModifier;
48
54 internal RuntimeUnloadableJavaType(RuntimeContext context, string name) :
55 base(context, TypeFlags.None, RuntimeJavaType.UnloadableModifiersHack, name)
56 {
57
58 }
59
65 internal RuntimeUnloadableJavaType(RuntimeContext context, Type missingType) :
66 this(context, missingType.FullName) // TODO demangle and re-mangle appropriately
67 {
68 this.missingType = missingType;
69 }
70
77 internal RuntimeUnloadableJavaType(RuntimeContext context, string name, Type customModifier) :
78 this(context, name)
79 {
80 this.customModifier = customModifier;
81 }
82
83 internal override RuntimeJavaType BaseTypeWrapper => null;
84
85 internal override RuntimeClassLoader ClassLoader => null;
86
87 internal override RuntimeJavaType EnsureLoadable(RuntimeClassLoader loader)
88 {
89 var tw = loader.TryLoadClassByName(this.Name);
90 if (tw == null)
91 throw new NoClassDefFoundError(this.Name);
92
93 return tw;
94 }
95
96 internal override string SigName
97 {
98 get
99 {
100 var name = Name;
101 if (name.StartsWith("["))
102 return name;
103
104 return "L" + name + ";";
105 }
106 }
107
108 protected override void LazyPublishMembers()
109 {
110 throw new InvalidOperationException("LazyPublishMembers called on UnloadableTypeWrapper: " + Name);
111 }
112
113 internal override Type TypeAsTBD => throw new InvalidOperationException("get_Type called on UnloadableTypeWrapper: " + Name);
114
115 internal override RuntimeJavaType[] Interfaces
116 {
117 get
118 {
119#if IMPORTER
120 if (missingType != null)
121 {
122 Context.StaticCompiler.IssueMissingTypeMessage(missingType);
123 return Array.Empty<RuntimeJavaType>();
124 }
125#endif
126
127 throw new InvalidOperationException("get_Interfaces called on UnloadableTypeWrapper: " + Name);
128 }
129 }
130
131 internal override RuntimeJavaType[] InnerClasses => throw new InvalidOperationException("get_InnerClasses called on UnloadableTypeWrapper: " + Name);
132
133 internal override RuntimeJavaType DeclaringTypeWrapper => throw new InvalidOperationException("get_DeclaringTypeWrapper called on UnloadableTypeWrapper: " + Name);
134
135 internal override void Finish()
136 {
137 throw new InvalidOperationException("Finish called on UnloadableTypeWrapper: " + Name);
138 }
139
140 internal Type MissingType => missingType;
141
142 internal Type CustomModifier => customModifier;
143
144 internal void SetCustomModifier(Type type)
145 {
146 this.customModifier = type;
147 }
148
149#if EMITTERS
150
151 internal Type GetCustomModifier(RuntimeJavaTypeFactory context)
152 {
153 // we don't need to lock, because we're only supposed to be called while holding the finish lock
154 return customModifier ?? (customModifier = context.DefineUnloadable(this.Name));
155 }
156
157 internal override void EmitCheckcast(CodeEmitter ilgen)
158 {
159 throw new InvalidOperationException("EmitCheckcast called on UnloadableTypeWrapper: " + Name);
160 }
161
162 internal override void EmitInstanceOf(CodeEmitter ilgen)
163 {
164 throw new InvalidOperationException("EmitInstanceOf called on UnloadableTypeWrapper: " + Name);
165 }
166
167#endif // EMITTERS
168
169 }
170
171}
IKVM.Reflection.Type Type
global::java.lang.invoke.LambdaForm.Name Name
Runtime support for a class loader.
Maintains services relevant to an instane of the IKVM runtime.