提交 9fc091e1 编写于 作者: C Cyrus Najmabadi

Remove unused parameters

上级 1fcb4464
...@@ -67,7 +67,7 @@ private Rewriter(bool isAllThrowStatements) ...@@ -67,7 +67,7 @@ private Rewriter(bool isAllThrowStatements)
Debug.Assert(_assignmentTargetOpt != null); Debug.Assert(_assignmentTargetOpt != null);
return generateDeclaration return generateDeclaration
? GenerateVariableDeclaration(switchExpression, leadingTrivia, declaratorToRemoveTypeOpt) ? GenerateVariableDeclaration(switchExpression, declaratorToRemoveTypeOpt)
: GenerateAssignment(switchExpression, nodeToGenerate, leadingTrivia); : GenerateAssignment(switchExpression, nodeToGenerate, leadingTrivia);
} }
...@@ -82,7 +82,7 @@ private ExpressionStatementSyntax GenerateAssignment(ExpressionSyntax switchExpr ...@@ -82,7 +82,7 @@ private ExpressionStatementSyntax GenerateAssignment(ExpressionSyntax switchExpr
.WithLeadingTrivia(leadingTrivia); .WithLeadingTrivia(leadingTrivia);
} }
private StatementSyntax GenerateVariableDeclaration(ExpressionSyntax switchExpression, SyntaxTriviaList leadingTrivia, ITypeSymbol declaratorToRemoveTypeOpt) private StatementSyntax GenerateVariableDeclaration(ExpressionSyntax switchExpression, ITypeSymbol declaratorToRemoveTypeOpt)
{ {
Debug.Assert(_assignmentTargetOpt is IdentifierNameSyntax); Debug.Assert(_assignmentTargetOpt is IdentifierNameSyntax);
......
...@@ -74,14 +74,10 @@ internal static bool IsTriggerCharacter(SourceText text, int characterPosition, ...@@ -74,14 +74,10 @@ internal static bool IsTriggerCharacter(SourceText text, int characterPosition,
internal static ImmutableHashSet<char> CommonTriggerCharactersWithArgumentList { get; } = ImmutableHashSet.Create('.', '#', '>', ':', '(', '[', ' '); internal static ImmutableHashSet<char> CommonTriggerCharactersWithArgumentList { get; } = ImmutableHashSet.Create('.', '#', '>', ':', '(', '[', ' ');
internal static bool IsTriggerCharacterOrArgumentListCharacter(SourceText text, int characterPosition, OptionSet options) internal static bool IsTriggerCharacterOrArgumentListCharacter(SourceText text, int characterPosition, OptionSet options)
{ => IsTriggerCharacter(text, characterPosition, options) || IsArgumentListCharacter(text, characterPosition);
return IsTriggerCharacter(text, characterPosition, options) || IsArgumentListCharacter(text, characterPosition, options);
}
private static bool IsArgumentListCharacter(SourceText text, int characterPosition, OptionSet options) private static bool IsArgumentListCharacter(SourceText text, int characterPosition)
{ => IsArgumentListCharacter(text[characterPosition]);
return IsArgumentListCharacter(text[characterPosition]);
}
internal static bool IsArgumentListCharacter(char ch) internal static bool IsArgumentListCharacter(char ch)
{ {
......
...@@ -98,7 +98,7 @@ public override async Task ProvideCompletionsAsync(CompletionContext context) ...@@ -98,7 +98,7 @@ public override async Task ProvideCompletionsAsync(CompletionContext context)
var serializedOptions = ImmutableDictionary<string, string>.Empty.Add(HideAdvancedMembers, hideAdvancedMembers.ToString()); var serializedOptions = ImmutableDictionary<string, string>.Empty.Add(HideAdvancedMembers, hideAdvancedMembers.ToString());
var items = CreateCompletionItems(document.Project.Solution.Workspace, var items = CreateCompletionItems(document.Project.Solution.Workspace,
semanticModel, symbols, token, span, position, serializedOptions); semanticModel, symbols, token, position, serializedOptions);
context.AddItems(items); context.AddItems(items);
} }
...@@ -270,15 +270,15 @@ private static TextSpan GetCompletionItemSpan(SourceText text, int position) ...@@ -270,15 +270,15 @@ private static TextSpan GetCompletionItemSpan(SourceText text, int position)
} }
private IEnumerable<CompletionItem> CreateCompletionItems( private IEnumerable<CompletionItem> CreateCompletionItems(
Workspace workspace, SemanticModel semanticModel, ImmutableArray<ISymbol> symbols, SyntaxToken token, TextSpan itemSpan, int position, ImmutableDictionary<string, string> options) Workspace workspace, SemanticModel semanticModel, ImmutableArray<ISymbol> symbols, SyntaxToken token, int position, ImmutableDictionary<string, string> options)
{ {
var builder = SharedPools.Default<StringBuilder>().Allocate(); var builder = SharedPools.Default<StringBuilder>().Allocate();
try try
{ {
foreach (var symbol in symbols) foreach (var symbol in symbols)
{ {
yield return CreateItem(workspace, semanticModel, symbol, token, position, builder, options); yield return CreateItem(semanticModel, symbol, token, position, builder, options);
if (TryCreateSpecialTypeItem(workspace, semanticModel, symbol, token, position, builder, options, out var item)) if (TryCreateSpecialTypeItem(semanticModel, symbol, token, position, builder, options, out var item))
{ {
yield return item; yield return item;
} }
...@@ -291,7 +291,7 @@ private static TextSpan GetCompletionItemSpan(SourceText text, int position) ...@@ -291,7 +291,7 @@ private static TextSpan GetCompletionItemSpan(SourceText text, int position)
} }
private bool TryCreateSpecialTypeItem( private bool TryCreateSpecialTypeItem(
Workspace workspace, SemanticModel semanticModel, ISymbol symbol, SyntaxToken token, int position, StringBuilder builder, SemanticModel semanticModel, ISymbol symbol, SyntaxToken token, int position, StringBuilder builder,
ImmutableDictionary<string, string> options, out CompletionItem item) ImmutableDictionary<string, string> options, out CompletionItem item)
{ {
// If the type is a SpecialType, create an additional item using // If the type is a SpecialType, create an additional item using
...@@ -299,7 +299,7 @@ private static TextSpan GetCompletionItemSpan(SourceText text, int position) ...@@ -299,7 +299,7 @@ private static TextSpan GetCompletionItemSpan(SourceText text, int position)
var typeSymbol = symbol as ITypeSymbol; var typeSymbol = symbol as ITypeSymbol;
if (typeSymbol.IsSpecialType()) if (typeSymbol.IsSpecialType())
{ {
item = CreateItem(workspace, semanticModel, symbol, token, position, builder, options, CrefFormatForSpecialTypes); item = CreateItem(semanticModel, symbol, token, position, builder, options, CrefFormatForSpecialTypes);
return true; return true;
} }
...@@ -308,15 +308,15 @@ private static TextSpan GetCompletionItemSpan(SourceText text, int position) ...@@ -308,15 +308,15 @@ private static TextSpan GetCompletionItemSpan(SourceText text, int position)
} }
private CompletionItem CreateItem( private CompletionItem CreateItem(
Workspace workspace, SemanticModel semanticModel, ISymbol symbol, SyntaxToken token, int position, StringBuilder builder, ImmutableDictionary<string, string> options) SemanticModel semanticModel, ISymbol symbol, SyntaxToken token, int position, StringBuilder builder, ImmutableDictionary<string, string> options)
{ {
// For every symbol, we create an item that uses the regular CrefFormat, // For every symbol, we create an item that uses the regular CrefFormat,
// which uses intrinsic type keywords // which uses intrinsic type keywords
return CreateItem(workspace, semanticModel, symbol, token, position, builder, options, CrefFormat); return CreateItem(semanticModel, symbol, token, position, builder, options, CrefFormat);
} }
private CompletionItem CreateItem( private CompletionItem CreateItem(
Workspace workspace, SemanticModel semanticModel, ISymbol symbol, SyntaxToken token, int position, StringBuilder builder, ImmutableDictionary<string, string> options, SemanticModel semanticModel, ISymbol symbol, SyntaxToken token, int position, StringBuilder builder, ImmutableDictionary<string, string> options,
SymbolDisplayFormat unqualifiedCrefFormat) SymbolDisplayFormat unqualifiedCrefFormat)
{ {
builder.Clear(); builder.Clear();
......
...@@ -49,21 +49,21 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -49,21 +49,21 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
var semanticModel = await document.GetSemanticModelForSpanAsync(new Text.TextSpan(token.SpanStart, 0), cancellationToken).ConfigureAwait(false); var semanticModel = await document.GetSemanticModelForSpanAsync(new Text.TextSpan(token.SpanStart, 0), cancellationToken).ConfigureAwait(false);
var typeInferenceService = document.GetLanguageService<ITypeInferenceService>(); var typeInferenceService = document.GetLanguageService<ITypeInferenceService>();
if (IsTupleTypeElement(token, semanticModel, position, cancellationToken, out var result) if (IsTupleTypeElement(token, semanticModel, cancellationToken, out var result)
|| IsParameterDeclaration(token, semanticModel, position, cancellationToken, out result) || IsParameterDeclaration(token, semanticModel, cancellationToken, out result)
|| IsTypeParameterDeclaration(token, semanticModel, position, out result) || IsTypeParameterDeclaration(token, out result)
|| IsLocalFunctionDeclaration(token, semanticModel, position, cancellationToken, out result) || IsLocalFunctionDeclaration(token, semanticModel, cancellationToken, out result)
|| IsLocalVariableDeclaration(token, semanticModel, position, cancellationToken, out result) || IsLocalVariableDeclaration(token, semanticModel, cancellationToken, out result)
|| IsEmbeddedVariableDeclaration(token, semanticModel, position, cancellationToken, out result) || IsEmbeddedVariableDeclaration(token, semanticModel, cancellationToken, out result)
|| IsForEachVariableDeclaration(token, semanticModel, position, cancellationToken, out result) || IsForEachVariableDeclaration(token, semanticModel, cancellationToken, out result)
|| IsIncompleteMemberDeclaration(token, semanticModel, position, cancellationToken, out result) || IsIncompleteMemberDeclaration(token, semanticModel, cancellationToken, out result)
|| IsFieldDeclaration(token, semanticModel, position, cancellationToken, out result) || IsFieldDeclaration(token, semanticModel, cancellationToken, out result)
|| IsMethodDeclaration(token, semanticModel, position, cancellationToken, out result) || IsMethodDeclaration(token, semanticModel, cancellationToken, out result)
|| IsPropertyDeclaration(token, semanticModel, position, cancellationToken, out result) || IsPropertyDeclaration(token, semanticModel, cancellationToken, out result)
|| IsPossibleOutVariableDeclaration(token, semanticModel, position, typeInferenceService, cancellationToken, out result) || IsPossibleOutVariableDeclaration(token, semanticModel, typeInferenceService, cancellationToken, out result)
|| IsTupleLiteralElement(token, semanticModel, position, cancellationToken, out result) || IsTupleLiteralElement(token, semanticModel, cancellationToken, out result)
|| IsPossibleVariableOrLocalMethodDeclaration(token, semanticModel, position, cancellationToken, out result) || IsPossibleVariableOrLocalMethodDeclaration(token, semanticModel, cancellationToken, out result)
|| IsPatternMatching(token, semanticModel, position, cancellationToken, out result)) || IsPatternMatching(token, semanticModel, cancellationToken, out result))
{ {
return result; return result;
} }
...@@ -72,7 +72,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -72,7 +72,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
} }
private static bool IsTupleTypeElement( private static bool IsTupleTypeElement(
SyntaxToken token, SemanticModel semanticModel, int position, SyntaxToken token, SemanticModel semanticModel,
CancellationToken cancellationToken, out NameDeclarationInfo result) CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
result = IsFollowingTypeOrComma<TupleElementSyntax>( result = IsFollowingTypeOrComma<TupleElementSyntax>(
...@@ -86,7 +86,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -86,7 +86,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
} }
private static bool IsTupleLiteralElement( private static bool IsTupleLiteralElement(
SyntaxToken token, SemanticModel semanticModel, int position, SyntaxToken token, SemanticModel semanticModel,
CancellationToken cancellationToken, out NameDeclarationInfo result) CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
// Incomplete code like // Incomplete code like
...@@ -110,7 +110,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -110,7 +110,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
return false; return false;
} }
private static bool IsPossibleOutVariableDeclaration(SyntaxToken token, SemanticModel semanticModel, int position, private static bool IsPossibleOutVariableDeclaration(SyntaxToken token, SemanticModel semanticModel,
ITypeInferenceService typeInferenceService, CancellationToken cancellationToken, out NameDeclarationInfo result) ITypeInferenceService typeInferenceService, CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
if (!token.IsKind(SyntaxKind.IdentifierToken) || !token.Parent.IsKind(SyntaxKind.IdentifierName)) if (!token.IsKind(SyntaxKind.IdentifierToken) || !token.Parent.IsKind(SyntaxKind.IdentifierName))
...@@ -146,7 +146,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -146,7 +146,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
} }
private static bool IsPossibleVariableOrLocalMethodDeclaration( private static bool IsPossibleVariableOrLocalMethodDeclaration(
SyntaxToken token, SemanticModel semanticModel, int position, SyntaxToken token, SemanticModel semanticModel,
CancellationToken cancellationToken, out NameDeclarationInfo result) CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
result = IsLastTokenOfType<ExpressionStatementSyntax>( result = IsLastTokenOfType<ExpressionStatementSyntax>(
...@@ -161,7 +161,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -161,7 +161,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
} }
private static bool IsPropertyDeclaration(SyntaxToken token, SemanticModel semanticModel, private static bool IsPropertyDeclaration(SyntaxToken token, SemanticModel semanticModel,
int position, CancellationToken cancellationToken, out NameDeclarationInfo result) CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
result = IsLastTokenOfType<PropertyDeclarationSyntax>( result = IsLastTokenOfType<PropertyDeclarationSyntax>(
token, token,
...@@ -175,7 +175,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -175,7 +175,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
} }
private static bool IsMethodDeclaration(SyntaxToken token, SemanticModel semanticModel, private static bool IsMethodDeclaration(SyntaxToken token, SemanticModel semanticModel,
int position, CancellationToken cancellationToken, out NameDeclarationInfo result) CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
result = IsLastTokenOfType<MethodDeclarationSyntax>( result = IsLastTokenOfType<MethodDeclarationSyntax>(
token, token,
...@@ -276,7 +276,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -276,7 +276,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
} }
private static bool IsFieldDeclaration(SyntaxToken token, SemanticModel semanticModel, private static bool IsFieldDeclaration(SyntaxToken token, SemanticModel semanticModel,
int position, CancellationToken cancellationToken, out NameDeclarationInfo result) CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
result = IsFollowingTypeOrComma<VariableDeclarationSyntax>(token, semanticModel, result = IsFollowingTypeOrComma<VariableDeclarationSyntax>(token, semanticModel,
v => v.Type, v => v.Type,
...@@ -287,7 +287,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -287,7 +287,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
} }
private static bool IsIncompleteMemberDeclaration(SyntaxToken token, SemanticModel semanticModel, private static bool IsIncompleteMemberDeclaration(SyntaxToken token, SemanticModel semanticModel,
int position, CancellationToken cancellationToken, out NameDeclarationInfo result) CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
result = IsLastTokenOfType<IncompleteMemberSyntax>(token, semanticModel, result = IsLastTokenOfType<IncompleteMemberSyntax>(token, semanticModel,
i => i.Type, i => i.Type,
...@@ -298,7 +298,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -298,7 +298,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
} }
private static bool IsLocalFunctionDeclaration(SyntaxToken token, SemanticModel semanticModel, private static bool IsLocalFunctionDeclaration(SyntaxToken token, SemanticModel semanticModel,
int position, CancellationToken cancellationToken, out NameDeclarationInfo result) CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
result = IsLastTokenOfType<LocalFunctionStatementSyntax>(token, semanticModel, result = IsLastTokenOfType<LocalFunctionStatementSyntax>(token, semanticModel,
typeSyntaxGetter: f => f.ReturnType, typeSyntaxGetter: f => f.ReturnType,
...@@ -309,7 +309,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -309,7 +309,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
} }
private static bool IsLocalVariableDeclaration(SyntaxToken token, SemanticModel semanticModel, private static bool IsLocalVariableDeclaration(SyntaxToken token, SemanticModel semanticModel,
int position, CancellationToken cancellationToken, out NameDeclarationInfo result) CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
// If we only have a type, this can still end up being a local function (depending on the modifiers). // If we only have a type, this can still end up being a local function (depending on the modifiers).
var possibleDeclarationComputer = token.IsKind(SyntaxKind.CommaToken) var possibleDeclarationComputer = token.IsKind(SyntaxKind.CommaToken)
...@@ -328,7 +328,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -328,7 +328,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
} }
private static bool IsEmbeddedVariableDeclaration(SyntaxToken token, SemanticModel semanticModel, private static bool IsEmbeddedVariableDeclaration(SyntaxToken token, SemanticModel semanticModel,
int position, CancellationToken cancellationToken, out NameDeclarationInfo result) CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
result = IsFollowingTypeOrComma<VariableDeclarationSyntax>(token, semanticModel, result = IsFollowingTypeOrComma<VariableDeclarationSyntax>(token, semanticModel,
typeSyntaxGetter: v => v.Type, typeSyntaxGetter: v => v.Type,
...@@ -341,7 +341,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -341,7 +341,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
} }
private static bool IsForEachVariableDeclaration(SyntaxToken token, SemanticModel semanticModel, private static bool IsForEachVariableDeclaration(SyntaxToken token, SemanticModel semanticModel,
int position, CancellationToken cancellationToken, out NameDeclarationInfo result) CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
// This is parsed as ForEachVariableStatementSyntax: // This is parsed as ForEachVariableStatementSyntax:
// foreach (int $$ // foreach (int $$
...@@ -356,8 +356,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -356,8 +356,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
return result.Type != null; return result.Type != null;
} }
private static bool IsTypeParameterDeclaration(SyntaxToken token, SemanticModel semanticModel, private static bool IsTypeParameterDeclaration(SyntaxToken token, out NameDeclarationInfo result)
int position, out NameDeclarationInfo result)
{ {
if (token.IsKind(SyntaxKind.LessThanToken, SyntaxKind.CommaToken) && if (token.IsKind(SyntaxKind.LessThanToken, SyntaxKind.CommaToken) &&
token.Parent.IsKind(SyntaxKind.TypeParameterList)) token.Parent.IsKind(SyntaxKind.TypeParameterList))
...@@ -377,7 +376,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -377,7 +376,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
} }
private static bool IsParameterDeclaration(SyntaxToken token, SemanticModel semanticModel, private static bool IsParameterDeclaration(SyntaxToken token, SemanticModel semanticModel,
int position, CancellationToken cancellationToken, out NameDeclarationInfo result) CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
result = IsLastTokenOfType<ParameterSyntax>( result = IsLastTokenOfType<ParameterSyntax>(
token, semanticModel, token, semanticModel,
...@@ -389,7 +388,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document ...@@ -389,7 +388,7 @@ internal static async Task<NameDeclarationInfo> GetDeclarationInfoAsync(Document
} }
private static bool IsPatternMatching(SyntaxToken token, SemanticModel semanticModel, private static bool IsPatternMatching(SyntaxToken token, SemanticModel semanticModel,
int position, CancellationToken cancellationToken, out NameDeclarationInfo result) CancellationToken cancellationToken, out NameDeclarationInfo result)
{ {
result = default; result = default;
if (token.Parent.IsParentKind(SyntaxKind.IsExpression)) if (token.Parent.IsParentKind(SyntaxKind.IsExpression))
......
...@@ -24,7 +24,7 @@ protected override bool IsValidContext(int position, CSharpSyntaxContext context ...@@ -24,7 +24,7 @@ protected override bool IsValidContext(int position, CSharpSyntaxContext context
if (context.ContainingTypeDeclaration != null) if (context.ContainingTypeDeclaration != null)
{ {
return return
IsConstructorInitializerContext(position, context) || IsConstructorInitializerContext(context) ||
IsInstanceExpressionOrStatement(context); IsInstanceExpressionOrStatement(context);
} }
...@@ -41,7 +41,7 @@ private static bool IsInstanceExpressionOrStatement(CSharpSyntaxContext context) ...@@ -41,7 +41,7 @@ private static bool IsInstanceExpressionOrStatement(CSharpSyntaxContext context)
return false; return false;
} }
private bool IsConstructorInitializerContext(int position, CSharpSyntaxContext context) private bool IsConstructorInitializerContext(CSharpSyntaxContext context)
{ {
// cases: // cases:
// Goo() : | // Goo() : |
......
...@@ -37,12 +37,11 @@ public override void Convert(SyntaxEditor editor, bool convertToQuery, Cancellat ...@@ -37,12 +37,11 @@ public override void Convert(SyntaxEditor editor, bool convertToQuery, Cancellat
editor.ReplaceNode( editor.ReplaceNode(
ForEachInfo.ForEachStatement, ForEachInfo.ForEachStatement,
CreateDefaultReplacementStatement(ForEachInfo, identifiersUsedInStatements, block, convertToQuery) CreateDefaultReplacementStatement(identifiersUsedInStatements, block, convertToQuery)
.WithAdditionalAnnotations(Formatter.Annotation)); .WithAdditionalAnnotations(Formatter.Annotation));
} }
private StatementSyntax CreateDefaultReplacementStatement( private StatementSyntax CreateDefaultReplacementStatement(
ForEachInfo<ForEachStatementSyntax, StatementSyntax> forEachInfo,
IEnumerable<SyntaxToken> identifiers, IEnumerable<SyntaxToken> identifiers,
BlockSyntax block, BlockSyntax block,
bool convertToQuery) bool convertToQuery)
......
...@@ -163,12 +163,12 @@ private bool CanEncapsulate(FieldDeclarationSyntax field) ...@@ -163,12 +163,12 @@ private bool CanEncapsulate(FieldDeclarationSyntax field)
if (newPropertyName == field.Name) if (newPropertyName == field.Name)
{ {
// If we wind up with the field's old name, give the field the unique version of its current name. // If we wind up with the field's old name, give the field the unique version of its current name.
return Tuple.Create(MakeUnique(GenerateFieldName(field, field.Name), field.ContainingType), newPropertyName); return Tuple.Create(MakeUnique(GenerateFieldName(field.Name), field.ContainingType), newPropertyName);
} }
// Otherwise, ensure the property's name is unique. // Otherwise, ensure the property's name is unique.
newPropertyName = MakeUnique(newPropertyName, field.ContainingType); newPropertyName = MakeUnique(newPropertyName, field.ContainingType);
var newFieldName = GenerateFieldName(field, newPropertyName); var newFieldName = GenerateFieldName(newPropertyName);
// If converting the new property's name into a field name results in the old field name, we're done. // If converting the new property's name into a field name results in the old field name, we're done.
if (newFieldName == field.Name) if (newFieldName == field.Name)
...@@ -186,12 +186,10 @@ private bool IsNew(IFieldSymbol field) ...@@ -186,12 +186,10 @@ private bool IsNew(IFieldSymbol field)
return field.DeclaringSyntaxReferences.Any(d => d.GetSyntax().GetAncestor<FieldDeclarationSyntax>().Modifiers.Any(SyntaxKind.NewKeyword)); return field.DeclaringSyntaxReferences.Any(d => d.GetSyntax().GetAncestor<FieldDeclarationSyntax>().Modifiers.Any(SyntaxKind.NewKeyword));
} }
private string GenerateFieldName(IFieldSymbol field, string correspondingPropertyName) private string GenerateFieldName(string correspondingPropertyName)
{ => char.ToLower(correspondingPropertyName[0]).ToString() + correspondingPropertyName.Substring(1);
return char.ToLower(correspondingPropertyName[0]).ToString() + correspondingPropertyName.Substring(1);
}
protected string MakeUnique(string baseName, INamedTypeSymbol containingType, bool considerBaseMembers = true) protected string MakeUnique(string baseName, INamedTypeSymbol containingType)
{ {
var containingTypeMemberNames = containingType.GetAccessibleMembersInThisAndBaseTypes<ISymbol>(containingType).Select(m => m.Name); var containingTypeMemberNames = containingType.GetAccessibleMembersInThisAndBaseTypes<ISymbol>(containingType).Select(m => m.Name);
return NameGenerator.GenerateUniqueName(baseName, containingTypeMemberNames.ToSet(), StringComparer.Ordinal); return NameGenerator.GenerateUniqueName(baseName, containingTypeMemberNames.ToSet(), StringComparer.Ordinal);
......
...@@ -7,12 +7,12 @@ namespace Microsoft.CodeAnalysis.CSharp.GenerateMember.GenerateParameterizedMemb ...@@ -7,12 +7,12 @@ namespace Microsoft.CodeAnalysis.CSharp.GenerateMember.GenerateParameterizedMemb
{ {
internal static class CSharpCommonGenerationServiceMethods internal static class CSharpCommonGenerationServiceMethods
{ {
public static bool AreSpecialOptionsActive(SemanticModel semanticModel) public static bool AreSpecialOptionsActive()
{ {
return false; return false;
} }
public static bool IsValidSymbol(ISymbol symbol, SemanticModel semanticModel) public static bool IsValidSymbol()
{ {
return false; return false;
} }
......
...@@ -51,14 +51,10 @@ protected override bool ContainingTypesOrSelfHasUnsafeKeyword(INamedTypeSymbol c ...@@ -51,14 +51,10 @@ protected override bool ContainingTypesOrSelfHasUnsafeKeyword(INamedTypeSymbol c
} }
protected override bool AreSpecialOptionsActive(SemanticModel semanticModel) protected override bool AreSpecialOptionsActive(SemanticModel semanticModel)
{ => CSharpCommonGenerationServiceMethods.AreSpecialOptionsActive();
return CSharpCommonGenerationServiceMethods.AreSpecialOptionsActive(semanticModel);
}
protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticModel) protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticModel)
{ => CSharpCommonGenerationServiceMethods.IsValidSymbol();
return CSharpCommonGenerationServiceMethods.IsValidSymbol(symbol, semanticModel);
}
protected override bool TryInitializeImplicitConversionState( protected override bool TryInitializeImplicitConversionState(
SemanticDocument document, SemanticDocument document,
......
...@@ -27,9 +27,9 @@ protected override AbstractInvocationInfo CreateInvocationMethodInfo(SemanticDoc ...@@ -27,9 +27,9 @@ protected override AbstractInvocationInfo CreateInvocationMethodInfo(SemanticDoc
=> new CSharpGenerateParameterizedMemberService<CSharpGenerateDeconstructMethodService>.InvocationExpressionInfo(document, state); => new CSharpGenerateParameterizedMemberService<CSharpGenerateDeconstructMethodService>.InvocationExpressionInfo(document, state);
protected override bool AreSpecialOptionsActive(SemanticModel semanticModel) protected override bool AreSpecialOptionsActive(SemanticModel semanticModel)
=> CSharpCommonGenerationServiceMethods.AreSpecialOptionsActive(semanticModel); => CSharpCommonGenerationServiceMethods.AreSpecialOptionsActive();
protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticModel) protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticModel)
=> CSharpCommonGenerationServiceMethods.IsValidSymbol(symbol, semanticModel); => CSharpCommonGenerationServiceMethods.IsValidSymbol();
} }
} }
...@@ -41,10 +41,10 @@ protected override AbstractInvocationInfo CreateInvocationMethodInfo(SemanticDoc ...@@ -41,10 +41,10 @@ protected override AbstractInvocationInfo CreateInvocationMethodInfo(SemanticDoc
} }
protected override bool AreSpecialOptionsActive(SemanticModel semanticModel) protected override bool AreSpecialOptionsActive(SemanticModel semanticModel)
=> CSharpCommonGenerationServiceMethods.AreSpecialOptionsActive(semanticModel); => CSharpCommonGenerationServiceMethods.AreSpecialOptionsActive();
protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticModel) protected override bool IsValidSymbol(ISymbol symbol, SemanticModel semanticModel)
=> CSharpCommonGenerationServiceMethods.IsValidSymbol(symbol, semanticModel); => CSharpCommonGenerationServiceMethods.IsValidSymbol();
protected override bool TryInitializeExplicitInterfaceState( protected override bool TryInitializeExplicitInterfaceState(
SemanticDocument document, SemanticDocument document,
......
...@@ -619,7 +619,7 @@ protected override bool IsConversionImplicit(Compilation compilation, ITypeSymbo ...@@ -619,7 +619,7 @@ protected override bool IsConversionImplicit(Compilation compilation, ITypeSymbo
afterThisLocation); afterThisLocation);
} }
private NamespaceDeclarationSyntax GetDeclaringNamespace(List<string> containers, int indexDone, CompilationUnitSyntax compilationUnit) private NamespaceDeclarationSyntax GetDeclaringNamespace(List<string> containers, CompilationUnitSyntax compilationUnit)
{ {
foreach (var member in compilationUnit.Members) foreach (var member in compilationUnit.Members)
{ {
......
...@@ -68,7 +68,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) ...@@ -68,7 +68,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
// type of the out-var-decl affects overload resolution or generic instantiation). // type of the out-var-decl affects overload resolution or generic instantiation).
var originalRoot = editor.OriginalRoot; var originalRoot = editor.OriginalRoot;
var originalNodes = diagnostics.SelectAsArray(diagnostic => FindDiagnosticNodes(document, diagnostic, options, cancellationToken)); var originalNodes = diagnostics.SelectAsArray(diagnostic => FindDiagnosticNodes(diagnostic, cancellationToken));
await editor.ApplyExpressionLevelSemanticEditsAsync( await editor.ApplyExpressionLevelSemanticEditsAsync(
document, document,
...@@ -85,13 +85,12 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) ...@@ -85,13 +85,12 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
(semanticModel, currentRoot, t, currentNode) (semanticModel, currentRoot, t, currentNode)
=> ReplaceIdentifierWithInlineDeclaration( => ReplaceIdentifierWithInlineDeclaration(
options, semanticModel, currentRoot, t.declarator, options, semanticModel, currentRoot, t.declarator,
t.identifier, t.invocationOrCreation, currentNode, declarationsToRemove), t.identifier, currentNode, declarationsToRemove),
cancellationToken).ConfigureAwait(false); cancellationToken).ConfigureAwait(false);
} }
private (VariableDeclaratorSyntax declarator, IdentifierNameSyntax identifier, SyntaxNode invocationOrCreation) FindDiagnosticNodes( private (VariableDeclaratorSyntax declarator, IdentifierNameSyntax identifier, SyntaxNode invocationOrCreation) FindDiagnosticNodes(
Document document, Diagnostic diagnostic, Diagnostic diagnostic, CancellationToken cancellationToken)
OptionSet options, CancellationToken cancellationToken)
{ {
// Recover the nodes we care about. // Recover the nodes we care about.
var declaratorLocation = diagnostic.AdditionalLocations[0]; var declaratorLocation = diagnostic.AdditionalLocations[0];
...@@ -110,8 +109,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) ...@@ -110,8 +109,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
private SyntaxNode ReplaceIdentifierWithInlineDeclaration( private SyntaxNode ReplaceIdentifierWithInlineDeclaration(
OptionSet options, SemanticModel semanticModel, OptionSet options, SemanticModel semanticModel,
SyntaxNode currentRoot, VariableDeclaratorSyntax declarator, SyntaxNode currentRoot, VariableDeclaratorSyntax declarator,
IdentifierNameSyntax identifier, SyntaxNode invocationOrCreation, IdentifierNameSyntax identifier, SyntaxNode currentNode, HashSet<StatementSyntax> declarationsToRemove)
SyntaxNode currentNode, HashSet<StatementSyntax> declarationsToRemove)
{ {
declarator = currentRoot.GetCurrentNode(declarator); declarator = currentRoot.GetCurrentNode(declarator);
identifier = currentRoot.GetCurrentNode(identifier); identifier = currentRoot.GetCurrentNode(identifier);
...@@ -234,7 +232,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) ...@@ -234,7 +232,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
sourceText, identifier, newType, singleDeclarator ? null : declarator); sourceText, identifier, newType, singleDeclarator ? null : declarator);
// Check if using out-var changed problem semantics. // Check if using out-var changed problem semantics.
var semanticsChanged = SemanticsChanged(semanticModel, currentRoot, currentNode, identifier, declarationExpression); var semanticsChanged = SemanticsChanged(semanticModel, currentNode, identifier, declarationExpression);
if (semanticsChanged) if (semanticsChanged)
{ {
// Switching to 'var' changed semantics. Just use the original type of the local. // Switching to 'var' changed semantics. Just use the original type of the local.
...@@ -326,7 +324,6 @@ private static IEnumerable<SyntaxTrivia> MassageTrivia(IEnumerable<SyntaxTrivia> ...@@ -326,7 +324,6 @@ private static IEnumerable<SyntaxTrivia> MassageTrivia(IEnumerable<SyntaxTrivia>
private bool SemanticsChanged( private bool SemanticsChanged(
SemanticModel semanticModel, SemanticModel semanticModel,
SyntaxNode root,
SyntaxNode nodeToReplace, SyntaxNode nodeToReplace,
IdentifierNameSyntax identifier, IdentifierNameSyntax identifier,
DeclarationExpressionSyntax declarationExpression) DeclarationExpressionSyntax declarationExpression)
......
...@@ -186,7 +186,7 @@ protected virtual TextSpan GetTextSpan(SyntaxToken genericIdentifier, SyntaxToke ...@@ -186,7 +186,7 @@ protected virtual TextSpan GetTextSpan(SyntaxToken genericIdentifier, SyntaxToke
symbol.GetDocumentationPartsFactory(semanticModel, position, documentationCommentFormattingService), symbol.GetDocumentationPartsFactory(semanticModel, position, documentationCommentFormattingService),
GetPreambleParts(namedType, semanticModel, position), GetPreambleParts(namedType, semanticModel, position),
GetSeparatorParts(), GetSeparatorParts(),
GetPostambleParts(namedType), GetPostambleParts(),
namedType.TypeParameters.Select(p => Convert(p, semanticModel, position, documentationCommentFormattingService, cancellationToken)).ToList()); namedType.TypeParameters.Select(p => Convert(p, semanticModel, position, documentationCommentFormattingService, cancellationToken)).ToList());
} }
else else
...@@ -222,14 +222,13 @@ protected virtual TextSpan GetTextSpan(SyntaxToken genericIdentifier, SyntaxToke ...@@ -222,14 +222,13 @@ protected virtual TextSpan GetTextSpan(SyntaxToken genericIdentifier, SyntaxToke
isOptional: false, isOptional: false,
documentationFactory: parameter.GetDocumentationPartsFactory(semanticModel, position, formatter), documentationFactory: parameter.GetDocumentationPartsFactory(semanticModel, position, formatter),
displayParts: parameter.ToMinimalDisplayParts(semanticModel, position, s_minimallyQualifiedFormat), displayParts: parameter.ToMinimalDisplayParts(semanticModel, position, s_minimallyQualifiedFormat),
selectedDisplayParts: GetSelectedDisplayParts(parameter, semanticModel, position, cancellationToken)); selectedDisplayParts: GetSelectedDisplayParts(parameter, semanticModel, position));
} }
private IList<SymbolDisplayPart> GetSelectedDisplayParts( private IList<SymbolDisplayPart> GetSelectedDisplayParts(
ITypeParameterSymbol typeParam, ITypeParameterSymbol typeParam,
SemanticModel semanticModel, SemanticModel semanticModel,
int position, int position)
CancellationToken cancellationToken)
{ {
var parts = new List<SymbolDisplayPart>(); var parts = new List<SymbolDisplayPart>();
......
...@@ -22,10 +22,7 @@ internal partial class GenericNameSignatureHelpProvider ...@@ -22,10 +22,7 @@ internal partial class GenericNameSignatureHelpProvider
return result; return result;
} }
private IList<SymbolDisplayPart> GetPostambleParts(INamedTypeSymbol namedType) private IList<SymbolDisplayPart> GetPostambleParts()
{ => SpecializedCollections.SingletonList(Punctuation(SyntaxKind.GreaterThanToken));
return SpecializedCollections.SingletonList(
Punctuation(SyntaxKind.GreaterThanToken));
}
} }
} }
...@@ -81,7 +81,7 @@ protected override async Task<SignatureHelpItems> GetItemsWorkerAsync(Document d ...@@ -81,7 +81,7 @@ protected override async Task<SignatureHelpItems> GetItemsWorkerAsync(Document d
var syntaxFacts = document.GetLanguageService<ISyntaxFactsService>(); var syntaxFacts = document.GetLanguageService<ISyntaxFactsService>();
var (items, selectedItem) = type.TypeKind == TypeKind.Delegate var (items, selectedItem) = type.TypeKind == TypeKind.Delegate
? GetDelegateTypeConstructors(objectCreationExpression, semanticModel, symbolDisplayService, anonymousTypeDisplayService, type, within, cancellationToken) ? GetDelegateTypeConstructors(objectCreationExpression, semanticModel, symbolDisplayService, anonymousTypeDisplayService, type, cancellationToken)
: GetNormalTypeConstructors(document, objectCreationExpression, semanticModel, symbolDisplayService, anonymousTypeDisplayService, documentationCommentFormattingService, type, within, cancellationToken); : GetNormalTypeConstructors(document, objectCreationExpression, semanticModel, symbolDisplayService, anonymousTypeDisplayService, documentationCommentFormattingService, type, within, cancellationToken);
return CreateSignatureHelpItems(items, textSpan, return CreateSignatureHelpItems(items, textSpan,
......
...@@ -19,7 +19,6 @@ internal partial class ObjectCreationExpressionSignatureHelpProvider ...@@ -19,7 +19,6 @@ internal partial class ObjectCreationExpressionSignatureHelpProvider
ISymbolDisplayService symbolDisplayService, ISymbolDisplayService symbolDisplayService,
IAnonymousTypeDisplayService anonymousTypeDisplayService, IAnonymousTypeDisplayService anonymousTypeDisplayService,
INamedTypeSymbol delegateType, INamedTypeSymbol delegateType,
INamedTypeSymbol containingType,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var invokeMethod = delegateType.DelegateInvokeMethod; var invokeMethod = delegateType.DelegateInvokeMethod;
...@@ -36,8 +35,8 @@ internal partial class ObjectCreationExpressionSignatureHelpProvider ...@@ -36,8 +35,8 @@ internal partial class ObjectCreationExpressionSignatureHelpProvider
documentationFactory: null, documentationFactory: null,
prefixParts: GetDelegateTypePreambleParts(invokeMethod, semanticModel, position), prefixParts: GetDelegateTypePreambleParts(invokeMethod, semanticModel, position),
separatorParts: GetSeparatorParts(), separatorParts: GetSeparatorParts(),
suffixParts: GetDelegateTypePostambleParts(invokeMethod), suffixParts: GetDelegateTypePostambleParts(),
parameters: GetDelegateTypeParameters(invokeMethod, semanticModel, position, cancellationToken)); parameters: GetDelegateTypeParameters(invokeMethod, semanticModel, position));
return (SpecializedCollections.SingletonList(item), 0); return (SpecializedCollections.SingletonList(item), 0);
} }
...@@ -52,7 +51,7 @@ private IList<SymbolDisplayPart> GetDelegateTypePreambleParts(IMethodSymbol invo ...@@ -52,7 +51,7 @@ private IList<SymbolDisplayPart> GetDelegateTypePreambleParts(IMethodSymbol invo
return result; return result;
} }
private IList<SignatureHelpSymbolParameter> GetDelegateTypeParameters(IMethodSymbol invokeMethod, SemanticModel semanticModel, int position, CancellationToken cancellationToken) private IList<SignatureHelpSymbolParameter> GetDelegateTypeParameters(IMethodSymbol invokeMethod, SemanticModel semanticModel, int position)
{ {
const string TargetName = "target"; const string TargetName = "target";
...@@ -86,10 +85,7 @@ private IList<SignatureHelpSymbolParameter> GetDelegateTypeParameters(IMethodSym ...@@ -86,10 +85,7 @@ private IList<SignatureHelpSymbolParameter> GetDelegateTypeParameters(IMethodSym
displayParts: parts)); displayParts: parts));
} }
private IList<SymbolDisplayPart> GetDelegateTypePostambleParts(IMethodSymbol invokeMethod) private IList<SymbolDisplayPart> GetDelegateTypePostambleParts()
{ => SpecializedCollections.SingletonList(Punctuation(SyntaxKind.CloseParenToken));
return SpecializedCollections.SingletonList(
Punctuation(SyntaxKind.CloseParenToken));
}
} }
} }
...@@ -77,7 +77,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) ...@@ -77,7 +77,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
if (resultOpt != null) if (resultOpt != null)
{ {
var result = resultOpt.Value; var result = resultOpt.Value;
var updatedNode = FixOne(result, cancellationToken); var updatedNode = FixOne(result);
if (updatedNode != null) if (updatedNode != null)
{ {
return currentRoot.ReplaceNode(result.Invocation, updatedNode); return currentRoot.ReplaceNode(result.Invocation, updatedNode);
...@@ -91,7 +91,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) ...@@ -91,7 +91,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
private static InvocationExpressionSyntax GetInvocationExpression(Diagnostic d, CancellationToken cancellationToken) private static InvocationExpressionSyntax GetInvocationExpression(Diagnostic d, CancellationToken cancellationToken)
=> (InvocationExpressionSyntax)d.AdditionalLocations[0].FindNode(getInnermostNodeForTie: true, cancellationToken); => (InvocationExpressionSyntax)d.AdditionalLocations[0].FindNode(getInnermostNodeForTie: true, cancellationToken);
private ExpressionSyntax FixOne(Result result, CancellationToken cancellationToken) private ExpressionSyntax FixOne(Result result)
{ {
var invocation = result.Invocation; var invocation = result.Invocation;
var expression = invocation.Expression is MemberAccessExpressionSyntax memberAccess var expression = invocation.Expression is MemberAccessExpressionSyntax memberAccess
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册