Skip to content

Commit a3eb575

Browse files
committed
updated with changes that came from last sync
1 parent c9f334a commit a3eb575

18 files changed

+184
-54
lines changed

RetailCoder.VBE/Inspections/Concrete/Inspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ before moving them into the ParseTreeResults after qualifying them
139139

140140
if (argListWithOneByRefParamListener != null)
141141
{
142-
result.AddRange(argListWithOneByRefParamListener.Contexts.Select(context => new QualifiedContext<VBAParser.ArgListContext>(componentTreePair.Key, context)));
142+
result.AddRange(argListWithOneByRefParamListener.Contexts.Select(context => new QualifiedContext<VBAParser.SubstmtContext>(componentTreePair.Key, context)));
143143
}
144144
if (emptyStringLiteralListener != null)
145145
{

RetailCoder.VBE/Inspections/ProcedureCanBeWrittenAsFunctionInspection.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public ProcedureCanBeWrittenAsFunctionInspection(RubberduckParserState state)
2727
public override string Description { get { return InspectionsUI.ProcedureCanBeWrittenAsFunctionInspectionName; } }
2828
public override CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } }
2929

30-
public IEnumerable<QualifiedContext<VBAParser.ArgListContext>> ParseTreeResults { get { return _results.OfType<QualifiedContext<VBAParser.ArgListContext>>(); } }
30+
public IEnumerable<QualifiedContext<VBAParser.SubstmtContext>> ParseTreeResults { get { return _results.OfType<QualifiedContext<VBAParser.SubstmtContext>>(); } }
3131

3232
public void SetResults(IEnumerable<QualifiedContext> results)
3333
{
@@ -62,17 +62,17 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
6262
.Select(result => new ProcedureCanBeWrittenAsFunctionInspectionResult(
6363
this,
6464
State,
65-
new QualifiedContext<VBAParser.ArgListContext>(result.QualifiedName,result.Context.GetChild<VBAParser.ArgListContext>(0)),
65+
new QualifiedContext<VBAParser.SubstmtContext>(result.QualifiedName,result.Context.GetChild<VBAParser.SubstmtContext>(0)),
6666
new QualifiedContext<VBAParser.SubStmtContext>(result.QualifiedName, (VBAParser.SubStmtContext)result.Context))
6767
);
6868
}
6969

7070
public class SingleByRefParamArgListListener : VBAParserBaseListener
7171
{
72-
private readonly IList<VBAParser.ArgListContext> _contexts = new List<VBAParser.ArgListContext>();
73-
public IEnumerable<VBAParser.ArgListContext> Contexts { get { return _contexts; } }
72+
private readonly IList<VBAParser.SubstmtContext> _contexts = new List<VBAParser.SubstmtContext>();
73+
public IEnumerable<VBAParser.SubstmtContext> Contexts { get { return _contexts; } }
7474

75-
public override void ExitArgList(VBAParser.ArgListContext context)
75+
public override void ExitArgList(VBAParser.SubstmtContext context)
7676
{
7777
var args = context.arg();
7878
if (args != null && args.All(a => a.PARAMARRAY() == null && a.LPAREN() == null) && args.Count(a => a.BYREF() != null || (a.BYREF() == null && a.BYVAL() == null)) == 1)

RetailCoder.VBE/Inspections/QuickFixes/DeclareAsExplicitVariantQuickFix.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ private string DeclareExplicitVariant(VBAParser.ArgContext context, out string i
6868
var fix = string.Empty;
6969
foreach (var child in memberContext.children)
7070
{
71-
if (child is VBAParser.ArgListContext)
71+
if (child is VBAParser.SubstmtContext)
7272
{
73-
foreach (var tree in ((VBAParser.ArgListContext) child).children)
73+
foreach (var tree in ((VBAParser.SubstmtContext) child).children)
7474
{
7575
if (tree.Equals(context))
7676
{

RetailCoder.VBE/Inspections/QuickFixes/PassParameterByReferenceQuickFix.cs

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ private string GetUniqueTargetStringForByValAtEndOfLine(string procLineWithByVal
9999

100100
var positionOfLineContinuation = procLineWithByValToken.LastIndexOf(Tokens.LineContinuation);
101101
var positionOfLastByValToken = procLineWithByValToken.LastIndexOf(Tokens.ByVal);
102-
return procLineWithByValToken.Substring(positionOfLastByValToken, positionOfLineContinuation - positionOfLastByValToken + 2);
102+
return procLineWithByValToken.Substring(positionOfLastByValToken, positionOfLineContinuation - positionOfLastByValToken + Tokens.LineContinuation.Length);
103103
}
104104
private void SetMemberLineValues(string[] procedureLines)
105105
{
106+
106107
string line;
107108
bool byValTokenFound = false;
108109
bool byValIdentifierNameFound = false;
@@ -116,17 +117,108 @@ private void SetMemberLineValues(string[] procedureLines)
116117
}
117118
if (byValTokenFound)
118119
{
120+
int lineNum = GetIdentifierLineNumber(_target.IdentifierName);
121+
if(lineNum > 0)
122+
{
123+
_byValIdentifierNameProcLine = lineNum;
124+
byValIdentifierNameFound = true;
125+
}
126+
/*
119127
if (line.Contains(_target.IdentifierName))
120128
{
121129
_byValIdentifierNameProcLine = zbIndexByValLine + 1;
122130
byValIdentifierNameFound = true;
123131
}
132+
*/
124133
}
125134
}
126135

127136
System.Diagnostics.Debug.Assert(_byValTokenProcLine > 0);
128137
System.Diagnostics.Debug.Assert(_byValIdentifierNameProcLine > 0);
129138
return;
130139
}
140+
private int GetIdentifierLineNumber(string identifier)
141+
{
142+
var names = new List<string>();
143+
var test = (SubStmtContext)Context.Parent.Parent;
144+
var next = test.children;
145+
for (int idx = 0; idx < next.Count; idx++)
146+
{
147+
if (next[idx] is SubstmtContext)
148+
{
149+
var child = (SubstmtContext)next[idx];
150+
var arg = child.children;
151+
for (int idx2 = 0; idx2 < arg.Count; idx2++)
152+
{
153+
if (arg[idx2] is ArgContext)
154+
{
155+
var asdf = (ArgContext)arg[idx2];
156+
var kids = asdf.children;
157+
for (int idx3 = 0; idx3 < kids.Count; idx3++)
158+
{
159+
var _start = (ParserRuleContext)kids[0];
160+
var _stop = (ParserRuleContext)kids[kids.Count-1];
161+
int startCol = _start.Start.Column;
162+
int stopCol = _start.Stop.Column;
163+
164+
if (kids[idx3] is UnrestrictedIdentifierContext)
165+
{
166+
var idRef = (UnrestrictedIdentifierContext)kids[idx3];
167+
var name = idRef.Start.Text;
168+
if (name.Equals(identifier))
169+
{
170+
int lineNum = idRef.Start.Line;
171+
return lineNum;
172+
}
173+
}
174+
}
175+
}
176+
}
177+
}
178+
}
179+
return -1;
180+
}
181+
private int GetIdentifierStartIndex(string identifier, out int stopIndex)
182+
{
183+
var names = new List<string>();
184+
var test = (SubStmtContext)Context.Parent.Parent;
185+
var next = test.children;
186+
for (int idx = 0; idx < next.Count; idx++)
187+
{
188+
if (next[idx] is SubstmtContext)
189+
{
190+
var child = (SubstmtContext)next[idx];
191+
var arg = child.children;
192+
for (int idx2 = 0; idx2 < arg.Count; idx2++)
193+
{
194+
if (arg[idx2] is ArgContext)
195+
{
196+
var asdf = (ArgContext)arg[idx2];
197+
var kids = asdf.children;
198+
for (int idx3 = 0; idx3 < kids.Count; idx3++)
199+
{
200+
var _start = (ParserRuleContext)kids[0];
201+
var _stop = (ParserRuleContext)kids[kids.Count - 1];
202+
stopIndex = _start.Stop.Column;
203+
return _start.Start.Column;
204+
205+
if (kids[idx3] is UnrestrictedIdentifierContext)
206+
{
207+
var idRef = (UnrestrictedIdentifierContext)kids[idx3];
208+
var name = idRef.Start.Text;
209+
if (name.Equals(identifier))
210+
{
211+
int lineNum = idRef.Start.Line;
212+
return lineNum;
213+
}
214+
}
215+
}
216+
}
217+
}
218+
}
219+
}
220+
stopIndex = -1;
221+
return -1;
222+
}
131223
}
132224
}

RetailCoder.VBE/Inspections/Results/ProcedureCanBeWrittenAsFunctionInspectionResult.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ namespace Rubberduck.Inspections.Results
1616
public class ProcedureCanBeWrittenAsFunctionInspectionResult : InspectionResultBase
1717
{
1818
private IEnumerable<QuickFixBase> _quickFixes;
19-
private readonly QualifiedContext<VBAParser.ArgListContext> _argListQualifiedContext;
19+
private readonly QualifiedContext<VBAParser.SubstmtContext> _argListQualifiedContext;
2020
private readonly QualifiedContext<VBAParser.SubStmtContext> _subStmtQualifiedContext;
2121
private readonly RubberduckParserState _state;
2222

2323
public ProcedureCanBeWrittenAsFunctionInspectionResult(IInspection inspection, RubberduckParserState state,
24-
QualifiedContext<VBAParser.ArgListContext> argListQualifiedContext, QualifiedContext<VBAParser.SubStmtContext> subStmtQualifiedContext)
24+
QualifiedContext<VBAParser.SubstmtContext> argListQualifiedContext, QualifiedContext<VBAParser.SubStmtContext> subStmtQualifiedContext)
2525
: base(inspection, subStmtQualifiedContext.ModuleName, subStmtQualifiedContext.Context.subroutineName())
2626
{
2727
_target = state.AllUserDeclarations.Single(declaration => declaration.DeclarationType == DeclarationType.Procedure
@@ -57,14 +57,14 @@ public class ChangeProcedureToFunction : QuickFixBase
5757
public override bool CanFixInProject { get { return false; } }
5858

5959
private readonly RubberduckParserState _state;
60-
private readonly QualifiedContext<VBAParser.ArgListContext> _argListQualifiedContext;
60+
private readonly QualifiedContext<VBAParser.SubstmtContext> _argListQualifiedContext;
6161
private readonly QualifiedContext<VBAParser.SubStmtContext> _subStmtQualifiedContext;
6262
private readonly QualifiedContext<VBAParser.ArgContext> _argQualifiedContext;
6363

6464
private int _lineOffset;
6565

6666
public ChangeProcedureToFunction(RubberduckParserState state,
67-
QualifiedContext<VBAParser.ArgListContext> argListQualifiedContext,
67+
QualifiedContext<VBAParser.SubstmtContext> argListQualifiedContext,
6868
QualifiedContext<VBAParser.SubStmtContext> subStmtQualifiedContext,
6969
QualifiedSelection selection)
7070
: base(subStmtQualifiedContext.Context, selection, InspectionsUI.ProcedureShouldBeFunctionInspectionQuickFix)

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerMemberViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public override string NameWithSignature
117117
}
118118

119119
var context =
120-
_declaration.Context.children.FirstOrDefault(d => d is VBAParser.ArgListContext) as VBAParser.ArgListContext;
120+
_declaration.Context.children.FirstOrDefault(d => d is VBAParser.SubstmtContext) as VBAParser.SubstmtContext;
121121

122122
if (context == null)
123123
{

RetailCoder.VBE/Refactorings/IntroduceParameter/IntroduceParameterRefactoring.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private void UpdateSignature(Declaration targetVariable)
142142
var functionDeclaration = _declarations.FindTarget(targetVariable.QualifiedSelection, ValidDeclarationTypes);
143143

144144
var proc = (dynamic)functionDeclaration.Context;
145-
var paramList = (VBAParser.ArgListContext)proc.argList();
145+
var paramList = (VBAParser.SubstmtContext)proc.argList();
146146
var module = functionDeclaration.QualifiedName.QualifiedModuleName.Component.CodeModule;
147147
{
148148
var interfaceImplementation = GetInterfaceImplementation(functionDeclaration);
@@ -182,14 +182,14 @@ private void UpdateSignature(Declaration targetVariable)
182182
private void UpdateSignature(Declaration targetMethod, Declaration targetVariable)
183183
{
184184
var proc = (dynamic)targetMethod.Context;
185-
var paramList = (VBAParser.ArgListContext)proc.argList();
185+
var paramList = (VBAParser.SubstmtContext)proc.argList();
186186
var module = targetMethod.QualifiedName.QualifiedModuleName.Component.CodeModule;
187187
{
188188
AddParameter(targetMethod, targetVariable, paramList, module);
189189
}
190190
}
191191

192-
private void AddParameter(Declaration targetMethod, Declaration targetVariable, VBAParser.ArgListContext paramList, ICodeModule module)
192+
private void AddParameter(Declaration targetMethod, Declaration targetVariable, VBAParser.SubstmtContext paramList, ICodeModule module)
193193
{
194194
var argList = paramList.arg();
195195
var lastParam = argList.LastOrDefault();

RetailCoder.VBE/Refactorings/RemoveParameters/RemoveParametersRefactoring.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private string GetOldSignature(Declaration target)
279279
private void AdjustSignatures()
280280
{
281281
var proc = (dynamic)_model.TargetDeclaration.Context;
282-
var paramList = (VBAParser.ArgListContext)proc.argList();
282+
var paramList = (VBAParser.SubstmtContext)proc.argList();
283283
var module = _model.TargetDeclaration.QualifiedName.QualifiedModuleName.Component.CodeModule;
284284
{
285285
// if we are adjusting a property getter, check if we need to adjust the letter/setter too
@@ -336,23 +336,23 @@ private void AdjustSignatures(Declaration declaration)
336336
var proc = (dynamic)declaration.Context.Parent;
337337
var module = declaration.QualifiedName.QualifiedModuleName.Component.CodeModule;
338338
{
339-
VBAParser.ArgListContext paramList;
339+
VBAParser.SubstmtContext paramList;
340340

341341
if (declaration.DeclarationType == DeclarationType.PropertySet
342342
|| declaration.DeclarationType == DeclarationType.PropertyLet)
343343
{
344-
paramList = (VBAParser.ArgListContext)proc.children[0].argList();
344+
paramList = (VBAParser.SubstmtContext)proc.children[0].argList();
345345
}
346346
else
347347
{
348-
paramList = (VBAParser.ArgListContext)proc.subStmt().argList();
348+
paramList = (VBAParser.SubstmtContext)proc.subStmt().argList();
349349
}
350350

351351
RemoveSignatureParameters(declaration, paramList, module);
352352
}
353353
}
354354

355-
private void RemoveSignatureParameters(Declaration target, VBAParser.ArgListContext paramList, ICodeModule module)
355+
private void RemoveSignatureParameters(Declaration target, VBAParser.SubstmtContext paramList, ICodeModule module)
356356
{
357357
// property set/let have one more parameter than is listed in the getter parameters
358358
var nonRemovedParamNames = paramList.arg().Where((a, s) => s >= _model.Parameters.Count || !_model.Parameters[s].IsRemoved).Select(s => s.GetText());

RetailCoder.VBE/Refactorings/Rename/RenameRefactoring.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ private void RenameDeclaration(Declaration target, string newName)
335335

336336
if (target.DeclarationType == DeclarationType.Parameter)
337337
{
338-
var argList = (VBAParser.ArgListContext)target.Context.Parent;
338+
var argList = (VBAParser.SubstmtContext)target.Context.Parent;
339339
var lineNum = argList.GetSelection().LineCount;
340340

341341
// delete excess lines to prevent removing our own changes

RetailCoder.VBE/Refactorings/ReorderParameters/ReorderParametersModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private void LoadParameters()
5050
Parameters.Clear();
5151

5252
var procedure = (dynamic)TargetDeclaration.Context;
53-
var argList = (VBAParser.ArgListContext)procedure.argList();
53+
var argList = (VBAParser.SubstmtContext)procedure.argList();
5454
var args = argList.arg();
5555

5656
var index = 0;

0 commit comments

Comments
 (0)