未验证 提交 ece86d58 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #40544 from CyrusNajmabadi/simplifyTypeNamesWork3

Obsolete non-.editorconfig 'simplification options'.  
......@@ -68,7 +68,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Simplification
End Module
</text>
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True}}
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {}
Await TestAsync(input, expected, simplificationOptionSet)
End Function
......@@ -100,7 +100,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Simplification
End Module
</text>
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True}}
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {}
Await TestAsync(input, expected, simplificationOptionSet)
End Function
......@@ -165,7 +165,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Simplification
End Class
</text>
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True}}
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {}
Await TestAsync(input, expected, simplificationOptionSet)
End Function
......@@ -202,7 +202,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Simplification
End Module
</text>
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True}}
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {}
Await TestAsync(input, expected, simplificationOptionSet)
End Function
......@@ -253,7 +253,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Simplification
End Class
</text>
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True}}
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {}
Await TestAsync(input, expected, simplificationOptionSet)
End Function
......@@ -303,7 +303,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Simplification
End Module
</text>
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True}}
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {}
Await TestAsync(input, expected, simplificationOptionSet)
End Function
......@@ -356,7 +356,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Simplification
End Module
</text>
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True}}
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {}
Await TestAsync(input, expected, simplificationOptionSet)
End Function
......@@ -407,7 +407,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Simplification
End Class
</text>
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True}}
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {}
Await TestAsync(input, expected, simplificationOptionSet)
End Function
......@@ -467,7 +467,7 @@ class D : C
}]]>
</text>
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.PreferImplicitTypeInference, True}}
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {}
Await TestAsync(input, expected, simplificationOptionSet)
End Function
......@@ -522,7 +522,7 @@ End Class
]]>
</text>
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.PreferImplicitTypeInference, True}}
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {}
Await TestAsync(input, expected, simplificationOptionSet)
End Function
......@@ -568,7 +568,7 @@ Namespace X
End Namespace
</text>
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True}}
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {}
Await TestAsync(input, expected, simplificationOptionSet)
End Function
......@@ -618,7 +618,7 @@ Namespace Y
End Namespace
</text>
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True}}
Dim simplificationOptionSet = New Dictionary(Of OptionKey, Object) From {}
Await TestAsync(input, expected, simplificationOptionSet)
End Function
......
......@@ -1470,7 +1470,6 @@ class C1
<Fact, Trait(Traits.Feature, Traits.Features.Simplification)>
Public Async Function TestCSharpSimplifyToVarLocalDeclaration() As Task
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {
{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True},
{CSharpCodeStyleOptions.VarForBuiltInTypes, CodeStyleOptions.TrueWithSilentEnforcement},
{CSharpCodeStyleOptions.VarWhenTypeIsApparent, CodeStyleOptions.TrueWithSilentEnforcement},
{CSharpCodeStyleOptions.VarElsewhere, CodeStyleOptions.TrueWithSilentEnforcement}
......@@ -1509,7 +1508,6 @@ class Program
<Fact, Trait(Traits.Feature, Traits.Features.Simplification)>
Public Async Function TestCSharpSimplifyToVarForeachDecl() As Task
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {
{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True},
{CSharpCodeStyleOptions.VarForBuiltInTypes, CodeStyleOptions.TrueWithSilentEnforcement},
{CSharpCodeStyleOptions.VarWhenTypeIsApparent, CodeStyleOptions.TrueWithSilentEnforcement},
{CSharpCodeStyleOptions.VarElsewhere, CodeStyleOptions.TrueWithSilentEnforcement}
......@@ -1550,7 +1548,6 @@ class Program
<Fact, Trait(Traits.Feature, Traits.Features.Simplification)>
Public Async Function TestCSharpSimplifyToVarCorrect() As Task
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {
{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True},
{CSharpCodeStyleOptions.VarForBuiltInTypes, CodeStyleOptions.TrueWithSilentEnforcement},
{CSharpCodeStyleOptions.VarWhenTypeIsApparent, CodeStyleOptions.TrueWithSilentEnforcement},
{CSharpCodeStyleOptions.VarElsewhere, CodeStyleOptions.TrueWithSilentEnforcement}
......@@ -1621,7 +1618,6 @@ class Program
<Fact, Trait(Traits.Feature, Traits.Features.Simplification)>
Public Async Function TestCSharpSimplifyToVarCorrect_QualifiedTypeNames() As Task
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {
{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True},
{CSharpCodeStyleOptions.VarForBuiltInTypes, CodeStyleOptions.TrueWithSilentEnforcement},
{CSharpCodeStyleOptions.VarWhenTypeIsApparent, CodeStyleOptions.TrueWithSilentEnforcement},
{CSharpCodeStyleOptions.VarElsewhere, CodeStyleOptions.TrueWithSilentEnforcement}
......@@ -1671,7 +1667,7 @@ class Program
<Fact, Trait(Traits.Feature, Traits.Features.Simplification)>
Public Async Function TestCSharpSimplifyToVarDontSimplify() As Task
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.PreferImplicitTypeInLocalDeclaration, True}}
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {}
Dim input =
<Workspace>
......@@ -2027,8 +2023,8 @@ class E
<WorkItem(838109, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/838109")>
<Fact, Trait(Traits.Feature, Traits.Features.Simplification)>
Public Async Function TestDoSimplifyToGenericName() As Task
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.AllowSimplificationToGenericType, True}}
Public Async Function TestDoNotSimplifyToGenericName() As Task
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {}
Dim input =
<Workspace>
......@@ -2079,7 +2075,7 @@ class E
{
public static void Main()
{
C<int>.D.F();
C.D.F();
}
}]]>
</text>
......@@ -2089,7 +2085,7 @@ class E
<Fact, WorkItem(838109, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/838109"), Trait(Traits.Feature, Traits.Features.Simplification)>
Public Async Function TestDontSimplifyAllNodes_SimplifyNestedType() As Task
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.AllowSimplificationToBaseType, False}}
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {}
Dim input =
<Workspace>
......@@ -2142,7 +2138,7 @@ static class M
{
public static void Main()
{
int k = Z<float>.X.Y;
int k = Preserve.X.Y;
}
}]]></text>
......@@ -4831,8 +4827,8 @@ End Class
<WorkItem(838109, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/838109")>
<Fact, Trait(Traits.Feature, Traits.Features.Simplification)>
Public Async Function TestVisualBasic_DoSimplifyToGenericName() As Task
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.AllowSimplificationToGenericType, True}}
Public Async Function TestVisualBasic_DoNotSimplifyToGenericName() As Task
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {}
Dim input =
<Workspace>
......@@ -4865,7 +4861,7 @@ Imports System
Class Program
Sub Main(args As String())
C(OfInteger).D.F()
C.D.F()
End Sub
End Class
Public Class C(Of T)
......@@ -4885,7 +4881,7 @@ End Class
<Fact, WorkItem(838109, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/838109"), Trait(Traits.Feature, Traits.Features.Simplification)>
Public Async Function TestVisualBasic_TestDontSimplifyAllNodes_SimplifyNestedType() As Task
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {{SimplificationOptions.AllowSimplificationToBaseType, False}}
Dim simplificationOption = New Dictionary(Of OptionKey, Object) From {}
Dim input =
<Workspace>
......@@ -4926,7 +4922,7 @@ End Class
NotInheritable Class M
Public Shared Sub Main()
ReDim Z(Of Integer).X.Y(1)
ReDim [Preserve].X.Y(1)
End Sub
End Class]]></text>
......
......@@ -770,7 +770,7 @@ private static bool CanReplace(ISymbol symbol)
return true;
}
return expression.TrySimplify(semanticModel, optionSet, out replacementNode, out issueSpan);
return expression.TrySimplify(semanticModel, out replacementNode, out issueSpan);
}
public static bool TryReduceExplicitName(
......@@ -843,7 +843,7 @@ private static bool CanReplace(ISymbol symbol)
if (!memberAccess.IsRightSideOfDot())
{
// Check if we need to replace this syntax with an alias identifier
if (memberAccess.TryReplaceWithAlias(semanticModel, optionSet.GetOption(SimplificationOptions.PreferAliasToQualification), cancellationToken, out var aliasReplacement))
if (memberAccess.TryReplaceWithAlias(semanticModel, cancellationToken, out var aliasReplacement))
{
// get the token text as it appears in source code to preserve e.g. unicode character escaping
var text = aliasReplacement.Name;
......@@ -1103,7 +1103,7 @@ public static bool IsAliasReplaceableExpression(this ExpressionSyntax expression
[PerformanceSensitive(
"https://github.com/dotnet/roslyn/issues/23582",
Constraint = "Most trees do not have using alias directives, so avoid the expensive " + nameof(CSharpExtensions.GetSymbolInfo) + " call for this case.")]
private static bool TryReplaceWithAlias(this ExpressionSyntax node, SemanticModel semanticModel, bool preferAliasToQualifiedName, CancellationToken cancellationToken, out IAliasSymbol aliasReplacement)
private static bool TryReplaceWithAlias(this ExpressionSyntax node, SemanticModel semanticModel, CancellationToken cancellationToken, out IAliasSymbol aliasReplacement)
{
aliasReplacement = null;
......@@ -1186,6 +1186,7 @@ private static bool TryReplaceWithAlias(this ExpressionSyntax node, SemanticMode
return false;
}
var preferAliasToQualifiedName = true;
if (node is QualifiedNameSyntax qualifiedName)
{
if (!qualifiedName.Right.HasAnnotation(Simplifier.SpecialTypeAnnotation))
......@@ -1486,12 +1487,6 @@ private static int GetNamespaceId(SyntaxList<MemberDeclarationSyntax> members, N
if (symbol.Kind == SymbolKind.Method && name.Kind() == SyntaxKind.GenericName)
{
// The option wants the generic method invocation name to be explicit, then quit the reduction
if (!optionSet.GetOption(SimplificationOptions.PreferImplicitTypeInference))
{
return false;
}
var genericName = (GenericNameSyntax)name;
replacementNode = SyntaxFactory.IdentifierName(genericName.Identifier)
.WithLeadingTrivia(genericName.GetLeadingTrivia())
......@@ -1522,7 +1517,7 @@ private static int GetNamespaceId(SyntaxList<MemberDeclarationSyntax> members, N
{
if (!name.IsRightSideOfDotOrColonColon())
{
if (name.TryReplaceWithAlias(semanticModel, optionSet.GetOption(SimplificationOptions.PreferAliasToQualification), cancellationToken, out var aliasReplacement))
if (name.TryReplaceWithAlias(semanticModel, cancellationToken, out var aliasReplacement))
{
// get the token text as it appears in source code to preserve e.g. Unicode character escaping
var text = aliasReplacement.Name;
......@@ -1972,7 +1967,6 @@ public static bool IsPartOfNamespaceDeclarationName(SyntaxNode node)
private static bool TrySimplify(
this ExpressionSyntax expression,
SemanticModel semanticModel,
OptionSet optionSet,
out ExpressionSyntax replacementNode,
out TextSpan issueSpan)
{
......@@ -1989,7 +1983,7 @@ public static bool IsPartOfNamespaceDeclarationName(SyntaxNode node)
return false;
}
if (TrySimplifyMemberAccessOrQualifiedName(memberAccess.Expression, memberAccess.Name, semanticModel, optionSet, out var newLeft, out issueSpan))
if (TrySimplifyMemberAccessOrQualifiedName(memberAccess.Expression, memberAccess.Name, semanticModel, out var newLeft, out issueSpan))
{
// replacement node might not be in it's simplest form, so add simplify annotation to it.
replacementNode = memberAccess.Update(newLeft, memberAccess.OperatorToken, memberAccess.Name)
......@@ -2005,7 +1999,7 @@ public static bool IsPartOfNamespaceDeclarationName(SyntaxNode node)
case SyntaxKind.QualifiedName:
{
var qualifiedName = (QualifiedNameSyntax)expression;
if (TrySimplifyMemberAccessOrQualifiedName(qualifiedName.Left, qualifiedName.Right, semanticModel, optionSet, out var newLeft, out issueSpan))
if (TrySimplifyMemberAccessOrQualifiedName(qualifiedName.Left, qualifiedName.Right, semanticModel, out var newLeft, out issueSpan))
{
// replacement node might not be in it's simplest form, so add simplify annotation to it.
replacementNode = qualifiedName.Update((NameSyntax)newLeft, qualifiedName.DotToken, qualifiedName.Right)
......@@ -2033,7 +2027,6 @@ private static bool ReplacementChangesSemantics(ExpressionSyntax originalExpress
ExpressionSyntax left,
ExpressionSyntax right,
SemanticModel semanticModel,
OptionSet optionSet,
out ExpressionSyntax replacementNode,
out TextSpan issueSpan)
{
......@@ -2077,15 +2070,10 @@ private static bool ReplacementChangesSemantics(ExpressionSyntax originalExpress
if (containingType != null && !containingType.Equals(leftSymbol))
{
if (leftSymbol is INamedTypeSymbol namedType)
if (leftSymbol is INamedTypeSymbol namedType &&
containingType.TypeArguments.Length != 0)
{
if ((namedType.GetBaseTypes().Contains(containingType) &&
!optionSet.GetOption(SimplificationOptions.AllowSimplificationToBaseType)) ||
(!optionSet.GetOption(SimplificationOptions.AllowSimplificationToGenericType) &&
containingType.TypeArguments.Length != 0))
{
return false;
}
return false;
}
// We have a static member access or a nested type member access using a more derived type.
......
......@@ -31,11 +31,6 @@ private CSharpUseImplicitTypeHelper()
return default;
}
if (!optionSet.GetOption(SimplificationOptions.PreferImplicitTypeInLocalDeclaration))
{
return default;
}
if (typeName.HasAnnotation(DoNotAllowVarAnnotation.Annotation))
{
return default;
......
......@@ -17,12 +17,6 @@ public SimplificationOptionsProvider()
}
public ImmutableArray<IOption> Options { get; } = ImmutableArray.Create<IOption>(
SimplificationOptions.PreferAliasToQualification,
SimplificationOptions.PreferOmittingModuleNamesInQualification,
SimplificationOptions.PreferImplicitTypeInference,
SimplificationOptions.PreferImplicitTypeInLocalDeclaration,
SimplificationOptions.AllowSimplificationToGenericType,
SimplificationOptions.AllowSimplificationToBaseType,
SimplificationOptions.NamingPreferences);
}
}
......@@ -15,6 +15,7 @@ public static class SimplificationOptions
/// This option tells the simplification engine if the Qualified Name should be replaced by Alias
/// if the user had initially not used the Alias
/// </summary>
[Obsolete("This option is no longer used")]
public static Option<bool> PreferAliasToQualification { get; } = new Option<bool>(nameof(SimplificationOptions), nameof(PreferAliasToQualification), true,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.PreferAliasToQualification"));
......@@ -22,78 +23,83 @@ public static class SimplificationOptions
/// This option influences the name reduction of members of a module in VB. If set to true, the
/// name reducer will e.g. reduce Namespace.Module.Member to Namespace.Member.
/// </summary>
[Obsolete("This option is no longer used")]
public static Option<bool> PreferOmittingModuleNamesInQualification { get; } = new Option<bool>(nameof(SimplificationOptions), nameof(PreferOmittingModuleNamesInQualification), true,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.PreferOmittingModuleNamesInQualification"));
/// <summary>
/// This option says that if we should simplify the Generic Name which has the type argument inferred
/// </summary>
[Obsolete("This option is no longer used")]
public static Option<bool> PreferImplicitTypeInference { get; } = new Option<bool>(nameof(SimplificationOptions), nameof(PreferImplicitTypeInference), true,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.PreferImplicitTypeInference"));
/// <summary>
/// This option says if we should simplify the Explicit Type in Local Declarations
/// </summary>
[Obsolete("This option is no longer used")]
public static Option<bool> PreferImplicitTypeInLocalDeclaration { get; } = new Option<bool>(nameof(SimplificationOptions), nameof(PreferImplicitTypeInLocalDeclaration), true,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.PreferImplicitTypeInLocalDeclaration"));
/// <summary>
/// This option says if we should simplify to NonGeneric Name rather than GenericName
/// </summary>
[Obsolete("This option is no longer used")]
public static Option<bool> AllowSimplificationToGenericType { get; } = new Option<bool>(nameof(SimplificationOptions), nameof(AllowSimplificationToGenericType), false,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.AllowSimplificationToGenericType"));
/// <summary>
/// This option says if we should simplify from Derived types to Base types in Static Member Accesses
/// </summary>
[Obsolete("This option is no longer used")]
public static Option<bool> AllowSimplificationToBaseType { get; } = new Option<bool>(nameof(SimplificationOptions), nameof(AllowSimplificationToBaseType), true,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.AllowSimplificationToBaseType"));
/// <summary>
/// This option says if we should simplify away the <see langword="this"/> or <see langword="Me"/> in member access expressions.
/// </summary>
[Obsolete]
[Obsolete("This option is no longer used")]
public static PerLanguageOption<bool> QualifyMemberAccessWithThisOrMe { get; } = new PerLanguageOption<bool>(nameof(SimplificationOptions), nameof(QualifyMemberAccessWithThisOrMe), defaultValue: false,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.QualifyMemberAccessWithThisOrMe"));
/// <summary>
/// This option says if we should simplify away the <see langword="this"/>. or <see langword="Me"/>. in field access expressions.
/// </summary>
[Obsolete]
[Obsolete("This option is no longer used")]
public static PerLanguageOption<bool> QualifyFieldAccess { get; } = new PerLanguageOption<bool>(nameof(SimplificationOptions), nameof(QualifyFieldAccess), defaultValue: false,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.QualifyFieldAccess"));
/// <summary>
/// This option says if we should simplify away the <see langword="this"/>. or <see langword="Me"/>. in property access expressions.
/// </summary>
[Obsolete]
[Obsolete("This option is no longer used")]
public static PerLanguageOption<bool> QualifyPropertyAccess { get; } = new PerLanguageOption<bool>(nameof(SimplificationOptions), nameof(QualifyPropertyAccess), defaultValue: false,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.QualifyPropertyAccess"));
/// <summary>
/// This option says if we should simplify away the <see langword="this"/>. or <see langword="Me"/>. in method access expressions.
/// </summary>
[Obsolete]
[Obsolete("This option is no longer used")]
public static PerLanguageOption<bool> QualifyMethodAccess { get; } = new PerLanguageOption<bool>(nameof(SimplificationOptions), nameof(QualifyMethodAccess), defaultValue: false,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.QualifyMethodAccess"));
/// <summary>
/// This option says if we should simplify away the <see langword="this"/>. or <see langword="Me"/>. in event access expressions.
/// </summary>
[Obsolete]
[Obsolete("This option is no longer used")]
public static PerLanguageOption<bool> QualifyEventAccess { get; } = new PerLanguageOption<bool>(nameof(SimplificationOptions), nameof(QualifyEventAccess), defaultValue: false,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.QualifyEventAccess"));
/// <summary>
/// This option says if we should prefer keyword for Intrinsic Predefined Types in Declarations
/// </summary>
[Obsolete]
[Obsolete("This option is no longer used")]
public static PerLanguageOption<bool> PreferIntrinsicPredefinedTypeKeywordInDeclaration { get; } = new PerLanguageOption<bool>(nameof(SimplificationOptions), nameof(PreferIntrinsicPredefinedTypeKeywordInDeclaration), defaultValue: true);
/// <summary>
/// This option says if we should prefer keyword for Intrinsic Predefined Types in Member Access Expression
/// </summary>
[Obsolete]
[Obsolete("This option is no longer used")]
public static PerLanguageOption<bool> PreferIntrinsicPredefinedTypeKeywordInMemberAccess { get; } = new PerLanguageOption<bool>(nameof(SimplificationOptions), nameof(PreferIntrinsicPredefinedTypeKeywordInMemberAccess), defaultValue: true);
/// <summary>
......
......@@ -799,9 +799,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
issueSpan = Nothing
' Failfast Conditions
If Not optionSet.GetOption(SimplificationOptions.PreferImplicitTypeInLocalDeclaration) OrElse
variableDeclarator.AsClause Is Nothing OrElse
Not variableDeclarator.Parent.IsKind(
If variableDeclarator.AsClause Is Nothing OrElse
Not variableDeclarator.Parent.IsKind(
SyntaxKind.LocalDeclarationStatement,
SyntaxKind.UsingStatement,
SyntaxKind.ForStatement,
......@@ -923,7 +922,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Return True
End If
Return expression.TrySimplify(semanticModel, optionSet, replacementNode, issueSpan)
Return expression.TrySimplify(semanticModel, replacementNode, issueSpan)
End Function
<Extension()>
......@@ -989,7 +988,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
If Not memberAccess.IsRightSideOfDot() Then
Dim aliasReplacement As IAliasSymbol = Nothing
If memberAccess.TryReplaceWithAlias(semanticModel, aliasReplacement, optionSet.GetOption(SimplificationOptions.PreferAliasToQualification)) Then
If memberAccess.TryReplaceWithAlias(semanticModel, aliasReplacement) Then
Dim identifierToken = SyntaxFactory.Identifier(
memberAccess.GetLeadingTrivia(),
aliasReplacement.Name,
......@@ -1047,10 +1046,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Return True
End If
If optionSet.GetOption(SimplificationOptions.PreferOmittingModuleNamesInQualification) Then
If TryOmitModuleName(memberAccess, semanticModel, replacementNode, issueSpan, cancellationToken) Then
Return True
End If
If TryOmitModuleName(memberAccess, semanticModel, replacementNode, issueSpan, cancellationToken) Then
Return True
End If
End If
......@@ -1224,10 +1221,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
End If
If symbol.Kind = SymbolKind.Method AndAlso name.Kind = SyntaxKind.GenericName Then
If Not optionSet.GetOption(SimplificationOptions.PreferImplicitTypeInference) Then
Return False
End If
Dim genericName = DirectCast(name, GenericNameSyntax)
replacementNode = SyntaxFactory.IdentifierName(genericName.Identifier).WithLeadingTrivia(genericName.GetLeadingTrivia()).WithTrailingTrivia(genericName.GetTrailingTrivia())
......@@ -1256,7 +1249,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
If Not name.IsRightSideOfDot() Then
Dim aliasReplacement As IAliasSymbol = Nothing
If name.TryReplaceWithAlias(semanticModel, aliasReplacement, optionSet.GetOption(SimplificationOptions.PreferAliasToQualification)) Then
If name.TryReplaceWithAlias(semanticModel, aliasReplacement) Then
Dim identifierToken = SyntaxFactory.Identifier(
name.GetLeadingTrivia(),
aliasReplacement.Name,
......@@ -1304,7 +1297,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
' check if the alias name ends with an Attribute suffix that can be omitted.
Dim replacementNodeWithoutAttributeSuffix As ExpressionSyntax = Nothing
Dim issueSpanWithoutAttributeSuffix As TextSpan = Nothing
If TryReduceAttributeSuffix(name, identifierToken, semanticModel, aliasReplacement IsNot Nothing, optionSet.GetOption(SimplificationOptions.PreferAliasToQualification), replacementNodeWithoutAttributeSuffix, issueSpanWithoutAttributeSuffix, cancellationToken) Then
If TryReduceAttributeSuffix(name, identifierToken, semanticModel, aliasReplacement IsNot Nothing, replacementNodeWithoutAttributeSuffix, issueSpanWithoutAttributeSuffix, cancellationToken) Then
If name.CanReplaceWithReducedName(replacementNodeWithoutAttributeSuffix, semanticModel, cancellationToken) Then
replacementNode = replacementNode.CopyAnnotationsTo(replacementNodeWithoutAttributeSuffix)
issueSpan = issueSpanWithoutAttributeSuffix
......@@ -1421,15 +1414,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Return True
End If
If optionSet.GetOption(SimplificationOptions.PreferOmittingModuleNamesInQualification) Then
If TryOmitModuleName(qualifiedName, semanticModel, replacementNode, issueSpan, cancellationToken) Then
Return True
End If
If TryOmitModuleName(qualifiedName, semanticModel, replacementNode, issueSpan, cancellationToken) Then
Return True
End If
Case SyntaxKind.IdentifierName
Dim identifier = DirectCast(name, IdentifierNameSyntax).Identifier
TryReduceAttributeSuffix(name, identifier, semanticModel, False, optionSet.GetOption(SimplificationOptions.PreferAliasToQualification), replacementNode, issueSpan, cancellationToken)
TryReduceAttributeSuffix(name, identifier, semanticModel, False, replacementNode, issueSpan, cancellationToken)
End Select
End If
......@@ -1502,7 +1493,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
identifierToken As SyntaxToken,
semanticModel As SemanticModel,
isIdentifierNameFromAlias As Boolean,
preferAliasToQualification As Boolean,
<Out()> ByRef replacementNode As ExpressionSyntax,
<Out()> ByRef issueSpan As TextSpan,
cancellationToken As CancellationToken
......@@ -1511,8 +1501,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
' When the replacement is an Alias we don't want the "Attribute" Suffix to be removed because this will result in symbol change
Dim aliasSymbol = semanticModel.GetAliasInfo(name, cancellationToken)
If (aliasSymbol IsNot Nothing AndAlso preferAliasToQualification AndAlso
String.Compare(aliasSymbol.Name, identifierToken.ValueText, StringComparison.OrdinalIgnoreCase) = 0) Then
If aliasSymbol IsNot Nothing AndAlso
String.Compare(aliasSymbol.Name, identifierToken.ValueText, StringComparison.OrdinalIgnoreCase) = 0 Then
Return False
End If
......@@ -1605,7 +1595,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Private Function TrySimplify(
expression As ExpressionSyntax,
semanticModel As SemanticModel,
optionSet As OptionSet,
<Out()> ByRef replacementNode As ExpressionSyntax,
<Out()> ByRef issueSpan As TextSpan
) As Boolean
......@@ -1617,7 +1606,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
If True Then
Dim memberAccess = DirectCast(expression, MemberAccessExpressionSyntax)
Dim newLeft As ExpressionSyntax = Nothing
If TrySimplifyMemberAccessOrQualifiedName(memberAccess.Expression, memberAccess.Name, semanticModel, optionSet, newLeft, issueSpan) Then
If TrySimplifyMemberAccessOrQualifiedName(memberAccess.Expression, memberAccess.Name, semanticModel, newLeft, issueSpan) Then
' replacement node might not be in it's simplest form, so add simplify annotation to it.
replacementNode = memberAccess.Update(memberAccess.Kind, newLeft, memberAccess.OperatorToken, memberAccess.Name).WithAdditionalAnnotations(Simplifier.Annotation)
......@@ -1632,7 +1621,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
If True Then
Dim qualifiedName = DirectCast(expression, QualifiedNameSyntax)
Dim newLeft As ExpressionSyntax = Nothing
If TrySimplifyMemberAccessOrQualifiedName(qualifiedName.Left, qualifiedName.Right, semanticModel, optionSet, newLeft, issueSpan) Then
If TrySimplifyMemberAccessOrQualifiedName(qualifiedName.Left, qualifiedName.Right, semanticModel, newLeft, issueSpan) Then
If Not TypeOf newLeft Is NameSyntax Then
Contract.Fail("QualifiedName Left = " + qualifiedName.Left.ToString() + " and QualifiedName Right = " + qualifiedName.Right.ToString() + " . Left is tried to be replaced with the PredefinedType " + replacementNode.ToString())
End If
......@@ -1661,7 +1650,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
left As ExpressionSyntax,
right As ExpressionSyntax,
semanticModel As SemanticModel,
optionSet As OptionSet,
<Out()> ByRef replacementNode As ExpressionSyntax,
<Out()> ByRef issueSpan As TextSpan
) As Boolean
......@@ -1686,13 +1674,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
If containingType IsNot Nothing AndAlso Not containingType.Equals(leftSymbol) Then
Dim namedType = TryCast(leftSymbol, INamedTypeSymbol)
If namedType IsNot Nothing Then
If ((namedType.GetBaseTypes().Contains(containingType) AndAlso
Not optionSet.GetOption(SimplificationOptions.AllowSimplificationToBaseType)) OrElse
(Not optionSet.GetOption(SimplificationOptions.AllowSimplificationToGenericType) AndAlso
containingType.TypeArguments.Length <> 0)) Then
Return False
End If
If namedType IsNot Nothing AndAlso
containingType.TypeArguments.Length <> 0 Then
Return False
End If
' We have a static member access or a nested type member access using a more derived type.
......@@ -1710,10 +1694,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
<Extension>
Private Function TryReplaceWithAlias(
node As ExpressionSyntax,
semanticModel As SemanticModel,
<Out> ByRef aliasReplacement As IAliasSymbol,
Optional preferAliasToQualifiedName As Boolean = False) As Boolean
node As ExpressionSyntax,
semanticModel As SemanticModel,
<Out> ByRef aliasReplacement As IAliasSymbol) As Boolean
aliasReplacement = Nothing
If Not node.IsAliasReplaceableExpression() Then
......@@ -1760,6 +1743,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Return False
End If
Dim preferAliasToQualifiedName = True
If TypeOf node Is QualifiedNameSyntax Then
Dim qualifiedName = DirectCast(node, QualifiedNameSyntax)
If Not qualifiedName.Right.HasAnnotation(Simplifier.SpecialTypeAnnotation) Then
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册