提交 f62a6794 编写于 作者: C chandera

Initial work to add options pages that allow users to adjust simplification...

Initial work to add options pages that allow users to adjust simplification options. (changeset 1226565)
上级 9689fa85
......@@ -656,10 +656,13 @@ private static bool CanReplace(ISymbol symbol)
replacementNode = null;
issueSpan = default(TextSpan);
if (memberAccess.Name == null ||
memberAccess.Expression == null ||
(!optionSet.GetOption(SimplificationOptions.AllowSimplifyingAwayThisOrMe, LanguageNames.CSharp) &&
memberAccess.Expression.CSharpKind() == SyntaxKind.ThisExpression))
if (memberAccess.Name == null || memberAccess.Expression == null)
{
return false;
}
if (optionSet.GetOption(SimplificationOptions.QualifyMemberAccessWithThisOrMe, semanticModel.Language) &&
memberAccess.Expression.CSharpKind() == SyntaxKind.ThisExpression)
{
return false;
}
......
......@@ -60,10 +60,10 @@ public override SyntaxToken Expand(SyntaxToken token, SemanticModel semanticMode
{
using (Logger.LogBlock(FeatureId.Simplifier, FunctionId.Simplifier_ExpandToken, cancellationToken))
{
var hungarianSemanticModel = (SemanticModel)semanticModel;
var rewriter = new Expander(hungarianSemanticModel, expandInsideNode, false, cancellationToken);
var csharpSemanticModel = (SemanticModel)semanticModel;
var rewriter = new Expander(csharpSemanticModel, expandInsideNode, false, cancellationToken);
var rewrittenToken = TryEscapeIdentifierToken(rewriter.VisitToken(token), token.Parent, hungarianSemanticModel).WithAdditionalAnnotations(Simplifier.Annotation);
var rewrittenToken = TryEscapeIdentifierToken(rewriter.VisitToken(token), token.Parent, csharpSemanticModel).WithAdditionalAnnotations(Simplifier.Annotation);
SyntaxToken rewrittenTokenWithElasticTrivia;
if (TryAddLeadingElasticTriviaIfNecessary(rewrittenToken, token, out rewrittenTokenWithElasticTrivia))
{
......
......@@ -6,6 +6,7 @@
using System.Threading;
using Microsoft.CodeAnalysis.CodeGeneration;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Simplification;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Shared.Extensions
......@@ -71,7 +72,8 @@ internal static partial class ICodeDefinitionFactoryExtensions
CancellationToken cancellationToken)
{
var fields = factory.CreateFieldsForParameters(parameters, parameterToNewFieldMap);
var statements = factory.CreateAssignmentStatements(parameters, parameterToExistingFieldMap, parameterToNewFieldMap);
var statements = factory.CreateAssignmentStatements(parameters, parameterToExistingFieldMap, parameterToNewFieldMap)
.Select(s => s.WithAdditionalAnnotations(Simplifier.Annotation));
foreach (var field in fields)
{
......
......@@ -67,6 +67,6 @@ public class SimplificationOptions
#if MEF
[ExportOption]
#endif
public static readonly PerLanguageOption<bool> AllowSimplifyingAwayThisOrMe = new PerLanguageOption<bool>(FeatureName, "AllowSimplifyingAwayThisOrMe", defaultValue: true);
public static readonly PerLanguageOption<bool> QualifyMemberAccessWithThisOrMe = new PerLanguageOption<bool>(FeatureName, "QualifyMemberAccessWithThisOrMe", defaultValue: false);
}
}
......@@ -949,10 +949,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
optionSet As OptionSet,
cancellationToken As CancellationToken
) As Boolean
If memberAccess.Expression Is Nothing OrElse
memberAccess.Name Is Nothing OrElse
(Not optionSet.GetOption(SimplificationOptions.AllowSimplifyingAwayThisOrMe, LanguageNames.VisualBasic) AndAlso
memberAccess.Expression.VisualBasicKind() = SyntaxKind.MeExpression) Then
If memberAccess.Expression Is Nothing OrElse memberAccess.Name Is Nothing Then
Return False
End If
If optionSet.GetOption(SimplificationOptions.QualifyMemberAccessWithThisOrMe, semanticModel.Language) AndAlso
memberAccess.Expression.VisualBasicKind() = SyntaxKind.MeExpression Then
Return False
End If
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册