/// <summary> /// Create a type defrinition for the given class file and all inner classes. /// </summary> public override void CreateType(NetTypeDefinition declaringType, NetModule module, TargetFramework target) { // Create basic type typeDef = new NetTypeDefinition(ClassFile.Empty, target, Scope) { Name = name, Namespace = @namespace, Attributes = Attributes }; module.Types.Add(typeDef); target.TypeNameMap.Add("custom/" + name, typeDef); }
/// <summary> /// Create a type defrinition for the given class file and all inner classes. /// </summary> public override void CreateType(NetTypeDefinition declaringType, NetModule module, TargetFramework target) { if (declaringType == null) throw new ArgumentNullException("declaringType"); docClass = target.GetXmlClass(cf); var name = NameConverter.UpperCamelCase(inner.IsAnonymous ? cf.Name : inner.Name); name = CreateTypeName(declaringType, cf, name, null); var finalFullName = parentFullName + "/" + name; var attributes = GetAttributes(cf); typeDef = new NetTypeDefinition(cf, target, module.Scope) { Name = name, Attributes = attributes }; typeDef.OriginalJavaClassName = cf.ClassName; typeDef.Description = (docClass != null) ? docClass.Description : null; parent.AddNestedType(typeDef, "", module, ref finalFullName); // Prepare generics CreateGenericParameters(cf, typeDef); // Add mapping RegisterType(target, cf, typeDef); CreateNestedTypes(cf, typeDef, finalFullName, module, target); }
/// <summary> /// Adds the given nested type to my type declaration. /// </summary> protected internal override void AddNestedType(NetTypeDefinition nestedType, string namePrefix, NetModule module, ref string fullNestedTypeName) { if (TypeDefinition.IsInterface) { // Add to namespace instead (alter name to avoid duplicates) nestedType.Name = typeDef.Name + "_" + namePrefix + nestedType.Name; nestedType.Namespace = typeDef.Namespace; nestedType.DeclaringType = null; fullNestedTypeName = nestedType.FullName; module.Types.Add(nestedType); } else { TypeDefinition.NestedTypes.Add(nestedType); } }
/// <summary> /// Create a type definition for the given class file and all inner classes. /// </summary> public override void CreateType(NetTypeDefinition declaringType, NetModule module, TargetFramework target) { if (declaringType != null) throw new ArgumentException("Declaring type should be null"); docClass = target.GetXmlClass(cf); var fullName = GetFullName(); var dotIndex = fullName.LastIndexOf('.'); var ns = (dotIndex > 0) ? ConvertNamespace(fullName, dotIndex) : String.Empty; var name = (dotIndex > 0) ? NameConverter.UpperCamelCase(fullName.Substring(dotIndex + 1)) : fullName; name = CreateTypeName(null, cf, name, ns); typeDef = new NetTypeDefinition(cf, target, module.Scope); typeDef.Name = name; typeDef.Namespace = ns; typeDef.OriginalJavaClassName = cf.ClassName; typeDef.Attributes = GetAttributes(cf, cf.Fields.Any()); typeDef.IgnoreGenericArguments = !AddGenericParameters; typeDef.Description = (docClass != null) ? docClass.Description : null; module.Types.Add(typeDef); // Prepare generics CreateGenericParameters(cf, typeDef); // Add mapping var finalFullName = string.IsNullOrEmpty(ns) ? name : ns + "." + name; RegisterType(target, cf, typeDef); CreateNestedTypes(cf, typeDef, finalFullName, module, target); }
protected override void CreateNestedTypes(ClassFile cf, Model.NetTypeDefinition declaringType, string parentFullName, Model.NetModule module, TargetFramework target) { // Do nothing }
/// <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")); }
/// <summary> /// Adds the given nested type to my type declaration. /// </summary> protected internal override void AddNestedType(NetTypeDefinition nestedType, string namePrefix, NetModule module, ref string fullNestedTypeName) { TypeDefinition.NestedTypes.Add(nestedType); }
/// <summary> /// Adds the given nested type to my type declaration. /// </summary> protected internal override void AddNestedType(NetTypeDefinition nestedType, string namePrefix, NetModule module, ref string fullNestedTypeName) { if (typeDef.IsInterface) { // Add to my parent parent.AddNestedType(nestedType, cf.Name + "_" + namePrefix, module, ref fullNestedTypeName); } else { typeDef.NestedTypes.Add(nestedType); } }
/// <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 }; var hash = JarReferenceHash.ComputeJarReferenceHash(jarFilePath); var attr = new NetCustomAttribute(attrType, hash); assemblyAttributes.Add(attr); } // Save CodeGenerator.Generate(folder, module.Types, assemblyAttributes, target, this, target); }