diff --git a/src/EditorFeatures/Test2/Simplification/TypeInferenceSimplifierTests.vb b/src/EditorFeatures/Test2/Simplification/TypeInferenceSimplifierTests.vb index a9754a9ca76527c25dc2abcf92e9f7572cebd6af..71460429d24babcabe668506fcf80699b9364a68 100644 --- a/src/EditorFeatures/Test2/Simplification/TypeInferenceSimplifierTests.vb +++ b/src/EditorFeatures/Test2/Simplification/TypeInferenceSimplifierTests.vb @@ -68,7 +68,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Simplification End Module - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 }]]> - 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 ]]> - 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 - 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 - 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 diff --git a/src/EditorFeatures/Test2/Simplification/TypeNameSimplifierTest.vb b/src/EditorFeatures/Test2/Simplification/TypeNameSimplifierTest.vb index a8b50405bef1be5eecc08b34d0dc7b2ba784da8e..eebd19e1897df693fbb57ec868678e8fa9b831da 100644 --- a/src/EditorFeatures/Test2/Simplification/TypeNameSimplifierTest.vb +++ b/src/EditorFeatures/Test2/Simplification/TypeNameSimplifierTest.vb @@ -1470,7 +1470,6 @@ class C1 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 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 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 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 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 = @@ -2027,8 +2023,8 @@ class E - 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 = @@ -2079,7 +2075,7 @@ class E { public static void Main() { - C.D.F(); + C.D.F(); } }]]> @@ -2089,7 +2085,7 @@ class E 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 = @@ -2142,7 +2138,7 @@ static class M { public static void Main() { - int k = Z.X.Y; + int k = Preserve.X.Y; } }]]> @@ -4831,8 +4827,8 @@ End Class - 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 = @@ -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 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 = @@ -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]]> diff --git a/src/Workspaces/CSharp/Portable/Extensions/ExpressionSyntaxExtensions.cs b/src/Workspaces/CSharp/Portable/Extensions/ExpressionSyntaxExtensions.cs index a0c9c2af79a0893024b32318e4dc06f20c6a9197..886dc0e5f75ad9dd096d43df9b3d82a8b022554f 100644 --- a/src/Workspaces/CSharp/Portable/Extensions/ExpressionSyntaxExtensions.cs +++ b/src/Workspaces/CSharp/Portable/Extensions/ExpressionSyntaxExtensions.cs @@ -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 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 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. diff --git a/src/Workspaces/CSharp/Portable/Utilities/CSharpUseImplicitTypeHelper.cs b/src/Workspaces/CSharp/Portable/Utilities/CSharpUseImplicitTypeHelper.cs index e1e2e78d661449a777cc8f76a3c02a3849b4d49c..59aac19f0e5e1ba9495a473010042b9e494808b7 100644 --- a/src/Workspaces/CSharp/Portable/Utilities/CSharpUseImplicitTypeHelper.cs +++ b/src/Workspaces/CSharp/Portable/Utilities/CSharpUseImplicitTypeHelper.cs @@ -31,11 +31,6 @@ private CSharpUseImplicitTypeHelper() return default; } - if (!optionSet.GetOption(SimplificationOptions.PreferImplicitTypeInLocalDeclaration)) - { - return default; - } - if (typeName.HasAnnotation(DoNotAllowVarAnnotation.Annotation)) { return default; diff --git a/src/Workspaces/Core/Portable/Simplification/SimplificationOptionProvider.cs b/src/Workspaces/Core/Portable/Simplification/SimplificationOptionProvider.cs index 96fa895b7046a13989f477809d0c3208fad3b20b..f1767ff02e8cbe74ea63ed65ed1238b6e9c414b5 100644 --- a/src/Workspaces/Core/Portable/Simplification/SimplificationOptionProvider.cs +++ b/src/Workspaces/Core/Portable/Simplification/SimplificationOptionProvider.cs @@ -17,12 +17,6 @@ public SimplificationOptionsProvider() } public ImmutableArray Options { get; } = ImmutableArray.Create( - SimplificationOptions.PreferAliasToQualification, - SimplificationOptions.PreferOmittingModuleNamesInQualification, - SimplificationOptions.PreferImplicitTypeInference, - SimplificationOptions.PreferImplicitTypeInLocalDeclaration, - SimplificationOptions.AllowSimplificationToGenericType, - SimplificationOptions.AllowSimplificationToBaseType, SimplificationOptions.NamingPreferences); } } diff --git a/src/Workspaces/Core/Portable/Simplification/SimplificationOptions.cs b/src/Workspaces/Core/Portable/Simplification/SimplificationOptions.cs index 11b8b35ac15fb27a67702e1d3038c36ac8a1618c..af5a889423fbfcdfc4747b86eff96a931c6d89ad 100644 --- a/src/Workspaces/Core/Portable/Simplification/SimplificationOptions.cs +++ b/src/Workspaces/Core/Portable/Simplification/SimplificationOptions.cs @@ -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 /// + [Obsolete("This option is no longer used")] public static Option PreferAliasToQualification { get; } = new Option(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. /// + [Obsolete("This option is no longer used")] public static Option PreferOmittingModuleNamesInQualification { get; } = new Option(nameof(SimplificationOptions), nameof(PreferOmittingModuleNamesInQualification), true, storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.PreferOmittingModuleNamesInQualification")); /// /// This option says that if we should simplify the Generic Name which has the type argument inferred /// + [Obsolete("This option is no longer used")] public static Option PreferImplicitTypeInference { get; } = new Option(nameof(SimplificationOptions), nameof(PreferImplicitTypeInference), true, storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.PreferImplicitTypeInference")); /// /// This option says if we should simplify the Explicit Type in Local Declarations /// + [Obsolete("This option is no longer used")] public static Option PreferImplicitTypeInLocalDeclaration { get; } = new Option(nameof(SimplificationOptions), nameof(PreferImplicitTypeInLocalDeclaration), true, storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.PreferImplicitTypeInLocalDeclaration")); /// /// This option says if we should simplify to NonGeneric Name rather than GenericName /// + [Obsolete("This option is no longer used")] public static Option AllowSimplificationToGenericType { get; } = new Option(nameof(SimplificationOptions), nameof(AllowSimplificationToGenericType), false, storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.AllowSimplificationToGenericType")); /// /// This option says if we should simplify from Derived types to Base types in Static Member Accesses /// + [Obsolete("This option is no longer used")] public static Option AllowSimplificationToBaseType { get; } = new Option(nameof(SimplificationOptions), nameof(AllowSimplificationToBaseType), true, storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.AllowSimplificationToBaseType")); /// /// This option says if we should simplify away the or in member access expressions. /// - [Obsolete] + [Obsolete("This option is no longer used")] public static PerLanguageOption QualifyMemberAccessWithThisOrMe { get; } = new PerLanguageOption(nameof(SimplificationOptions), nameof(QualifyMemberAccessWithThisOrMe), defaultValue: false, storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.QualifyMemberAccessWithThisOrMe")); /// /// This option says if we should simplify away the . or . in field access expressions. /// - [Obsolete] + [Obsolete("This option is no longer used")] public static PerLanguageOption QualifyFieldAccess { get; } = new PerLanguageOption(nameof(SimplificationOptions), nameof(QualifyFieldAccess), defaultValue: false, storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.QualifyFieldAccess")); /// /// This option says if we should simplify away the . or . in property access expressions. /// - [Obsolete] + [Obsolete("This option is no longer used")] public static PerLanguageOption QualifyPropertyAccess { get; } = new PerLanguageOption(nameof(SimplificationOptions), nameof(QualifyPropertyAccess), defaultValue: false, storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.QualifyPropertyAccess")); /// /// This option says if we should simplify away the . or . in method access expressions. /// - [Obsolete] + [Obsolete("This option is no longer used")] public static PerLanguageOption QualifyMethodAccess { get; } = new PerLanguageOption(nameof(SimplificationOptions), nameof(QualifyMethodAccess), defaultValue: false, storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.QualifyMethodAccess")); /// /// This option says if we should simplify away the . or . in event access expressions. /// - [Obsolete] + [Obsolete("This option is no longer used")] public static PerLanguageOption QualifyEventAccess { get; } = new PerLanguageOption(nameof(SimplificationOptions), nameof(QualifyEventAccess), defaultValue: false, storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.QualifyEventAccess")); /// /// This option says if we should prefer keyword for Intrinsic Predefined Types in Declarations /// - [Obsolete] + [Obsolete("This option is no longer used")] public static PerLanguageOption PreferIntrinsicPredefinedTypeKeywordInDeclaration { get; } = new PerLanguageOption(nameof(SimplificationOptions), nameof(PreferIntrinsicPredefinedTypeKeywordInDeclaration), defaultValue: true); /// /// This option says if we should prefer keyword for Intrinsic Predefined Types in Member Access Expression /// - [Obsolete] + [Obsolete("This option is no longer used")] public static PerLanguageOption PreferIntrinsicPredefinedTypeKeywordInMemberAccess { get; } = new PerLanguageOption(nameof(SimplificationOptions), nameof(PreferIntrinsicPredefinedTypeKeywordInMemberAccess), defaultValue: true); /// diff --git a/src/Workspaces/VisualBasic/Portable/Extensions/ExpressionSyntaxExtensions.vb b/src/Workspaces/VisualBasic/Portable/Extensions/ExpressionSyntaxExtensions.vb index 4bbe367c4b18a6bdeea38f87c8131bc854db8191..2c47f727ff7f8f9bc6bacd09b829be5fb634fbd0 100644 --- a/src/Workspaces/VisualBasic/Portable/Extensions/ExpressionSyntaxExtensions.vb +++ b/src/Workspaces/VisualBasic/Portable/Extensions/ExpressionSyntaxExtensions.vb @@ -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 @@ -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, ByRef replacementNode As ExpressionSyntax, 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, ByRef replacementNode As ExpressionSyntax, 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, ByRef replacementNode As ExpressionSyntax, 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 Private Function TryReplaceWithAlias( - node As ExpressionSyntax, - semanticModel As SemanticModel, - ByRef aliasReplacement As IAliasSymbol, - Optional preferAliasToQualifiedName As Boolean = False) As Boolean + node As ExpressionSyntax, + semanticModel As SemanticModel, + 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