~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/ikvmstub/ikvmstub.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2002-2012 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.IO;
 
26
using System.Collections.Generic;
 
27
using ICSharpCode.SharpZipLib.Zip;
 
28
using IKVM.Attributes;
 
29
using IKVM.Internal;
 
30
using IKVM.Reflection;
 
31
using Type = IKVM.Reflection.Type;
 
32
 
 
33
static class NetExp
 
34
{
 
35
        private static int zipCount;
 
36
        private static ZipOutputStream zipFile;
 
37
        private static Dictionary<string, string> done = new Dictionary<string, string>();
 
38
        private static Dictionary<string, TypeWrapper> todo = new Dictionary<string, TypeWrapper>();
 
39
        private static FileInfo file;
 
40
        private static bool includeSerialVersionUID;
 
41
        private static bool includeNonPublicInterfaces;
 
42
        private static bool includeNonPublicMembers;
 
43
        private static List<string> namespaces = new List<string>();
 
44
 
 
45
        static int Main(string[] args)
 
46
        {
 
47
                IKVM.Internal.Tracer.EnableTraceConsoleListener();
 
48
                IKVM.Internal.Tracer.EnableTraceForDebug();
 
49
                string assemblyNameOrPath = null;
 
50
                bool continueOnError = false;
 
51
                bool autoLoadSharedClassLoaderAssemblies = false;
 
52
                List<string> references = new List<string>();
 
53
                List<string> libpaths = new List<string>();
 
54
                bool nostdlib = false;
 
55
                bool bootstrap = false;
 
56
                string outputFile = null;
 
57
                bool forwarders = false;
 
58
                foreach(string s in args)
 
59
                {
 
60
                        if(s.StartsWith("-") || assemblyNameOrPath != null)
 
61
                        {
 
62
                                if(s == "-serialver")
 
63
                                {
 
64
                                        Console.Error.WriteLine("The -serialver option is deprecated and will be removed in the future. Use -japi instead.");
 
65
                                        includeSerialVersionUID = true;
 
66
                                }
 
67
                                else if(s == "-japi")
 
68
                                {
 
69
                                        includeSerialVersionUID = true;
 
70
                                        includeNonPublicInterfaces = true;
 
71
                                        includeNonPublicMembers = true;
 
72
                                }
 
73
                                else if(s == "-skiperror")
 
74
                                {
 
75
                                        continueOnError = true;
 
76
                                }
 
77
                                else if(s == "-shared")
 
78
                                {
 
79
                                        autoLoadSharedClassLoaderAssemblies = true;
 
80
                                }
 
81
                                else if(s.StartsWith("-r:") || s.StartsWith("-reference:"))
 
82
                                {
 
83
                                        references.Add(s.Substring(s.IndexOf(':') + 1));
 
84
                                }
 
85
                                else if(s == "-nostdlib")
 
86
                                {
 
87
                                        nostdlib = true;
 
88
                                }
 
89
                                else if(s.StartsWith("-lib:"))
 
90
                                {
 
91
                                        libpaths.Add(s.Substring(5));
 
92
                                }
 
93
                                else if(s == "-bootstrap")
 
94
                                {
 
95
                                        bootstrap = true;
 
96
                                }
 
97
                                else if(s.StartsWith("-out:"))
 
98
                                {
 
99
                                        outputFile = s.Substring(5);
 
100
                                }
 
101
                                else if(s.StartsWith("-namespace:"))
 
102
                                {
 
103
                                        namespaces.Add(s.Substring(11) + ".");
 
104
                                }
 
105
                                else if(s == "-forwarders")
 
106
                                {
 
107
                                        forwarders = true;
 
108
                                }
 
109
                                else
 
110
                                {
 
111
                                        // unrecognized option, or multiple assemblies, print usage message and exit
 
112
                                        assemblyNameOrPath = null;
 
113
                                        break;
 
114
                                }
 
115
                        }
 
116
                        else
 
117
                        {
 
118
                                assemblyNameOrPath = s;
 
119
                        }
 
120
                }
 
121
                if(assemblyNameOrPath == null)
 
122
                {
 
123
                        Console.Error.WriteLine(GetVersionAndCopyrightInfo());
 
124
                        Console.Error.WriteLine();
 
125
                        Console.Error.WriteLine("usage: ikvmstub [-options] <assemblyNameOrPath>");
 
126
                        Console.Error.WriteLine();
 
127
                        Console.Error.WriteLine("options:");
 
128
                        Console.Error.WriteLine("    -out:<outputfile>          Specify the output filename");
 
129
                        Console.Error.WriteLine("    -reference:<filespec>      Reference an assembly (short form -r:<filespec>)");
 
130
                        Console.Error.WriteLine("    -japi                      Generate jar suitable for comparison with japitools");
 
131
                        Console.Error.WriteLine("    -skiperror                 Continue when errors are encountered");
 
132
                        Console.Error.WriteLine("    -shared                    Process all assemblies in shared group");
 
133
                        Console.Error.WriteLine("    -nostdlib                  Do not reference standard libraries");
 
134
                        Console.Error.WriteLine("    -lib:<dir>                 Additional directories to search for references");
 
135
                        Console.Error.WriteLine("    -namespace:<ns>            Only include types from specified namespace");
 
136
                        Console.Error.WriteLine("    -forwarders                Export forwarded types too");
 
137
                        return 1;
 
138
                }
 
139
                if(File.Exists(assemblyNameOrPath) && nostdlib)
 
140
                {
 
141
                        // Add the target assembly to the references list, to allow it to be considered as "mscorlib".
 
142
                        // This allows "ikvmstub -nostdlib \...\mscorlib.dll" to work.
 
143
                        references.Add(assemblyNameOrPath);
 
144
                }
 
145
                StaticCompiler.Resolver.Warning += new AssemblyResolver.WarningEvent(Resolver_Warning);
 
146
                StaticCompiler.Resolver.Init(StaticCompiler.Universe, nostdlib, references, libpaths);
 
147
                Dictionary<string, Assembly> cache = new Dictionary<string, Assembly>();
 
148
                foreach (string reference in references)
 
149
                {
 
150
                        Assembly[] dummy = null;
 
151
                        if (!StaticCompiler.Resolver.ResolveReference(cache, ref dummy, reference))
 
152
                        {
 
153
                                Console.Error.WriteLine("Error: reference not found {0}", reference);
 
154
                                return 1;
 
155
                        }
 
156
                }
 
157
                Assembly assembly = null;
 
158
                try
 
159
                {
 
160
                        file = new FileInfo(assemblyNameOrPath);
 
161
                }
 
162
                catch(System.Exception x)
 
163
                {
 
164
                        Console.Error.WriteLine("Error: unable to load \"{0}\"\n  {1}", assemblyNameOrPath, x.Message);
 
165
                        return 1;
 
166
                }
 
167
                if(file != null && file.Exists)
 
168
                {
 
169
                        assembly = StaticCompiler.LoadFile(assemblyNameOrPath);
 
170
                }
 
171
                else
 
172
                {
 
173
                        assembly = StaticCompiler.Resolver.LoadWithPartialName(assemblyNameOrPath);
 
174
                }
 
175
                int rc = 0;
 
176
                if(assembly == null)
 
177
                {
 
178
                        Console.Error.WriteLine("Error: Assembly \"{0}\" not found", assemblyNameOrPath);
 
179
                }
 
180
                else
 
181
                {
 
182
                        if (bootstrap)
 
183
                        {
 
184
                                StaticCompiler.runtimeAssembly = StaticCompiler.LoadFile(typeof(NetExp).Assembly.Location);
 
185
                                ClassLoaderWrapper.SetBootstrapClassLoader(new BootstrapBootstrapClassLoader());
 
186
                        }
 
187
                        else
 
188
                        {
 
189
                                StaticCompiler.LoadFile(typeof(NetExp).Assembly.Location);
 
190
                                StaticCompiler.runtimeAssembly = StaticCompiler.LoadFile(Path.Combine(typeof(NetExp).Assembly.Location, "../IKVM.Runtime.dll"));
 
191
                                JVM.CoreAssembly = StaticCompiler.LoadFile(Path.Combine(typeof(NetExp).Assembly.Location, "../IKVM.OpenJDK.Core.dll"));
 
192
                        }
 
193
                        if (AttributeHelper.IsJavaModule(assembly.ManifestModule))
 
194
                        {
 
195
                                Console.Error.WriteLine("Warning: Running ikvmstub on ikvmc compiled assemblies is not supported.");
 
196
                        }
 
197
                        if (outputFile == null)
 
198
                        {
 
199
                                outputFile = assembly.GetName().Name + ".jar";
 
200
                        }
 
201
                        try
 
202
                        {
 
203
                                using (zipFile = new ZipOutputStream(new FileStream(outputFile, FileMode.Create)))
 
204
                                {
 
205
                                        zipFile.SetComment(GetVersionAndCopyrightInfo());
 
206
                                        try
 
207
                                        {
 
208
                                                List<Assembly> assemblies = new List<Assembly>();
 
209
                                                assemblies.Add(assembly);
 
210
                                                if (autoLoadSharedClassLoaderAssemblies)
 
211
                                                {
 
212
                                                        LoadSharedClassLoaderAssemblies(assembly, assemblies);
 
213
                                                }
 
214
                                                foreach (Assembly asm in assemblies)
 
215
                                                {
 
216
                                                        if (ProcessTypes(asm.GetTypes(), continueOnError) != 0)
 
217
                                                        {
 
218
                                                                rc = 1;
 
219
                                                                if (!continueOnError)
 
220
                                                                {
 
221
                                                                        break;
 
222
                                                                }
 
223
                                                        }
 
224
                                                        if (forwarders && ProcessTypes(asm.ManifestModule.__GetExportedTypes(), continueOnError) != 0)
 
225
                                                        {
 
226
                                                                rc = 1;
 
227
                                                                if (!continueOnError)
 
228
                                                                {
 
229
                                                                        break;
 
230
                                                                }
 
231
                                                        }
 
232
                                                }
 
233
                                        }
 
234
                                        catch (System.Exception x)
 
235
                                        {
 
236
                                                Console.Error.WriteLine(x);
 
237
                                                
 
238
                                                if (!continueOnError)
 
239
                                                {
 
240
                                                        Console.Error.WriteLine("Warning: Assembly reflection encountered an error. Resultant JAR may be incomplete.");
 
241
                                                }
 
242
                                                
 
243
                                                rc = 1;
 
244
                                        }
 
245
                                }
 
246
                        }
 
247
                        catch (ZipException x)
 
248
                        {
 
249
                                rc = 1;
 
250
                                if (zipCount == 0)
 
251
                                {
 
252
                                        Console.Error.WriteLine("Error: Assembly contains no public IKVM.NET compatible types");
 
253
                                }
 
254
                                else
 
255
                                {
 
256
                                        Console.Error.WriteLine("Error: {0}", x.Message);
 
257
                                }
 
258
                        }
 
259
                }
 
260
                return rc;
 
261
        }
 
262
 
 
263
        static void Resolver_Warning(AssemblyResolver.WarningId warning, string message, string[] parameters)
 
264
        {
 
265
                if (warning != AssemblyResolver.WarningId.HigherVersion)
 
266
                {
 
267
                        Console.Error.WriteLine("Warning: " + message, parameters);
 
268
                }
 
269
        }
 
270
 
 
271
        private static string GetVersionAndCopyrightInfo()
 
272
        {
 
273
                System.Reflection.Assembly asm = System.Reflection.Assembly.GetEntryAssembly();
 
274
                object[] desc = asm.GetCustomAttributes(typeof(System.Reflection.AssemblyTitleAttribute), false);
 
275
                if (desc.Length == 1)
 
276
                {
 
277
                        object[] copyright = asm.GetCustomAttributes(typeof(System.Reflection.AssemblyCopyrightAttribute), false);
 
278
                        if (copyright.Length == 1)
 
279
                        {
 
280
                                return string.Format("{0} version {1}{2}{3}{2}http://www.ikvm.net/",
 
281
                                        ((System.Reflection.AssemblyTitleAttribute)desc[0]).Title,
 
282
                                        asm.GetName().Version,
 
283
                                        Environment.NewLine,
 
284
                                        ((System.Reflection.AssemblyCopyrightAttribute)copyright[0]).Copyright);
 
285
                        }
 
286
                }
 
287
                return "";
 
288
        }
 
289
 
 
290
        private static void LoadSharedClassLoaderAssemblies(Assembly assembly, List<Assembly> assemblies)
 
291
        {
 
292
                if (assembly.GetManifestResourceInfo("ikvm.exports") != null)
 
293
                {
 
294
                        using (Stream stream = assembly.GetManifestResourceStream("ikvm.exports"))
 
295
                        {
 
296
                                BinaryReader rdr = new BinaryReader(stream);
 
297
                                int assemblyCount = rdr.ReadInt32();
 
298
                                for (int i = 0; i < assemblyCount; i++)
 
299
                                {
 
300
                                        string name = rdr.ReadString();
 
301
                                        int typeCount = rdr.ReadInt32();
 
302
                                        if (typeCount > 0)
 
303
                                        {
 
304
                                                for (int j = 0; j < typeCount; j++)
 
305
                                                {
 
306
                                                        rdr.ReadInt32();
 
307
                                                }
 
308
                                                try
 
309
                                                {
 
310
                                                        assemblies.Add(StaticCompiler.Load(name));
 
311
                                                }
 
312
                                                catch
 
313
                                                {
 
314
                                                        Console.WriteLine("Warning: Unable to load shared class loader assembly: {0}", name);
 
315
                                                }
 
316
                                        }
 
317
                                }
 
318
                        }
 
319
                }
 
320
        }
 
321
 
 
322
        private static void WriteClass(TypeWrapper tw)
 
323
        {
 
324
                string name = tw.Name.Replace('.', '/');
 
325
                string super = null;
 
326
                if (tw.IsInterface)
 
327
                {
 
328
                        super = "java/lang/Object";
 
329
                }
 
330
                else if (tw.BaseTypeWrapper != null)
 
331
                {
 
332
                        super = tw.BaseTypeWrapper.Name.Replace('.', '/');
 
333
                }
 
334
                IKVM.StubGen.ClassFileWriter writer = new IKVM.StubGen.ClassFileWriter(tw.Modifiers, name, super, 0, 49);
 
335
                foreach (TypeWrapper iface in tw.Interfaces)
 
336
                {
 
337
                        if (iface.IsPublic || includeNonPublicInterfaces)
 
338
                        {
 
339
                                writer.AddInterface(iface.Name.Replace('.', '/'));      
 
340
                        }
 
341
                }
 
342
                IKVM.StubGen.InnerClassesAttribute innerClassesAttribute = null;
 
343
                if (tw.DeclaringTypeWrapper != null)
 
344
                {
 
345
                        TypeWrapper outer = tw.DeclaringTypeWrapper;
 
346
                        string innername = name;
 
347
                        int idx = name.LastIndexOf('$');
 
348
                        if (idx >= 0)
 
349
                        {
 
350
                                innername = innername.Substring(idx + 1);
 
351
                        }
 
352
                        innerClassesAttribute = new IKVM.StubGen.InnerClassesAttribute(writer);
 
353
                        innerClassesAttribute.Add(name, outer.Name.Replace('.', '/'), innername, (ushort)tw.ReflectiveModifiers);
 
354
                }
 
355
                foreach (TypeWrapper inner in tw.InnerClasses)
 
356
                {
 
357
                        if (inner.IsPublic)
 
358
                        {
 
359
                                if (innerClassesAttribute == null)
 
360
                                {
 
361
                                        innerClassesAttribute = new IKVM.StubGen.InnerClassesAttribute(writer);
 
362
                                }
 
363
                                string namePart = inner.Name;
 
364
                                namePart = namePart.Substring(namePart.LastIndexOf('$') + 1);
 
365
                                innerClassesAttribute.Add(inner.Name.Replace('.', '/'), name, namePart, (ushort)inner.ReflectiveModifiers);
 
366
                        }
 
367
                }
 
368
                if (innerClassesAttribute != null)
 
369
                {
 
370
                        writer.AddAttribute(innerClassesAttribute);
 
371
                }
 
372
                string genericTypeSignature = tw.GetGenericSignature();
 
373
                if (genericTypeSignature != null)
 
374
                {
 
375
                        writer.AddStringAttribute("Signature", genericTypeSignature);
 
376
                }
 
377
                writer.AddStringAttribute("IKVM.NET.Assembly", GetAssemblyName(tw));
 
378
                if (tw.TypeAsBaseType.IsDefined(StaticCompiler.Universe.Import(typeof(ObsoleteAttribute)), false))
 
379
                {
 
380
                        writer.AddAttribute(new IKVM.StubGen.DeprecatedAttribute(writer));
 
381
                }
 
382
                foreach (MethodWrapper mw in tw.GetMethods())
 
383
                {
 
384
                        if (!mw.IsHideFromReflection && (mw.IsPublic || mw.IsProtected || includeNonPublicMembers))
 
385
                        {
 
386
                                IKVM.StubGen.FieldOrMethod m;
 
387
                                if (mw.Name == "<init>")
 
388
                                {
 
389
                                        m = writer.AddMethod(mw.Modifiers, mw.Name, mw.Signature.Replace('.', '/'));
 
390
                                        IKVM.StubGen.CodeAttribute code = new IKVM.StubGen.CodeAttribute(writer);
 
391
                                        code.MaxLocals = (ushort)(mw.GetParameters().Length * 2 + 1);
 
392
                                        code.MaxStack = 3;
 
393
                                        ushort index1 = writer.AddClass("java/lang/UnsatisfiedLinkError");
 
394
                                        ushort index2 = writer.AddString("ikvmstub generated stubs can only be used on IKVM.NET");
 
395
                                        ushort index3 = writer.AddMethodRef("java/lang/UnsatisfiedLinkError", "<init>", "(Ljava/lang/String;)V");
 
396
                                        code.ByteCode = new byte[] {
 
397
                                                187, (byte)(index1 >> 8), (byte)index1, // new java/lang/UnsatisfiedLinkError
 
398
                                                89,                                                                             // dup
 
399
                                                19,      (byte)(index2 >> 8), (byte)index2,     // ldc_w "..."
 
400
                                                183, (byte)(index3 >> 8), (byte)index3, // invokespecial java/lang/UnsatisfiedLinkError/init()V
 
401
                                                191                                                                             // athrow
 
402
                                        };
 
403
                                        m.AddAttribute(code);
 
404
                                }
 
405
                                else
 
406
                                {
 
407
                                        Modifiers mods = mw.Modifiers;
 
408
                                        if ((mods & Modifiers.Abstract) == 0)
 
409
                                        {
 
410
                                                mods |= Modifiers.Native;
 
411
                                        }
 
412
                                        m = writer.AddMethod(mods, mw.Name, mw.Signature.Replace('.', '/'));
 
413
                                        if (mw.IsOptionalAttributeAnnotationValue)
 
414
                                        {
 
415
                                                m.AddAttribute(new IKVM.StubGen.AnnotationDefaultClassFileAttribute(writer, GetAnnotationDefault(writer, mw.ReturnType)));
 
416
                                        }
 
417
                                }
 
418
                                MethodBase mb = mw.GetMethod();
 
419
                                if (mb != null)
 
420
                                {
 
421
                                        ThrowsAttribute throws = AttributeHelper.GetThrows(mb);
 
422
                                        if (throws == null)
 
423
                                        {
 
424
                                                string[] throwsArray = mw.GetDeclaredExceptions();
 
425
                                                if (throwsArray != null && throwsArray.Length > 0)
 
426
                                                {
 
427
                                                        IKVM.StubGen.ExceptionsAttribute attrib = new IKVM.StubGen.ExceptionsAttribute(writer);
 
428
                                                        foreach (string ex in throwsArray)
 
429
                                                        {
 
430
                                                                attrib.Add(ex.Replace('.', '/'));
 
431
                                                        }
 
432
                                                        m.AddAttribute(attrib);
 
433
                                                }
 
434
                                        }
 
435
                                        else
 
436
                                        {
 
437
                                                IKVM.StubGen.ExceptionsAttribute attrib = new IKVM.StubGen.ExceptionsAttribute(writer);
 
438
                                                if (throws.classes != null)
 
439
                                                {
 
440
                                                        foreach (string ex in throws.classes)
 
441
                                                        {
 
442
                                                                attrib.Add(ex.Replace('.', '/'));
 
443
                                                        }
 
444
                                                }
 
445
                                                if (throws.types != null)
 
446
                                                {
 
447
                                                        foreach (Type ex in throws.types)
 
448
                                                        {
 
449
                                                                attrib.Add(ClassLoaderWrapper.GetWrapperFromType(ex).Name.Replace('.', '/'));
 
450
                                                        }
 
451
                                                }
 
452
                                                m.AddAttribute(attrib);
 
453
                                        }
 
454
                                        if (mb.IsDefined(StaticCompiler.Universe.Import(typeof(ObsoleteAttribute)), false)
 
455
                                                // HACK the instancehelper methods are marked as Obsolete (to direct people toward the ikvm.extensions methods instead)
 
456
                                                // but in the Java world most of them are not deprecated (and to keep the Japi results clean we need to reflect this)
 
457
                                                && (!mb.Name.StartsWith("instancehelper_")
 
458
                                                        || mb.DeclaringType.FullName != "java.lang.String"
 
459
                                                        // the Java deprecated methods actually have two Obsolete attributes
 
460
                                                        || mb.__GetCustomAttributes(StaticCompiler.Universe.Import(typeof(ObsoleteAttribute)), false).Count == 2))
 
461
                                        {
 
462
                                                m.AddAttribute(new IKVM.StubGen.DeprecatedAttribute(writer));
 
463
                                        }
 
464
                                        IList<CustomAttributeData> attr = CustomAttributeData.__GetCustomAttributes(mb, JVM.LoadType(typeof(AnnotationDefaultAttribute)), false);
 
465
                                        if (attr.Count == 1)
 
466
                                        {
 
467
                                                m.AddAttribute(new IKVM.StubGen.AnnotationDefaultClassFileAttribute(writer, GetAnnotationDefault(writer, attr[0].ConstructorArguments[0])));
 
468
                                        }
 
469
                                }
 
470
                                string sig = tw.GetGenericMethodSignature(mw);
 
471
                                if (sig != null)
 
472
                                {
 
473
                                        m.AddAttribute(writer.MakeStringAttribute("Signature", sig));
 
474
                                }
 
475
                        }
 
476
                }
 
477
                bool hasSerialVersionUID = false;
 
478
                foreach (FieldWrapper fw in tw.GetFields())
 
479
                {
 
480
                        if (!fw.IsHideFromReflection)
 
481
                        {
 
482
                                bool isSerialVersionUID = includeSerialVersionUID && fw.Name == "serialVersionUID" && fw.FieldTypeWrapper == PrimitiveTypeWrapper.LONG;
 
483
                                hasSerialVersionUID |= isSerialVersionUID;
 
484
                                if (fw.IsPublic || fw.IsProtected || isSerialVersionUID || includeNonPublicMembers)
 
485
                                {
 
486
                                        object constant = null;
 
487
                                        if (fw.GetField() != null && fw.GetField().IsLiteral && (fw.FieldTypeWrapper.IsPrimitive || fw.FieldTypeWrapper == CoreClasses.java.lang.String.Wrapper))
 
488
                                        {
 
489
                                                constant = fw.GetField().GetRawConstantValue();
 
490
                                                if (fw.GetField().FieldType.IsEnum)
 
491
                                                {
 
492
                                                        constant = EnumHelper.GetPrimitiveValue(EnumHelper.GetUnderlyingType(fw.GetField().FieldType), constant);
 
493
                                                }
 
494
                                        }
 
495
                                        IKVM.StubGen.FieldOrMethod f = writer.AddField(fw.Modifiers, fw.Name, fw.Signature.Replace('.', '/'), constant);
 
496
                                        string sig = tw.GetGenericFieldSignature(fw);
 
497
                                        if (sig != null)
 
498
                                        {
 
499
                                                f.AddAttribute(writer.MakeStringAttribute("Signature", sig));
 
500
                                        }
 
501
                                        if (fw.GetField() != null && fw.GetField().IsDefined(StaticCompiler.Universe.Import(typeof(ObsoleteAttribute)), false))
 
502
                                        {
 
503
                                                f.AddAttribute(new IKVM.StubGen.DeprecatedAttribute(writer));
 
504
                                        }
 
505
                                }
 
506
                        }
 
507
                }
 
508
                if (includeSerialVersionUID && !hasSerialVersionUID && IsSerializable(tw))
 
509
                {
 
510
                        // class is serializable but doesn't have an explicit serialVersionUID, so we add the field to record
 
511
                        // the serialVersionUID as we see it (mainly to make the Japi reports more realistic)
 
512
                        writer.AddField(Modifiers.Private | Modifiers.Static | Modifiers.Final, "serialVersionUID", "J", IKVM.StubGen.SerialVersionUID.Compute(tw));
 
513
                }
 
514
                AddMetaAnnotations(writer, tw);
 
515
                zipCount++;
 
516
                MemoryStream mem = new MemoryStream();
 
517
                writer.Write(mem);
 
518
                ZipEntry entry = new ZipEntry(name + ".class");
 
519
                entry.Size = mem.Position;
 
520
                zipFile.PutNextEntry(entry);
 
521
                mem.WriteTo(zipFile);
 
522
        }
 
523
 
 
524
        private static string GetAssemblyName(TypeWrapper tw)
 
525
        {
 
526
                ClassLoaderWrapper loader = tw.GetClassLoader();
 
527
                AssemblyClassLoader acl = loader as AssemblyClassLoader;
 
528
                if (acl != null)
 
529
                {
 
530
                        return acl.GetAssembly(tw).FullName;
 
531
                }
 
532
                else
 
533
                {
 
534
                        return ((GenericClassLoader)loader).GetName();
 
535
                }
 
536
        }
 
537
 
 
538
        private static bool IsSerializable(TypeWrapper tw)
 
539
        {
 
540
                if (tw.Name == "java.io.Serializable")
 
541
                {
 
542
                        return true;
 
543
                }
 
544
                while (tw != null)
 
545
                {
 
546
                        foreach (TypeWrapper iface in tw.Interfaces)
 
547
                        {
 
548
                                if (IsSerializable(iface))
 
549
                                {
 
550
                                        return true;
 
551
                                }
 
552
                        }
 
553
                        tw = tw.BaseTypeWrapper;
 
554
                }
 
555
                return false;
 
556
        }
 
557
 
 
558
        private static void AddMetaAnnotations(IKVM.StubGen.ClassFileWriter writer, TypeWrapper tw)
 
559
        {
 
560
                DotNetTypeWrapper.AttributeAnnotationTypeWrapperBase attributeAnnotation = tw as DotNetTypeWrapper.AttributeAnnotationTypeWrapperBase;
 
561
                if (attributeAnnotation != null)
 
562
                {
 
563
                        // TODO write the annotation directly, instead of going thru the object[] encoding
 
564
                        IKVM.StubGen.RuntimeVisibleAnnotationsAttribute annot = new IKVM.StubGen.RuntimeVisibleAnnotationsAttribute(writer);
 
565
                        annot.Add(new object[] {
 
566
                                        AnnotationDefaultAttribute.TAG_ANNOTATION,
 
567
                                        "Ljava/lang/annotation/Retention;",
 
568
                                        "value",
 
569
                                        new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/RetentionPolicy;", "RUNTIME" }
 
570
                                });
 
571
                        AttributeTargets validOn = attributeAnnotation.AttributeTargets;
 
572
                        List<object[]> targets = new List<object[]>();
 
573
                        if ((validOn & (AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Delegate | AttributeTargets.Assembly)) != 0)
 
574
                        {
 
575
                                targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "TYPE" });
 
576
                        }
 
577
                        if ((validOn & AttributeTargets.Constructor) != 0)
 
578
                        {
 
579
                                targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "CONSTRUCTOR" });
 
580
                        }
 
581
                        if ((validOn & AttributeTargets.Field) != 0)
 
582
                        {
 
583
                                targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "FIELD" });
 
584
                        }
 
585
                        if ((validOn & (AttributeTargets.Method | AttributeTargets.ReturnValue)) != 0)
 
586
                        {
 
587
                                targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "METHOD" });
 
588
                        }
 
589
                        if ((validOn & AttributeTargets.Parameter) != 0)
 
590
                        {
 
591
                                targets.Add(new object[] { AnnotationDefaultAttribute.TAG_ENUM, "Ljava/lang/annotation/ElementType;", "PARAMETER" });
 
592
                        }
 
593
                        annot.Add(new object[] {
 
594
                                        AnnotationDefaultAttribute.TAG_ANNOTATION,
 
595
                                        "Ljava/lang/annotation/Target;",
 
596
                                        "value",
 
597
                                        new object[] { AnnotationDefaultAttribute.TAG_ARRAY, targets.ToArray() }
 
598
                                });
 
599
                        writer.AddAttribute(annot);
 
600
                }
 
601
        }
 
602
 
 
603
        private static byte[] GetAnnotationDefault(IKVM.StubGen.ClassFileWriter classFile, TypeWrapper type)
 
604
        {
 
605
                MemoryStream mem = new MemoryStream();
 
606
                IKVM.StubGen.BigEndianStream bes = new IKVM.StubGen.BigEndianStream(mem);
 
607
                if (type == PrimitiveTypeWrapper.BOOLEAN)
 
608
                {
 
609
                        bes.WriteByte((byte)'Z');
 
610
                        bes.WriteUInt16(classFile.AddInt(0));
 
611
                }
 
612
        else if(type == PrimitiveTypeWrapper.BYTE)
 
613
        {
 
614
                        bes.WriteByte((byte)'B');
 
615
                        bes.WriteUInt16(classFile.AddInt(0));
 
616
        }
 
617
        else if(type == PrimitiveTypeWrapper.CHAR)
 
618
        {
 
619
                        bes.WriteByte((byte)'C');
 
620
                        bes.WriteUInt16(classFile.AddInt(0));
 
621
        }
 
622
        else if(type == PrimitiveTypeWrapper.SHORT)
 
623
        {
 
624
                        bes.WriteByte((byte)'S');
 
625
                        bes.WriteUInt16(classFile.AddInt(0));
 
626
        }
 
627
        else if(type == PrimitiveTypeWrapper.INT)
 
628
        {
 
629
                        bes.WriteByte((byte)'I');
 
630
                        bes.WriteUInt16(classFile.AddInt(0));
 
631
        }
 
632
        else if(type == PrimitiveTypeWrapper.FLOAT)
 
633
        {
 
634
                        bes.WriteByte((byte)'F');
 
635
                        bes.WriteUInt16(classFile.AddFloat(0));
 
636
        }
 
637
        else if(type == PrimitiveTypeWrapper.LONG)
 
638
        {
 
639
                        bes.WriteByte((byte)'J');
 
640
                        bes.WriteUInt16(classFile.AddLong(0));
 
641
        }
 
642
                else if (type == PrimitiveTypeWrapper.DOUBLE)
 
643
        {
 
644
                        bes.WriteByte((byte)'D');
 
645
                        bes.WriteUInt16(classFile.AddDouble(0));
 
646
        }
 
647
                else if (type == CoreClasses.java.lang.String.Wrapper)
 
648
                {
 
649
                        bes.WriteByte((byte)'s');
 
650
                        bes.WriteUInt16(classFile.AddUtf8(""));
 
651
                }
 
652
                else if ((type.Modifiers & Modifiers.Enum) != 0)
 
653
                {
 
654
                        bes.WriteByte((byte)'e');
 
655
                        bes.WriteUInt16(classFile.AddUtf8("L" + type.Name.Replace('.', '/') + ";"));
 
656
                        bes.WriteUInt16(classFile.AddUtf8("__unspecified"));
 
657
                }
 
658
                else if (type == CoreClasses.java.lang.Class.Wrapper)
 
659
                {
 
660
                        bes.WriteByte((byte)'c');
 
661
                        bes.WriteUInt16(classFile.AddUtf8("Likvm/internal/__unspecified;"));
 
662
                }
 
663
                else if (type.IsArray)
 
664
                {
 
665
                        bes.WriteByte((byte)'[');
 
666
                        bes.WriteUInt16(0);
 
667
                }
 
668
                else
 
669
                {
 
670
                        throw new InvalidOperationException();
 
671
                }
 
672
                return mem.ToArray();
 
673
        }
 
674
 
 
675
        private static byte[] GetAnnotationDefault(IKVM.StubGen.ClassFileWriter classFile, CustomAttributeTypedArgument value)
 
676
        {
 
677
                MemoryStream mem = new MemoryStream();
 
678
                IKVM.StubGen.BigEndianStream bes = new IKVM.StubGen.BigEndianStream(mem);
 
679
                try
 
680
                {
 
681
                        WriteAnnotationElementValue(classFile, bes, value);
 
682
                }
 
683
                catch (InvalidCastException)
 
684
                {
 
685
                        Console.Error.WriteLine("Warning: incorrect annotation default value");
 
686
                }
 
687
                catch (IndexOutOfRangeException)
 
688
                {
 
689
                        Console.Error.WriteLine("Warning: incorrect annotation default value");
 
690
                }
 
691
                return mem.ToArray();
 
692
        }
 
693
 
 
694
        private static void WriteAnnotationElementValue(IKVM.StubGen.ClassFileWriter classFile, IKVM.StubGen.BigEndianStream bes, CustomAttributeTypedArgument value)
 
695
        {
 
696
                if (value.ArgumentType == Types.Boolean)
 
697
                {
 
698
                        bes.WriteByte((byte)'Z');
 
699
                        bes.WriteUInt16(classFile.AddInt((bool)value.Value ? 1 : 0));
 
700
                }
 
701
                else if (value.ArgumentType == Types.Byte)
 
702
                {
 
703
                        bes.WriteByte((byte)'B');
 
704
                        bes.WriteUInt16(classFile.AddInt((byte)value.Value));
 
705
                }
 
706
                else if (value.ArgumentType == Types.Char)
 
707
                {
 
708
                        bes.WriteByte((byte)'C');
 
709
                        bes.WriteUInt16(classFile.AddInt((char)value.Value));
 
710
                }
 
711
                else if (value.ArgumentType == Types.Int16)
 
712
                {
 
713
                        bes.WriteByte((byte)'S');
 
714
                        bes.WriteUInt16(classFile.AddInt((short)value.Value));
 
715
                }
 
716
                else if (value.ArgumentType == Types.Int32)
 
717
                {
 
718
                        bes.WriteByte((byte)'I');
 
719
                        bes.WriteUInt16(classFile.AddInt((int)value.Value));
 
720
                }
 
721
                else if (value.ArgumentType == Types.Single)
 
722
                {
 
723
                        bes.WriteByte((byte)'F');
 
724
                        bes.WriteUInt16(classFile.AddFloat((float)value.Value));
 
725
                }
 
726
                else if (value.ArgumentType == Types.Int64)
 
727
                {
 
728
                        bes.WriteByte((byte)'J');
 
729
                        bes.WriteUInt16(classFile.AddLong((long)value.Value));
 
730
                }
 
731
                else if (value.ArgumentType == Types.Double)
 
732
                {
 
733
                        bes.WriteByte((byte)'D');
 
734
                        bes.WriteUInt16(classFile.AddDouble((double)value.Value));
 
735
                }
 
736
                else if (value.ArgumentType == Types.String)
 
737
                {
 
738
                        bes.WriteByte((byte)'s');
 
739
                        bes.WriteUInt16(classFile.AddUtf8((string)value.Value));
 
740
                }
 
741
                else if (value.ArgumentType == Types.Object.MakeArrayType())
 
742
                {
 
743
                        CustomAttributeTypedArgument[] array = (CustomAttributeTypedArgument[])value.Value;
 
744
                        byte type = (byte)array[0].Value;
 
745
                        if (type == AnnotationDefaultAttribute.TAG_ARRAY)
 
746
                        {
 
747
                                bes.WriteByte((byte)'[');
 
748
                                bes.WriteUInt16((ushort)(array.Length - 1));
 
749
                                for (int i = 1; i < array.Length; i++)
 
750
                                {
 
751
                                        WriteAnnotationElementValue(classFile, bes, array[i]);
 
752
                                }
 
753
                        }
 
754
                        else if (type == AnnotationDefaultAttribute.TAG_CLASS)
 
755
                        {
 
756
                                bes.WriteByte((byte)'c');
 
757
                                bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
 
758
                        }
 
759
                        else if (type == AnnotationDefaultAttribute.TAG_ENUM)
 
760
                        {
 
761
                                bes.WriteByte((byte)'e');
 
762
                                bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
 
763
                                bes.WriteUInt16(classFile.AddUtf8((string)array[2].Value));
 
764
                        }
 
765
                        else if (type == AnnotationDefaultAttribute.TAG_ANNOTATION)
 
766
                        {
 
767
                                bes.WriteByte((byte)'@');
 
768
                                bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
 
769
                                bes.WriteUInt16((ushort)((array.Length - 2) / 2));
 
770
                                for (int i = 2; i < array.Length; i += 2)
 
771
                                {
 
772
                                        bes.WriteUInt16(classFile.AddUtf8((string)array[i].Value));
 
773
                                        WriteAnnotationElementValue(classFile, bes, array[i + 1]);
 
774
                                }
 
775
                        }
 
776
                        else
 
777
                        {
 
778
                                Console.Error.WriteLine("Warning: incorrect annotation default element tag: " + type);
 
779
                        }
 
780
                }
 
781
                else
 
782
                {
 
783
                        Console.Error.WriteLine("Warning: incorrect annotation default element type: " + value.ArgumentType);
 
784
                }
 
785
        }
 
786
 
 
787
        private static bool ExportNamespace(Type type)
 
788
        {
 
789
                if (namespaces.Count == 0)
 
790
                {
 
791
                        return true;
 
792
                }
 
793
                string name = type.FullName;
 
794
                foreach (string ns in namespaces)
 
795
                {
 
796
                        if (name.StartsWith(ns, StringComparison.Ordinal))
 
797
                        {
 
798
                                return true;
 
799
                        }
 
800
                }
 
801
                return false;
 
802
        }
 
803
 
 
804
        private static int ProcessTypes(Type[] types, bool continueOnError)
 
805
        {
 
806
                int rc = 0;
 
807
                foreach (Type t in types)
 
808
                {
 
809
                        if (t.IsPublic
 
810
                                && ExportNamespace(t)
 
811
                                && !t.IsGenericTypeDefinition
 
812
                                && !AttributeHelper.IsHideFromJava(t)
 
813
                                && (!t.IsGenericType || !AttributeHelper.IsJavaModule(t.Module)))
 
814
                        {
 
815
                                TypeWrapper c;
 
816
                                if (ClassLoaderWrapper.IsRemappedType(t) || t.IsPrimitive || t == Types.Void)
 
817
                                {
 
818
                                        c = DotNetTypeWrapper.GetWrapperFromDotNetType(t);
 
819
                                }
 
820
                                else
 
821
                                {
 
822
                                        c = ClassLoaderWrapper.GetWrapperFromType(t);
 
823
                                }
 
824
                                if (c != null)
 
825
                                {
 
826
                                        AddToExportList(c);
 
827
                                }
 
828
                        }
 
829
                }
 
830
                bool keepGoing;
 
831
                do
 
832
                {
 
833
                        keepGoing = false;
 
834
                        foreach (TypeWrapper c in new List<TypeWrapper>(todo.Values))
 
835
                        {
 
836
                                if(!done.ContainsKey(c.Name))
 
837
                                {
 
838
                                        keepGoing = true;
 
839
                                        done.Add(c.Name, null);
 
840
                                        
 
841
                                        try
 
842
                                        {
 
843
                                                ProcessClass(c);
 
844
                                        }
 
845
                                        catch (Exception x)
 
846
                                        {
 
847
                                                if (continueOnError)
 
848
                                                {
 
849
                                                        rc = 1;
 
850
                                                        Console.WriteLine(x);
 
851
                                                }
 
852
                                                else
 
853
                                                {
 
854
                                                        throw;
 
855
                                                }
 
856
                                        }
 
857
                                        WriteClass(c);
 
858
                                }
 
859
                        }
 
860
                } while(keepGoing);
 
861
                return rc;
 
862
        }
 
863
 
 
864
        private static void AddToExportList(TypeWrapper c)
 
865
        {
 
866
                todo[c.Name] = c;
 
867
        }
 
868
 
 
869
        private static bool IsNonVectorArray(TypeWrapper tw)
 
870
        {
 
871
                return !tw.IsArray && tw.TypeAsBaseType.IsArray;
 
872
        }
 
873
 
 
874
        private static void AddToExportListIfNeeded(TypeWrapper tw)
 
875
        {
 
876
                while (tw.IsArray)
 
877
                {
 
878
                        tw = tw.ElementTypeWrapper;
 
879
                }
 
880
                if (tw.IsUnloadable && tw.Name.StartsWith("Missing/"))
 
881
                {
 
882
                        Console.Error.WriteLine("Error: unable to find assembly '{0}'", tw.Name.Substring(8));
 
883
                        Environment.Exit(1);
 
884
                        return;
 
885
                }
 
886
                if (tw is StubTypeWrapper)
 
887
                {
 
888
                        // skip
 
889
                }
 
890
                else if ((tw.TypeAsTBD != null && tw.TypeAsTBD.IsGenericType) || IsNonVectorArray(tw) || !tw.IsPublic)
 
891
                {
 
892
                        AddToExportList(tw);
 
893
                }
 
894
        }
 
895
 
 
896
        private static void AddToExportListIfNeeded(TypeWrapper[] types)
 
897
        {
 
898
                foreach (TypeWrapper tw in types)
 
899
                {
 
900
                        AddToExportListIfNeeded(tw);
 
901
                }
 
902
        }
 
903
 
 
904
        private static void ProcessClass(TypeWrapper tw)
 
905
        {
 
906
                TypeWrapper superclass = tw.BaseTypeWrapper;
 
907
                if (superclass != null)
 
908
                {
 
909
                        AddToExportListIfNeeded(superclass);
 
910
                }
 
911
                AddToExportListIfNeeded(tw.Interfaces);
 
912
                TypeWrapper outerClass = tw.DeclaringTypeWrapper;
 
913
                if (outerClass != null)
 
914
                {
 
915
                        AddToExportList(outerClass);
 
916
                }
 
917
                foreach (TypeWrapper innerClass in tw.InnerClasses)
 
918
                {
 
919
                        if (innerClass.IsPublic)
 
920
                        {
 
921
                                AddToExportList(innerClass);
 
922
                        }
 
923
                }
 
924
                foreach (MethodWrapper mw in tw.GetMethods())
 
925
                {
 
926
                        if (mw.IsPublic || mw.IsProtected)
 
927
                        {
 
928
                                mw.Link();
 
929
                                AddToExportListIfNeeded(mw.ReturnType);
 
930
                                AddToExportListIfNeeded(mw.GetParameters());
 
931
                        }
 
932
                }
 
933
                foreach (FieldWrapper fw in tw.GetFields())
 
934
                {
 
935
                        if (fw.IsPublic || fw.IsProtected)
 
936
                        {
 
937
                                fw.Link();
 
938
                                AddToExportListIfNeeded(fw.FieldTypeWrapper);
 
939
                        }
 
940
                }
 
941
        }
 
942
}
 
943
 
 
944
static class Intrinsics
 
945
{
 
946
        internal static bool IsIntrinsic(MethodWrapper methodWrapper)
 
947
        {
 
948
                return false;
 
949
        }
 
950
}
 
951
 
 
952
static class StaticCompiler
 
953
{
 
954
        internal static readonly Universe Universe = new Universe();
 
955
        internal static readonly AssemblyResolver Resolver = new AssemblyResolver();
 
956
        internal static Assembly runtimeAssembly;
 
957
 
 
958
        internal static Type GetRuntimeType(string typeName)
 
959
        {
 
960
                return runtimeAssembly.GetType(typeName, true);
 
961
        }
 
962
 
 
963
        internal static Assembly LoadFile(string fileName)
 
964
        {
 
965
                return Resolver.LoadFile(fileName);
 
966
        }
 
967
 
 
968
        internal static Assembly Load(string name)
 
969
        {
 
970
                return Universe.Load(name);
 
971
        }
 
972
}
 
973
 
 
974
static class FakeTypes
 
975
{
 
976
        private static readonly Type genericType;
 
977
 
 
978
        class Holder<T> { }
 
979
 
 
980
        static FakeTypes()
 
981
        {
 
982
                genericType = StaticCompiler.Universe.Import(typeof(Holder<>));
 
983
        }
 
984
 
 
985
        internal static Type GetAttributeType(Type type)
 
986
        {
 
987
                return genericType.MakeGenericType(type);
 
988
        }
 
989
 
 
990
        internal static Type GetAttributeReturnValueType(Type type)
 
991
        {
 
992
                return genericType.MakeGenericType(type);
 
993
        }
 
994
 
 
995
        internal static Type GetAttributeMultipleType(Type type)
 
996
        {
 
997
                return genericType.MakeGenericType(type);
 
998
        }
 
999
 
 
1000
        internal static Type GetDelegateType(Type type)
 
1001
        {
 
1002
                return genericType.MakeGenericType(type);
 
1003
        }
 
1004
 
 
1005
        internal static Type GetEnumType(Type type)
 
1006
        {
 
1007
                return genericType.MakeGenericType(type);
 
1008
        }
 
1009
}
 
1010
 
 
1011
sealed class BootstrapBootstrapClassLoader : ClassLoaderWrapper
 
1012
{
 
1013
        internal BootstrapBootstrapClassLoader()
 
1014
                : base(CodeGenOptions.None, null)
 
1015
        {
 
1016
                TypeWrapper javaLangObject = new StubTypeWrapper(Modifiers.Public, "java.lang.Object", null, true);
 
1017
                SetRemappedType(JVM.Import(typeof(object)), javaLangObject);
 
1018
                SetRemappedType(JVM.Import(typeof(string)), new StubTypeWrapper(Modifiers.Public | Modifiers.Final, "java.lang.String", javaLangObject, true));
 
1019
                SetRemappedType(JVM.Import(typeof(Exception)), new StubTypeWrapper(Modifiers.Public, "java.lang.Throwable", javaLangObject, true));
 
1020
                SetRemappedType(JVM.Import(typeof(IComparable)), new StubTypeWrapper(Modifiers.Public | Modifiers.Abstract | Modifiers.Interface, "java.lang.Comparable", null, true));
 
1021
                TypeWrapper tw = new StubTypeWrapper(Modifiers.Public | Modifiers.Abstract | Modifiers.Interface, "java.lang.AutoCloseable", null, true);
 
1022
                tw.SetMethods(new MethodWrapper[] { new SimpleCallMethodWrapper(tw, "close", "()V", JVM.Import(typeof(IDisposable)).GetMethod("Dispose"), PrimitiveTypeWrapper.VOID, TypeWrapper.EmptyArray, Modifiers.Public | Modifiers.Abstract, MemberFlags.None, SimpleOpCode.Callvirt, SimpleOpCode.Callvirt) });
 
1023
                SetRemappedType(JVM.Import(typeof(IDisposable)), tw);
 
1024
 
 
1025
                RegisterInitiatingLoader(new StubTypeWrapper(Modifiers.Public, "java.lang.Enum", javaLangObject, false));
 
1026
                RegisterInitiatingLoader(new StubTypeWrapper(Modifiers.Public | Modifiers.Abstract | Modifiers.Interface, "java.lang.annotation.Annotation", null, false));
 
1027
                RegisterInitiatingLoader(new StubTypeWrapper(Modifiers.Public | Modifiers.Final, "java.lang.Class", javaLangObject, false));
 
1028
        }
 
1029
}
 
1030
 
 
1031
sealed class StubTypeWrapper : TypeWrapper
 
1032
{
 
1033
        private readonly bool remapped;
 
1034
        private readonly TypeWrapper baseWrapper;
 
1035
 
 
1036
        internal StubTypeWrapper(Modifiers modifiers, string name, TypeWrapper baseWrapper, bool remapped)
 
1037
                : base(modifiers, name)
 
1038
        {
 
1039
                this.remapped = remapped;
 
1040
                this.baseWrapper = baseWrapper;
 
1041
        }
 
1042
 
 
1043
        internal override TypeWrapper BaseTypeWrapper
 
1044
        {
 
1045
                get { return baseWrapper; }
 
1046
        }
 
1047
 
 
1048
        internal override ClassLoaderWrapper GetClassLoader()
 
1049
        {
 
1050
                return ClassLoaderWrapper.GetBootstrapClassLoader();
 
1051
        }
 
1052
 
 
1053
        internal override Type TypeAsTBD
 
1054
        {
 
1055
                get { throw new NotSupportedException(); }
 
1056
        }
 
1057
 
 
1058
        internal override TypeWrapper[] Interfaces
 
1059
        {
 
1060
                get { return TypeWrapper.EmptyArray; }
 
1061
        }
 
1062
 
 
1063
        internal override TypeWrapper[] InnerClasses
 
1064
        {
 
1065
                get { return TypeWrapper.EmptyArray; }
 
1066
        }
 
1067
 
 
1068
        internal override TypeWrapper DeclaringTypeWrapper
 
1069
        {
 
1070
                get { return null; }
 
1071
        }
 
1072
 
 
1073
        internal override void Finish()
 
1074
        {
 
1075
        }
 
1076
 
 
1077
        internal override bool IsRemapped
 
1078
        {
 
1079
                get { return remapped; }
 
1080
        }
 
1081
}