IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
Redirect.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2010 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 System;
26using System.Xml.Linq;
27
28using IKVM.Reflection;
30using IKVM.Runtime;
31
32using Type = IKVM.Reflection.Type;
33
35{
36
37 public sealed class Redirect : MapXmlElement
38 {
39
45 public static Redirect Read(XElement element)
46 {
47 var redirect = new Redirect();
48 Load(redirect, element);
49 return redirect;
50 }
51
57 public static void Load(Redirect redirect, XElement element)
58 {
59 Load((MapXmlElement)redirect, element);
60 redirect.Class = (string)element.Attribute("class");
61 redirect.Name = (string)element.Attribute("name");
62 redirect.Sig = (string)element.Attribute("sig");
63 redirect.Type = (string)element.Attribute("type");
64 }
65
66 public string Class { get; set; }
67
68 public string Name { get; set; }
69
70 public string Sig { get; set; }
71
72 public string Type { get; set; }
73
74 internal void Emit(RuntimeClassLoader loader, CodeEmitter ilgen)
75 {
76 if (Type == null && Class == null)
77 throw new NotImplementedException();
78 if (Name == null || Sig == null)
79 throw new NotImplementedException();
80
81 var redirParamTypes = loader.ArgTypeListFromSig(Sig);
82 for (int i = 0; i < redirParamTypes.Length; i++)
83 ilgen.EmitLdarg(i);
84
85 // HACK if the class name contains a comma, we assume it is a .NET type
86 if (Type != null)
87 {
88 var type = loader.Context.Resolver.ResolveCoreType(Type).AsReflection();
89 var mi = type.GetMethod(Name, redirParamTypes);
90 if (mi == null)
91 {
92 throw new InvalidOperationException();
93 }
94 ilgen.Emit(OpCodes.Call, mi);
95 }
96 else
97 {
98 var tw = loader.LoadClassByName(Class);
99 var mw = tw.GetMethod(Name, Sig, false);
100 if (mw == null)
101 {
102 throw new InvalidOperationException();
103 }
104 mw.Link();
105 mw.EmitCall(ilgen);
106 }
107
108 // TODO we may need a cast here (or a stack to return type conversion)
109 ilgen.Emit(OpCodes.Ret);
110 }
111
112 }
113
114}
global::java.lang.Class Class
global::java.lang.invoke.LambdaForm.Name Name
Runtime support for a class loader.
RuntimeContext Context
Gets a reference to the RuntimeContext that this RuntimeClassLoader is hosted within.
ISymbolResolver Resolver
Gets the ISymbolResolver associated with this instance of the runtime.
static Redirect Read(XElement element)
Reads the XML element into a new Redirect instance.
Definition Redirect.cs:45
static void Load(Redirect redirect, XElement element)
Loads the XML element into the instance.
Definition Redirect.cs:57