public BoundInterfaceMethodDeclaration(Method method, string adapter, CodeGenerationOptions opt) { this.method = method; this.opt = opt; Name = method.AdjustedName; ReturnType = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal)); IsDeclaration = true; if (method.DeclaringType.IsGeneratable) { Comments.Add($"// Metadata.xml XPath method reference: path=\"{method.GetMetadataXPathReference (method.DeclaringType)}\""); } if (method.Deprecated != null) { Attributes.Add(new ObsoleteAttr(method.Deprecated.Replace("\"", "\"\""))); } if (method.IsReturnEnumified) { Attributes.Add(new GeneratedEnumAttr(true)); } if (method.IsInterfaceDefaultMethod) { Attributes.Add(new CustomAttr("[global::Java.Interop.JavaInterfaceDefaultMethod]")); } SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt); Attributes.Add(new RegisterAttr(method.JavaName, method.JniSignature, method.ConnectorName + ":" + method.GetAdapterName(opt, adapter), additionalProperties: method.AdditionalAttributeString())); method.JavadocInfo?.AddJavadocs(Comments); SourceWriterExtensions.AddMethodCustomAttributes(Attributes, method); this.AddMethodParameters(method.Parameters, opt); }
// static sbyte n_ByteValueExact (IntPtr jnienv, IntPtr native__this) // { // var __this = global::Java.Lang.Object.GetObject<Android.Icu.Math.BigDecimal> (jnienv, native__this, JniHandleOwnership.DoNotTransfer); // return __this.ByteValueExact (); // } public MethodCallback(GenBase type, Method method, CodeGenerationOptions options, string propertyName, bool isFormatted) { this.type = type; this.method = method; property_name = propertyName; is_formatted = isFormatted; opt = options; delegate_field = new MethodCallbackDelegateField(method, options); delegate_getter = new GetDelegateHandlerMethod(method, options); Name = "n_" + method.Name + method.IDSignature; ReturnType = new TypeReferenceWriter(method.RetVal.NativeType); IsStatic = true; IsPrivate = method.IsInterfaceDefaultMethod; if (!string.IsNullOrWhiteSpace(method.Deprecated)) { Attributes.Add(new ObsoleteAttr()); } SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt); Parameters.Add(new MethodParameterWriter("jnienv", TypeReferenceWriter.IntPtr)); Parameters.Add(new MethodParameterWriter("native__this", TypeReferenceWriter.IntPtr)); foreach (var p in method.Parameters) { Parameters.Add(new MethodParameterWriter(options.GetSafeIdentifier(p.UnsafeNativeName), new TypeReferenceWriter(p.NativeType))); } }
public InterfaceInvokerProperty(InterfaceGen iface, Property property, CodeGenerationOptions opt, CodeGeneratorContext context) { this.property = property; this.opt = opt; Name = property.AdjustedName; PropertyType = new TypeReferenceWriter(opt.GetTypeReferenceName(property)); IsPublic = true; IsUnsafe = true; SourceWriterExtensions.AddSupportedOSPlatform(Attributes, property.Getter, opt); HasGet = property.Getter != null; if (property.Getter != null) { HasGet = true; getter_callback = new MethodCallback(iface, property.Getter, opt, property.AdjustedName, false); } if (property.Setter != null) { HasSet = true; setter_callback = new MethodCallback(iface, property.Setter, opt, property.AdjustedName, false); } context_this = context.ContextType.GetObjectHandleProperty(opt, "this"); }
public MethodExtensionAsyncWrapper(Method method, CodeGenerationOptions opt, string selfType) { Name = method.AdjustedName + "Async"; IsStatic = true; SetVisibility(method.Visibility); ReturnType = new TypeReferenceWriter("global::System.Threading.Tasks.Task"); if (!method.IsVoid) { ReturnType.Name += "<" + opt.GetTypeReferenceName(method.RetVal) + ">"; } SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt); Body.Add($"return global::System.Threading.Tasks.Task.Run (() => self.{method.AdjustedName} ({method.Parameters.GetCall (opt)}));"); Parameters.Add(new MethodParameterWriter("self", new TypeReferenceWriter(selfType)) { IsExtension = true }); this.AddMethodParameters(method.Parameters, opt); }
public InterfaceListenerEvent(InterfaceGen iface, Method method, string name, string nameSpec, string fullDelegateName, string wrefSuffix, string add, string remove, bool hasHandlerArgument, CodeGenerationOptions opt) { Name = name; EventType = new TypeReferenceWriter(opt.GetOutputName(fullDelegateName)); IsPublic = true; SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt); HasAdd = true; AddBody.Add($"global::Java.Interop.EventHelper.AddEventHandler<{opt.GetOutputName (iface.FullName)}, {opt.GetOutputName (iface.FullName)}Implementor>("); AddBody.Add($"ref weak_implementor_{wrefSuffix},"); AddBody.Add($"__Create{iface.Name}Implementor,"); AddBody.Add($"{add + (hasHandlerArgument ? "_Event_With_Handler_Helper" : null)},"); AddBody.Add($"__h => __h.{nameSpec}Handler += value);"); HasRemove = true; RemoveBody.Add($"global::Java.Interop.EventHelper.RemoveEventHandler<{opt.GetOutputName (iface.FullName)}, {opt.GetOutputName (iface.FullName)}Implementor>("); RemoveBody.Add($"ref weak_implementor_{wrefSuffix},"); RemoveBody.Add($"{opt.GetOutputName (iface.FullName)}Implementor.__IsEmpty,"); RemoveBody.Add($"{remove},"); RemoveBody.Add($"__h => __h.{nameSpec}Handler -= value);"); if (hasHandlerArgument) { helper_method = new InterfaceListenerEventHandlerHelper(iface, method, add, opt); } }
public BoundMethodExtensionStringOverload(Method method, CodeGenerationOptions opt, string selfType) { this.method = method; this.opt = opt; self_type = selfType; Name = method.Name; IsStatic = true; SetVisibility(method.Visibility); ReturnType = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal).Replace("Java.Lang.ICharSequence", "string").Replace("global::string", "string")); if (method.Deprecated != null) { Attributes.Add(new ObsoleteAttr(method.Deprecated.Replace("\"", "\"\"").Trim())); } SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt); Parameters.Add(new MethodParameterWriter("self", new TypeReferenceWriter(selfType)) { IsExtension = true }); this.AddMethodParametersStringOverloads(method.Parameters, opt); }
public BoundAbstractProperty(GenBase gen, Property property, CodeGenerationOptions opt) { Name = property.AdjustedName; PropertyType = new TypeReferenceWriter(opt.GetTypeReferenceName(property.Getter.RetVal)); SetVisibility(property.Getter.RetVal.IsGeneric ? "protected" : property.Getter.Visibility); IsAbstract = true; HasGet = true; var baseProp = gen.BaseSymbol != null?gen.BaseSymbol.GetPropertyByName(property.Name, true) : null; if (baseProp != null) { IsOverride = true; } else { IsShadow = gen.RequiresNew(property); getter_callback = new MethodCallback(gen, property.Getter, opt, property.AdjustedName, false); if (property.Setter != null) { setter_callback = new MethodCallback(gen, property.Setter, opt, property.AdjustedName, false); } } if (gen.IsGeneratable) { GetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.MetadataXPathReference}/method[@name='{property.Getter.JavaName}'{property.Getter.Parameters.GetMethodXPathPredicate ()}]\""); } if (property.Getter.IsReturnEnumified) { GetterAttributes.Add(new GeneratedEnumAttr(true)); } SourceWriterExtensions.AddSupportedOSPlatform(GetterAttributes, property.Getter, opt); GetterAttributes.Add(new RegisterAttr(property.Getter.JavaName, property.Getter.JniSignature, property.Getter.GetConnectorNameFull(opt), additionalProperties: property.Getter.AdditionalAttributeString())); SourceWriterExtensions.AddMethodCustomAttributes(GetterAttributes, property.Getter); if (property.Setter != null) { HasSet = true; if (gen.IsGeneratable) { SetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.MetadataXPathReference}/method[@name='{property.Setter.JavaName}'{property.Setter.Parameters.GetMethodXPathPredicate ()}]\""); } SourceWriterExtensions.AddSupportedOSPlatform(SetterAttributes, property.Setter, opt); SourceWriterExtensions.AddMethodCustomAttributes(SetterAttributes, property.Setter); SetterAttributes.Add(new RegisterAttr(property.Setter.JavaName, property.Setter.JniSignature, property.Setter.GetConnectorNameFull(opt), additionalProperties: property.Setter.AdditionalAttributeString())); } }
public InterfaceListenerEventHandlerHelper(InterfaceGen iface, Method method, string add, CodeGenerationOptions opt) { Name = add + "_Event_With_Handler_Helper"; Parameters.Add(new MethodParameterWriter("value", new TypeReferenceWriter(opt.GetOutputName(iface.FullName)))); ReturnType = TypeReferenceWriter.Void; SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt); Body.Add($"{add} (value, null);"); }
public GenericExplicitInterfaceImplementationProperty(Property property, GenericSymbol gen, string adapter, Dictionary <string, string> mappings, CodeGenerationOptions opt) { Name = property.AdjustedName; PropertyType = new TypeReferenceWriter(opt.GetTypeReferenceName(property)); ExplicitInterfaceImplementation = opt.GetOutputName(gen.Gen.FullName); Comments.Add($"// This method is explicitly implemented as a member of an instantiated {gen.FullName}"); if (property.Getter != null) { HasGet = true; if (gen.Gen.IsGeneratable) { GetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.Gen.MetadataXPathReference}/method[@name='{property.Getter.JavaName}'{property.Getter.Parameters.GetMethodXPathPredicate ()}]\""); } if (property.Getter.GenericArguments != null && property.Getter.GenericArguments.Any()) { GetterAttributes.Add(new CustomAttr(property.Getter.GenericArguments.ToGeneratedAttributeString())); } SourceWriterExtensions.AddSupportedOSPlatform(GetterAttributes, property.Getter, opt); GetterAttributes.Add(new RegisterAttr(property.Getter.JavaName, property.Getter.JniSignature, property.Getter.ConnectorName + ":" + property.Getter.GetAdapterName(opt, adapter), additionalProperties: property.Getter.AdditionalAttributeString())); GetBody.Add($"return {property.Name};"); } if (property.Setter != null) { HasSet = true; if (gen.Gen.IsGeneratable) { SetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.Gen.MetadataXPathReference}/method[@name='{property.Setter.JavaName}'{property.Setter.Parameters.GetMethodXPathPredicate ()}]\""); } if (property.Setter.GenericArguments != null && property.Setter.GenericArguments.Any()) { SetterAttributes.Add(new CustomAttr(property.Setter.GenericArguments.ToGeneratedAttributeString())); } SourceWriterExtensions.AddSupportedOSPlatform(SetterAttributes, property.Setter, opt); SetterAttributes.Add(new RegisterAttr(property.Setter.JavaName, property.Setter.JniSignature, property.Setter.ConnectorName + ":" + property.Setter.GetAdapterName(opt, adapter), additionalProperties: property.Setter.AdditionalAttributeString())); // Temporarily rename the parameter to "value" var pname = property.Setter.Parameters [0].Name; property.Setter.Parameters [0].Name = "value"; SetBody.Add($"{property.Name} = {property.Setter.Parameters.GetGenericCall (opt, mappings)};"); property.Setter.Parameters [0].Name = pname; } }
public BoundMethodAbstractDeclaration(GenBase gen, Method method, CodeGenerationOptions opt, GenBase impl) { this.method = method; this.opt = opt; ReturnType = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal)); this.AddMethodParameters(method.Parameters, opt); if (method.RetVal.IsGeneric && gen != null) { Name = method.Name; ExplicitInterfaceImplementation = opt.GetOutputName(gen.FullName); SourceWriterExtensions.AddMethodCustomAttributes(Attributes, method); Body.Add("throw new NotImplementedException ();"); return; } Name = method.AdjustedName; IsAbstract = true; IsShadow = impl.RequiresNew(method.Name, method); SetVisibility(method.Visibility); NewFirst = true; if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1) { method_callback = new MethodCallback(impl, method, opt, null, method.IsReturnCharSequence); } method.JavadocInfo?.AddJavadocs(Comments); if (method.DeclaringType.IsGeneratable) { Comments.Add($"// Metadata.xml XPath method reference: path=\"{method.GetMetadataXPathReference (method.DeclaringType)}\""); } SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt); if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1) { Attributes.Add(new RegisterAttr(method.JavaName, method.JniSignature, method.ConnectorName, additionalProperties: method.AdditionalAttributeString())); } SourceWriterExtensions.AddMethodCustomAttributes(Attributes, method); }
public BoundInterfacePropertyDeclaration(GenBase gen, Property property, string adapter, CodeGenerationOptions opt) { Name = property.AdjustedName; PropertyType = new TypeReferenceWriter(opt.GetTypeReferenceName(property)); IsAutoProperty = true; if (property.Getter != null) { HasGet = true; if (gen.IsGeneratable) { GetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.MetadataXPathReference}/method[@name='{property.Getter.JavaName}'{property.Getter.Parameters.GetMethodXPathPredicate ()}]\""); } if (property.Getter.GenericArguments?.Any() == true) { GetterAttributes.Add(new CustomAttr(property.Getter.GenericArguments.ToGeneratedAttributeString())); } SourceWriterExtensions.AddSupportedOSPlatform(GetterAttributes, property.Getter, opt); if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1) { GetterAttributes.Add(new RegisterAttr(property.Getter.JavaName, property.Getter.JniSignature, property.Getter.ConnectorName + ":" + property.Getter.GetAdapterName(opt, adapter), additionalProperties: property.Getter.AdditionalAttributeString())); } } if (property.Setter != null) { HasSet = true; if (gen.IsGeneratable) { SetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.MetadataXPathReference}/method[@name='{property.Setter.JavaName}'{property.Setter.Parameters.GetMethodXPathPredicate ()}]\""); } if (property.Setter.GenericArguments?.Any() == true) { SetterAttributes.Add(new CustomAttr(property.Setter.GenericArguments.ToGeneratedAttributeString())); } SourceWriterExtensions.AddSupportedOSPlatform(SetterAttributes, property.Setter, opt); if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1) { SetterAttributes.Add(new RegisterAttr(property.Setter.JavaName, property.Setter.JniSignature, property.Setter.ConnectorName + ":" + property.Setter.GetAdapterName(opt, adapter), additionalProperties: property.Setter.AdditionalAttributeString())); } } }
// Historically .NET has not allowed interface implemented fields or constants, so we // initially worked around that by moving them to an abstract class, generally // IMyInterface -> MyInterfaceConsts // This was later expanded to accomodate static interface methods, creating a more appropriately named class // IMyInterface -> MyInterface // In this case the XXXConsts class is [Obsolete]'d and simply inherits from the newer class // in order to maintain backward compatibility. // If we're creating a binding that supports DIM, we remove the XXXConsts class as they've been // [Obsolete:iserror] for a long time, and we add [Obsolete] to the interface "class". public InterfaceMemberAlternativeClass(InterfaceGen iface, CodeGenerationOptions opt, CodeGeneratorContext context) { var should_obsolete = opt.SupportInterfaceConstants && opt.SupportDefaultInterfaceMethods; Name = iface.HasManagedName ? iface.Name.Substring(1) + "Consts" : iface.Name.Substring(1); Inherits = "Java.Lang.Object"; IsPublic = true; IsAbstract = true; UsePriorityOrder = true; SourceWriterExtensions.AddSupportedOSPlatform(Attributes, iface, opt); Attributes.Add(new RegisterAttr(iface.RawJniName, noAcw: true, additionalProperties: iface.AdditionalAttributeString()) { AcwLast = true }); if (should_obsolete) { Attributes.Add(new ObsoleteAttr($"Use the '{iface.FullName}' type. This class will be removed in a future release.") { WriteGlobal = true, NoAtSign = true }); } Constructors.Add(new ConstructorWriter { Name = Name, IsInternal = true }); var needs_class_ref = AddFields(iface, should_obsolete, opt, context); AddMethods(iface, should_obsolete, opt); if (needs_class_ref || iface.Methods.Where(m => m.IsStatic).Any()) { Fields.Add(new PeerMembersField(opt, iface.RawJniName, Name, false)); } if (!iface.HasManagedName && !opt.SupportInterfaceConstants) { sibling_classes.Add(new InterfaceConstsForwardClass(iface)); } }
public BoundPropertyStringVariant(Property property, CodeGenerationOptions opt) { var is_array = property.Getter.RetVal.IsArray; Name = property.Name; PropertyType = new TypeReferenceWriter("string" + (is_array ? "[]" : string.Empty)) { Nullable = opt.SupportNullableReferenceTypes }; SetVisibility((property.Setter ?? property.Getter).Visibility); SourceWriterExtensions.AddSupportedOSPlatform(Attributes, property.Getter, opt); HasGet = true; if (is_array) { GetBody.Add($"return CharSequence.ArrayToStringArray ({property.AdjustedName});"); } else { GetBody.Add($"return {property.AdjustedName} == null ? null : {property.AdjustedName}.ToString ();"); } if (property.Setter is null) { return; } HasSet = true; if (is_array) { SetBody.Add($"global::Java.Lang.ICharSequence[] jlsa = CharSequence.ArrayFromStringArray (value);"); SetBody.Add($"{property.AdjustedName} = jlsa;"); SetBody.Add($"foreach (var jls in jlsa) if (jls != null) jls.Dispose ();"); } else { SetBody.Add($"var jls = value == null ? null : new global::Java.Lang.String (value);"); SetBody.Add($"{property.AdjustedName} = jls;"); SetBody.Add($"if (jls != null) jls.Dispose ();"); } }
public BoundFieldAsProperty(GenBase type, Field field, CodeGenerationOptions opt) { this.field = field; this.opt = opt; Name = field.Name; var fieldType = field.Symbol.IsArray ? "IList<" + field.Symbol.ElementType + ">" + opt.NullableOperator : opt.GetTypeReferenceName(field); PropertyType = new TypeReferenceWriter(fieldType); field.JavadocInfo?.AddJavadocs(Comments); Comments.Add($"// Metadata.xml XPath field reference: path=\"{type.MetadataXPathReference}/field[@name='{field.JavaName}']\""); if (field.IsEnumified) { Attributes.Add(new GeneratedEnumAttr()); } SourceWriterExtensions.AddSupportedOSPlatform(Attributes, field, opt); if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1) { Attributes.Add(new RegisterAttr(field.JavaName, additionalProperties: field.AdditionalAttributeString())); } if (field.IsDeprecated) { Attributes.Add(new ObsoleteAttr(field.DeprecatedComment, field.IsDeprecatedError) { NoAtSign = true }); } SetVisibility(field.Visibility); UseExplicitPrivateKeyword = true; IsStatic = field.IsStatic; HasGet = true; if (!field.IsConst) { HasSet = true; } }
// static Delegate GetByteValueExactHandler () // { // if (cb_byteValueExact == null) // cb_byteValueExact = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_B) n_ByteValueExact); // return cb_byteValueExact; // } public GetDelegateHandlerMethod(Method method, CodeGenerationOptions opt) { this.method = method; this.opt = opt; Name = method.ConnectorName; ReturnType = TypeReferenceWriter.Delegate; IsStatic = true; IsPrivate = method.IsInterfaceDefaultMethod; if (!string.IsNullOrWhiteSpace(method.Deprecated)) { Attributes.Add(new ObsoleteAttr()); } SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt); }
public InterfaceInvokerMethod(InterfaceGen iface, Method method, CodeGenerationOptions opt, CodeGeneratorContext context) { this.method = method; this.opt = opt; Name = method.AdjustedName; ReturnType = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal)); IsPublic = true; IsUnsafe = true; IsStatic = method.IsStatic; method_callback = new MethodCallback(iface, method, opt, null, method.IsReturnCharSequence); context_this = context.ContextType.GetObjectHandleProperty(opt, "this"); SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt); this.AddMethodParameters(method.Parameters, opt); }
public BoundConstructor(ClassGen klass, Ctor constructor, bool useBase, CodeGenerationOptions opt, CodeGeneratorContext context) { this.constructor = constructor; this.opt = opt; this.context = context; Name = klass.Name; constructor.JavadocInfo?.AddJavadocs(Comments); Comments.Add(string.Format("// Metadata.xml XPath constructor reference: path=\"{0}/constructor[@name='{1}'{2}]\"", klass.MetadataXPathReference, klass.JavaSimpleName, constructor.Parameters.GetMethodXPathPredicate())); SourceWriterExtensions.AddSupportedOSPlatform(Attributes, constructor, opt); if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1) { Attributes.Add(new RegisterAttr(".ctor", constructor.JniSignature, string.Empty, additionalProperties: constructor.AdditionalAttributeString())); } if (constructor.Deprecated != null) { Attributes.Add(new ObsoleteAttr(constructor.Deprecated.Replace("\"", "\"\""))); } if (constructor.CustomAttributes != null) { Attributes.Add(new CustomAttr(constructor.CustomAttributes)); } if (constructor.Annotation != null) { Attributes.Add(new CustomAttr(constructor.Annotation)); } SetVisibility(constructor.Visibility); IsUnsafe = true; BaseCall = opt.CodeGenerationTarget == CodeGenerationTarget.JavaInterop1 ? $"{(useBase ? "base" : "this")} (ref *InvalidJniObjectReference, JniObjectReferenceOptions.None)" : $"{(useBase ? "base" : "this")} (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)"; context_this = context.ContextType.GetObjectHandleProperty(opt, "this"); this.AddMethodParameters(constructor.Parameters, opt); }
public BoundMethodStringOverload(Method method, CodeGenerationOptions opt) { this.method = method; this.opt = opt; Name = method.Name; IsStatic = method.IsStatic; SetVisibility(method.Visibility); ReturnType = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal).Replace("Java.Lang.ICharSequence", "string").Replace("global::string", "string")); if (method.Deprecated != null) { Attributes.Add(new ObsoleteAttr(method.Deprecated.Replace("\"", "\"\"").Trim())); } SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt); method.JavadocInfo?.AddJavadocs(Comments); this.AddMethodParametersStringOverloads(method.Parameters, opt); }
public BoundProperty(GenBase gen, Property property, CodeGenerationOptions opt, bool withCallbacks = true, bool forceOverride = false) { Name = property.AdjustedName; PropertyType = new TypeReferenceWriter(opt.GetTypeReferenceName(property.Getter.RetVal)); SetVisibility(gen is InterfaceGen ? string.Empty : property.Getter.IsAbstract && property.Getter.RetVal.IsGeneric ? "protected" : (property.Setter ?? property.Getter).Visibility); IsUnsafe = true; HasGet = true; var is_virtual = property.Getter.IsVirtual && (property.Setter == null || property.Setter.IsVirtual); if (is_virtual && withCallbacks) { IsVirtual = true; IsShadow = gen.RequiresNew(property); if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1) { getter_callback = new MethodCallback(gen, property.Getter, opt, property.AdjustedName, false); } if (property.Setter != null && opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1) { setter_callback = new MethodCallback(gen, property.Setter, opt, property.AdjustedName, false); } } if (forceOverride || ShouldForceOverride(property)) { IsVirtual = false; IsOverride = true; } if ((property.Getter ?? property.Setter).IsStatic) { IsStatic = true; IsVirtual = false; IsOverride = false; } else if (gen.BaseSymbol != null) { // It should be using AdjustedName instead of Name, but ICharSequence ("Formatted") properties are not caught by this... var base_prop = gen.BaseSymbol.GetPropertyByName(property.Name, true); // If the matching base getter we found is a DIM, we do not override it, it should stay virtual if (base_prop != null && !base_prop.Getter.IsInterfaceDefaultMethod) { IsVirtual = false; IsOverride = true; } } // Allow user to override our virtual/override logic if (!forceOverride && (property.Getter ?? property.Setter).ManagedOverride?.ToLowerInvariant() == "virtual") { IsVirtual = true; IsOverride = false; } else if (!forceOverride && (property.Getter ?? property.Setter).ManagedOverride?.ToLowerInvariant() == "override") { IsVirtual = false; IsOverride = true; } // Unlike [Register], [Obsolete] cannot be put on property accessors, so we can apply them only under limited condition... if (property.Getter.Deprecated != null && (property.Setter == null || property.Setter.Deprecated != null)) { Attributes.Add(new ObsoleteAttr(property.Getter.Deprecated.Replace("\"", "\"\"").Trim() + (property.Setter != null && property.Setter.Deprecated != property.Getter.Deprecated ? " " + property.Setter.Deprecated.Replace("\"", "\"\"").Trim() : null))); } SourceWriterExtensions.AddSupportedOSPlatform(Attributes, property.Getter, opt); SourceWriterExtensions.AddMethodCustomAttributes(GetterAttributes, property.Getter); if (gen.IsGeneratable) { GetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.MetadataXPathReference}/method[@name='{property.Getter.JavaName}'{property.Getter.Parameters.GetMethodXPathPredicate ()}]\""); } if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1) { GetterAttributes.Add(new RegisterAttr(property.Getter.JavaName, property.Getter.JniSignature, property.Getter.IsVirtual ? property.Getter.GetConnectorNameFull(opt) : string.Empty, additionalProperties: property.Getter.AdditionalAttributeString())); } SourceWriterExtensions.AddMethodBody(GetBody, property.Getter, opt); if (property.Setter != null) { HasSet = true; if (gen.IsGeneratable) { SetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.MetadataXPathReference}/method[@name='{property.Setter.JavaName}'{property.Setter.Parameters.GetMethodXPathPredicate ()}]\""); } SourceWriterExtensions.AddSupportedOSPlatform(SetterAttributes, property.Setter, opt); SourceWriterExtensions.AddMethodCustomAttributes(SetterAttributes, property.Setter); if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1) { SetterAttributes.Add(new RegisterAttr(property.Setter.JavaName, property.Setter.JniSignature, property.Setter.IsVirtual ? property.Setter.GetConnectorNameFull(opt) : string.Empty, additionalProperties: property.Setter.AdditionalAttributeString())); } var pname = property.Setter.Parameters [0].Name; property.Setter.Parameters [0].Name = "value"; SourceWriterExtensions.AddMethodBody(SetBody, property.Setter, opt); property.Setter.Parameters [0].Name = pname; } else if (property.GenerateDispatchingSetter) { HasSet = true; SetterComments.Add("// This is a dispatching setter"); SetBody.Add($"Set{property.Name} (value);"); } AddJavadocs(property); }
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); klass.JavadocInfo?.AddJavadocs(Comments); Comments.Add($"// Metadata.xml XPath class reference: path=\"{klass.MetadataXPathReference}\""); if (klass.IsDeprecated) { Attributes.Add(new ObsoleteAttr(klass.DeprecatedComment) { WriteAttributeSuffix = true }); } SourceWriterExtensions.AddSupportedOSPlatform(Attributes, klass, opt); if (opt.CodeGenerationTarget == CodeGenerationTarget.JavaInterop1) { Attributes.Add(new JniTypeSignatureAttr(klass.RawJniName, false)); } else { 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, opt); 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)); } 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> ()); }
public BoundMethod(GenBase type, Method method, CodeGenerationOptions opt, bool generateCallbacks) { JavaMethod = method; if (generateCallbacks && method.IsVirtual) { callback = new MethodCallback(type, method, opt, null, method.IsReturnCharSequence); } Name = method.AdjustedName; IsStatic = method.IsStatic; IsSealed = method.IsOverride && method.IsFinal; IsUnsafe = true; SetVisibility(type is InterfaceGen && !IsStatic ? string.Empty : method.Visibility); // TODO: Clean up this logic var is_explicit = opt.SupportDefaultInterfaceMethods && type is InterfaceGen && method.OverriddenInterfaceMethod != null; var virt_ov = is_explicit ? string.Empty : method.IsOverride ? (opt.SupportDefaultInterfaceMethods && method.OverriddenInterfaceMethod != null ? " virtual" : " override") : method.IsVirtual ? " virtual" : string.Empty; IsVirtual = virt_ov.Trim() == "virtual"; IsOverride = virt_ov.Trim() == "override"; // When using DIM, don't generate "virtual sealed" methods, remove both modifiers instead if (opt.SupportDefaultInterfaceMethods && method.OverriddenInterfaceMethod != null && IsVirtual && IsSealed) { IsVirtual = false; IsSealed = false; } if (is_explicit) { ExplicitInterfaceImplementation = GetDeclaringTypeOfExplicitInterfaceMethod(method.OverriddenInterfaceMethod); } if ((IsVirtual || !IsOverride) && type.RequiresNew(method.AdjustedName, method)) { IsShadow = true; } // Allow user to override our virtual/override logic if (method.ManagedOverride?.ToLowerInvariant() == "virtual") { IsVirtual = true; IsOverride = false; } else if (method.ManagedOverride?.ToLowerInvariant() == "override") { IsVirtual = false; IsOverride = true; } ReturnType = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal)); method.JavadocInfo?.AddJavadocs(Comments); if (method.DeclaringType.IsGeneratable) { Comments.Add($"// Metadata.xml XPath method reference: path=\"{method.GetMetadataXPathReference (method.DeclaringType)}\""); } if (method.Deprecated.HasValue()) { Attributes.Add(new ObsoleteAttr(method.Deprecated.Replace("\"", "\"\""))); } if (method.IsReturnEnumified) { Attributes.Add(new GeneratedEnumAttr(true)); } SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt); Attributes.Add(new RegisterAttr(method.JavaName, method.JniSignature, method.IsVirtual ? method.GetConnectorNameFull(opt) : string.Empty, additionalProperties: method.AdditionalAttributeString())); SourceWriterExtensions.AddMethodCustomAttributes(Attributes, method); this.AddMethodParameters(method.Parameters, opt); SourceWriterExtensions.AddMethodBody(Body, method, opt); }