public BoundClass(ClassGen klass, CodeGenerationOptions opt, CodeGeneratorContext context, GenerationInfo generationInfo) { context.ContextTypes.Push(klass); context.ContextGeneratedMethods = new List <Method> (); generationInfo.TypeRegistrations.Add(new KeyValuePair <string, string> (klass.RawJniName, klass.AssemblyQualifiedName)); var is_enum = klass.base_symbol != null && klass.base_symbol.FullName == "Java.Lang.Enum"; if (is_enum) { generationInfo.Enums.Add(klass.RawJniName.Replace('/', '.') + ":" + klass.Namespace + ":" + klass.JavaSimpleName); } this.opt = opt; Name = klass.Name; SetVisibility(klass.Visibility); IsShadow = klass.NeedsNew; IsAbstract = klass.IsAbstract; IsSealed = klass.IsFinal; IsPartial = true; UsePriorityOrder = true; AddImplementedInterfaces(klass); Comments.Add($"// Metadata.xml XPath class reference: path=\"{klass.MetadataXPathReference}\""); if (klass.IsDeprecated) { Attributes.Add(new ObsoleteAttr(klass.DeprecatedComment) { WriteAttributeSuffix = true }); } Attributes.Add(new RegisterAttr(klass.RawJniName, null, null, true, klass.AdditionalAttributeString()) { UseGlobal = true, UseShortForm = true }); if (klass.TypeParameters != null && klass.TypeParameters.Any()) { Attributes.Add(new CustomAttr(klass.TypeParameters.ToGeneratedAttributeString())); } // Figure out our base class string obj_type = null; if (klass.base_symbol != null) { obj_type = klass.base_symbol is GenericSymbol gs && gs.IsConcrete ? gs.GetGenericType(null) : opt.GetOutputName(klass.base_symbol.FullName); } if (klass.InheritsObject && obj_type != null) { Inherits = obj_type; } // Handle fields var seen = new HashSet <string> (); SourceWriterExtensions.AddFields(this, klass, klass.Fields, seen, opt, context); var ic = new InterfaceConstsClass(klass, seen, opt, context); if (ic.ShouldGenerate) { NestedTypes.Add(ic); } // Sibling classes if (!klass.AssemblyQualifiedName.Contains('/')) { foreach (InterfaceExtensionInfo nestedIface in klass.GetNestedInterfaceTypes()) { if (nestedIface.Type.Methods.Any(m => m.CanHaveStringOverload) || nestedIface.Type.Methods.Any(m => m.Asyncify)) { sibling_types.Add(new InterfaceExtensionsClass(nestedIface.Type, nestedIface.DeclaringType, opt)); } } } if (klass.IsAbstract) { sibling_types.Add(new ClassInvokerClass(klass, opt)); } AddNestedTypes(klass, opt, context, generationInfo); AddBindingInfrastructure(klass); AddConstructors(klass, opt, context); AddProperties(klass, opt); AddMethods(klass, opt, context); AddAbstractMembers(klass, opt, context); AddExplicitGenericInterfaceMembers(klass, opt); AddCharSequenceEnumerator(klass); context.ContextGeneratedMethods.Clear(); context.ContextTypes.Pop(); }
public ClassInvokerClass(ClassGen klass, CodeGenerationOptions opt) { Name = $"{klass.Name}Invoker"; IsInternal = true; IsPartial = true; UsePriorityOrder = true; Inherits = klass.Name; foreach (var igen in klass.GetAllDerivedInterfaces().Where(i => i.IsGeneric)) { Implements.Add(opt.GetOutputName(igen.FullName)); } Attributes.Add(new RegisterAttr(klass.RawJniName, noAcw: true, additionalProperties: klass.AdditionalAttributeString()) { UseGlobal = true }); var ctor = new ConstructorWriter { Name = Name, IsPublic = true, BaseCall = "base (handle, transfer)" }; ctor.Parameters.Add(new MethodParameterWriter("handle", TypeReferenceWriter.IntPtr)); ctor.Parameters.Add(new MethodParameterWriter("transfer", new TypeReferenceWriter("JniHandleOwnership"))); Constructors.Add(ctor); // ClassInvokerHandle Fields.Add(new PeerMembersField(opt, klass.RawJniName, $"{klass.Name}Invoker", false)); Properties.Add(new JniPeerMembersGetter()); Properties.Add(new ThresholdTypeGetter()); AddMemberInvokers(klass, opt, new HashSet <string> ()); }
public ClassInvokerClass(ClassGen klass, CodeGenerationOptions opt) { Name = $"{klass.Name}Invoker"; IsInternal = true; IsPartial = true; UsePriorityOrder = true; Inherits = klass.Name; foreach (var igen in klass.GetAllDerivedInterfaces().Where(i => i.IsGeneric)) { Implements.Add(opt.GetOutputName(igen.FullName)); } if (opt.CodeGenerationTarget == CodeGenerationTarget.JavaInterop1) { Attributes.Add(new JniTypeSignatureAttr(klass.RawJniName, false)); } else { Attributes.Add(new RegisterAttr(klass.RawJniName, noAcw: true, additionalProperties: klass.AdditionalAttributeString()) { UseGlobal = true }); } SourceWriterExtensions.AddSupportedOSPlatform(Attributes, klass, opt); ConstructorWriter ctor = opt.CodeGenerationTarget == CodeGenerationTarget.JavaInterop1 ? new ConstructorWriter { Name = Name, IsPublic = true, BaseCall = "base (ref reference, options)", Parameters = { new MethodParameterWriter("reference", new TypeReferenceWriter("ref JniObjectReference")), new MethodParameterWriter("options", new TypeReferenceWriter("JniObjectReferenceOptions")), }, } : new ConstructorWriter { Name = Name, IsPublic = true, BaseCall = "base (handle, transfer)", Parameters = { new MethodParameterWriter("handle", TypeReferenceWriter.IntPtr), new MethodParameterWriter("transfer", new TypeReferenceWriter("JniHandleOwnership")), }, } ; Constructors.Add(ctor); // ClassInvokerHandle Fields.Add(new PeerMembersField(opt, klass.RawJniName, $"{klass.Name}Invoker", false)); Properties.Add(new JniPeerMembersGetter()); if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1) { Properties.Add(new ThresholdTypeGetter()); } AddMemberInvokers(klass, opt, new HashSet <string> ()); }