Beispiel #1
0
            private string GetUniqueVariableNameInScope(VBasic.VisualBasicSyntaxNode node, string variableNameBase)
            {
                // Need to check not just the symbols this node has access to, but whether there are any nested blocks which have access to this node and contain a conflicting name
                var scopeStarts = node.GetAncestorOrThis <VBSyntax.StatementSyntax>().DescendantNodesAndSelf()
                                  .OfType <VBSyntax.StatementSyntax>().Select(n => n.SpanStart).ToList();
                string uniqueName = NameGenerator.GenerateUniqueName(variableNameBase, string.Empty,
                                                                     n => {
                    var matchingSymbols = scopeStarts.SelectMany(scopeStart => _semanticModel.LookupSymbols(scopeStart, name: n));
                    return(!_generatedNames.Contains(n) && !matchingSymbols.Any());
                });

                _generatedNames.Add(uniqueName);
                return(uniqueName);
            }
 private static List <int> GetScopeStarts(VBasic.VisualBasicSyntaxNode node)
 {
     return(node.GetAncestorOrThis <VBSyntax.StatementSyntax>().DescendantNodesAndSelf()
            .OfType <VBSyntax.StatementSyntax>().Select(n => n.SpanStart).ToList());
 }