Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React to Obsoleted attribute renaming #6116

Merged
merged 1 commit into from
Sep 3, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed partial class PlatformCompatibilityAnalyzer
/// </summary>
private class Versions
{
public Version? ObsoletedIn { get; set; }
public Version? Obsoleted { get; set; }
public string? ObsoletedMessage { get; set; }
public string? ObsoletedUrl { get; set; }
public Version? SupportedFirst { get; set; }
Expand All @@ -35,7 +35,7 @@ private class Versions
public string? UnsupportedMessage { get; set; }
public Version? UnsupportedSecond { get; set; }
public bool IsSet() => SupportedFirst != null || UnsupportedFirst != null ||
SupportedSecond != null || UnsupportedSecond != null || ObsoletedIn != null;
SupportedSecond != null || UnsupportedSecond != null || Obsoleted != null;
}

private sealed class PlatformAttributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public sealed partial class PlatformCompatibilityAnalyzer : DiagnosticAnalyzer
{
internal const string SupportRuleId = "CA1416";
internal const string ObsoletedRuleId = "CA1422";
private static readonly ImmutableArray<string> s_osPlatformAttributes = ImmutableArray.Create(SupportedOSPlatformAttribute, UnsupportedOSPlatformAttribute, ObsoletedInOSPlatformAttribute);
private static readonly ImmutableArray<string> s_osPlatformAttributes = ImmutableArray.Create(SupportedOSPlatformAttribute, UnsupportedOSPlatformAttribute, ObsoletedOSPlatformAttribute);

private static readonly LocalizableString s_localizableTitle = CreateLocalizableResourceString(nameof(PlatformCompatibilityTitle));
private static readonly LocalizableString s_localizableDescription = CreateLocalizableResourceString(nameof(PlatformCompatibilityDescription));

// We are adding the new attributes into older versions of .Net 5.0, so there could be multiple referenced assemblies each with their own
// version of internal attribute type which will cause ambiguity, to avoid that we are comparing the attributes by their name
private const string ObsoletedInOSPlatformAttribute = nameof(ObsoletedInOSPlatformAttribute);
private const string ObsoletedOSPlatformAttribute = nameof(ObsoletedOSPlatformAttribute);
private const string SupportedOSPlatformAttribute = nameof(SupportedOSPlatformAttribute);
private const string UnsupportedOSPlatformAttribute = nameof(UnsupportedOSPlatformAttribute);
private const string UnsupportedOSPlatformGuardAttribute = nameof(UnsupportedOSPlatformGuardAttribute);
Expand Down Expand Up @@ -528,10 +528,10 @@ static bool IsKnownValueGuarded(
attribute.UnsupportedSecond = null;
}

if (attribute.ObsoletedIn != null &&
attribute.ObsoletedIn.IsGreaterThanOrEqualTo(info.Version))
if (attribute.Obsoleted != null &&
attribute.Obsoleted.IsGreaterThanOrEqualTo(info.Version))
{
attribute.ObsoletedIn = null;
attribute.Obsoleted = null;
attribute.ObsoletedMessage = null;
attribute.ObsoletedUrl = null;
}
Expand Down Expand Up @@ -752,7 +752,7 @@ static void RemoveUnsupportsOnDifferentPlatforms(SmallDictionary<string, Version
attribute.SupportedSecond = null;
attribute.UnsupportedMessage = null;
}
attribute.ObsoletedIn = null;
attribute.Obsoleted = null;
attribute.ObsoletedMessage = null;
attribute.ObsoletedUrl = null;
}
Expand Down Expand Up @@ -897,7 +897,7 @@ static bool GetSupportedPlatforms(SmallDictionary<string, Versions> attributes,
}
}

AddObsoletedIn(csAttributes, obsoletedBuilder, pName, pAttribute);
AddObsoleted(csAttributes, obsoletedBuilder, pName, pAttribute);
}

obsoletedPlatforms = obsoletedBuilder.ToImmutable();
Expand Down Expand Up @@ -1058,7 +1058,7 @@ static bool GetPlatformNames(SmallDictionary<string, Versions> attributes, Small
}
}

AddObsoletedIn(csAttributes, obsoletedBuilder, pName, pAttribute);
AddObsoleted(csAttributes, obsoletedBuilder, pName, pAttribute);
}

obsoletedPlatforms = obsoletedBuilder.ToImmutable();
Expand All @@ -1067,11 +1067,11 @@ static bool GetPlatformNames(SmallDictionary<string, Versions> attributes, Small
}
}

static void AddObsoletedIn(SmallDictionary<string, Versions>? csAttributes, ArrayBuilder<string> obsoletedBuilder, string pName, Versions pAttribute)
static void AddObsoleted(SmallDictionary<string, Versions>? csAttributes, ArrayBuilder<string> obsoletedBuilder, string pName, Versions pAttribute)
{
if (pAttribute.ObsoletedIn != null)
if (pAttribute.Obsoleted != null)
{
if (IsEmptyVersion(pAttribute.ObsoletedIn)) // Do not need to add the version part if it is 0.0
if (IsEmptyVersion(pAttribute.Obsoleted)) // Do not need to add the version part if it is 0.0
{
if (csAttributes != null && HasVersionedCallsite(csAttributes, pName))
{
Expand All @@ -1084,7 +1084,7 @@ static void AddObsoletedIn(SmallDictionary<string, Versions>? csAttributes, Arra
}
else
{
obsoletedBuilder.Add(AppendMessageAndUrl(pAttribute, GetFormattedString(PlatformCompatibilityVersionAndLater, pName, pAttribute.ObsoletedIn)));
obsoletedBuilder.Add(AppendMessageAndUrl(pAttribute, GetFormattedString(PlatformCompatibilityVersionAndLater, pName, pAttribute.Obsoleted)));
}
}
}
Expand Down Expand Up @@ -1221,7 +1221,7 @@ static bool HasVersionedCallsite(SmallDictionary<string, Versions> csAttributes,
{
if (csAttributes.TryGetValue(pName, out var attribute))
{
var version = attribute.ObsoletedIn;
var version = attribute.Obsoleted;
var supportedVersion = attribute.SupportedSecond ?? attribute.SupportedFirst;
if (supportedVersion != null)
{
Expand Down Expand Up @@ -1596,33 +1596,33 @@ private static bool IsNotSuppressedByCallSite(SmallDictionary<string, Versions>
}

// Check if obsoleted attribute guarded by callsite attributes
if (attribute.ObsoletedIn != null)
if (attribute.Obsoleted != null)
{
if (callSiteAttributes.TryGetValue(platformName, out var callSiteAttribute))
{
if (callSiteAttribute.SupportedFirst != null)
{
if ((callSiteAttribute.ObsoletedIn == null || callSiteAttribute.ObsoletedIn > attribute.ObsoletedIn) &&
(callSiteAttribute.UnsupportedFirst == null || callSiteAttribute.UnsupportedFirst > attribute.ObsoletedIn))
if ((callSiteAttribute.Obsoleted == null || callSiteAttribute.Obsoleted > attribute.Obsoleted) &&
(callSiteAttribute.UnsupportedFirst == null || callSiteAttribute.UnsupportedFirst > attribute.Obsoleted))
{
diagnosticAttribute.ObsoletedIn = (Version)attribute.ObsoletedIn.Clone();
diagnosticAttribute.Obsoleted = (Version)attribute.Obsoleted.Clone();
diagnosticAttribute.ObsoletedMessage = attribute.ObsoletedMessage;
diagnosticAttribute.ObsoletedUrl = attribute.ObsoletedUrl;
}
}
else if (msBuildPlatforms.Contains(platformName, StringComparer.OrdinalIgnoreCase) &&
(callSiteAttribute.UnsupportedFirst != null && callSiteAttribute.UnsupportedFirst > attribute.ObsoletedIn ||
callSiteAttribute.ObsoletedIn != null && callSiteAttribute.ObsoletedIn > attribute.ObsoletedIn))
(callSiteAttribute.UnsupportedFirst != null && callSiteAttribute.UnsupportedFirst > attribute.Obsoleted ||
callSiteAttribute.Obsoleted != null && callSiteAttribute.Obsoleted > attribute.Obsoleted))
{
diagnosticAttribute.ObsoletedIn = (Version)attribute.ObsoletedIn.Clone();
diagnosticAttribute.Obsoleted = (Version)attribute.Obsoleted.Clone();
diagnosticAttribute.ObsoletedMessage = attribute.ObsoletedMessage;
diagnosticAttribute.ObsoletedUrl = attribute.ObsoletedUrl;
}
}
else if (msBuildPlatforms.Contains(platformName, StringComparer.OrdinalIgnoreCase) &&
!callSiteAttributes.Values.Any(AllowList))
{
diagnosticAttribute.ObsoletedIn = (Version)attribute.ObsoletedIn.Clone();
diagnosticAttribute.Obsoleted = (Version)attribute.Obsoleted.Clone();
diagnosticAttribute.ObsoletedMessage = attribute.ObsoletedMessage;
diagnosticAttribute.ObsoletedUrl = attribute.ObsoletedUrl;
}
Expand Down Expand Up @@ -1716,7 +1716,7 @@ private static Versions CopyAllAttributes(Versions copyTo, Versions copyFrom)
copyTo.UnsupportedFirst = (Version?)copyFrom.UnsupportedFirst?.Clone();
copyTo.UnsupportedSecond = (Version?)copyFrom.UnsupportedSecond?.Clone();
copyTo.UnsupportedMessage = copyFrom.UnsupportedMessage;
copyTo.ObsoletedIn = (Version?)copyFrom.ObsoletedIn?.Clone();
copyTo.Obsoleted = (Version?)copyFrom.Obsoleted?.Clone();
copyTo.ObsoletedMessage = copyFrom.ObsoletedMessage;
copyTo.ObsoletedUrl = copyFrom.ObsoletedUrl;
return copyTo;
Expand Down Expand Up @@ -1829,13 +1829,13 @@ static void MergePlatformAttributes(ImmutableArray<AttributeData> immediateAttri
}
}

if (childAttribute.ObsoletedIn != null &&
(childAttribute.ObsoletedIn < existing.UnsupportedFirst ||
if (childAttribute.Obsoleted != null &&
(childAttribute.Obsoleted < existing.UnsupportedFirst ||
existing.SupportedFirst != null &&
(existing.UnsupportedSecond == null || existing.UnsupportedSecond > childAttribute.ObsoletedIn)) &&
(existing.ObsoletedIn == null || childAttribute.ObsoletedIn < existing.ObsoletedIn))
(existing.UnsupportedSecond == null || existing.UnsupportedSecond > childAttribute.Obsoleted)) &&
(existing.Obsoleted == null || childAttribute.Obsoleted < existing.Obsoleted))
{
existing.ObsoletedIn = childAttribute.ObsoletedIn;
existing.Obsoleted = childAttribute.Obsoleted;
existing.ObsoletedMessage = childAttribute.ObsoletedMessage;
existing.ObsoletedUrl = childAttribute.ObsoletedMessage;
}
Expand Down Expand Up @@ -1896,10 +1896,10 @@ static void MergePlatformAttributes(ImmutableArray<AttributeData> immediateAttri

// Check for Obsoleted attributes, only lower version could overwrite
if (childAttributes.TryGetValue(platform, out var childAttr) &&
childAttr.ObsoletedIn != null &&
(attributes.ObsoletedIn == null || childAttr.ObsoletedIn < attributes.ObsoletedIn))
childAttr.Obsoleted != null &&
(attributes.Obsoleted == null || childAttr.Obsoleted < attributes.Obsoleted))
{
attributes.ObsoletedIn = childAttr.ObsoletedIn;
attributes.Obsoleted = childAttr.Obsoleted;
attributes.ObsoletedMessage = childAttr.ObsoletedMessage;
attributes.ObsoletedUrl = childAttr.ObsoletedUrl;
}
Expand Down Expand Up @@ -2110,7 +2110,7 @@ private static bool AddAttribute(AttributeData attribute, Version version, Versi
}
else
{
Debug.Assert(name == ObsoletedInOSPlatformAttribute);
Debug.Assert(name == ObsoletedOSPlatformAttribute);
AddOrUpdateObsoletedAttribute(attribute, attributes, version);
}

Expand All @@ -2121,19 +2121,19 @@ static void AddOrUpdateObsoletedAttribute(AttributeData attribute, Versions attr
var message = PopulateMessage(attribute);
var url = PopulateUrl(attribute);

if (attributes.ObsoletedIn != null)
if (attributes.Obsoleted != null)
{
// only keep lowest version, ignore other versions
if (attributes.ObsoletedIn > version)
if (attributes.Obsoleted > version)
{
attributes.ObsoletedIn = version;
attributes.Obsoleted = version;
attributes.ObsoletedMessage = message;
attributes.ObsoletedUrl = url;
}
}
else
{
attributes.ObsoletedIn = version;
attributes.Obsoleted = version;
attributes.ObsoletedMessage = message;
attributes.ObsoletedUrl = url;
}
Expand Down
Loading