Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJackson Schuster <jschuster@microsoft.com>2021-12-10 00:23:39 +0300
committerJackson Schuster <jschuster@microsoft.com>2021-12-10 01:44:46 +0300
commit012f3c0773c498c8601eb9af806aba1267b40342 (patch)
tree46965de7068594e8a0042b1d2a3805918d6b1d28 /src
parent02d5a8c2fa2ead9bab2d14f00749010a37316802 (diff)
Use the ISymbol extensions for Requires analyzers
Diffstat (limited to 'src')
-rw-r--r--src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs b/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs
index efe00031b..e08359149 100644
--- a/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs
+++ b/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs
@@ -6,14 +6,35 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace ILLink.RoslynAnalyzer
{
public static class RequiresISymbolExtensions
{
// TODO: Consider sharing with linker IsMethodInRequiresUnreferencedCodeScope method
+ /// <summary>
+ /// True if the source of a call is considered to be annotated with the Requires... attribute
+ /// </summary>
public static bool IsInRequiresScope (this ISymbol member, string requiresAttribute)
{
+ return member.IsInRequiresScope (requiresAttribute, true);
+ }
+
+ /// <summary>
+ /// True if member of a call is considered to be annotated with the Requires... attribute.
+ /// Doesn't check the associated symbol for overrides and virtual methods because the analyzer should warn on mismatched between the property AND the accessors
+ /// </summary>
+ /// <param name="containingSymbol">
+ /// Symbol that is either an overriding member or an overriden/virtual member
+ /// </param>
+ public static bool IsOverrideInRequiresScope(this ISymbol member, string requiresAttribute)
+ {
+ return member.IsInRequiresScope(requiresAttribute, false);
+ }
+
+ private static bool IsInRequiresScope (this ISymbol member, string requiresAttribute, bool checkAssociatedSymbol)
+ {
if (member is ISymbol containingSymbol) {
if (containingSymbol.HasAttribute (requiresAttribute)
|| (containingSymbol is not ITypeSymbol &&
@@ -21,7 +42,8 @@ namespace ILLink.RoslynAnalyzer
return true;
}
}
- if (member is IMethodSymbol { AssociatedSymbol: { } associated } && associated.HasAttribute (requiresAttribute))
+ // Only check associated symbol if not override or virtual method
+ if (checkAssociatedSymbol && member is IMethodSymbol { AssociatedSymbol: { } associated } && associated.HasAttribute (requiresAttribute))
return true;
return false;