forked from KathleenDollard/CodeFirstMetadata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.txt
57 lines (48 loc) · 2.32 KB
/
test2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// This file was generated, if you change it your changes are toast
// Generation was last done on 12/4/2014 12:00:00 AM using template DiagnosticTemplate
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace KathleensAnalyzer
{
// TODO: Consider implementing other interfaces that implement IDiagnosticAnalyzer instead of or in addition to ISymbolAnalyzer
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class IfElseBraceDiagnosticCodeFirst : DiagnosticAnalyzer
{
public const string DiagnosticId = "KADGEN1001";
internal const string Description = "Needs braces";
internal const string MessageFormat = "{0} needs braces";
internal const string Category = "Style";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Description, MessageFormat, Category, DiagnosticSeverity.Error, true);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get { return ImmutableArray.Create(Rule); } }
public override void Initialize(AnalysisContext context)
{
context.RegisterSyntaxNodeAction(AnalyzeNodes, SyntaxKind.IfStatement, SyntaxKind.IfStatement);
}
private void AnalyzeNodes(SyntaxNodeAnalysisContext context)
{
var ifStatementSyntax = context.Node as IfStatementSyntax;
if (ifStatementSyntax != null
&& (!ifStatementSyntax.Statement.IsKind(SyntaxKind.Block)))
{
Location loc = ifStatementSyntax.IfKeyword.GetLocation();
Diagnostic diagnostic = Diagnostic.Create(Rule, loc, "if statement");
context.ReportDiagnostic(diagnostic);
}
var elseClauseSyntax = context.Node as ElseClauseSyntax;
if (elseClauseSyntax != null
&& (!elseClauseSyntax.Statement.IsKind(SyntaxKind.Block)
&& !elseClauseSyntax.Statement.IsKind(SyntaxKind.IfStatement)))
{
Location loc = elseClauseSyntax.ElseKeyword.GetLocation();
Diagnostic diagnostic = Diagnostic.Create(Rule, loc, "else statement");
context.ReportDiagnostic(diagnostic);
}
}
}
}