private void AdjustReferences(IEnumerable <IdentifierReference> references, Declaration method) { foreach (var reference in references.Where(item => item.Context != method.Context)) { var module = reference.QualifiedModuleName.Component.CodeModule; VBAParser.ArgumentListContext argumentList = null; var callStmt = ParserRuleContextHelper.GetParent <VBAParser.CallStmtContext>(reference.Context); if (callStmt != null) { argumentList = CallStatement.GetArgumentList(callStmt); } if (argumentList == null) { var indexExpression = ParserRuleContextHelper.GetParent <VBAParser.IndexExprContext>(reference.Context); if (indexExpression != null) { argumentList = ParserRuleContextHelper.GetChild <VBAParser.ArgumentListContext>(indexExpression); } } if (argumentList == null) { continue; } RemoveCallParameter(argumentList, module); } }
private void AdjustReferences(IEnumerable <IdentifierReference> references) { foreach (var reference in references.Where(item => item.Context != _model.TargetDeclaration.Context)) { VBAParser.ArgumentListContext argumentList = null; var callStmt = reference.Context.GetAncestor <VBAParser.CallStmtContext>(); if (callStmt != null) { argumentList = CallStatement.GetArgumentList(callStmt); } if (argumentList == null) { var indexExpression = reference.Context.GetAncestor <VBAParser.IndexExprContext>(); if (indexExpression != null) { argumentList = indexExpression.GetChild <VBAParser.ArgumentListContext>(); } } if (argumentList == null) { continue; } using (var module = _projectsProvider.Component(reference.QualifiedModuleName).CodeModule) { RewriteCall(argumentList, module); } } }
private bool IsCallStmt(IdentifierReference usage) { var callStmt = usage.Context.GetAncestor <VBAParser.CallStmtContext>(); if (callStmt == null) { return(false); } var indexExpr = usage.Context.GetAncestor <VBAParser.IndexExprContext>(); if (indexExpr != null) { var memberAccessStmt = usage.Context.GetAncestor <VBAParser.MemberAccessExprContext>(); if (memberAccessStmt != null && callStmt.SourceInterval.ProperlyContains(memberAccessStmt.SourceInterval) && memberAccessStmt.SourceInterval.ProperlyContains(indexExpr.SourceInterval)) { return(false); } } var argumentList = CallStatement.GetArgumentList(callStmt); if (argumentList == null) { return(true); } return(!usage.Context.IsDescendentOf(argumentList)); }
private bool IsCallStmt(IdentifierReference usage) { var callStmt = usage.Context.GetAncestor <VBAParser.CallStmtContext>(); if (callStmt == null) { return(false); } var argumentList = CallStatement.GetArgumentList(callStmt); if (argumentList == null) { return(true); } return(!usage.Context.IsDescendentOf(argumentList)); }
private bool IsCallStmt(IdentifierReference usage) { var callStmt = ParserRuleContextHelper.GetParent <VBAParser.CallStmtContext>(usage.Context); if (callStmt == null) { return(false); } var argumentList = CallStatement.GetArgumentList(callStmt); if (argumentList == null) { return(true); } return(!ParserRuleContextHelper.HasParent(usage.Context, argumentList)); }
private void AdjustReferences(IEnumerable <IdentifierReference> references) { foreach (var reference in references.Where(item => item.Context != _model.TargetDeclaration.Context)) { dynamic proc = reference.Context; var module = reference.QualifiedModuleName.Component.CodeModule; VBAParser.ArgumentListContext argumentList = null; var callStmt = ParserRuleContextHelper.GetParent <VBAParser.CallStmtContext>(reference.Context); if (callStmt != null) { argumentList = CallStatement.GetArgumentList(callStmt); } if (argumentList == null) { continue; } RewriteCall(argumentList, module); } }
private void AdjustReferences(IEnumerable <IdentifierReference> references, Declaration method, IRewriteSession rewriteSession) { foreach (var reference in references.Where(item => item.Context != method.Context)) { VBAParser.ArgumentListContext argumentList = null; var callStmt = reference.Context.GetAncestor <VBAParser.CallStmtContext>(); if (callStmt != null) { argumentList = CallStatement.GetArgumentList(callStmt); } if (argumentList == null) { var indexExpression = reference.Context.GetAncestor <VBAParser.IndexExprContext>(); if (indexExpression != null) { argumentList = indexExpression.GetChild <VBAParser.ArgumentListContext>(); } } if (argumentList == null) { var whitespaceIndexExpression = reference.Context.GetAncestor <VBAParser.WhitespaceIndexExprContext>(); if (whitespaceIndexExpression != null) { argumentList = whitespaceIndexExpression.GetChild <VBAParser.ArgumentListContext>(); } } if (argumentList == null) { continue; } RemoveCallArguments(argumentList, reference.QualifiedModuleName, rewriteSession); } }
private void UpdateCalls() { var procedureName = Identifier.GetName(_subStmtQualifiedContext.Context.subroutineName().identifier()); var procedure = _state.AllDeclarations.SingleOrDefault(d => !d.IsBuiltIn && d.IdentifierName == procedureName && d.Context is VBAParser.SubStmtContext && d.QualifiedName.QualifiedModuleName.Equals(_subStmtQualifiedContext.ModuleName)); if (procedure == null) { return; } foreach (var reference in procedure.References.OrderByDescending(o => o.Selection.StartLine).ThenByDescending(d => d.Selection.StartColumn)) { var startLine = reference.Selection.StartLine; if (procedure.ComponentName == reference.QualifiedModuleName.ComponentName && procedure.Selection.EndLine < reference.Selection.StartLine) { startLine += _lineOffset; } var module = reference.QualifiedModuleName.Component.CodeModule; var referenceParent = ParserRuleContextHelper.GetParent <VBAParser.CallStmtContext>(reference.Context); if (referenceParent == null) { continue; } VBAParser.ArgumentListContext argList = CallStatement.GetArgumentList(referenceParent); List <string> paramNames = new List <string>(); string argsCall = string.Empty; int argsCallOffset = 0; if (argList != null) { argsCallOffset = argList.GetSelection().EndColumn - reference.Context.GetSelection().EndColumn; argsCall = argList.GetText(); if (argList.positionalOrNamedArgumentList().positionalArgumentOrMissing() != null) { paramNames.AddRange(argList.positionalOrNamedArgumentList().positionalArgumentOrMissing().Select(p => { if (p is VBAParser.SpecifiedPositionalArgumentContext) { return(((VBAParser.SpecifiedPositionalArgumentContext)p).positionalArgument().GetText()); } else { return(string.Empty); } }).ToList()); } if (argList.positionalOrNamedArgumentList().namedArgumentList() != null) { paramNames.AddRange(argList.positionalOrNamedArgumentList().namedArgumentList().namedArgument().Select(p => p.GetText()).ToList()); } if (argList.positionalOrNamedArgumentList().requiredPositionalArgument() != null) { paramNames.Add(argList.positionalOrNamedArgumentList().requiredPositionalArgument().GetText()); } } var referenceText = reference.Context.GetText(); var newCall = paramNames.ToList().ElementAt(_argListQualifiedContext.Context.arg().ToList().IndexOf(_argQualifiedContext.Context)) + " = " + _subStmtQualifiedContext.Context.subroutineName().GetText() + "(" + argsCall + ")"; var oldLines = module.Lines[startLine, reference.Selection.LineCount]; var newText = oldLines.Remove(reference.Selection.StartColumn - 1, referenceText.Length + argsCallOffset) .Insert(reference.Selection.StartColumn - 1, newCall); module.DeleteLines(startLine, reference.Selection.LineCount); module.InsertLines(startLine, newText); } }