private void AddParameter(Declaration targetMethod, Declaration targetVariable, VBAParser.ArgListContext paramList, CodeModule module) { var argList = paramList.arg(); var lastParam = argList.LastOrDefault(); var newContent = GetOldSignature(targetMethod); if (lastParam == null) { // Increase index by one because VBA is dumb enough to use 1-based indexing newContent = newContent.Insert(newContent.IndexOf('(') + 1, GetParameterDefinition(targetVariable)); } else if (targetMethod.DeclarationType != DeclarationType.PropertyLet && targetMethod.DeclarationType != DeclarationType.PropertySet) { newContent = newContent.Replace(argList.Last().GetText(), argList.Last().GetText() + ", " + GetParameterDefinition(targetVariable)); } else { newContent = newContent.Replace(argList.Last().GetText(), GetParameterDefinition(targetVariable) + ", " + argList.Last().GetText()); } module.ReplaceLine(paramList.Start.Line, newContent); module.DeleteLines(paramList.Start.Line + 1, paramList.GetSelection().LineCount - 1); }
private void RemoveSignatureParameters(Declaration target, VBAParser.ArgListContext paramList, CodeModule module) { var paramNames = paramList.arg(); var paramsRemoved = _model.Parameters.Where(item => item.IsRemoved).ToList(); var signature = GetOldSignature(target); foreach (var param in paramsRemoved) { try { signature = ReplaceCommas(signature.Replace(paramNames.ElementAt(param.Index).GetText(), ""), _model.Parameters.FindIndex(item => item == param) - paramsRemoved.FindIndex(item => item == param)); } catch (ArgumentOutOfRangeException) { } } var lineNum = paramList.GetSelection().LineCount; module.ReplaceLine(paramList.Start.Line, signature); for (var line = paramList.Start.Line + 1; line < paramList.Start.Line + lineNum; line++) { module.ReplaceLine(line, ""); } }
private void RewriteSignature(Declaration target, VBAParser.ArgListContext paramList, ICodeModule module) { var parameters = paramList.arg().Select((s, i) => new { Index = i, Text = s.GetText() }).ToList(); var reorderedParams = new List <string>(); foreach (var param in _model.Parameters) { var parameterAtIndex = parameters.SingleOrDefault(s => s.Index == param.Index); if (parameterAtIndex != null) { reorderedParams.Add(parameterAtIndex.Text); } } // property let/set and paramarrays for (var index = reorderedParams.Count; index < parameters.Count; index++) { reorderedParams.Add(parameters[index].Text); } var signature = GetOldSignature(target); signature = signature.Remove(signature.IndexOf('(')); var asTypeText = target.AsTypeContext == null ? string.Empty : " " + target.AsTypeContext.GetText(); signature += '(' + string.Join(", ", reorderedParams) + ")" + (asTypeText == " " ? string.Empty : asTypeText); var lineCount = paramList.GetSelection().LineCount; module.ReplaceLine(paramList.Start.Line, signature.Replace(" _" + Environment.NewLine, string.Empty)); module.DeleteLines(paramList.Start.Line + 1, lineCount - 1); }
private void RewriteSignature(Declaration target, VBAParser.ArgListContext paramList, CodeModule module) { var argList = paramList.arg(); var newContent = GetOldSignature(target); var lineNum = paramList.GetSelection().LineCount; var parameterIndex = 0; var currentStringIndex = 0; for (var i = parameterIndex; i < _model.Parameters.Count; i++) { var oldParam = argList.ElementAt(parameterIndex).GetText(); var newParam = argList.ElementAt(_model.Parameters.ElementAt(parameterIndex).Index).GetText(); var parameterStringIndex = newContent.IndexOf(oldParam, currentStringIndex, StringComparison.Ordinal); if (parameterStringIndex > -1) { var beginningSub = newContent.Substring(0, parameterStringIndex); var replaceSub = newContent.Substring(parameterStringIndex).Replace(oldParam, newParam); newContent = beginningSub + replaceSub; parameterIndex++; currentStringIndex = beginningSub.Length + newParam.Length; } } module.ReplaceLine(paramList.Start.Line, newContent); for (var line = paramList.Start.Line + 1; line < paramList.Start.Line + lineNum; line++) { module.ReplaceLine(line, ""); } }
private void RemoveSignatureParameters(Declaration target, VBAParser.ArgListContext paramList, CodeModule module) { // property set/let have one more parameter than is listed in the getter parameters var nonRemovedParamNames = paramList.arg().Where((a, s) => s >= _model.Parameters.Count || !_model.Parameters[s].IsRemoved).Select(s => s.GetText()); var signature = GetOldSignature(target); signature = signature.Remove(signature.IndexOf('(')); var asTypeText = target.AsTypeContext == null ? string.Empty : " " + target.AsTypeContext.GetText(); signature += '(' + string.Join(", ", nonRemovedParamNames) + ")" + (asTypeText == " " ? string.Empty : asTypeText); var lineCount = paramList.GetSelection().LineCount; module.ReplaceLine(paramList.Start.Line, signature.Replace(" _" + Environment.NewLine, string.Empty)); module.DeleteLines(paramList.Start.Line + 1, lineCount - 1); }