提交 ee0a9fe6 编写于 作者: C CyrusNajmabadi

Rename feature to 'Use throw expressoin.'

上级 9c2115fb
......@@ -309,8 +309,8 @@
<Compile Include="Organizing\OrganizeModifiersTests.cs" />
<Compile Include="Organizing\OrganizeTypeDeclarationTests.cs" />
<Compile Include="Organizing\OrganizeUsingsTests.cs" />
<Compile Include="SimplifyNullCheck\SimplifyNullCheckTests_FixAllTests.cs" />
<Compile Include="SimplifyNullCheck\SimplifyNullCheckTests.cs" />
<Compile Include="UseThrowExpression\UseThrowExpressionTests_FixAllTests.cs" />
<Compile Include="UseThrowExpression\UseThrowExpressionTests.cs" />
<Compile Include="Structure\AbstractCSharpSyntaxNodeStructureTests.cs" />
<Compile Include="Structure\AbstractCSharpSyntaxTriviaStructureTests.cs" />
<Compile Include="Structure\AccessorDeclarationStructureTests.cs" />
......
......@@ -4,22 +4,22 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.SimplifyNullCheck;
using Microsoft.CodeAnalysis.CSharp.UseThrowExpression;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.SimplifyNullCheck;
using Microsoft.CodeAnalysis.UseThrowExpression;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.SimplifyNullCheck
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UseThrowExpression
{
public partial class SimplifyNullCheckTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
public partial class UseThrowExpressionTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
{
internal override Tuple<DiagnosticAnalyzer, CodeFixProvider> CreateDiagnosticProviderAndFixer(Workspace workspace)
{
return Tuple.Create<DiagnosticAnalyzer, CodeFixProvider>(
new CSharpSimplifyNullCheckDiagnosticAnalyzer(),
new SimplifyNullCheckCodeFixProvider());
new CSharpUseThrowExpressionDiagnosticAnalyzer(),
new UseThrowExpressionCodeFixProvider());
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsSimplifyNullCheck)]
......@@ -33,7 +33,7 @@ class C
{
void M(string s)
{
[|if|] (s == null) throw new ArgumentNullException(nameof(s));
if (s == null) [|throw|] new ArgumentNullException(nameof(s));
_s = s;
}
}",
......@@ -59,7 +59,7 @@ class C
{
void M(string s)
{
[|if|] (s == null) { throw new ArgumentNullException(nameof(s)); }
if (s == null) { [|throw|] new ArgumentNullException(nameof(s)); }
_s = s;
}
}",
......@@ -102,7 +102,7 @@ class C
{
void M(string s)
{
[|if|] (s == null) { throw new ArgumentNullException(nameof(s)) };
if (s == null) { [|throw|] new ArgumentNullException(nameof(s)) };
_s = s;
}
}", parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp6));
......@@ -119,7 +119,7 @@ class C
{
void M(string s, string t)
{
[|if|] (s == null) { throw new ArgumentNullException(nameof(s)); }
if (s == null) { [|throw|] new ArgumentNullException(nameof(s)); }
if (t == null) { throw new ArgumentNullException(nameof(t)); }
_s = s;
}
......@@ -147,7 +147,7 @@ class C
{
void M(string s, string t)
{
[|if|] (s == null) { throw new ArgumentNullException(nameof(s)) };
if (s == null) { [|throw|] new ArgumentNullException(nameof(s)) };
s = ""something"";
_s = s;
}
......@@ -165,7 +165,7 @@ class C
{
void M(string s)
{
[|if|] (null == s) throw new ArgumentNullException(nameof(s));
if (null == s) [|throw|] new ArgumentNullException(nameof(s));
_s = s;
}
}",
......@@ -192,7 +192,7 @@ class C
void M()
{
string s = null;
[|if|] (null == s) throw new ArgumentNullException(nameof(s));
if (null == s) [|throw|] new ArgumentNullException(nameof(s));
_s = s;
}
}",
......@@ -221,7 +221,7 @@ class C
void M()
{
[|if|] (null == s) throw new ArgumentNullException(nameof(s));
if (null == s) [|throw|] new ArgumentNullException(nameof(s));
_s = s;
}
}");
......@@ -239,7 +239,7 @@ class C
void M(string s)
{
_s = s;
[|if|] (s == null) throw new ArgumentNullException(nameof(s));
if (s == null) [|throw|] new ArgumentNullException(nameof(s));
}
}");
}
......
......@@ -2,13 +2,12 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.SimplifyNullCheck;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.SimplifyNullCheck
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UseThrowExpression
{
public partial class SimplifyNullCheckTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
public partial class UseThrowExpressionTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
{
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsSimplifyNullCheck)]
public async Task FixAllInDocument1()
......@@ -21,7 +20,7 @@ class C
{
void M(string s, string t)
{
{|FixAllInDocument:if|} (s == null) { throw new ArgumentNullException(nameof(s)); }
if (s == null) { {|FixAllInDocument:throw|} new ArgumentNullException(nameof(s)); }
if (t == null) { throw new ArgumentNullException(nameof(t)); }
_s = s;
_t = t;
......@@ -52,7 +51,7 @@ class C
void M(string s, string t)
{
if (s == null) { throw new ArgumentNullException(nameof(s)); }
{|FixAllInDocument:if|} (t == null) { throw new ArgumentNullException(nameof(t)); }
if (t == null) { {|FixAllInDocument:throw|} new ArgumentNullException(nameof(t)); }
_s = s;
_t = t;
}
......@@ -84,7 +83,7 @@ class C
{
void M(string s, string t)
{
{|FixAllInDocument:if|} (s == null) { throw new ArgumentNullException(nameof(s)); }
if (s == null) { {|FixAllInDocument:throw|} new ArgumentNullException(nameof(s)); }
_s = s;
}
}
......@@ -148,7 +147,7 @@ class C
{
void M(string s, string t)
{
{|FixAllInProject:if|} (s == null) { throw new ArgumentNullException(nameof(s)); }
if (s == null) { {|FixAllInProject:throw|} new ArgumentNullException(nameof(s)); }
_s = s;
}
}
......
......@@ -354,7 +354,7 @@
<Compile Include="Organizing\Organizers\OperatorDeclarationOrganizer.cs" />
<Compile Include="Organizing\Organizers\PropertyDeclarationOrganizer.cs" />
<Compile Include="Organizing\Organizers\StructDeclarationOrganizer.cs" />
<Compile Include="SimplifyNullCheck\CSharpSimplifyNullCheckDiagnosticAnalyzer.cs" />
<Compile Include="UseThrowExpression\CSharpUseThrowExpressionDiagnosticAnalyzer.cs" />
<Compile Include="Structure\CSharpBlockStructureProvider.cs" />
<Compile Include="Structure\CSharpStructureHelpers.cs" />
<Compile Include="Structure\CSharpBlockStructureService.cs" />
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.SimplifyNullCheck;
using Microsoft.CodeAnalysis.UseThrowExpression;
namespace Microsoft.CodeAnalysis.CSharp.SimplifyNullCheck
namespace Microsoft.CodeAnalysis.CSharp.UseThrowExpression
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class CSharpSimplifyNullCheckDiagnosticAnalyzer : AbstractSimplifyNullCheckDiagnosticAnalyzer
internal class CSharpUseThrowExpressionDiagnosticAnalyzer : AbstractUseThrowExpressionDiagnosticAnalyzer
{
protected override bool IsSupported(ParseOptions options)
{
......
......@@ -38,13 +38,13 @@ internal static class PredefinedCodeFixProviderNames
public const string RemoveUnnecessaryImports = "Remove Unnecessary Usings or Imports";
public const string RenameTracking = "Rename Tracking";
public const string SimplifyNames = "Simplify Names";
public const string SimplifyNullCheck = nameof(SimplifyNullCheck);
public const string SpellCheck = "Spell Check";
public const string Suppression = nameof(Suppression);
public const string AddOverloads = "Add Overloads to member";
public const string AddNew = "Add new keyword to member";
public const string UseImplicitType = nameof(UseImplicitType);
public const string UseExplicitType = nameof(UseExplicitType);
public const string UseThrowExpression = nameof(UseThrowExpression);
public const string PreferFrameworkType = nameof(PreferFrameworkType);
}
}
......@@ -19,7 +19,7 @@ internal static class IDEDiagnosticIds
public const string PreferIntrinsicPredefinedTypeInMemberAccessDiagnosticId = "IDE0013";
public const string PreferFrameworkTypeInDeclarationsDiagnosticId = "IDE0014";
public const string PreferFrameworkTypeInMemberAccessDiagnosticId = "IDE0015";
public const string SimplifyNullCheckDiagnosticId = "IDE0016";
public const string UseThrowExpressionDiagnosticId = "IDE0016";
// Analyzer error Ids
public const string AnalyzerChangedId = "IDE1001";
......
......@@ -92,9 +92,9 @@
</Compile>
<Compile Include="AddMissingReference\AbstractAddMissingReferenceCodeFixProvider.cs" />
<Compile Include="AddMissingReference\CodeAction.cs" />
<Compile Include="SimplifyNullCheck\AbstractSimplifyNullCheckDiagnosticAnalyzer.cs" />
<Compile Include="SimplifyNullCheck\SimplifyNullCheckCodeFixProvider.cs" />
<Compile Include="SimplifyNullCheck\SimplifyNullCheckCodeFixProvider.FixAllProvider.cs" />
<Compile Include="UseThrowExpression\AbstractUseThrowExpressionDiagnosticAnalyzer.cs" />
<Compile Include="UseThrowExpression\UseThrowExpressionCodeFixProvider.cs" />
<Compile Include="UseThrowExpression\UseThrowExpressionCodeFixProvider.FixAllProvider.cs" />
<Compile Include="Structure\BlockTypes.cs" />
<Compile Include="CodeLens\CodeLensReferencesServiceFactory.cs" />
<Compile Include="Structure\Syntax\BlockStructureExtensions.cs" />
......
......@@ -2331,15 +2331,6 @@ internal class FeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Simplify null check.
/// </summary>
internal static string Simplify_null_check {
get {
return ResourceManager.GetString("Simplify_null_check", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Solution.
/// </summary>
......@@ -2894,6 +2885,15 @@ internal class FeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Use &apos;throw&apos; expression.
/// </summary>
internal static string Use_throw_expression {
get {
return ResourceManager.GetString("Use_throw_expression", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User Diagnostic Analyzer Failure..
/// </summary>
......
......@@ -1067,7 +1067,7 @@ This version used in: {2}</value>
<data name="Install_package_0" xml:space="preserve">
<value>Install package '{0}'</value>
</data>
<data name="Simplify_null_check" xml:space="preserve">
<value>Simplify null check</value>
<data name="Use_throw_expression" xml:space="preserve">
<value>Use 'throw' expression</value>
</data>
</root>
\ No newline at end of file
......@@ -9,7 +9,7 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Semantics;
namespace Microsoft.CodeAnalysis.SimplifyNullCheck
namespace Microsoft.CodeAnalysis.UseThrowExpression
{
/// <summary>
/// Looks for patterns of the form:
......@@ -30,13 +30,13 @@ namespace Microsoft.CodeAnalysis.SimplifyNullCheck
/// Note: this analyzer can be udpated to run on VB once VB supports 'throw'
/// expressions as well.
/// </summary>
internal abstract class AbstractSimplifyNullCheckDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer
internal abstract class AbstractUseThrowExpressionDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer
{
private static readonly LocalizableString s_localizableTitle = new LocalizableResourceString(nameof(FeaturesResources.Simplify_null_check), FeaturesResources.ResourceManager, typeof(FeaturesResources));
private static readonly LocalizableString s_localizableMessage = new LocalizableResourceString(nameof(FeaturesResources.Simplify_null_check), WorkspacesResources.ResourceManager, typeof(WorkspacesResources));
private static readonly LocalizableString s_localizableTitle = new LocalizableResourceString(nameof(FeaturesResources.Use_throw_expression), FeaturesResources.ResourceManager, typeof(FeaturesResources));
private static readonly LocalizableString s_localizableMessage = new LocalizableResourceString(nameof(FeaturesResources.Use_throw_expression), FeaturesResources.ResourceManager, typeof(FeaturesResources));
private static DiagnosticDescriptor s_descriptor = new DiagnosticDescriptor(
IDEDiagnosticIds.SimplifyNullCheckDiagnosticId,
IDEDiagnosticIds.UseThrowExpressionDiagnosticId,
s_localizableTitle,
s_localizableMessage,
DiagnosticCategory.Style,
......@@ -139,7 +139,7 @@ private void AnalyzeOperation(OperationAnalysisContext context)
assignmentExpression.Value.Syntax.GetLocation());
var descriptor = new DiagnosticDescriptor(
IDEDiagnosticIds.SimplifyNullCheckDiagnosticId,
IDEDiagnosticIds.UseThrowExpressionDiagnosticId,
s_localizableTitle,
s_localizableMessage,
DiagnosticCategory.Style,
......@@ -147,7 +147,7 @@ private void AnalyzeOperation(OperationAnalysisContext context)
isEnabledByDefault: true);
context.ReportDiagnostic(
Diagnostic.Create(descriptor, ifOperation.Syntax.GetLocation(), additionalLocations: allLocations));
Diagnostic.Create(descriptor, throwStatement.GetLocation(), additionalLocations: allLocations));
}
private bool TryFindAssignmentExpression(
......
......@@ -7,9 +7,9 @@
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
namespace Microsoft.CodeAnalysis.SimplifyNullCheck
namespace Microsoft.CodeAnalysis.UseThrowExpression
{
internal partial class SimplifyNullCheckCodeFixProvider
internal partial class UseThrowExpressionCodeFixProvider
{
/// <summary>
/// A specialized <see cref="FixAllProvider"/> for this CodeFixProvider.
......@@ -34,15 +34,15 @@ internal partial class SimplifyNullCheckCodeFixProvider
///
/// This FixAllProvider avoids this entirely by not doing any textual merging.
/// Instead, we just take all the fixes to apply in the document, as we use
/// the core <see cref="SimplifyNullCheckCodeFixProvider.FixAllAsync"/> to do
/// the core <see cref="UseThrowExpressionCodeFixProvider.FixAllAsync"/> to do
/// all the editing at once on the SyntaxTree. Because we're doing real tree
/// edits with actual nodes, there is no issue with anything getting messed up.
/// </summary>
private class SimplifyNullCheckFixAllProvider : BatchFixAllProvider
private class UseThrowExpressionFixAllProvider : BatchFixAllProvider
{
private readonly SimplifyNullCheckCodeFixProvider _provider;
private readonly UseThrowExpressionCodeFixProvider _provider;
public SimplifyNullCheckFixAllProvider(SimplifyNullCheckCodeFixProvider provider)
public UseThrowExpressionFixAllProvider(UseThrowExpressionCodeFixProvider provider)
{
_provider = provider;
}
......
......@@ -13,17 +13,17 @@
using Microsoft.CodeAnalysis.Editing;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.SimplifyNullCheck
namespace Microsoft.CodeAnalysis.UseThrowExpression
{
[ExportCodeFixProvider(LanguageNames.CSharp,
Name = PredefinedCodeFixProviderNames.SimplifyNullCheck), Shared]
internal partial class SimplifyNullCheckCodeFixProvider : CodeFixProvider
Name = PredefinedCodeFixProviderNames.UseThrowExpression), Shared]
internal partial class UseThrowExpressionCodeFixProvider : CodeFixProvider
{
public override ImmutableArray<string> FixableDiagnosticIds
=> ImmutableArray.Create(IDEDiagnosticIds.SimplifyNullCheckDiagnosticId);
=> ImmutableArray.Create(IDEDiagnosticIds.UseThrowExpressionDiagnosticId);
public override FixAllProvider GetFixAllProvider()
=> new SimplifyNullCheckFixAllProvider(this);
=> new UseThrowExpressionFixAllProvider(this);
public override Task RegisterCodeFixesAsync(CodeFixContext context)
{
......@@ -76,7 +76,7 @@ private class MyCodeAction : CodeAction.DocumentChangeAction
{
public MyCodeAction(
Func<CancellationToken, Task<Document>> createChangedDocument)
: base(FeaturesResources.Simplify_null_check, createChangedDocument)
: base(FeaturesResources.Use_throw_expression, createChangedDocument)
{
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册