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
diff options
context:
space:
mode:
authorJackson Schuster <jschuster@microsoft.com>2021-12-09 21:16:29 +0300
committerJackson Schuster <jschuster@microsoft.com>2021-12-10 01:40:47 +0300
commit35e9b3b3aad4d5c252b653bb864ef3ecb8653c73 (patch)
treeff199419c2d3602562cf1027d907da29174efa22
parent8a26f1cc23c41a59e041a93aa3a1e92ce587e293 (diff)
Move IsMemberInRequiresScope logic to extension method for DiagnosticAnalyzer
-rw-r--r--src/ILLink.RoslynAnalyzer/COMAnalyzer.cs9
-rw-r--r--src/ILLink.RoslynAnalyzer/DiagnosticAnalyzerExtenstions.cs27
-rw-r--r--src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs1
3 files changed, 29 insertions, 8 deletions
diff --git a/src/ILLink.RoslynAnalyzer/COMAnalyzer.cs b/src/ILLink.RoslynAnalyzer/COMAnalyzer.cs
index 320efc7df..f7586a94c 100644
--- a/src/ILLink.RoslynAnalyzer/COMAnalyzer.cs
+++ b/src/ILLink.RoslynAnalyzer/COMAnalyzer.cs
@@ -40,13 +40,8 @@ namespace ILLink.RoslynAnalyzer
if (!targetMethod.HasAttribute (DllImportAttribute))
return;
- if (operationContext.ContainingSymbol is ISymbol containingSymbol) {
- if (containingSymbol.HasAttribute (RequiresUnreferencedCodeAttribute)
- || (containingSymbol is not ITypeSymbol &&
- containingSymbol.ContainingType.HasAttribute (RequiresUnreferencedCodeAttribute))) {
- return;
- }
- }
+ if (this.IsMemberInRequiresScope (operationContext.ContainingSymbol, RequiresUnreferencedCodeAttribute))
+ return;
bool comDangerousMethod = IsComInterop (targetMethod.ReturnType);
foreach (var parameter in targetMethod.Parameters) {
diff --git a/src/ILLink.RoslynAnalyzer/DiagnosticAnalyzerExtenstions.cs b/src/ILLink.RoslynAnalyzer/DiagnosticAnalyzerExtenstions.cs
new file mode 100644
index 000000000..390870d89
--- /dev/null
+++ b/src/ILLink.RoslynAnalyzer/DiagnosticAnalyzerExtenstions.cs
@@ -0,0 +1,27 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.Diagnostics;
+
+namespace ILLink.RoslynAnalyzer
+{
+ static class RoslynDiagnosticAnalyzerExtenstions
+ {
+ public static bool IsMemberInRequiresScope(this DiagnosticAnalyzer _, ISymbol member, string requiresAttribute)
+ {
+ if (member is ISymbol containingSymbol) {
+ if (containingSymbol.HasAttribute (requiresAttribute)
+ || (containingSymbol is not ITypeSymbol &&
+ containingSymbol.ContainingType.HasAttribute (requiresAttribute))) {
+ return true;
+ }
+ }
+ if (member is IMethodSymbol { AssociatedSymbol: { } associated } && associated.HasAttribute (requiresAttribute))
+ return true;
+
+ return false;
+ }
+ }
+
+}
diff --git a/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs b/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs
index 1c6654e2b..436845323 100644
--- a/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs
+++ b/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs
@@ -348,7 +348,6 @@ namespace ILLink.RoslynAnalyzer
/// </summary>
protected bool IsMemberInRequiresScope (ISymbol member)
{
- if (containingSymbol.HasAttribute (RequiresAttributeName) ||
containingSymbol.ContainingType.HasAttribute (RequiresAttributeName)) {
return true;
}