Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,36 @@ public void ObsoletedOSPlatformAttributeUnneededSupport ()
Assert.True (writer.ToString ().Contains ("[global::System.Obsolete (@\"This method has an invalid deprecated-since!\")]"), writer.ToString ());
}

[Test]
public void ObsoletedOSPlatformAttributeInterfaceInfrastructureSupport ()
{
var xml = @"<api>
<package name='com.xamarin.android' jni-name='com/xamarin/android'>
<interface abstract='false' deprecated='This interface was deprecated in API-25' final='false' name='MyType' static='false' visibility='public' jni-signature='Lcom/xamarin/android/MyType;' deprecated-since='25' />
</package>
</api>";

options.UseObsoletedOSPlatformAttributes = true;

var gens = ParseApiDefinition (xml);
var iface = gens.OfType<InterfaceGen> ().Single (g => g.Name == "IMyType");

generator.Context.ContextTypes.Push (iface);
var invoker = new InterfaceInvokerClass (iface, options, generator.Context);
var extensions = new InterfaceExtensionsClass (iface, iface.Name, options);
generator.Context.ContextTypes.Pop ();

// Ensure attribute was added to invoker class
var invoker_attribute = invoker.Attributes.OfType<ObsoletedOSPlatformAttr> ().Single ();
Assert.AreEqual ("This interface was deprecated in API-25", invoker_attribute.Message);
Assert.AreEqual (25, invoker_attribute.Version);

// Ensure attribute was added to extensions class
var extensions_attribute = invoker.Attributes.OfType<ObsoletedOSPlatformAttr> ().Single ();
Assert.AreEqual ("This interface was deprecated in API-25", extensions_attribute.Message);
Assert.AreEqual (25, extensions_attribute.Version);
}

[Test]
public void ObsoleteGetterOnlyProperty ()
{
Expand Down
2 changes: 2 additions & 0 deletions tools/generator/SourceWriters/InterfaceExtensionsClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public InterfaceExtensionsClass (InterfaceGen iface, string declaringTypeName, C
IsStatic = true;
IsPartial = true;

SourceWriterExtensions.AddObsolete (Attributes, iface.DeprecatedComment, opt, iface.IsDeprecated, deprecatedSince: iface.DeprecatedSince);

foreach (var method in iface.Methods.Where (m => !m.IsStatic)) {
if (method.CanHaveStringOverload) {
// TODO: Don't allow obsolete here to match old generator.
Expand Down
2 changes: 2 additions & 0 deletions tools/generator/SourceWriters/InterfaceInvokerClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public InterfaceInvokerClass (InterfaceGen iface, CodeGenerationOptions opt, Cod
MemberType = (!ji) ? null : (MemberTypes?) MemberTypes.TypeInfo,
});

SourceWriterExtensions.AddObsolete (Attributes, iface.DeprecatedComment, opt, iface.IsDeprecated, deprecatedSince: iface.DeprecatedSince);

Fields.Add (new PeerMembersField (opt, iface.RawJniName, $"{iface.Name}Invoker", false));

if (!ji) {
Expand Down