Esempio n. 1
0
        /// <summary>
        /// Create wrapper for given jar file
        /// </summary>
        private void CreateAssembly(JarFile jf, string folder)
        {
            // Create java type wrappers
            var module = new NetModule(jf.Scope);

            var classTypeBuilders = jf.ClassNames.SelectMany(n => StandardTypeBuilder.Create(jf.LoadClass(n), target));

            var typeBuilders = classTypeBuilders.OrderBy(x => x.Priority).ToList();

            typeBuilders.ForEach(x => x.CreateType(null, module, target));

            // Implement and finalize types
            Implement(typeBuilders, target);

            var assemblyAttributes = new List <NetCustomAttribute>();

            if (!importAsStubs)
            {
                // Import code
                var attrType = new NetTypeDefinition(ClassFile.Empty, target, AttributeConstants.Dot42Scope)
                {
                    Name      = AttributeConstants.JavaCodeAttributeName,
                    Namespace = AttributeConstants.Dot42AttributeNamespace
                };
                string hash = JarReferenceHash.ComputeJarReferenceHash(jarFilePath);
                var    attr = new NetCustomAttribute(attrType, hash, Path.GetFileName(jarFilePath));
                assemblyAttributes.Add(attr);
            }

            // Save
            CodeGenerator.Generate(folder, module.Types, assemblyAttributes, target, this, target);
        }
Esempio n. 2
0
        /// <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("Create took {0}ms", 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("Implement took {0}ms", x.TotalMilliseconds)))
            {
                JarImporter.Implement(typeBuilders, target);
            }

            // Save
            using (Profiler.Profile(x => Console.WriteLine("Generate took {0}ms", 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"));
        }