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
63 changes: 0 additions & 63 deletions tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,69 +1406,6 @@ public void SupportedOSPlatformConstFields ()
StringAssert.Contains ("[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android30.0\")]", builder.ToString (), "Should contain SupportedOSPlatform!");
}

[Test]
public void UnsupportedOSPlatform ()
{
var klass = SupportTypeBuilder.CreateClass ("java.code.MyClass", options);
klass.ApiRemovedSince = new AndroidSdkVersion (30);

generator.Context.ContextTypes.Push (klass);
generator.WriteType (klass, string.Empty, new GenerationInfo ("", "", "MyAssembly"));
generator.Context.ContextTypes.Pop ();

StringAssert.Contains ("[global::System.Runtime.Versioning.UnsupportedOSPlatformAttribute (\"android30.0\")]", builder.ToString (), "Should contain UnsupportedOSPlatform!");
}

[Test]
public void UnsupportedOSPlatformConstFields ()
{
var klass = new TestClass ("java.lang.Object", "com.mypackage.foo");
var field = new TestField ("java.lang.String", "bar").SetConstant ("MY_VALUE");

field.ApiRemovedSince = new AndroidSdkVersion (30);

klass.Fields.Add (field);

generator.Context.ContextTypes.Push (klass);
generator.WriteType (klass, string.Empty, new GenerationInfo ("", "", "MyAssembly"));
generator.Context.ContextTypes.Pop ();

StringAssert.Contains ("[global::System.Runtime.Versioning.UnsupportedOSPlatformAttribute (\"android30.0\")]", builder.ToString (), "Should contain UnsupportedOSPlatform!");
}


[Test]
public void UnsupportedOSPlatformIgnoresMethodOverrides ()
{
// Given:
// public class TextView {
// public Object doThing () { ... }
// }
// public class TextView2 : TextView {
// public Object doThing () { ... } // removed-since = 30
// }
// We should not write [UnsupportedOSPlatform] on TextView2.doThing (), because the base method isn't "removed".
var xml = @$"<api>
<package name='java.lang' jni-name='java/lang'>
<class abstract='false' deprecated='not deprecated' final='false' name='Object' static='false' visibility='public' jni-signature='Ljava/lang/Object;' />
</package>
<package name='android.widget' jni-name='android/widget'>
<class abstract='false' deprecated='not deprecated' extends='java.lang.Object' extends-generic-aware='java.lang.Object' final='false' name='TextView' static='false' visibility='public'>
<method abstract='false' deprecated='not deprecated' final='false' name='doThing' bridge='false' native='false' return='java.lang.Object' static='false' synchronized='false' synthetic='false' visibility='public' />
</class>
<class abstract='false' deprecated='not deprecated' extends='android.widget.TextView' extends-generic-aware='java.lang.Object' final='false' name='TextView2' static='false' visibility='public'>
<method abstract='false' deprecated='not deprecated' final='false' name='doThing' bridge='false' native='false' return='java.lang.Object' static='false' synchronized='false' synthetic='false' visibility='public' removed-since='30' />
</class>
</package>
</api>";

var gens = ParseApiDefinition (xml);
var klass = gens.Single (g => g.Name == "TextView2");
var actual = GetGeneratedTypeOutput (klass);

StringAssert.DoesNotContain ("[global::System.Runtime.Versioning.UnsupportedOSPlatformAttribute (\"android30.0\")]", actual, "Should contain UnsupportedOSPlatform!");
}

[Test]
public void StringPropertyOverride ([Values ("true", "false")] string final)
{
Expand Down
9 changes: 0 additions & 9 deletions tests/generator-Tests/Unit-Tests/XmlApiImporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ public void CreateClass_CorrectApiSinceOverridePackage ()
Assert.AreEqual (9, klass.ApiAvailableSince.ApiLevel);
}

[Test]
public void CreateClass_CorrectApiRemoved ()
{
var xml = XDocument.Parse ("<package name='com.example.test' jni-name='com/example/test'><class name='myclass' removed-since='7' /></package>");
var klass = XmlApiImporter.CreateClass (xml.Root, xml.Root.Element ("class"), opt);

Assert.AreEqual (7, klass.ApiRemovedSince.ApiLevel);
}

[Test]
public void CreateCtor_EnsureValidName ()
{
Expand Down
1 change: 0 additions & 1 deletion tools/generator/ApiVersionsSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public static class ApiVersionsSupport
public interface IApiAvailability
{
AndroidSdkVersion ApiAvailableSince { get; set; }
AndroidSdkVersion ApiRemovedSince { get; set; }
}

static IEnumerable<GenBase> FlattenGens (IEnumerable<GenBase> gens)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ public static Ctor CreateCtor (GenBase declaringType, XElement elem, CodeGenerat
var ctor = new Ctor (declaringType) {
AnnotatedVisibility = elem.XGetAttribute ("annotated-visibility"),
ApiAvailableSince = declaringType.ApiAvailableSince,
ApiRemovedSince = declaringType.ApiRemovedSince,
CustomAttributes = elem.XGetAttribute ("customAttributes"),
Deprecated = elem.Deprecated (),
DeprecatedSince = elem.XGetAttributeAsAndroidSdkVersionOrNull ("deprecated-since"),
Expand Down Expand Up @@ -212,7 +211,6 @@ public static Field CreateField (GenBase declaringType, XElement elem, CodeGener
var field = new Field {
AnnotatedVisibility = elem.XGetAttribute ("annotated-visibility"),
ApiAvailableSince = declaringType.ApiAvailableSince,
ApiRemovedSince = declaringType.ApiRemovedSince,
DeprecatedComment = elem.XGetAttribute ("deprecated"),
DeprecatedSince = elem.XGetAttributeAsAndroidSdkVersionOrNull ("deprecated-since"),
IsAcw = true,
Expand Down Expand Up @@ -371,7 +369,6 @@ public static Method CreateMethod (GenBase declaringType, XElement elem, CodeGen
var method = new Method (declaringType) {
AnnotatedVisibility = elem.XGetAttribute ("annotated-visibility"),
ApiAvailableSince = declaringType.ApiAvailableSince,
ApiRemovedSince = declaringType.ApiRemovedSince,
ArgsType = elem.Attribute ("argsType")?.Value,
CustomAttributes = elem.XGetAttribute ("customAttributes"),
Deprecated = elem.Deprecated (),
Expand Down Expand Up @@ -518,12 +515,9 @@ static XElement GetPreviousClass (XNode n, string nameValue)
// Elements need to be passed in the above order. (package, class, member)
static void FillApiSince (ApiVersionsSupport.IApiAvailability model, params XElement[] elems)
{
foreach (var elem in elems) {
foreach (var elem in elems)
if (AndroidSdkVersion.TryParse (elem.XGetAttribute ("api-since"), out var result))
model.ApiAvailableSince = result;
if (AndroidSdkVersion.TryParse (elem.XGetAttribute ("removed-since"), out var removed))
model.ApiRemovedSince = removed;
}
}

static bool IsObfuscatedName (int threshold, string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class Field : ApiVersionsSupport.IApiAvailability, ISourceLineInfo
public string AnnotatedVisibility { get; set; }
public string Annotation { get; set; }
public AndroidSdkVersion ApiAvailableSince { get; set; }
public AndroidSdkVersion ApiRemovedSince { get; set; }
public string DeprecatedComment { get; set; }
public AndroidSdkVersion? DeprecatedSince { get; set; }
public bool IsAcw { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ IEnumerable<GenBase> Ancestors ()

public AndroidSdkVersion ApiAvailableSince { get; set; }

public AndroidSdkVersion ApiRemovedSince { get; set; }

public virtual ClassGen BaseGen => null;

public GenBase BaseSymbol =>
Expand Down Expand Up @@ -323,11 +321,6 @@ public void FixupMethodOverrides (CodeGenerationOptions opt)
m.DeprecatedSince = bm.DeprecatedSince;
}

// If a "removed" method overrides a "not removed" method, the method was
// likely moved to a base class, so don't mark it as removed.
if (m.ApiRemovedSince > 0 && bm.ApiRemovedSince == 0)
m.ApiRemovedSince = default;

break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ protected MethodBase (GenBase declaringType)
public string AnnotatedVisibility { get; set; }
public string Annotation { get; internal set; }
public AndroidSdkVersion ApiAvailableSince { get; set; }
public AndroidSdkVersion ApiRemovedSince { get; set; }
public string AssemblyName { get; set; }
public GenBase DeclaringType { get; }
public string Deprecated { get; set; }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,7 @@ public static void AddParameterListCallArgs (List<string> body, ParameterList pa
}

public static void AddSupportedOSPlatform (List<AttributeWriter> attributes, ApiVersionsSupport.IApiAvailability member, CodeGenerationOptions opt)
{
AddSupportedOSPlatform (attributes, member.ApiAvailableSince, opt);
AddUnsupportedOSPlatform (attributes, member.ApiRemovedSince, opt);
}
=> AddSupportedOSPlatform (attributes, member.ApiAvailableSince, opt);

public static void AddSupportedOSPlatform (List<AttributeWriter> attributes, AndroidSdkVersion since, CodeGenerationOptions opt)
{
Expand All @@ -321,13 +318,6 @@ public static void AddSupportedOSPlatform (List<AttributeWriter> attributes, And
attributes.Add (new SupportedOSPlatformAttr (since));
}

public static void AddUnsupportedOSPlatform (List<AttributeWriter> attributes, AndroidSdkVersion since, CodeGenerationOptions opt)
{
// Here it makes sense to still write 'android15' because it will be missing in later versions like `android35`.
if (since > 0 && opt.CodeGenerationTarget == CodeGenerationTarget.XAJavaInterop1)
attributes.Add (new UnsupportedOSPlatformAttr (since));
}

public static void AddObsolete (List<AttributeWriter> attributes, string message, CodeGenerationOptions opt, bool forceDeprecate = false, bool isError = false, AndroidSdkVersion? deprecatedSince = null)
{
// Bail if we're not obsolete
Expand Down