IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
RuntimeManagedJavaType.DelegateInnerClassJavaType.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;
25using System.Text;
26
27using IKVM.Attributes;
28
29#if IMPORTER || EXPORTER
30using Type = IKVM.Reflection.Type;
31#endif
32
33#if IMPORTER
35#endif
36
37#if EXPORTER
39#endif
40
41namespace IKVM.Runtime
42{
43
44 sealed partial class RuntimeManagedJavaType
45 {
46
47 sealed class DelegateInnerClassJavaType : FakeJavaType
48 {
49
50 readonly Type fakeType;
51
58 internal DelegateInnerClassJavaType(RuntimeContext context, string name, Type delegateType) :
59 base(context, Modifiers.Public | Modifiers.Interface | Modifiers.Abstract, name, null)
60 {
61#if IMPORTER || EXPORTER
62 this.fakeType = context.FakeTypes.GetDelegateType(delegateType);
63#elif !FIRST_PASS
64 this.fakeType = typeof(ikvm.@internal.DelegateInterface<>).MakeGenericType(delegateType);
65#endif
66 var invoke = delegateType.GetMethod("Invoke");
67 var parameters = invoke.GetParameters();
68 var argTypeWrappers = new RuntimeJavaType[parameters.Length];
69 var sb = new ValueStringBuilder();
70 sb.Append("(");
71 var flags = MemberFlags.None;
72
73 for (int i = 0; i < parameters.Length; i++)
74 {
75 var parameterType = parameters[i].ParameterType;
76 if (parameterType.IsByRef)
77 {
78 flags |= MemberFlags.DelegateInvokeWithByRefParameter;
79 parameterType = RuntimeArrayJavaType.MakeArrayType(parameterType.GetElementType(), 1);
80 }
81 argTypeWrappers[i] = Context.ClassLoaderFactory.GetJavaTypeFromType(parameterType);
82 sb.Append(argTypeWrappers[i].SigName);
83 }
84
85 var returnType = Context.ClassLoaderFactory.GetJavaTypeFromType(invoke.ReturnType);
86 sb.Append(")");
87 sb.Append(returnType.SigName);
88 SetMethods([new DynamicOnlyJavaMethod(this, "Invoke", sb.ToString(), returnType, argTypeWrappers, flags)]);
89 SetFields([]);
90 }
91
92 internal override RuntimeJavaType DeclaringTypeWrapper => Context.ClassLoaderFactory.GetJavaTypeFromType(fakeType.GetGenericArguments()[0]);
93
94 internal override RuntimeClassLoader ClassLoader => DeclaringTypeWrapper.ClassLoader;
95
96 internal override Type TypeAsTBD => fakeType;
97
98 internal override bool IsFastClassLiteralSafe => true;
99
100 internal override MethodParametersEntry[] GetMethodParameters(RuntimeJavaMethod mw)
101 {
102 return DeclaringTypeWrapper.GetMethodParameters(DeclaringTypeWrapper.GetMethod(mw.Name, mw.Signature, false));
103 }
104
105 }
106
107 }
108
109}
IKVM.Reflection.Type Type
RuntimeClassLoaderFactory ClassLoaderFactory
Gets the RuntimeClassLoaderFactory associated with this instance of the runtime.
MemberFlags
Describes various options applied to a member.