Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
65268326
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
65268326
编写于
5月 29, 2018
作者:
S
Sam Harwell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass effective severity as a separate argument to Diagnostic.Create
上级
a97916c3
变更
38
隐藏空白更改
内联
并排
Showing
38 changed file
with
204 addition
and
186 deletion
+204
-186
src/Features/CSharp/Portable/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersDiagnosticAnalyzer.cs
...iers/CSharpAddAccessibilityModifiersDiagnosticAnalyzer.cs
+4
-2
src/Features/CSharp/Portable/AddBraces/CSharpAddBracesDiagnosticAnalyzer.cs
...p/Portable/AddBraces/CSharpAddBracesDiagnosticAnalyzer.cs
+7
-2
src/Features/CSharp/Portable/Diagnostics/Analyzers/CSharpTypeStyleDiagnosticAnalyzerBase.cs
...ostics/Analyzers/CSharpTypeStyleDiagnosticAnalyzerBase.cs
+4
-4
src/Features/CSharp/Portable/InlineDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs
...eDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs
+4
-2
src/Features/CSharp/Portable/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessAnalyzer.cs
...onalAccess/InvokeDelegateWithConditionalAccessAnalyzer.cs
+2
-1
src/Features/CSharp/Portable/OrderModifiers/CSharpOrderModifiersDiagnosticAnalyzer.cs
.../OrderModifiers/CSharpOrderModifiersDiagnosticAnalyzer.cs
+4
-4
src/Features/CSharp/Portable/RemoveUnreachableCode/CSharpRemoveUnreachableCodeDiagnosticAnalyzer.cs
...ableCode/CSharpRemoveUnreachableCodeDiagnosticAnalyzer.cs
+1
-1
src/Features/CSharp/Portable/UseDeconstruction/CSharpUseDeconstructionDiagnosticAnalyzer.cs
...construction/CSharpUseDeconstructionDiagnosticAnalyzer.cs
+10
-4
src/Features/CSharp/Portable/UseDefaultLiteral/CSharpUseDefaultLiteralDiagnosticAnalyzer.cs
...faultLiteral/CSharpUseDefaultLiteralDiagnosticAnalyzer.cs
+6
-3
src/Features/CSharp/Portable/UseExpressionBody/UseExpressionBodyDiagnosticAnalyzer.cs
.../UseExpressionBody/UseExpressionBodyDiagnosticAnalyzer.cs
+5
-10
src/Features/CSharp/Portable/UseInferredMemberName/CSharpUseInferredMemberNameDiagnosticAnalyzer.cs
...mberName/CSharpUseInferredMemberNameDiagnosticAnalyzer.cs
+12
-6
src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionDiagnosticAnalyzer.cs
...LocalFunction/CSharpUseLocalFunctionDiagnosticAnalyzer.cs
+12
-6
src/Features/CSharp/Portable/UsePatternMatching/CSharpAsAndNullCheckDiagnosticAnalyzer.cs
...PatternMatching/CSharpAsAndNullCheckDiagnosticAnalyzer.cs
+4
-2
src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckDiagnosticAnalyzer.cs
...PatternMatching/CSharpIsAndCastCheckDiagnosticAnalyzer.cs
+4
-2
src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.cs
...hing/CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.cs
+1
-1
src/Features/Core/Portable/AddRequiredParentheses/AbstractAddRequiredParenthesesDiagnosticAnalyzer.cs
...heses/AbstractAddRequiredParenthesesDiagnosticAnalyzer.cs
+2
-1
src/Features/Core/Portable/CodeStyle/AbstractCodeStyleDiagnosticAnalyzer.cs
...Portable/CodeStyle/AbstractCodeStyleDiagnosticAnalyzer.cs
+15
-39
src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyleDiagnosticAnalyzerBase.cs
...iagnostics/Analyzers/NamingStyleDiagnosticAnalyzerBase.cs
+2
-2
src/Features/Core/Portable/Diagnostics/Analyzers/PreferFrameworkTypeDiagnosticAnalyzerBase.cs
...cs/Analyzers/PreferFrameworkTypeDiagnosticAnalyzerBase.cs
+5
-12
src/Features/Core/Portable/Diagnostics/Analyzers/SimplifyTypeNamesDiagnosticAnalyzerBase.cs
...tics/Analyzers/SimplifyTypeNamesDiagnosticAnalyzerBase.cs
+25
-23
src/Features/Core/Portable/MakeFieldReadonly/AbstractMakeFieldReadonlyDiagnosticAnalyzer.cs
...ldReadonly/AbstractMakeFieldReadonlyDiagnosticAnalyzer.cs
+5
-2
src/Features/Core/Portable/OrderModifiers/AbstractOrderModifiersDiagnosticAnalyzer.cs
...rderModifiers/AbstractOrderModifiersDiagnosticAnalyzer.cs
+6
-7
src/Features/Core/Portable/PopulateSwitch/PopulateSwitchDiagnosticAnalyzer.cs
...rtable/PopulateSwitch/PopulateSwitchDiagnosticAnalyzer.cs
+1
-1
src/Features/Core/Portable/QualifyMemberAccess/AbstractQualifyMemberAccessDiagnosticAnalyzer.cs
...erAccess/AbstractQualifyMemberAccessDiagnosticAnalyzer.cs
+5
-2
src/Features/Core/Portable/RemoveUnnecessaryParentheses/AbstractRemoveUnnecessaryParenthesesDiagnosticAnalyzer.cs
...AbstractRemoveUnnecessaryParenthesesDiagnosticAnalyzer.cs
+5
-2
src/Features/Core/Portable/UseAutoProperty/AbstractUseAutoPropertyAnalyzer.cs
...rtable/UseAutoProperty/AbstractUseAutoPropertyAnalyzer.cs
+6
-18
src/Features/Core/Portable/UseCoalesceExpression/AbstractUseCoalesceExpressionDiagnosticAnalyzer.cs
...ession/AbstractUseCoalesceExpressionDiagnosticAnalyzer.cs
+4
-2
src/Features/Core/Portable/UseCoalesceExpression/AbstractUseCoalesceExpressionForNullableDiagnosticAnalyzer.cs
...ractUseCoalesceExpressionForNullableDiagnosticAnalyzer.cs
+4
-2
src/Features/Core/Portable/UseCollectionInitializer/AbstractUseCollectionInitializerDiagnosticAnalyzer.cs
...zer/AbstractUseCollectionInitializerDiagnosticAnalyzer.cs
+4
-2
src/Features/Core/Portable/UseConditionalExpression/AbstractUseConditionalExpressionDiagnosticAnalyzer.cs
...ion/AbstractUseConditionalExpressionDiagnosticAnalyzer.cs
+4
-2
src/Features/Core/Portable/UseExplicitTupleName/UseExplicitTupleNameDiagnosticAnalyzer.cs
...plicitTupleName/UseExplicitTupleNameDiagnosticAnalyzer.cs
+3
-1
src/Features/Core/Portable/UseIsNullCheck/AbstractUseIsNullDiagnosticAnalyzer.cs
...ble/UseIsNullCheck/AbstractUseIsNullDiagnosticAnalyzer.cs
+2
-1
src/Features/Core/Portable/UseNullPropagation/AbstractUseNullPropagationDiagnosticAnalyzer.cs
...opagation/AbstractUseNullPropagationDiagnosticAnalyzer.cs
+2
-1
src/Features/Core/Portable/UseObjectInitializer/AbstractUseObjectInitializerDiagnosticAnalyzer.cs
...ializer/AbstractUseObjectInitializerDiagnosticAnalyzer.cs
+4
-2
src/Features/Core/Portable/UseThrowExpression/AbstractUseThrowExpressionDiagnosticAnalyzer.cs
...xpression/AbstractUseThrowExpressionDiagnosticAnalyzer.cs
+1
-3
src/Features/VisualBasic/Portable/AddAccessibilityModifiers/VisualBasicAddAccessibilityModifiersDiagnosticAnalyzer.vb
...VisualBasicAddAccessibilityModifiersDiagnosticAnalyzer.vb
+4
-2
src/Features/VisualBasic/Portable/OrderModifiers/VisualBasicOrderModifiersDiagnosticAnalyzer.vb
...rModifiers/VisualBasicOrderModifiersDiagnosticAnalyzer.vb
+3
-3
src/Features/VisualBasic/Portable/UseInferredMemberName/VisualBasicUseInferredMemberNameDiagnosticAnalyzer.vb
...ame/VisualBasicUseInferredMemberNameDiagnosticAnalyzer.vb
+12
-6
未找到文件。
src/Features/CSharp/Portable/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -132,9 +132,11 @@ public CSharpAddAccessibilityModifiersDiagnosticAnalyzer()
// Have an issue to flag, either add or remove. Report issue to user.
var
additionalLocations
=
ImmutableArray
.
Create
(
member
.
GetLocation
());
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
CreateDescriptorWithSeverity
(
option
.
Notification
.
Value
)
,
Descriptor
,
name
.
GetLocation
(),
additionalLocations
:
additionalLocations
));
option
.
Notification
.
Value
,
additionalLocations
:
additionalLocations
,
properties
:
null
));
}
}
}
src/Features/CSharp/Portable/AddBraces/CSharpAddBracesDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -78,8 +78,13 @@ public void AnalyzeNode(SyntaxNodeAnalysisContext context)
}
var
firstToken
=
statement
.
GetFirstToken
();
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
option
.
Notification
.
Value
),
firstToken
.
GetLocation
(),
SyntaxFacts
.
GetText
(
firstToken
.
Kind
())));
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
Descriptor
,
firstToken
.
GetLocation
(),
option
.
Notification
.
Value
,
additionalLocations
:
null
,
properties
:
null
,
SyntaxFacts
.
GetText
(
firstToken
.
Kind
())));
}
}
}
src/Features/CSharp/Portable/Diagnostics/Analyzers/CSharpTypeStyleDiagnosticAnalyzerBase.cs
浏览文件 @
65268326
...
...
@@ -70,11 +70,11 @@ private void HandleVariableDeclaration(SyntaxNodeAnalysisContext context)
}
// The severity preference is not Hidden, as indicated by IsStylePreferred.
var
descriptor
=
GetDescriptorWithSeverity
(
typeStyle
.
Severity
)
;
context
.
ReportDiagnostic
(
CreateDiagnostic
(
descriptor
,
declarationStatement
,
declaredType
.
Span
));
var
descriptor
=
Descriptor
;
context
.
ReportDiagnostic
(
CreateDiagnostic
(
descriptor
,
declarationStatement
,
declaredType
.
Span
,
typeStyle
.
Severity
));
}
private
Diagnostic
CreateDiagnostic
(
DiagnosticDescriptor
descriptor
,
SyntaxNode
declaration
,
TextSpan
diagnosticSpan
)
=>
Diagnostic
.
Create
(
descriptor
,
declaration
.
SyntaxTree
.
GetLocation
(
diagnosticSpan
));
private
Diagnostic
CreateDiagnostic
(
DiagnosticDescriptor
descriptor
,
SyntaxNode
declaration
,
TextSpan
diagnosticSpan
,
DiagnosticSeverity
severity
)
=>
Diagnostic
.
Create
(
descriptor
,
declaration
.
SyntaxTree
.
GetLocation
(
diagnosticSpan
)
,
severity
,
additionalLocations
:
null
,
properties
:
null
);
}
}
src/Features/CSharp/Portable/InlineDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -241,9 +241,11 @@ private void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context, INamedTypeSymb
:
localDeclarator
;
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
option
.
Notification
.
Value
)
,
Descriptor
,
reportNode
.
GetLocation
(),
additionalLocations
:
allLocations
));
option
.
Notification
.
Value
,
additionalLocations
:
allLocations
,
properties
:
null
));
}
private
bool
WouldCauseDefiniteAssignmentErrors
(
...
...
src/Features/CSharp/Portable/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -180,8 +180,9 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
// Put a diagnostic with the appropriate severity on the expression-statement itself.
syntaxContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
severity
)
,
Descriptor
,
expressionStatement
.
GetLocation
(),
severity
,
additionalLocations
,
properties
));
// If the if-statement extends past the expression statement, then fade out the rest.
...
...
src/Features/CSharp/Portable/OrderModifiers/CSharpOrderModifiersDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -22,7 +22,7 @@ public CSharpOrderModifiersDiagnosticAnalyzer()
protected
override
void
Recurse
(
SyntaxTreeAnalysisContext
context
,
Dictionary
<
int
,
int
>
preferredOrder
,
Diagnostic
Descriptor
descriptor
,
Diagnostic
Severity
severity
,
SyntaxNode
root
)
{
foreach
(
var
child
in
root
.
ChildNodesAndTokens
())
...
...
@@ -32,19 +32,19 @@ public CSharpOrderModifiersDiagnosticAnalyzer()
var
node
=
child
.
AsNode
();
if
(
node
is
MemberDeclarationSyntax
memberDeclaration
)
{
CheckModifiers
(
context
,
preferredOrder
,
descriptor
,
memberDeclaration
);
CheckModifiers
(
context
,
preferredOrder
,
severity
,
memberDeclaration
);
// Recurse and check children. Note: we only do this if we're on an actual
// member declaration. Once we hit something that isn't, we don't need to
// keep recursing. This prevents us from actually entering things like method
// bodies.
Recurse
(
context
,
preferredOrder
,
descriptor
,
node
);
Recurse
(
context
,
preferredOrder
,
severity
,
node
);
}
else
if
(
node
is
AccessorListSyntax
accessorList
)
{
foreach
(
var
accessor
in
accessorList
.
Accessors
)
{
CheckModifiers
(
context
,
preferredOrder
,
descriptor
,
accessor
);
CheckModifiers
(
context
,
preferredOrder
,
severity
,
accessor
);
}
}
}
...
...
src/Features/CSharp/Portable/RemoveUnreachableCode/CSharpRemoveUnreachableCodeDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -133,7 +133,7 @@ private void AnalyzeSemanticModel(SemanticModelAnalysisContext context)
// statement in this group.
var
additionalLocations
=
SpecializedCollections
.
SingletonEnumerable
(
firstStatementLocation
);
var
descriptor
=
fadeOutCode
?
UnnecessaryWithSuggestionDescriptor
:
Hidden
Descriptor
;
var
descriptor
=
fadeOutCode
?
UnnecessaryWithSuggestionDescriptor
:
Descriptor
;
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
descriptor
,
firstStatementLocation
,
additionalLocations
));
...
...
src/Features/CSharp/Portable/UseDeconstruction/CSharpUseDeconstructionDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -75,8 +75,11 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
}
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
this
.
GetDescriptorWithSeverity
(
severity
),
variableDeclaration
.
Variables
[
0
].
Identifier
.
GetLocation
()));
Descriptor
,
variableDeclaration
.
Variables
[
0
].
Identifier
.
GetLocation
(),
severity
,
additionalLocations
:
null
,
properties
:
null
));
}
private
void
AnalyzeForEachStatement
(
...
...
@@ -90,8 +93,11 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
}
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
this
.
GetDescriptorWithSeverity
(
severity
),
forEachStatement
.
Identifier
.
GetLocation
()));
Descriptor
,
forEachStatement
.
Identifier
.
GetLocation
(),
severity
,
additionalLocations
:
null
,
properties
:
null
));
}
public
static
bool
TryAnalyzeVariableDeclaration
(
...
...
src/Features/CSharp/Portable/UseDefaultLiteral/CSharpUseDefaultLiteralDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -50,9 +50,12 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
// Create a normal diagnostic that covers the entire default expression.
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
optionSet
.
GetOption
(
CSharpCodeStyleOptions
.
PreferSimpleDefaultExpression
).
Notification
.
Value
),
defaultExpression
.
GetLocation
()));
Diagnostic
.
Create
(
Descriptor
,
defaultExpression
.
GetLocation
(),
optionSet
.
GetOption
(
CSharpCodeStyleOptions
.
PreferSimpleDefaultExpression
).
Notification
.
Value
,
additionalLocations
:
null
,
properties
:
null
));
// Also fade out the part of the default expression from the open paren through
// the close paren.
...
...
src/Features/CSharp/Portable/UseExpressionBody/UseExpressionBodyDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -28,7 +28,7 @@ public UseExpressionBodyDiagnosticAnalyzer()
{
_syntaxKinds
=
_helpers
.
SelectMany
(
h
=>
h
.
SyntaxKinds
).
ToImmutableArray
();
SupportedDiagnostics
=
_helpers
.
SelectAsArray
(
h
=>
CreateDescriptorWithId
(
h
.
DiagnosticId
,
h
.
UseExpressionBodyTitle
,
h
.
UseExpressionBodyTitle
,
DiagnosticSeverity
.
Hidden
));
h
=>
CreateDescriptorWithId
(
h
.
DiagnosticId
,
h
.
UseExpressionBodyTitle
,
h
.
UseExpressionBodyTitle
));
}
public
override
DiagnosticAnalyzerCategory
GetAnalyzerCategory
()
...
...
@@ -97,8 +97,8 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
var
additionalLocations
=
ImmutableArray
.
Create
(
declaration
.
GetLocation
());
var
properties
=
ImmutableDictionary
<
string
,
string
>.
Empty
.
Add
(
nameof
(
UseExpressionBody
),
""
);
return
Diagnostic
.
Create
(
CreateDescriptorWithId
(
helper
.
DiagnosticId
,
helper
.
UseExpressionBodyTitle
,
helper
.
UseExpressionBodyTitle
,
severity
,
GetCustomTags
(
severity
)
),
location
,
additionalLocations
:
additionalLocations
,
properties
:
properties
);
CreateDescriptorWithId
(
helper
.
DiagnosticId
,
helper
.
UseExpressionBodyTitle
,
helper
.
UseExpressionBodyTitle
),
location
,
severity
,
additionalLocations
:
additionalLocations
,
properties
:
properties
);
}
var
(
canOffer
,
fixesError
)
=
helper
.
CanOfferUseBlockBody
(
optionSet
,
declaration
,
forAnalyzer
:
true
);
...
...
@@ -118,16 +118,11 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
var
additionalLocations
=
ImmutableArray
.
Create
(
declaration
.
GetLocation
());
return
Diagnostic
.
Create
(
CreateDescriptorWithId
(
helper
.
DiagnosticId
,
helper
.
UseBlockBodyTitle
,
helper
.
UseBlockBodyTitle
,
severity
,
GetCustomTags
(
severity
)
),
location
,
additionalLocations
:
additionalLocations
,
properties
:
properties
);
CreateDescriptorWithId
(
helper
.
DiagnosticId
,
helper
.
UseBlockBodyTitle
,
helper
.
UseBlockBodyTitle
),
location
,
severity
,
additionalLocations
:
additionalLocations
,
properties
:
properties
);
}
return
null
;
}
private
static
string
[]
GetCustomTags
(
DiagnosticSeverity
severity
)
=>
severity
==
DiagnosticSeverity
.
Hidden
?
new
[]
{
WellKnownDiagnosticTags
.
NotConfigurable
}
:
Array
.
Empty
<
string
>();
}
}
src/Features/CSharp/Portable/UseInferredMemberName/CSharpUseInferredMemberNameDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -48,9 +48,12 @@ private void ReportDiagnosticsIfNeeded(NameColonSyntax nameColon, SyntaxNodeAnal
// Create a normal diagnostic
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
optionSet
.
GetOption
(
CodeStyleOptions
.
PreferInferredTupleNames
,
context
.
Compilation
.
Language
).
Notification
.
Value
),
nameColon
.
GetLocation
()));
Diagnostic
.
Create
(
Descriptor
,
nameColon
.
GetLocation
(),
optionSet
.
GetOption
(
CodeStyleOptions
.
PreferInferredTupleNames
,
context
.
Compilation
.
Language
).
Notification
.
Value
,
additionalLocations
:
null
,
properties
:
null
));
// Also fade out the part of the name-colon syntax
var
fadeSpan
=
TextSpan
.
FromBounds
(
nameColon
.
Name
.
SpanStart
,
nameColon
.
ColonToken
.
Span
.
End
);
...
...
@@ -76,9 +79,12 @@ private void ReportDiagnosticsIfNeeded(NameEqualsSyntax nameEquals, SyntaxNodeAn
// Create a normal diagnostic
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
optionSet
.
GetOption
(
CodeStyleOptions
.
PreferInferredAnonymousTypeMemberNames
,
context
.
Compilation
.
Language
).
Notification
.
Value
),
nameEquals
.
GetLocation
()));
Diagnostic
.
Create
(
Descriptor
,
nameEquals
.
GetLocation
(),
optionSet
.
GetOption
(
CodeStyleOptions
.
PreferInferredAnonymousTypeMemberNames
,
context
.
Compilation
.
Language
).
Notification
.
Value
,
additionalLocations
:
null
,
properties
:
null
));
// Also fade out the part of the name-equals syntax
var
fadeSpan
=
TextSpan
.
FromBounds
(
nameEquals
.
Name
.
SpanStart
,
nameEquals
.
EqualsToken
.
Span
.
End
);
...
...
src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -135,25 +135,31 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext, INamedTyp
// If the diagnostic is not hidden, then just place the user visible part
// on the local being initialized with the lambda.
syntaxContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
severity
)
,
Descriptor
,
localDeclaration
.
Declaration
.
Variables
[
0
].
Identifier
.
GetLocation
(),
additionalLocations
));
severity
,
additionalLocations
,
properties
:
null
));
}
else
{
// If the diagnostic is hidden, place it on the entire construct.
syntaxContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
severity
)
,
Descriptor
,
localDeclaration
.
GetLocation
(),
additionalLocations
));
severity
,
additionalLocations
,
properties
:
null
));
var
anonymousFunctionStatement
=
anonymousFunction
.
GetAncestor
<
StatementSyntax
>();
if
(
localDeclaration
!=
anonymousFunctionStatement
)
{
syntaxContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
severity
)
,
Descriptor
,
anonymousFunctionStatement
.
GetLocation
(),
additionalLocations
));
severity
,
additionalLocations
,
properties
:
null
));
}
}
}
...
...
src/Features/CSharp/Portable/UsePatternMatching/CSharpAsAndNullCheckDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -195,9 +195,11 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
// Put a diagnostic with the appropriate severity on the declaration-statement itself.
syntaxContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
styleOption
.
Notification
.
Value
)
,
Descriptor
,
declarationStatement
.
GetLocation
(),
additionalLocations
));
styleOption
.
Notification
.
Value
,
additionalLocations
,
properties
:
null
));
}
// Ensure that all usages of the pattern variable are
...
...
src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -145,9 +145,11 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
// Put a diagnostic with the appropriate severity on the declaration-statement itself.
syntaxContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
severity
)
,
Descriptor
,
localDeclarationStatement
.
GetLocation
(),
additionalLocations
));
severity
,
additionalLocations
,
properties
:
null
));
}
public
bool
TryGetPatternPieces
(
...
...
src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -90,7 +90,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext context)
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
this
.
Hidden
Descriptor
,
isExpression
.
GetLocation
()));
this
.
Descriptor
,
isExpression
.
GetLocation
()));
}
public
(
HashSet
<
CastExpressionSyntax
>,
string
localName
)
AnalyzeExpression
(
...
...
src/Features/Core/Portable/AddRequiredParentheses/AbstractAddRequiredParenthesesDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -139,8 +139,9 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
var
properties
=
GetProperties
(
includeInFixAll
,
equivalenceKey
);
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
severity
)
,
Descriptor
,
operatorToken
.
GetLocation
(),
severity
,
additionalLocations
,
properties
));
...
...
src/Features/Core/Portable/CodeStyle/AbstractCodeStyleDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -12,13 +12,7 @@ internal abstract class AbstractCodeStyleDiagnosticAnalyzer : DiagnosticAnalyzer
{
protected
readonly
string
DescriptorId
;
/// <summary>
/// Diagnostic descriptors corresponding to each of the DiagnosticSeverities.
/// </summary>
protected
readonly
DiagnosticDescriptor
HiddenDescriptor
;
protected
readonly
DiagnosticDescriptor
InfoDescriptor
;
protected
readonly
DiagnosticDescriptor
WarningDescriptor
;
protected
readonly
DiagnosticDescriptor
ErrorDescriptor
;
protected
readonly
DiagnosticDescriptor
Descriptor
;
/// <summary>
/// Diagnostic descriptor for code you want to fade out *and* want to have a smart-tag
...
...
@@ -55,51 +49,33 @@ internal abstract class AbstractCodeStyleDiagnosticAnalyzer : DiagnosticAnalyzer
_localizableMessage
=
message
??
title
;
_configurable
=
configurable
;
HiddenDescriptor
=
CreateDescriptorWithSeverity
(
DiagnosticSeverity
.
Hidden
);
InfoDescriptor
=
CreateDescriptorWithSeverity
(
DiagnosticSeverity
.
Info
);
WarningDescriptor
=
CreateDescriptorWithSeverity
(
DiagnosticSeverity
.
Warning
);
ErrorDescriptor
=
CreateDescriptorWithSeverity
(
DiagnosticSeverity
.
Error
);
UnnecessaryWithSuggestionDescriptor
=
CreateUnnecessaryDescriptor
(
DiagnosticSeverity
.
Hidden
);
UnnecessaryWithoutSuggestionDescriptor
=
CreateUnnecessaryDescriptor
(
descriptorId
+
"WithoutSuggestion"
,
DiagnosticSeverity
.
Hidden
);
Descriptor
=
CreateDescriptor
();
UnnecessaryWithSuggestionDescriptor
=
CreateUnnecessaryDescriptor
();
UnnecessaryWithoutSuggestionDescriptor
=
CreateUnnecessaryDescriptor
(
descriptorId
+
"WithoutSuggestion"
);
SupportedDiagnostics
=
ImmutableArray
.
Create
(
Hidden
Descriptor
,
UnnecessaryWithoutSuggestionDescriptor
,
UnnecessaryWithSuggestionDescriptor
);
Descriptor
,
UnnecessaryWithoutSuggestionDescriptor
,
UnnecessaryWithSuggestionDescriptor
);
}
protected
DiagnosticDescriptor
CreateUnnecessaryDescriptor
(
DiagnosticSeverity
severity
)
=>
CreateUnnecessaryDescriptor
(
DescriptorId
,
severity
);
protected
DiagnosticDescriptor
CreateUnnecessaryDescriptor
()
=>
CreateUnnecessaryDescriptor
(
DescriptorId
);
protected
DiagnosticDescriptor
CreateUnnecessaryDescriptor
(
string
descriptorId
,
DiagnosticSeverity
severity
)
protected
DiagnosticDescriptor
CreateUnnecessaryDescriptor
(
string
descriptorId
)
=>
CreateDescriptorWithId
(
descriptorId
,
_localizableTitle
,
_localizableMessage
,
severity
,
DiagnosticCustomTags
.
Unnecessary
);
DiagnosticCustomTags
.
Unnecessary
);
public
override
ImmutableArray
<
DiagnosticDescriptor
>
SupportedDiagnostics
{
get
;
}
protected
DiagnosticDescriptor
GetDescriptorWithSeverity
(
DiagnosticSeverity
severity
)
{
switch
(
severity
)
{
case
DiagnosticSeverity
.
Hidden
:
return
HiddenDescriptor
;
case
DiagnosticSeverity
.
Info
:
return
InfoDescriptor
;
case
DiagnosticSeverity
.
Warning
:
return
WarningDescriptor
;
case
DiagnosticSeverity
.
Error
:
return
ErrorDescriptor
;
default
:
throw
new
InvalidOperationException
();
}
}
protected
DiagnosticDescriptor
CreateDescriptorWithSeverity
(
DiagnosticSeverity
severity
,
params
string
[]
customTags
)
=>
CreateDescriptorWithId
(
DescriptorId
,
_localizableTitle
,
_localizableMessage
,
severity
,
customTags
);
protected
DiagnosticDescriptor
CreateDescriptor
(
params
string
[]
customTags
)
=>
CreateDescriptorWithId
(
DescriptorId
,
_localizableTitle
,
_localizableMessage
,
customTags
);
protected
DiagnosticDescriptor
CreateDescriptorWithTitle
(
LocalizableString
title
,
DiagnosticSeverity
severity
,
params
string
[]
customTags
)
=>
CreateDescriptorWithId
(
DescriptorId
,
title
,
title
,
severity
,
customTags
);
protected
DiagnosticDescriptor
CreateDescriptorWithTitle
(
LocalizableString
title
,
params
string
[]
customTags
)
=>
CreateDescriptorWithId
(
DescriptorId
,
title
,
title
,
customTags
);
protected
DiagnosticDescriptor
CreateDescriptorWithId
(
string
id
,
LocalizableString
title
,
LocalizableString
message
,
DiagnosticSeverity
severity
,
params
string
[]
customTags
)
params
string
[]
customTags
)
{
if
(!
_configurable
)
{
...
...
@@ -109,7 +85,7 @@ protected DiagnosticDescriptor CreateDescriptorWithTitle(LocalizableString title
return
new
DiagnosticDescriptor
(
id
,
title
,
message
,
DiagnosticCategory
.
Style
,
severity
,
DiagnosticSeverity
.
Hidden
,
isEnabledByDefault
:
true
,
customTags
:
customTags
);
}
...
...
src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyleDiagnosticAnalyzerBase.cs
浏览文件 @
65268326
...
...
@@ -145,7 +145,7 @@ void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
s_localizableTitleNamingStyle
,
string
.
Format
(
FeaturesResources
.
Naming_rule_violation_0
,
failureReason
),
DiagnosticCategory
.
Style
,
applicableRule
.
EnforcementLevel
,
DiagnosticSeverity
.
Hidden
,
isEnabledByDefault
:
true
);
var
builder
=
ImmutableDictionary
.
CreateBuilder
<
string
,
string
>();
...
...
@@ -153,7 +153,7 @@ void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
builder
[
"OptionName"
]
=
nameof
(
SimplificationOptions
.
NamingPreferences
);
builder
[
"OptionLanguage"
]
=
compilation
.
Language
;
return
Diagnostic
.
Create
(
descriptor
,
symbol
.
Locations
.
First
(),
builder
.
ToImmutable
());
return
Diagnostic
.
Create
(
descriptor
,
symbol
.
Locations
.
First
(),
applicableRule
.
EnforcementLevel
,
additionalLocations
:
null
,
builder
.
ToImmutable
());
}
[
PerformanceSensitive
(
"https://github.com/dotnet/roslyn/issues/23582"
,
OftenCompletesSynchronously
=
true
)]
...
...
src/Features/Core/Portable/Diagnostics/Analyzers/PreferFrameworkTypeDiagnosticAnalyzerBase.cs
浏览文件 @
65268326
...
...
@@ -111,16 +111,9 @@ protected void AnalyzeNode(SyntaxNodeAnalysisContext context)
}
// earlier we did a context insensitive check to see if this style was preferred in *any* context at all.
// now, we have to make a context sensitive check to see if options settings for our context requires us to report a diagnostic.
if
(
ShouldReportDiagnostic
(
predefinedTypeNode
,
optionSet
,
language
,
out
var
d
iagnosticId
,
out
var
diagnosticS
everity
))
if
(
ShouldReportDiagnostic
(
predefinedTypeNode
,
optionSet
,
language
,
out
var
d
escriptor
,
out
var
s
everity
))
{
var
descriptor
=
new
DiagnosticDescriptor
(
diagnosticId
,
s_preferFrameworkTypeTitle
,
s_preferFrameworkTypeMessage
,
DiagnosticCategory
.
Style
,
diagnosticSeverity
,
isEnabledByDefault
:
true
);
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
descriptor
,
predefinedTypeNode
.
GetLocation
()));
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
descriptor
,
predefinedTypeNode
.
GetLocation
(),
severity
,
additionalLocations
:
null
,
properties
:
null
));
}
}
...
...
@@ -128,7 +121,7 @@ protected void AnalyzeNode(SyntaxNodeAnalysisContext context)
/// Detects the context of this occurrence of predefined type and determines if we should report it.
/// </summary>
private
bool
ShouldReportDiagnostic
(
TPredefinedTypeSyntax
predefinedTypeNode
,
OptionSet
optionSet
,
string
language
,
out
string
diagnosticId
,
out
DiagnosticSeverity
severity
)
out
DiagnosticDescriptor
descriptor
,
out
DiagnosticSeverity
severity
)
{
CodeStyleOption
<
bool
>
optionValue
;
...
...
@@ -136,12 +129,12 @@ protected void AnalyzeNode(SyntaxNodeAnalysisContext context)
// check the appropriate option and determine if we should report a diagnostic.
if
(
IsInMemberAccessOrCrefReferenceContext
(
predefinedTypeNode
))
{
d
iagnosticId
=
IDEDiagnosticIds
.
PreferFrameworkTypeInMemberAccessDiagnosticId
;
d
escriptor
=
s_descriptorPreferFrameworkTypeInMemberAccess
;
optionValue
=
optionSet
.
GetOption
(
GetOptionForMemberAccessContext
,
language
);
}
else
{
d
iagnosticId
=
IDEDiagnosticIds
.
PreferFrameworkTypeInDeclarationsDiagnosticId
;
d
escriptor
=
s_descriptorPreferFrameworkTypeInDeclarations
;
optionValue
=
optionSet
.
GetOption
(
GetOptionForDeclarationContext
,
language
);
}
...
...
src/Features/Core/Portable/Diagnostics/Analyzers/SimplifyTypeNamesDiagnosticAnalyzerBase.cs
浏览文件 @
65268326
...
...
@@ -122,29 +122,32 @@ protected bool TrySimplifyTypeNameExpression(SemanticModel model, SyntaxNode nod
PerLanguageOption
<
CodeStyleOption
<
bool
>>
option
;
DiagnosticDescriptor
descriptor
;
DiagnosticSeverity
severity
;
switch
(
diagnosticId
)
{
case
IDEDiagnosticIds
.
SimplifyNamesDiagnosticId
:
descriptor
=
s_descriptorSimplifyNames
;
severity
=
descriptor
.
DefaultSeverity
;
break
;
case
IDEDiagnosticIds
.
SimplifyMemberAccessDiagnosticId
:
descriptor
=
s_descriptorSimplifyMemberAccess
;
severity
=
descriptor
.
DefaultSeverity
;
break
;
case
IDEDiagnosticIds
.
RemoveQualificationDiagnosticId
:
descriptor
=
GetRemoveQualificationDiagnosticDescriptor
(
model
,
node
,
optionSet
,
cancellationToken
);
(
descriptor
,
severity
)
=
GetRemoveQualificationDiagnosticDescriptor
(
model
,
node
,
optionSet
,
cancellationToken
);
break
;
case
IDEDiagnosticIds
.
PreferIntrinsicPredefinedTypeInDeclarationsDiagnosticId
:
option
=
CodeStyleOptions
.
PreferIntrinsicPredefinedTypeKeywordInDeclaration
;
descriptor
=
GetApplicablePredefinedTypeDiagnosticDescriptor
(
(
descriptor
,
severity
)
=
GetApplicablePredefinedTypeDiagnosticDescriptor
(
IDEDiagnosticIds
.
PreferIntrinsicPredefinedTypeInDeclarationsDiagnosticId
,
option
,
optionSet
);
break
;
case
IDEDiagnosticIds
.
PreferIntrinsicPredefinedTypeInMemberAccessDiagnosticId
:
option
=
CodeStyleOptions
.
PreferIntrinsicPredefinedTypeKeywordInMemberAccess
;
descriptor
=
GetApplicablePredefinedTypeDiagnosticDescriptor
(
(
descriptor
,
severity
)
=
GetApplicablePredefinedTypeDiagnosticDescriptor
(
IDEDiagnosticIds
.
PreferIntrinsicPredefinedTypeInMemberAccessDiagnosticId
,
option
,
optionSet
);
break
;
...
...
@@ -161,49 +164,48 @@ protected bool TrySimplifyTypeNameExpression(SemanticModel model, SyntaxNode nod
var
builder
=
ImmutableDictionary
.
CreateBuilder
<
string
,
string
>();
builder
[
"OptionName"
]
=
nameof
(
CodeStyleOptions
.
PreferIntrinsicPredefinedTypeKeywordInMemberAccess
);
// TODO: need the actual one
builder
[
"OptionLanguage"
]
=
model
.
Language
;
diagnostic
=
Diagnostic
.
Create
(
descriptor
,
tree
.
GetLocation
(
issueSpan
),
builder
.
ToImmutable
());
diagnostic
=
Diagnostic
.
Create
(
descriptor
,
tree
.
GetLocation
(
issueSpan
),
severity
,
additionalLocations
:
null
,
builder
.
ToImmutable
());
return
true
;
}
private
DiagnosticDescriptor
GetApplicablePredefinedTypeDiagnosticDescriptor
<
T
>(
string
id
,
PerLanguageOption
<
T
>
option
,
OptionSet
optionSet
)
where
T
:
CodeStyleOption
<
bool
>
private
(
DiagnosticDescriptor
descriptor
,
DiagnosticSeverity
severity
)
GetApplicablePredefinedTypeDiagnosticDescriptor
<
T
>(
string
id
,
PerLanguageOption
<
T
>
option
,
OptionSet
optionSet
)
where
T
:
CodeStyleOption
<
bool
>
{
var
optionValue
=
optionSet
.
GetOption
(
option
,
GetLanguageName
());
DiagnosticDescriptor
descriptor
=
null
;
if
(
optionValue
.
Notification
.
Value
!=
DiagnosticSeverity
.
Hidden
)
{
descriptor
=
new
DiagnosticDescriptor
(
id
,
s_localizableTitleSimplifyNames
,
s_localizableMessage
,
DiagnosticCategory
.
Style
,
optionValue
.
Notification
.
Value
,
isEnabledByDefault
:
true
,
customTags
:
DiagnosticCustomTags
.
Unnecessary
);
switch
(
id
)
{
case
IDEDiagnosticIds
.
PreferIntrinsicPredefinedTypeInDeclarationsDiagnosticId
:
descriptor
=
s_descriptorPreferIntrinsicTypeInDeclarations
;
break
;
case
IDEDiagnosticIds
.
PreferIntrinsicPredefinedTypeInMemberAccessDiagnosticId
:
descriptor
=
s_descriptorPreferIntrinsicTypeInMemberAccess
;
break
;
default
:
throw
ExceptionUtilities
.
UnexpectedValue
(
id
);
}
}
return
descriptor
;
return
(
descriptor
,
optionValue
.
Notification
.
Value
)
;
}
private
DiagnosticDescriptor
GetRemoveQualificationDiagnosticDescriptor
(
SemanticModel
model
,
SyntaxNode
node
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
)
private
(
DiagnosticDescriptor
descriptor
,
DiagnosticSeverity
severity
)
GetRemoveQualificationDiagnosticDescriptor
(
SemanticModel
model
,
SyntaxNode
node
,
OptionSet
optionSet
,
CancellationToken
cancellationToken
)
{
var
symbolInfo
=
model
.
GetSymbolInfo
(
node
,
cancellationToken
);
if
(
symbolInfo
.
Symbol
==
null
)
{
return
null
;
return
default
;
}
var
applicableOption
=
QualifyMembersHelpers
.
GetApplicableOptionFromSymbolKind
(
symbolInfo
.
Symbol
.
Kind
);
var
optionValue
=
optionSet
.
GetOption
(
applicableOption
,
GetLanguageName
());
var
severity
=
optionValue
.
Notification
.
Value
;
return
new
DiagnosticDescriptor
(
IDEDiagnosticIds
.
RemoveQualificationDiagnosticId
,
s_localizableTitleRemoveThisOrMe
,
s_localizableMessage
,
DiagnosticCategory
.
Style
,
severity
,
isEnabledByDefault
:
true
,
customTags
:
DiagnosticCustomTags
.
Unnecessary
);
return
(
s_descriptorRemoveThisOrMe
,
severity
);
}
public
DiagnosticAnalyzerCategory
GetAnalyzerCategory
()
...
...
src/Features/Core/Portable/MakeFieldReadonly/AbstractMakeFieldReadonlyDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -92,8 +92,11 @@ private void AnalyzeSemanticModel(SemanticModelAnalysisContext context)
foreach
(
var
symbol
in
candidateFields
)
{
var
diagnostic
=
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
option
.
Notification
.
Value
),
symbol
.
Locations
[
0
]);
Descriptor
,
symbol
.
Locations
[
0
],
option
.
Notification
.
Value
,
additionalLocations
:
null
,
properties
:
null
);
context
.
ReportDiagnostic
(
diagnostic
);
}
...
...
src/Features/Core/Portable/OrderModifiers/AbstractOrderModifiersDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -54,31 +54,30 @@ private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context)
return
;
}
var
descriptor
=
GetDescriptorWithSeverity
(
option
.
Notification
.
Value
);
Recurse
(
context
,
preferredOrder
,
descriptor
,
root
);
Recurse
(
context
,
preferredOrder
,
option
.
Notification
.
Value
,
root
);
}
protected
abstract
void
Recurse
(
SyntaxTreeAnalysisContext
context
,
Dictionary
<
int
,
int
>
preferredOrder
,
Diagnostic
Descriptor
descriptor
,
Diagnostic
Severity
severity
,
SyntaxNode
root
);
protected
void
CheckModifiers
(
SyntaxTreeAnalysisContext
context
,
Dictionary
<
int
,
int
>
preferredOrder
,
Diagnostic
Descriptor
descriptor
,
Diagnostic
Severity
severity
,
SyntaxNode
memberDeclaration
)
{
var
modifiers
=
_syntaxFacts
.
GetModifiers
(
memberDeclaration
);
if
(!
IsOrdered
(
preferredOrder
,
modifiers
))
{
if
(
descriptor
.
DefaultS
everity
==
DiagnosticSeverity
.
Hidden
)
if
(
s
everity
==
DiagnosticSeverity
.
Hidden
)
{
// If the severity is hidden, put the marker on all the modifiers so that the
// user can bring up the fix anywhere in the modifier list.
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
d
escriptor
,
context
.
Tree
.
GetLocation
(
Diagnostic
.
Create
(
D
escriptor
,
context
.
Tree
.
GetLocation
(
TextSpan
.
FromBounds
(
modifiers
.
First
().
SpanStart
,
modifiers
.
Last
().
Span
.
End
))));
}
else
...
...
@@ -86,7 +85,7 @@ private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context)
// If the Severity is not hidden, then just put the user visible portion on the
// first token. That way we don't
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
descriptor
,
modifiers
.
First
().
GetLocation
()
));
Diagnostic
.
Create
(
Descriptor
,
modifiers
.
First
().
GetLocation
(),
severity
,
additionalLocations
:
null
,
properties
:
null
));
}
}
}
...
...
src/Features/Core/Portable/PopulateSwitch/PopulateSwitchDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -46,7 +46,7 @@ private void AnalyzeOperation(OperationAnalysisContext context)
.
Add
(
PopulateSwitchHelpers
.
MissingDefaultCase
,
missingDefaultCase
.
ToString
());
var
diagnostic
=
Diagnostic
.
Create
(
Hidden
Descriptor
,
Descriptor
,
switchBlock
.
GetFirstToken
().
GetLocation
(),
properties
:
properties
,
additionalLocations
:
new
[]
{
switchBlock
.
GetLocation
()
});
...
...
src/Features/Core/Portable/QualifyMemberAccess/AbstractQualifyMemberAccessDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -116,8 +116,11 @@ private void AnalyzeOperation(OperationAnalysisContext context)
if
(
severity
!=
DiagnosticSeverity
.
Hidden
)
{
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
severity
),
simpleName
.
GetLocation
()));
Descriptor
,
simpleName
.
GetLocation
(),
severity
,
additionalLocations
:
null
,
properties
:
null
));
}
}
}
...
...
src/Features/Core/Portable/RemoveUnnecessaryParentheses/AbstractRemoveUnnecessaryParenthesesDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -110,8 +110,11 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
var
additionalLocations
=
ImmutableArray
.
Create
(
parenthesizedExpression
.
GetLocation
());
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
CreateUnnecessaryDescriptor
(
severity
),
parenthesizedExpression
.
GetFirstToken
().
GetLocation
(),
additionalLocations
));
UnnecessaryWithSuggestionDescriptor
,
parenthesizedExpression
.
GetFirstToken
().
GetLocation
(),
severity
,
additionalLocations
,
properties
:
null
));
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
UnnecessaryWithoutSuggestionDescriptor
,
...
...
src/Features/Core/Portable/UseAutoProperty/AbstractUseAutoPropertyAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -317,34 +317,22 @@ private void Process(AnalysisResult result, SemanticModelAnalysisContext context
// Place the appropriate marker on the field depending on the user option.
var
diagnostic1
=
Diagnostic
.
Create
(
GetFieldDescriptor
(
option
),
nodeToFade
.
GetLocation
(),
additionalLocations
:
additionalLocations
);
UnnecessaryWithSuggestionDescriptor
,
nodeToFade
.
GetLocation
(),
option
.
Notification
.
Value
,
additionalLocations
:
additionalLocations
,
properties
:
null
);
// Also, place a hidden marker on the property. If they bring up a lightbulb
// there, they'll be able to see that they can convert it to an auto-prop.
var
diagnostic2
=
Diagnostic
.
Create
(
Hidden
Descriptor
,
propertyDeclaration
.
GetLocation
(),
Descriptor
,
propertyDeclaration
.
GetLocation
(),
additionalLocations
:
additionalLocations
);
context
.
ReportDiagnostic
(
diagnostic1
);
context
.
ReportDiagnostic
(
diagnostic2
);
}
private
DiagnosticDescriptor
GetFieldDescriptor
(
CodeStyleOption
<
bool
>
styleOption
)
{
if
(
styleOption
.
Value
)
{
switch
(
styleOption
.
Notification
.
Value
)
{
case
DiagnosticSeverity
.
Error
:
return
ErrorDescriptor
;
case
DiagnosticSeverity
.
Warning
:
return
WarningDescriptor
;
case
DiagnosticSeverity
.
Info
:
return
InfoDescriptor
;
}
}
return
UnnecessaryWithSuggestionDescriptor
;
}
protected
virtual
bool
IsEligibleHeuristic
(
IFieldSymbol
field
,
TPropertyDeclaration
propertyDeclaration
,
Compilation
compilation
,
CancellationToken
cancellationToken
)
...
...
src/Features/Core/Portable/UseCoalesceExpression/AbstractUseCoalesceExpressionDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -130,9 +130,11 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
whenPartToCheck
.
GetLocation
());
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
this
.
GetDescriptorWithSeverity
(
option
.
Notification
.
Value
)
,
Descriptor
,
conditionalExpression
.
GetLocation
(),
locations
));
option
.
Notification
.
Value
,
locations
,
properties
:
null
));
}
}
}
src/Features/Core/Portable/UseCoalesceExpression/AbstractUseCoalesceExpressionForNullableDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -129,9 +129,11 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
whenPartToKeep
.
GetLocation
());
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
this
.
GetDescriptorWithSeverity
(
option
.
Notification
.
Value
)
,
Descriptor
,
conditionalExpression
.
GetLocation
(),
locations
));
option
.
Notification
.
Value
,
locations
,
properties
:
null
));
}
}
}
src/Features/Core/Portable/UseCollectionInitializer/AbstractUseCollectionInitializerDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -112,9 +112,11 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context, INamedTypeSymbol ien
var
severity
=
option
.
Notification
.
Value
;
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
CreateDescriptorWithSeverity
(
severity
)
,
Descriptor
,
objectCreationExpression
.
GetLocation
(),
additionalLocations
:
locations
));
severity
,
additionalLocations
:
locations
,
properties
:
null
));
FadeOutCode
(
context
,
optionSet
,
matches
.
Value
,
locations
);
}
...
...
src/Features/Core/Portable/UseConditionalExpression/AbstractUseConditionalExpressionDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -69,9 +69,11 @@ private void AnalyzeOperation(OperationAnalysisContext context)
var
additionalLocations
=
ImmutableArray
.
Create
(
ifStatement
.
GetLocation
());
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
this
.
CreateDescriptorWithSeverity
(
option
.
Notification
.
Value
)
,
Descriptor
,
ifStatement
.
GetFirstToken
().
GetLocation
(),
additionalLocations
));
option
.
Notification
.
Value
,
additionalLocations
,
properties
:
null
));
}
}
}
src/Features/Core/Portable/UseExplicitTupleName/UseExplicitTupleNameDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -63,8 +63,10 @@ private void AnalyzeOperation(OperationAnalysisContext context)
var
properties
=
ImmutableDictionary
<
string
,
string
>.
Empty
.
Add
(
nameof
(
ElementName
),
namedField
.
Name
);
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
severity
)
,
Descriptor
,
nameNode
.
GetLocation
(),
severity
,
additionalLocations
:
null
,
properties
));
}
}
...
...
src/Features/Core/Portable/UseIsNullCheck/AbstractUseIsNullDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -144,7 +144,8 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context, IMethodSymbol refe
var
severity
=
option
.
Notification
.
Value
;
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
severity
),
nameNode
.
GetLocation
(),
Descriptor
,
nameNode
.
GetLocation
(),
severity
,
additionalLocations
,
properties
));
}
...
...
src/Features/Core/Portable/UseNullPropagation/AbstractUseNullPropagationDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -179,8 +179,9 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context, INamedTypeSymbol e
}
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
this
.
GetDescriptorWithSeverity
(
option
.
Notification
.
Value
)
,
Descriptor
,
conditionalExpression
.
GetLocation
(),
option
.
Notification
.
Value
,
locations
,
properties
));
}
...
...
src/Features/Core/Portable/UseObjectInitializer/AbstractUseObjectInitializerDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -89,9 +89,11 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
var
severity
=
option
.
Notification
.
Value
;
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
CreateDescriptorWithSeverity
(
severity
)
,
Descriptor
,
objectCreationExpression
.
GetLocation
(),
additionalLocations
:
locations
));
severity
,
additionalLocations
:
locations
,
properties
:
null
));
FadeOutCode
(
context
,
optionSet
,
matches
.
Value
,
locations
);
}
...
...
src/Features/Core/Portable/UseThrowExpression/AbstractUseThrowExpressionDiagnosticAnalyzer.cs
浏览文件 @
65268326
...
...
@@ -146,10 +146,8 @@ private void AnalyzeOperation(OperationAnalysisContext context, INamedTypeSymbol
throwOperation
.
Exception
.
Syntax
.
GetLocation
(),
assignmentExpression
.
Value
.
Syntax
.
GetLocation
());
var
descriptor
=
GetDescriptorWithSeverity
(
option
.
Notification
.
Value
);
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
descriptor
,
throwStatementSyntax
.
GetLocation
(),
additionalLocations
:
allLocations
));
Diagnostic
.
Create
(
Descriptor
,
throwStatementSyntax
.
GetLocation
(),
option
.
Notification
.
Value
,
additionalLocations
:
allLocations
,
properties
:
null
));
// Fade out the rest of the if that surrounds the 'throw' exception.
...
...
src/Features/VisualBasic/Portable/AddAccessibilityModifiers/VisualBasicAddAccessibilityModifiersDiagnosticAnalyzer.vb
浏览文件 @
65268326
...
...
@@ -83,9 +83,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.AddAccessibilityModifiers
' Have an issue to flag, either add or remove. Report issue to user.
Dim
additionalLocations
=
ImmutableArray
.
Create
(
member
.
GetLocation
())
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
CreateDescriptorWithSeverity
(
[
option
]
.
Notification
.
Value
)
,
Descriptor
,
name
.
GetLocation
(),
additionalLocations
:
=
additionalLocations
))
[
option
]
.
Notification
.
Value
,
additionalLocations
:
=
additionalLocations
,
properties
:
=
Nothing
))
End
Sub
Private
Function
MatchesDefaultAccessibility
(
accessibility
As
Accessibility
,
member
As
StatementSyntax
)
As
Boolean
...
...
src/Features/VisualBasic/Portable/OrderModifiers/VisualBasicOrderModifiersDiagnosticAnalyzer.vb
浏览文件 @
65268326
...
...
@@ -19,7 +19,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.OrderModifiers
Protected
Overrides
Sub
Recurse
(
context
As
SyntaxTreeAnalysisContext
,
preferredOrder
As
Dictionary
(
Of
Integer
,
Integer
),
descriptor
As
DiagnosticDescriptor
,
severity
As
DiagnosticSeverity
,
root
As
SyntaxNode
)
For
Each
child
In
root
.
ChildNodesAndTokens
()
...
...
@@ -27,10 +27,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.OrderModifiers
Dim
declarationStatement
=
TryCast
(
child
.
AsNode
(),
DeclarationStatementSyntax
)
If
declarationStatement
IsNot
Nothing
Then
If
ShouldCheck
(
declarationStatement
)
Then
CheckModifiers
(
context
,
preferredOrder
,
descriptor
,
declarationStatement
)
CheckModifiers
(
context
,
preferredOrder
,
severity
,
declarationStatement
)
End
If
Recurse
(
context
,
preferredOrder
,
descriptor
,
declarationStatement
)
Recurse
(
context
,
preferredOrder
,
severity
,
declarationStatement
)
End
If
End
If
Next
...
...
src/Features/VisualBasic/Portable/UseInferredMemberName/VisualBasicUseInferredMemberNameDiagnosticAnalyzer.vb
浏览文件 @
65268326
...
...
@@ -48,9 +48,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UseInferredMemberName
' Create a normal diagnostic
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
optionSet
.
GetOption
(
CodeStyleOptions
.
PreferInferredTupleNames
,
context
.
Compilation
.
Language
).
Notification
.
Value
),
nameColonEquals
.
GetLocation
()))
Diagnostic
.
Create
(
Descriptor
,
nameColonEquals
.
GetLocation
(),
optionSet
.
GetOption
(
CodeStyleOptions
.
PreferInferredTupleNames
,
context
.
Compilation
.
Language
).
Notification
.
Value
,
additionalLocations
:
=
Nothing
,
properties
:
=
Nothing
))
' Also fade out the part of the name-colon-equals syntax
Dim
fadeSpan
=
TextSpan
.
FromBounds
(
nameColonEquals
.
Name
.
SpanStart
,
nameColonEquals
.
ColonEqualsToken
.
Span
.
End
)
...
...
@@ -76,9 +79,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UseInferredMemberName
' Create a normal diagnostic
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GetDescriptorWithSeverity
(
optionSet
.
GetOption
(
CodeStyleOptions
.
PreferInferredAnonymousTypeMemberNames
,
context
.
Compilation
.
Language
).
Notification
.
Value
),
syntaxTree
.
GetLocation
(
fadeSpan
)))
Diagnostic
.
Create
(
Descriptor
,
syntaxTree
.
GetLocation
(
fadeSpan
),
optionSet
.
GetOption
(
CodeStyleOptions
.
PreferInferredAnonymousTypeMemberNames
,
context
.
Compilation
.
Language
).
Notification
.
Value
,
additionalLocations
:
=
Nothing
,
properties
:
=
Nothing
))
' Also fade out the part of the name-equals syntax
context
.
ReportDiagnostic
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录