/// <summary> /// Copy the properties of the source attribute into this attribute /// </summary> public void CopyPropertiesFrom(NetCustomAttribute source) { foreach (var entry in source.properties) { Properties[entry.Key] = entry.Value; } }
/// <summary> /// Finalize all references now that all types have been created /// </summary> public void Complete(ClassFile declaringClass, TargetFramework target) { if (method == null) return; // Add DexImport attribute var ca = new NetCustomAttribute(null, javaMethod.Name, javaMethod.Descriptor); ca.Properties.Add(AttributeConstants.DexImportAttributeAccessFlagsName, (int)javaMethod.AccessFlags); if (method.HasUnsignedPartner) { ca.Properties.Add(AttributeConstants.DexImportAttributeIgnoreFromJavaName, true); } var signature = (javaMethod.Signature != null) ? javaMethod.Signature.Original : null; if ((signature != null) && (signature != javaMethod.Descriptor)) { ca.Properties.Add(AttributeConstants.DexImportAttributeSignature, signature); } method.CustomAttributes.Add(ca); }
/// <summary> /// Finalize all references now that all types have been created /// </summary> public void Complete(ClassFile declaringClass, TargetFramework target) { if (field == null) return; // Setup field value var cValue = javaField.ConstantValue; // Fixup value if (cValue != null) { if (field.FieldType.IsSingle() && (float.IsPositiveInfinity((float)cValue) || float.IsNegativeInfinity((float)cValue))) cValue = null; if (field.FieldType.IsDouble() && (double.IsPositiveInfinity((double)cValue) || double.IsNegativeInfinity((double)cValue))) cValue = null; } if (cValue != null) { field.DefaultValue = cValue; } else if (field.DeclaringType.IsEnum) { /*field.DefaultValue = field.DeclaringType.Fields.ToList().IndexOf(field); field.Attributes |= FieldAttributes.Literal | FieldAttributes.Static; field.Attributes &= ~FieldAttributes.InitOnly;*/ field.Attributes |= FieldAttributes.InitOnly | FieldAttributes.Static; field.Attributes &= ~FieldAttributes.Literal; } else { field.Attributes &= ~FieldAttributes.Literal; } // Add DexImport attribute var ca = new NetCustomAttribute(null, javaField.Name, javaField.Descriptor); ca.Properties.Add(AttributeConstants.DexImportAttributeAccessFlagsName, (int)javaField.AccessFlags); field.CustomAttributes.Add(ca); }
/// <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); }