mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Extract duplicated code in analyzers
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -18,15 +17,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
ClassDeclarationSyntax classDeclaration,
|
||||
ITypeSymbol type)
|
||||
{
|
||||
if (context.Node is not ClassDeclarationSyntax classDeclaration)
|
||||
return;
|
||||
|
||||
var type = context.SemanticModel.GetDeclaredSymbol(classDeclaration);
|
||||
if (type is null)
|
||||
return;
|
||||
|
||||
// Ignore abstract classes, because they may be used to define
|
||||
// base implementations for commands, in which case the command
|
||||
// attribute doesn't make sense.
|
||||
@@ -53,7 +48,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.ClassDeclaration);
|
||||
context.HandleClassDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -18,15 +17,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
ClassDeclarationSyntax classDeclaration,
|
||||
ITypeSymbol type)
|
||||
{
|
||||
if (context.Node is not ClassDeclarationSyntax classDeclaration)
|
||||
return;
|
||||
|
||||
var type = context.SemanticModel.GetDeclaredSymbol(classDeclaration);
|
||||
if (type is null)
|
||||
return;
|
||||
|
||||
var hasCommandAttribute = type
|
||||
.GetAttributes()
|
||||
.Select(a => a.AttributeClass)
|
||||
@@ -47,7 +42,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.ClassDeclaration);
|
||||
context.HandleClassDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -18,15 +17,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
if (property.ContainingType.IsAbstract)
|
||||
return;
|
||||
|
||||
@@ -47,7 +42,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -16,15 +16,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
var option = CommandOptionSymbol.TryResolve(property);
|
||||
if (option is null)
|
||||
return;
|
||||
@@ -38,7 +34,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -18,15 +18,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
var option = CommandOptionSymbol.TryResolve(property);
|
||||
if (option is null)
|
||||
return;
|
||||
@@ -60,7 +56,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Linq;
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -17,15 +17,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
var option = CommandOptionSymbol.TryResolve(property);
|
||||
if (option is null)
|
||||
return;
|
||||
@@ -59,7 +55,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -18,15 +17,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
var option = CommandOptionSymbol.TryResolve(property);
|
||||
if (option is null)
|
||||
return;
|
||||
@@ -49,7 +44,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -16,15 +16,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
var option = CommandOptionSymbol.TryResolve(property);
|
||||
if (option is null)
|
||||
return;
|
||||
@@ -41,7 +37,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -16,15 +16,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
var option = CommandOptionSymbol.TryResolve(property);
|
||||
if (option is null)
|
||||
return;
|
||||
@@ -41,7 +37,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -18,15 +17,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
var option = CommandOptionSymbol.TryResolve(property);
|
||||
if (option is null)
|
||||
return;
|
||||
@@ -51,7 +46,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -18,15 +17,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
if (property.ContainingType.IsAbstract)
|
||||
return;
|
||||
|
||||
@@ -47,7 +42,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -25,15 +24,11 @@ namespace CliFx.Analyzers
|
||||
.Select(i => i.ConstructedFrom)
|
||||
.Any(s => s.DisplayNameMatches("System.Collections.Generic.IEnumerable<T>"));
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
if (IsScalar(property.Type))
|
||||
return;
|
||||
|
||||
@@ -64,7 +59,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -25,15 +24,11 @@ namespace CliFx.Analyzers
|
||||
.Select(i => i.ConstructedFrom)
|
||||
.Any(s => s.DisplayNameMatches("System.Collections.Generic.IEnumerable<T>"));
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
if (!CommandParameterSymbol.IsParameterProperty(property))
|
||||
return;
|
||||
|
||||
@@ -62,7 +57,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -18,15 +18,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
var parameter = CommandParameterSymbol.TryResolve(property);
|
||||
if (parameter is null)
|
||||
return;
|
||||
@@ -60,7 +56,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Linq;
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -17,15 +17,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
var parameter = CommandParameterSymbol.TryResolve(property);
|
||||
if (parameter is null)
|
||||
return;
|
||||
@@ -53,7 +49,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -18,15 +17,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
var parameter = CommandParameterSymbol.TryResolve(property);
|
||||
if (parameter is null)
|
||||
return;
|
||||
@@ -49,7 +44,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
@@ -18,15 +17,11 @@ namespace CliFx.Analyzers
|
||||
{
|
||||
}
|
||||
|
||||
private void Analyze(SyntaxNodeAnalysisContext context)
|
||||
private void Analyze(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
PropertyDeclarationSyntax propertyDeclaration,
|
||||
IPropertySymbol property)
|
||||
{
|
||||
if (context.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
var parameter = CommandParameterSymbol.TryResolve(property);
|
||||
if (parameter is null)
|
||||
return;
|
||||
@@ -51,7 +46,7 @@ namespace CliFx.Analyzers
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
base.Initialize(context);
|
||||
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.PropertyDeclaration);
|
||||
context.HandlePropertyDeclaration(Analyze);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
namespace CliFx.Analyzers.Utils.Extensions
|
||||
{
|
||||
@@ -7,5 +10,39 @@ namespace CliFx.Analyzers.Utils.Extensions
|
||||
{
|
||||
public static bool DisplayNameMatches(this ISymbol symbol, string name) =>
|
||||
string.Equals(symbol.ToDisplayString(), name, StringComparison.Ordinal);
|
||||
|
||||
public static void HandleClassDeclaration(
|
||||
this AnalysisContext analysisContext,
|
||||
Action<SyntaxNodeAnalysisContext, ClassDeclarationSyntax, ITypeSymbol> handler)
|
||||
{
|
||||
analysisContext.RegisterSyntaxNodeAction(ctx =>
|
||||
{
|
||||
if (ctx.Node is not ClassDeclarationSyntax classDeclaration)
|
||||
return;
|
||||
|
||||
var type = ctx.SemanticModel.GetDeclaredSymbol(classDeclaration);
|
||||
if (type is null)
|
||||
return;
|
||||
|
||||
handler(ctx, classDeclaration, type);
|
||||
}, SyntaxKind.ClassDeclaration);
|
||||
}
|
||||
|
||||
public static void HandlePropertyDeclaration(
|
||||
this AnalysisContext analysisContext,
|
||||
Action<SyntaxNodeAnalysisContext, PropertyDeclarationSyntax, IPropertySymbol> handler)
|
||||
{
|
||||
analysisContext.RegisterSyntaxNodeAction(ctx =>
|
||||
{
|
||||
if (ctx.Node is not PropertyDeclarationSyntax propertyDeclaration)
|
||||
return;
|
||||
|
||||
var property = ctx.SemanticModel.GetDeclaredSymbol(propertyDeclaration);
|
||||
if (property is null)
|
||||
return;
|
||||
|
||||
handler(ctx, propertyDeclaration, property);
|
||||
}, SyntaxKind.PropertyDeclaration);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user