Skip to content

Commit 0ad0d40

Browse files
[generator] Revert changes to [UnsupportedOSPlatform] (#1367)
Context: #1313 Context: dotnet/android#10509 Reverts: * 28d6905 * 1cfb4f4 To reduce the chance of breakage in .NET 10, going to revert this feature on `release/10.0.1xx`. The changes will be left in `main` along with the fix: * #1366
2 parents 19be370 + 130b7c8 commit 0ad0d40

File tree

9 files changed

+2
-126
lines changed

9 files changed

+2
-126
lines changed

tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,69 +1406,6 @@ public void SupportedOSPlatformConstFields ()
14061406
StringAssert.Contains ("[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android30.0\")]", builder.ToString (), "Should contain SupportedOSPlatform!");
14071407
}
14081408

1409-
[Test]
1410-
public void UnsupportedOSPlatform ()
1411-
{
1412-
var klass = SupportTypeBuilder.CreateClass ("java.code.MyClass", options);
1413-
klass.ApiRemovedSince = new AndroidSdkVersion (30);
1414-
1415-
generator.Context.ContextTypes.Push (klass);
1416-
generator.WriteType (klass, string.Empty, new GenerationInfo ("", "", "MyAssembly"));
1417-
generator.Context.ContextTypes.Pop ();
1418-
1419-
StringAssert.Contains ("[global::System.Runtime.Versioning.UnsupportedOSPlatformAttribute (\"android30.0\")]", builder.ToString (), "Should contain UnsupportedOSPlatform!");
1420-
}
1421-
1422-
[Test]
1423-
public void UnsupportedOSPlatformConstFields ()
1424-
{
1425-
var klass = new TestClass ("java.lang.Object", "com.mypackage.foo");
1426-
var field = new TestField ("java.lang.String", "bar").SetConstant ("MY_VALUE");
1427-
1428-
field.ApiRemovedSince = new AndroidSdkVersion (30);
1429-
1430-
klass.Fields.Add (field);
1431-
1432-
generator.Context.ContextTypes.Push (klass);
1433-
generator.WriteType (klass, string.Empty, new GenerationInfo ("", "", "MyAssembly"));
1434-
generator.Context.ContextTypes.Pop ();
1435-
1436-
StringAssert.Contains ("[global::System.Runtime.Versioning.UnsupportedOSPlatformAttribute (\"android30.0\")]", builder.ToString (), "Should contain UnsupportedOSPlatform!");
1437-
}
1438-
1439-
1440-
[Test]
1441-
public void UnsupportedOSPlatformIgnoresMethodOverrides ()
1442-
{
1443-
// Given:
1444-
// public class TextView {
1445-
// public Object doThing () { ... }
1446-
// }
1447-
// public class TextView2 : TextView {
1448-
// public Object doThing () { ... } // removed-since = 30
1449-
// }
1450-
// We should not write [UnsupportedOSPlatform] on TextView2.doThing (), because the base method isn't "removed".
1451-
var xml = @$"<api>
1452-
<package name='java.lang' jni-name='java/lang'>
1453-
<class abstract='false' deprecated='not deprecated' final='false' name='Object' static='false' visibility='public' jni-signature='Ljava/lang/Object;' />
1454-
</package>
1455-
<package name='android.widget' jni-name='android/widget'>
1456-
<class abstract='false' deprecated='not deprecated' extends='java.lang.Object' extends-generic-aware='java.lang.Object' final='false' name='TextView' static='false' visibility='public'>
1457-
<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' />
1458-
</class>
1459-
<class abstract='false' deprecated='not deprecated' extends='android.widget.TextView' extends-generic-aware='java.lang.Object' final='false' name='TextView2' static='false' visibility='public'>
1460-
<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' />
1461-
</class>
1462-
</package>
1463-
</api>";
1464-
1465-
var gens = ParseApiDefinition (xml);
1466-
var klass = gens.Single (g => g.Name == "TextView2");
1467-
var actual = GetGeneratedTypeOutput (klass);
1468-
1469-
StringAssert.DoesNotContain ("[global::System.Runtime.Versioning.UnsupportedOSPlatformAttribute (\"android30.0\")]", actual, "Should contain UnsupportedOSPlatform!");
1470-
}
1471-
14721409
[Test]
14731410
public void StringPropertyOverride ([Values ("true", "false")] string final)
14741411
{

tests/generator-Tests/Unit-Tests/XmlApiImporterTests.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,6 @@ public void CreateClass_CorrectApiSinceOverridePackage ()
5151
Assert.AreEqual (9, klass.ApiAvailableSince.ApiLevel);
5252
}
5353

54-
[Test]
55-
public void CreateClass_CorrectApiRemoved ()
56-
{
57-
var xml = XDocument.Parse ("<package name='com.example.test' jni-name='com/example/test'><class name='myclass' removed-since='7' /></package>");
58-
var klass = XmlApiImporter.CreateClass (xml.Root, xml.Root.Element ("class"), opt);
59-
60-
Assert.AreEqual (7, klass.ApiRemovedSince.ApiLevel);
61-
}
62-
6354
[Test]
6455
public void CreateCtor_EnsureValidName ()
6556
{

tools/generator/ApiVersionsSupport.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public static class ApiVersionsSupport
2020
public interface IApiAvailability
2121
{
2222
AndroidSdkVersion ApiAvailableSince { get; set; }
23-
AndroidSdkVersion ApiRemovedSince { get; set; }
2423
}
2524

2625
static IEnumerable<GenBase> FlattenGens (IEnumerable<GenBase> gens)

tools/generator/Java.Interop.Tools.Generator.Importers/XmlApiImporter.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ public static Ctor CreateCtor (GenBase declaringType, XElement elem, CodeGenerat
159159
var ctor = new Ctor (declaringType) {
160160
AnnotatedVisibility = elem.XGetAttribute ("annotated-visibility"),
161161
ApiAvailableSince = declaringType.ApiAvailableSince,
162-
ApiRemovedSince = declaringType.ApiRemovedSince,
163162
CustomAttributes = elem.XGetAttribute ("customAttributes"),
164163
Deprecated = elem.Deprecated (),
165164
DeprecatedSince = elem.XGetAttributeAsAndroidSdkVersionOrNull ("deprecated-since"),
@@ -212,7 +211,6 @@ public static Field CreateField (GenBase declaringType, XElement elem, CodeGener
212211
var field = new Field {
213212
AnnotatedVisibility = elem.XGetAttribute ("annotated-visibility"),
214213
ApiAvailableSince = declaringType.ApiAvailableSince,
215-
ApiRemovedSince = declaringType.ApiRemovedSince,
216214
DeprecatedComment = elem.XGetAttribute ("deprecated"),
217215
DeprecatedSince = elem.XGetAttributeAsAndroidSdkVersionOrNull ("deprecated-since"),
218216
IsAcw = true,
@@ -371,7 +369,6 @@ public static Method CreateMethod (GenBase declaringType, XElement elem, CodeGen
371369
var method = new Method (declaringType) {
372370
AnnotatedVisibility = elem.XGetAttribute ("annotated-visibility"),
373371
ApiAvailableSince = declaringType.ApiAvailableSince,
374-
ApiRemovedSince = declaringType.ApiRemovedSince,
375372
ArgsType = elem.Attribute ("argsType")?.Value,
376373
CustomAttributes = elem.XGetAttribute ("customAttributes"),
377374
Deprecated = elem.Deprecated (),
@@ -518,12 +515,9 @@ static XElement GetPreviousClass (XNode n, string nameValue)
518515
// Elements need to be passed in the above order. (package, class, member)
519516
static void FillApiSince (ApiVersionsSupport.IApiAvailability model, params XElement[] elems)
520517
{
521-
foreach (var elem in elems) {
518+
foreach (var elem in elems)
522519
if (AndroidSdkVersion.TryParse (elem.XGetAttribute ("api-since"), out var result))
523520
model.ApiAvailableSince = result;
524-
if (AndroidSdkVersion.TryParse (elem.XGetAttribute ("removed-since"), out var removed))
525-
model.ApiRemovedSince = removed;
526-
}
527521
}
528522

529523
static bool IsObfuscatedName (int threshold, string name)

tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public class Field : ApiVersionsSupport.IApiAvailability, ISourceLineInfo
99
public string AnnotatedVisibility { get; set; }
1010
public string Annotation { get; set; }
1111
public AndroidSdkVersion ApiAvailableSince { get; set; }
12-
public AndroidSdkVersion ApiRemovedSince { get; set; }
1312
public string DeprecatedComment { get; set; }
1413
public AndroidSdkVersion? DeprecatedSince { get; set; }
1514
public bool IsAcw { get; set; }

tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBase.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ IEnumerable<GenBase> Ancestors ()
188188

189189
public AndroidSdkVersion ApiAvailableSince { get; set; }
190190

191-
public AndroidSdkVersion ApiRemovedSince { get; set; }
192-
193191
public virtual ClassGen BaseGen => null;
194192

195193
public GenBase BaseSymbol =>
@@ -323,11 +321,6 @@ public void FixupMethodOverrides (CodeGenerationOptions opt)
323321
m.DeprecatedSince = bm.DeprecatedSince;
324322
}
325323

326-
// If a "removed" method overrides a "not removed" method, the method was
327-
// likely moved to a base class, so don't mark it as removed.
328-
if (m.ApiRemovedSince > 0 && bm.ApiRemovedSince == 0)
329-
m.ApiRemovedSince = default;
330-
331324
break;
332325
}
333326
}

tools/generator/Java.Interop.Tools.Generator.ObjectModel/MethodBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ protected MethodBase (GenBase declaringType)
1616
public string AnnotatedVisibility { get; set; }
1717
public string Annotation { get; internal set; }
1818
public AndroidSdkVersion ApiAvailableSince { get; set; }
19-
public AndroidSdkVersion ApiRemovedSince { get; set; }
2019
public string AssemblyName { get; set; }
2120
public GenBase DeclaringType { get; }
2221
public string Deprecated { get; set; }

tools/generator/SourceWriters/Attributes/UnsupportedOSPlatformAttr.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

tools/generator/SourceWriters/Extensions/SourceWriterExtensions.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,7 @@ public static void AddParameterListCallArgs (List<string> body, ParameterList pa
308308
}
309309

310310
public static void AddSupportedOSPlatform (List<AttributeWriter> attributes, ApiVersionsSupport.IApiAvailability member, CodeGenerationOptions opt)
311-
{
312-
AddSupportedOSPlatform (attributes, member.ApiAvailableSince, opt);
313-
AddUnsupportedOSPlatform (attributes, member.ApiRemovedSince, opt);
314-
}
311+
=> AddSupportedOSPlatform (attributes, member.ApiAvailableSince, opt);
315312

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

324-
public static void AddUnsupportedOSPlatform (List<AttributeWriter> attributes, AndroidSdkVersion since, CodeGenerationOptions opt)
325-
{
326-
// Here it makes sense to still write 'android15' because it will be missing in later versions like `android35`.
327-
if (since > 0 && opt.CodeGenerationTarget == CodeGenerationTarget.XAJavaInterop1)
328-
attributes.Add (new UnsupportedOSPlatformAttr (since));
329-
}
330-
331321
public static void AddObsolete (List<AttributeWriter> attributes, string message, CodeGenerationOptions opt, bool forceDeprecate = false, bool isError = false, AndroidSdkVersion? deprecatedSince = null)
332322
{
333323
// Bail if we're not obsolete

0 commit comments

Comments
 (0)