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
7 changes: 7 additions & 0 deletions tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,12 @@ public void FixupDeprecatedBaseMethods ()

var gens = ParseApiDefinition (xml);

// Override method should not be marked deprecated because it's: deprecated='not deprecated'
Assert.IsNull (gens.Single (g => g.Name == "MyClass").Methods.Single (m => m.Name == "DoStuff").Deprecated);

options.FixObsoleteOverrides = true;
gens = ParseApiDefinition (xml);

// Override method should be marked deprecated because base method is
Assert.AreEqual ("deprecated", gens.Single (g => g.Name == "MyClass").Methods.Single (m => m.Name == "DoStuff").Deprecated);
}
Expand All @@ -1158,6 +1164,7 @@ public void FixupDeprecatedSinceBaseMethods ()
</package>
</api>";

options.FixObsoleteOverrides = true;
var gens = ParseApiDefinition (xml);

// Override method should match base method's 'deprecated-since'
Expand Down
1 change: 1 addition & 0 deletions tools/generator/CodeGenerationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public SymbolTable SymbolTable {
public bool UseShallowReferencedTypes { get; set; }
public bool UseObsoletedOSPlatformAttributes { get; set; }
public bool UseRestrictToAttributes { get; set; }
public bool FixObsoleteOverrides { get; set; }
public bool RemoveConstSugar => BuildingCoreAssembly;

bool? buildingCoreAssembly;
Expand Down
1 change: 1 addition & 0 deletions tools/generator/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static void Run (CodeGeneratorOptions options, DirectoryAssemblyResolver resolve
SupportNullableReferenceTypes = options.SupportNullableReferenceTypes,
UseObsoletedOSPlatformAttributes = options.UseObsoletedOSPlatformAttributes,
UseRestrictToAttributes = options.UseRestrictToAttributes,
FixObsoleteOverrides = options.FixObsoleteOverrides,
};
var resolverCache = new TypeDefinitionCache ();

Expand Down
4 changes: 3 additions & 1 deletion tools/generator/CodeGeneratorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public CodeGeneratorOptions ()
public bool SupportNestedInterfaceTypes { get; set; }
public bool SupportNullableReferenceTypes { get; set; }
public bool UseRestrictToAttributes { get; set; }
public bool FixObsoleteOverrides { get; set;} = true;
public bool UseLegacyJavaResolver { get; set; }
public bool UseObsoletedOSPlatformAttributes { get; set; }

Expand Down Expand Up @@ -104,14 +105,15 @@ public static CodeGeneratorOptions Parse (string[] args)
"SDK Platform {VERSION}/API level.",
v => opts.ApiLevel = v },
{ "lang-features=",
"For internal use. (Flags: interface-constants,default-interface-methods,nested-interface-types,nullable-reference-types,obsoleted-platform-attributes,restrict-to-attributes)",
"For internal use. (Flags: interface-constants,default-interface-methods,nested-interface-types,nullable-reference-types,obsoleted-platform-attributes,restrict-to-attributes,do-not-fix-obsolete-overrides)",
v => {
opts.SupportInterfaceConstants = v?.Contains ("interface-constants") == true;
opts.SupportDefaultInterfaceMethods = v?.Contains ("default-interface-methods") == true;
opts.SupportNestedInterfaceTypes = v?.Contains ("nested-interface-types") == true;
opts.SupportNullableReferenceTypes = v?.Contains ("nullable-reference-types") == true;
opts.UseObsoletedOSPlatformAttributes = v?.Contains ("obsoleted-platform-attributes") == true;
opts.UseRestrictToAttributes = v?.Contains ("restrict-to-attributes") == true;
opts.FixObsoleteOverrides = v?.Contains ("do-not-fix-obsolete-overrides") == false;
}},
{ "preserve-enums",
"For internal use.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,15 @@ public void FixupMethodOverrides (CodeGenerationOptions opt)
if (bm != null && bm.RetVal.FullName == m.RetVal.FullName) { // if return type is different, it could be still "new", not "override".
m.IsOverride = true;

// If method overrides a deprecated method, it also needs to be marked as deprecated
if (bm.Deprecated.HasValue () && !m.Deprecated.HasValue ())
m.Deprecated = bm.Deprecated;

// Fix issue when base method was deprecated before the overriding method, set both both to base method value
if (bm.DeprecatedSince.GetValueOrDefault (0) < m.DeprecatedSince.GetValueOrDefault (0))
m.DeprecatedSince = bm.DeprecatedSince;
if (opt.FixObsoleteOverrides) {
// If method overrides a deprecated method, it also needs to be marked as deprecated
if (bm.Deprecated.HasValue () && !m.Deprecated.HasValue ())
m.Deprecated = bm.Deprecated;

// Fix issue when base method was deprecated before the overriding method, set both both to base method value
if (bm.DeprecatedSince.GetValueOrDefault (0) < m.DeprecatedSince.GetValueOrDefault (0))
m.DeprecatedSince = bm.DeprecatedSince;
}

break;
}
Expand Down