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
*/
24
using
System
;
25
using
System.Runtime.CompilerServices
;
26
27
#if IMPORTER || EXPORTER
28
using
IKVM.Reflection
;
29
using
IKVM.Reflection.Emit
;
30
31
using
Type
=
IKVM
.
Reflection
.
Type
;
32
#else
33
#endif
34
35
namespace
IKVM.Runtime
36
{
37
41
class
RuntimeManagedJavaTypeFactory
42
{
43
44
readonly
RuntimeContext
context;
45
readonly ConditionalWeakTable<Type, RuntimeJavaType> cache =
new
ConditionalWeakTable<Type, RuntimeJavaType>();
46
52
public
RuntimeManagedJavaTypeFactory
(
RuntimeContext
context)
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
}
Type
IKVM.Reflection.Type Type
Definition
IkvmReflectionAssemblySymbol.cs:10
IKVM.Reflection.Type
Definition
Type.cs:32
IKVM.Runtime.RuntimeContext
Maintains services relevant to an instane of the IKVM runtime.
Definition
RuntimeContext.cs:28
IKVM.Runtime.RuntimeManagedJavaTypeFactory
Manages instances of RuntimeManagedJavaType.
Definition
RuntimeManagedJavaTypeFactory.cs:42
IKVM.Runtime.RuntimeManagedJavaTypeFactory.RuntimeManagedJavaTypeFactory
RuntimeManagedJavaTypeFactory(RuntimeContext context)
Initializes a new instance.
Definition
RuntimeManagedJavaTypeFactory.cs:52
IKVM.Runtime.RuntimeManagedJavaTypeFactory.GetBaseJavaType
RuntimeJavaType GetBaseJavaType(Type type)
Gets the RuntimeJavaType associated with the base type of the specified type.
Definition
RuntimeManagedJavaTypeFactory.cs:72
IKVM.Runtime.RuntimeManagedJavaTypeFactory.GetJavaTypeFromManagedType
RuntimeJavaType GetJavaTypeFromManagedType(Type type)
Gets the RuntimeJavaType associated with the specified managed type, or creates one on demand.
Definition
RuntimeManagedJavaTypeFactory.cs:62
IKVM.Reflection.Emit
Definition
ArrayMethod.cs:27
IKVM.Reflection
Definition
__MethodImplMap.cs:25
IKVM.Runtime
Definition
Accessor.cs:5
IKVM
Definition
MemoryBufferWriter.cs:7
System.Runtime.CompilerServices
Definition
CompilerFeatureRequiredAttribute.cs:5
System
Definition
HexConverter.cs:9
src
IKVM.Runtime
RuntimeManagedJavaTypeFactory.cs
Generated by
1.12.0