/// <summary> /// Create Dot42.dll /// </summary> private static void CreateFrameworkAssembly(JarFile jf, DocModel xmlModel, SourceProperties sourceProperties, string folder) { // Initialize all MappedTypeBuilder.Initialize(CompositionContainer); // Create java type wrappers var module = new NetModule(AttributeConstants.Dot42Scope); var classLoader = new AssemblyClassLoader(null); var target = new TargetFramework(null, classLoader, xmlModel, LogMissingParamNamesType, true, false, Enumerable.Empty <string>()); List <TypeBuilder> typeBuilders; using (Profiler.Profile(x => Console.WriteLine("{0:####} ms for Create()", x.TotalMilliseconds))) { var classTypeBuilders = jf.ClassNames.SelectMany(n => StandardTypeBuilder.Create(jf.LoadClass(n), target)); var customTypeBuilder = CompositionContainer.GetExportedValues <ICustomTypeBuilder>() .OrderBy(x => x.CustomTypeName) .Select(x => x.AsTypeBuilder()); typeBuilders = classTypeBuilders.Concat(customTypeBuilder) .OrderBy(x => x.Priority) .ToList(); typeBuilders.ForEach(x => x.CreateType(null, module, target)); } // Create JavaRef attribute //JavaRefAttributeBuilder.Build(asm.MainModule); // Implement and finalize types using (Profiler.Profile(x => Console.WriteLine("{0:####} ms for Implement()", x.TotalMilliseconds))) { JarImporter.Implement(typeBuilders, target); } // Save using (Profiler.Profile(x => Console.WriteLine("{0:####} ms for Generate()", x.TotalMilliseconds))) { CodeGenerator.Generate(folder, module.Types, new List <NetCustomAttribute>(), target, new FrameworkCodeGeneratorContext(), target); } // Create layout.xml var doc = new XDocument(new XElement("layout")); typeBuilders.ForEach(x => x.FillLayoutXml(jf, doc.Root)); doc.Save(Path.Combine(folder, "layout.xml")); // create dot42.typemap doc = new XDocument(new XElement("typemap")); typeBuilders.ForEach(x => x.FillTypemapXml(jf, doc.Root)); doc.Save(Path.Combine(folder, "dot42.typemap")); //using (var s = new FileStream(Path.Combine(folder, "dot42.typemap"), FileMode.Create)) // CompressedXml.WriteTo(doc, s, Encoding.UTF8); }
/// <summary> /// Create a builder /// </summary> public static IEnumerable <TypeBuilder> Create(ClassFile cf, TargetFramework target) { if (!ShouldImplement(cf, target)) { yield break; } TypeBuilder builder; if (MappedTypeBuilder.TryCreateTypeBuilder(cf, out builder)) { yield return(builder); } else { if (cf.IsInterface && cf.Fields.Any()) { yield return(new StandardInterfaceConstantsTypeBuilder(cf)); } yield return(new StandardTypeBuilder(cf)); } }