Skip to content

Commit 2397fad

Browse files
committed
Create shared extension method IsDelegatingHttpApiCall
1 parent 3132a7b commit 2397fad

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

OpenStackNetAnalyzers/OpenStackNetAnalyzers/DocumentDelegatingApiCallAnalyzer.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace OpenStackNetAnalyzers
22
{
3-
using System;
43
using System.Collections.Immutable;
54
using System.Linq;
65
using Microsoft.CodeAnalysis;
@@ -40,7 +39,7 @@ private void HandleNamedType(SymbolAnalysisContext context)
4039
if (symbol.TypeKind != TypeKind.Class)
4140
return;
4241

43-
if (!IsDelegatingHttpApiCall(context, symbol))
42+
if (!symbol.IsDelegatingHttpApiCall())
4443
return;
4544

4645
if (!string.IsNullOrEmpty(symbol.GetDocumentationCommentXml(cancellationToken: context.CancellationToken)))
@@ -49,23 +48,5 @@ private void HandleNamedType(SymbolAnalysisContext context)
4948
var locations = symbol.Locations;
5049
context.ReportDiagnostic(Diagnostic.Create(Descriptor, locations.FirstOrDefault(), locations.Skip(1)));
5150
}
52-
53-
private bool IsDelegatingHttpApiCall(SymbolAnalysisContext context, INamedTypeSymbol symbol)
54-
{
55-
while (symbol != null && symbol.SpecialType != SpecialType.System_Object)
56-
{
57-
if (symbol.IsGenericType)
58-
{
59-
var originalDefinition = symbol.OriginalDefinition;
60-
string fullyQualifiedName = originalDefinition.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
61-
if (string.Equals("global::OpenStack.Net.DelegatingHttpApiCall<T>", fullyQualifiedName, StringComparison.Ordinal))
62-
return true;
63-
}
64-
65-
symbol = symbol.BaseType;
66-
}
67-
68-
return false;
69-
}
7051
}
7152
}

OpenStackNetAnalyzers/OpenStackNetAnalyzers/SdkTypeSymbolExtensions.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ internal static class SdkTypeSymbolExtensions
77
{
88
private const string FullyQualifiedExtensibleJsonObject = "global::OpenStack.ObjectModel.ExtensibleJsonObject";
99

10+
private const string FullyQualifiedDelegatingHttpApiCallT = "global::OpenStack.Net.DelegatingHttpApiCall<T>";
11+
1012
public static bool IsExtensibleJsonObject(this INamedTypeSymbol symbol)
1113
{
1214
while (symbol != null && symbol.SpecialType != SpecialType.System_Object)
@@ -19,5 +21,23 @@ public static bool IsExtensibleJsonObject(this INamedTypeSymbol symbol)
1921

2022
return false;
2123
}
24+
25+
public static bool IsDelegatingHttpApiCall(this INamedTypeSymbol symbol)
26+
{
27+
while (symbol != null && symbol.SpecialType != SpecialType.System_Object)
28+
{
29+
if (symbol.IsGenericType)
30+
{
31+
var originalDefinition = symbol.OriginalDefinition;
32+
string fullyQualifiedName = originalDefinition.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
33+
if (string.Equals(FullyQualifiedDelegatingHttpApiCallT, fullyQualifiedName, StringComparison.Ordinal))
34+
return true;
35+
}
36+
37+
symbol = symbol.BaseType;
38+
}
39+
40+
return false;
41+
}
2242
}
2343
}

0 commit comments

Comments
 (0)