IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
RuntimeMirandaJavaMethod.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2014 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 IKVM.Attributes;
25
26#if IMPORTER || EXPORTER
28#else
29using System.Reflection.Emit;
30#endif
31
32namespace IKVM.Runtime
33{
34
36 {
37
38 sealed class AbstractMirandaMethodWrapper : RuntimeMirandaJavaMethod
39 {
40
46 internal AbstractMirandaMethodWrapper(RuntimeJavaType declaringType, RuntimeJavaMethod ifmethod) :
47 base(declaringType, ifmethod, Modifiers.Public | Modifiers.Abstract)
48 {
49
50 }
51
52 }
53
54 sealed class DefaultMirandaMethodWrapper : RuntimeMirandaJavaMethod
55 {
56
62 internal DefaultMirandaMethodWrapper(RuntimeJavaType declaringType, RuntimeJavaMethod ifmethod) :
63 base(declaringType, ifmethod, Modifiers.Public)
64 {
65
66 }
67
68 }
69
70 sealed class ErrorMirandaMethodWrapper : RuntimeMirandaJavaMethod
71 {
72
73 string error;
74
81 internal ErrorMirandaMethodWrapper(RuntimeJavaType declaringType, RuntimeJavaMethod ifmethod, string error) :
82 base(declaringType, ifmethod, Modifiers.Public)
83 {
84 this.error = error;
85 }
86
87 protected override RuntimeMirandaJavaMethod AddConflictError(RuntimeJavaMethod mw)
88 {
89 error += " " + mw.DeclaringType.Name + "." + mw.Name;
90 return this;
91 }
92
93 internal override string Error
94 {
95 get { return error; }
96 }
97
98 }
99
100 readonly RuntimeJavaMethod ifmethod;
101
108 RuntimeMirandaJavaMethod(RuntimeJavaType declaringType, RuntimeJavaMethod ifmethod, Modifiers modifiers) :
109 base(declaringType, ifmethod.Name, ifmethod.Signature, null, null, null, modifiers, MemberFlags.HideFromReflection | MemberFlags.MirandaMethod)
110 {
111 this.ifmethod = ifmethod;
112 }
113
114 internal static RuntimeMirandaJavaMethod Create(RuntimeJavaType declaringType, RuntimeJavaMethod ifmethod)
115 {
116 var dmmw = ifmethod as DefaultMirandaMethodWrapper;
117 if (dmmw != null)
118 return new DefaultMirandaMethodWrapper(declaringType, dmmw.BaseMethod);
119
120 return ifmethod.IsAbstract ? new AbstractMirandaMethodWrapper(declaringType, ifmethod) : new DefaultMirandaMethodWrapper(declaringType, ifmethod);
121 }
122
124 {
125 if (ifmethod == mw)
126 {
127 // an interface can be implemented multiple times
128 return this;
129 }
130 else if (ifmethod.DeclaringType.ImplementsInterface(mw.DeclaringType))
131 {
132 // we can override a base interface without problems
133 return this;
134 }
135 else if (mw.DeclaringType.ImplementsInterface(ifmethod.DeclaringType))
136 {
137 return Create(DeclaringType, mw);
138 }
139 else if (!ifmethod.IsAbstract && !mw.IsAbstract)
140 {
141 return AddConflictError(mw);
142 }
143 else if (!ifmethod.IsAbstract && mw.IsAbstract)
144 {
145 return new ErrorMirandaMethodWrapper(DeclaringType, mw, DeclaringType.Name + "." + Name + Signature);
146 }
147 else
148 {
149 return this;
150 }
151 }
152
154 {
155 return new ErrorMirandaMethodWrapper(DeclaringType, ifmethod, "Conflicting default methods:")
156 .AddConflictError(ifmethod)
157 .AddConflictError(mw);
158 }
159
160 internal bool IsConflictError
161 {
162 get { return Error != null && Error.StartsWith("Conflicting default methods:"); }
163 }
164
165 internal RuntimeJavaMethod BaseMethod
166 {
167 get { return ifmethod; }
168 }
169
170 internal virtual string Error
171 {
172 get { return null; }
173 }
174
175#if EMITTERS
176
177 protected override void CallImpl(CodeEmitter ilgen)
178 {
179 ilgen.Emit(OpCodes.Call, GetMethod());
180 }
181
182 protected override void CallvirtImpl(CodeEmitter ilgen)
183 {
184 ilgen.Emit(OpCodes.Callvirt, GetMethod());
185 }
186
187#endif // EMITTERS
188
189 }
190
191}
global::java.lang.invoke.LambdaForm.Name Name
virtual RuntimeMirandaJavaMethod AddConflictError(RuntimeJavaMethod mw)
MemberFlags
Describes various options applied to a member.