internal static string FindBetterName(IParameterSymbol symbol) { var method = symbol.GetEnclosingMethod(); return(symbol.Equals(method.Parameters[0], SymbolEqualityComparer.Default) ? Parameter1 : Parameter2); }
public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node) { if (_parameter.Equals(_semanticModel.GetSymbolInfo(node).Symbol)) { return(SyntaxFactory.IdentifierName("value").WithTriviaFrom(node)); } return(node); }
private static HashSet <string> GetParameterNames(IParameterSymbol parameterSymbol) { var reservedNames = new HashSet <string>(OrdinalComparer); ISymbol containingSymbol = parameterSymbol.ContainingSymbol; if (containingSymbol != null) { SymbolKind kind = containingSymbol.Kind; Debug.Assert(kind == SymbolKind.Method || kind == SymbolKind.Property, kind.ToString()); if (kind == SymbolKind.Method) { var methodSymbol = (IMethodSymbol)containingSymbol; foreach (IParameterSymbol symbol in methodSymbol.Parameters) { if (!parameterSymbol.Equals(symbol)) { reservedNames.Add(symbol.Name); } } } else if (kind == SymbolKind.Property) { var propertySymbol = (IPropertySymbol)containingSymbol; if (propertySymbol.IsIndexer) { foreach (IParameterSymbol symbol in propertySymbol.Parameters) { if (!parameterSymbol.Equals(symbol)) { reservedNames.Add(symbol.Name); } } } } } return(reservedNames); }
internal static string FindBetterName(IParameterSymbol symbol) { var method = symbol.GetEnclosingMethod(); var parameters = method.Parameters; if (parameters.Length != 2) { return("value"); } var isParameter1 = symbol.Equals(parameters[0], SymbolEqualityComparer.Default); return(isParameter1 ? "left" : "right"); }
private static bool IsIdentifierReferencingParam( SymbolAnalysisContext context, IdentifierNameSyntax identifier, IParameterSymbol param) { if (identifier.Identifier.ValueText != param.Name) { return(false); } var semanticModel = context.Compilation.GetSemanticModel(identifier.SyntaxTree); var idSymbol = semanticModel.GetSymbolInfo(identifier, context.CancellationToken).Symbol; return(param.Equals(idSymbol)); }
public static async Task <string> EnsureUniqueParameterNameAsync( IParameterSymbol parameterSymbol, string baseName, Solution solution, CancellationToken cancellationToken = default(CancellationToken)) { if (parameterSymbol == null) { throw new ArgumentNullException(nameof(parameterSymbol)); } if (solution == null) { throw new ArgumentNullException(nameof(solution)); } HashSet <string> reservedNames = GetParameterNames(parameterSymbol); foreach (ReferencedSymbol referencedSymbol in await SymbolFinder.FindReferencesAsync(parameterSymbol, solution, cancellationToken).ConfigureAwait(false)) { foreach (ReferenceLocation referenceLocation in referencedSymbol.Locations) { if (!referenceLocation.IsImplicit && !referenceLocation.IsCandidateLocation) { SemanticModel semanticModel = await referenceLocation.Document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); foreach (ISymbol symbol in semanticModel.LookupSymbols(referenceLocation.Location.SourceSpan.Start)) { if (!parameterSymbol.Equals(symbol)) { reservedNames.Add(symbol.Name); } } } } } return(EnsureUniqueName(baseName, reservedNames)); }
private static HashSet <string> GetParameterNames(IParameterSymbol parameterSymbol) { var reservedNames = new HashSet <string>(OrdinalComparer); ISymbol containingSymbol = parameterSymbol.ContainingSymbol; Debug.Assert(containingSymbol?.IsKind(SymbolKind.Method) == true); if (containingSymbol?.IsKind(SymbolKind.Method) == true) { var methodSymbol = (IMethodSymbol)containingSymbol; foreach (IParameterSymbol symbol in methodSymbol.Parameters) { if (!parameterSymbol.Equals(symbol)) { reservedNames.Add(symbol.Name); } } } return(reservedNames); }