IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
RuntimeManagedJavaTypeFactory.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;
26
27#if IMPORTER || EXPORTER
28using IKVM.Reflection;
30
31using Type = IKVM.Reflection.Type;
32#else
33#endif
34
35namespace IKVM.Runtime
36{
37
42 {
43
44 readonly RuntimeContext context;
45 readonly ConditionalWeakTable<Type, RuntimeJavaType> cache = new ConditionalWeakTable<Type, RuntimeJavaType>();
46
53 {
54 this.context = context ?? throw new ArgumentNullException(nameof(context));
55 }
56
62 public RuntimeJavaType GetJavaTypeFromManagedType(Type type)
63 {
64 return cache.GetValue(type, _ => context.AssemblyClassLoaderFactory.FromAssembly(_.Assembly).GetJavaTypeFromAssemblyType(_));
65 }
66
72 public RuntimeJavaType GetBaseJavaType(Type type)
73 {
74 // interfaces have no base type
75 if (type.IsInterface)
76 return null;
77
78 // remapped types extend their alter ego (e.g. cli.System.Object must appear to be derived from java.lang.Object)
79 if (context.ClassLoaderFactory.IsRemappedType(type))
80 {
81 // except when they're sealed.
82 if (type.IsSealed)
83 return context.JavaBase.TypeOfJavaLangObject;
84
85 return context.ClassLoaderFactory.GetJavaTypeFromType(type);
86 }
87
88 // if base type is remapped, return java type of remapped base type
89 if (context.ClassLoaderFactory.IsRemappedType(type.BaseType))
90 return GetJavaTypeFromManagedType(type.BaseType);
91
92 // return java type of base type
93 return context.ClassLoaderFactory.GetJavaTypeFromType(type.BaseType);
94 }
95
96 }
97
98}
IKVM.Reflection.Type Type
Maintains services relevant to an instane of the IKVM runtime.
Manages instances of RuntimeManagedJavaType.
RuntimeManagedJavaTypeFactory(RuntimeContext context)
Initializes a new instance.
RuntimeJavaType GetBaseJavaType(Type type)
Gets the RuntimeJavaType associated with the base type of the specified type.
RuntimeJavaType GetJavaTypeFromManagedType(Type type)
Gets the RuntimeJavaType associated with the specified managed type, or creates one on demand.