public static void RenameConflicting(ParametrizedNode method) { // variable name => case sensitive variable name // value is null if there are multiple casings for the variable -> the variable is conflicting Dictionary <string, string> caseInsensitive = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); LookupTableVisitor ltv = new LookupTableVisitor(SupportedLanguage.CSharp); method.AcceptVisitor(ltv, null); // add method name to caseInsensitive AddVariableToDict(caseInsensitive, method.Name, true); // add method parameters to caseInsensitive foreach (ParameterDeclarationExpression pde in method.Parameters) { AddVariableToDict(caseInsensitive, pde.ParameterName, true); } // add local variables to caseInsensitive foreach (KeyValuePair <string, List <LocalLookupVariable> > var in ltv.Variables) { AddVariableToDict(caseInsensitive, var.Key, true); } // add used identifiers to caseInsensitive FindIdentifiersVisitor fvv = new FindIdentifiersVisitor(); method.AcceptVisitor(fvv, null); foreach (KeyValuePair <string, string> pair in fvv.usedIdentifiers) { AddVariableToDict(caseInsensitive, pair.Key, false); } int index = 0; foreach (ParameterDeclarationExpression pde in method.Parameters) { if (caseInsensitive[pde.ParameterName] == null) { RenameVariable(method, pde.ParameterName, ref index); } } foreach (KeyValuePair <string, List <LocalLookupVariable> > var in ltv.Variables) { if (caseInsensitive[var.Key] == null) { RenameVariable(method, var.Key, ref index); } } }
public static void RenameConflicting(ParametrizedNode method) { // variable name => case sensitive variable name // value is null if there are multiple casings for the variable -> the variable is conflicting Dictionary<string, string> caseInsensitive = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); LookupTableVisitor ltv = new LookupTableVisitor(SupportedLanguage.CSharp); method.AcceptVisitor(ltv, null); // add method name to caseInsensitive AddVariableToDict(caseInsensitive, method.Name, true); // add method parameters to caseInsensitive foreach (ParameterDeclarationExpression pde in method.Parameters) { AddVariableToDict(caseInsensitive, pde.ParameterName, true); } // add local variables to caseInsensitive foreach (KeyValuePair<string, List<LocalLookupVariable>> var in ltv.Variables) { AddVariableToDict(caseInsensitive, var.Key, true); } // add used identifiers to caseInsensitive FindIdentifiersVisitor fvv = new FindIdentifiersVisitor(); method.AcceptVisitor(fvv, null); foreach (KeyValuePair<string, string> pair in fvv.usedIdentifiers) { AddVariableToDict(caseInsensitive, pair.Key, false); } int index = 0; foreach (ParameterDeclarationExpression pde in method.Parameters) { if (caseInsensitive[pde.ParameterName] == null) { RenameVariable(method, pde.ParameterName, ref index); } } foreach (KeyValuePair<string, List<LocalLookupVariable>> var in ltv.Variables) { if (caseInsensitive[var.Key] == null) { RenameVariable(method, var.Key, ref index); } } }