Skip to content

Commit e35c3a2

Browse files
committed
Parameterise error message
1 parent 3a1640b commit e35c3a2

File tree

3 files changed

+20
-139
lines changed

3 files changed

+20
-139
lines changed

Rubberduck.Refactorings/ExtractMethod/ExtractMethodSelectionValidation.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ protected override bool ShouldVisitNextChild(IRuleNode node, IEnumerable<VBAPars
224224
{
225225
if (_qualifiedSelection.Selection.Contains(context))
226226
{
227-
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasErrorStatement));
227+
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, string.Format(RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement, "Error")));
228228
return null;
229229
}
230230

@@ -235,7 +235,7 @@ protected override bool ShouldVisitNextChild(IRuleNode node, IEnumerable<VBAPars
235235
{
236236
if (_qualifiedSelection.Selection.Contains(context))
237237
{
238-
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasEndStatement));
238+
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, string.Format(RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement, "End")));
239239
return null;
240240
}
241241

@@ -246,7 +246,7 @@ protected override bool ShouldVisitNextChild(IRuleNode node, IEnumerable<VBAPars
246246
{
247247
if (_qualifiedSelection.Selection.Contains(context))
248248
{
249-
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasExitStatement));
249+
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, string.Format(RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement, "Exit")));
250250
return null;
251251
}
252252

@@ -257,7 +257,7 @@ protected override bool ShouldVisitNextChild(IRuleNode node, IEnumerable<VBAPars
257257
{
258258
if (_qualifiedSelection.Selection.Contains(context))
259259
{
260-
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasGoSubStatement));
260+
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, string.Format(RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement, "GoSub")));
261261
return null;
262262
}
263263

@@ -268,7 +268,7 @@ protected override bool ShouldVisitNextChild(IRuleNode node, IEnumerable<VBAPars
268268
{
269269
if (_qualifiedSelection.Selection.Contains(context))
270270
{
271-
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasGoToStatement));
271+
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, string.Format(RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement, "GoTo")));
272272
return null;
273273
}
274274

@@ -279,7 +279,7 @@ protected override bool ShouldVisitNextChild(IRuleNode node, IEnumerable<VBAPars
279279
{
280280
if (_qualifiedSelection.Selection.Contains(context))
281281
{
282-
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasOnErrorStatement));
282+
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, string.Format(RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement, "On Error")));
283283
return null;
284284
}
285285

@@ -290,7 +290,7 @@ protected override bool ShouldVisitNextChild(IRuleNode node, IEnumerable<VBAPars
290290
{
291291
if (_qualifiedSelection.Selection.Contains(context))
292292
{
293-
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasLineLabelStatement));
293+
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, string.Format(RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement, "line label")));
294294
return null;
295295
}
296296

@@ -301,7 +301,7 @@ protected override bool ShouldVisitNextChild(IRuleNode node, IEnumerable<VBAPars
301301
{
302302
if (_qualifiedSelection.Selection.Contains(context))
303303
{
304-
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasLineLabelStatement));
304+
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, string.Format(RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement, "line label")));
305305
return base.VisitCombinedLabels(context);
306306
}
307307

@@ -312,7 +312,7 @@ protected override bool ShouldVisitNextChild(IRuleNode node, IEnumerable<VBAPars
312312
{
313313
if (_qualifiedSelection.Selection.Contains(context))
314314
{
315-
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasLineLabelStatement));
315+
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, string.Format(RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement, "line label")));
316316
return null;
317317
}
318318

@@ -323,7 +323,7 @@ protected override bool ShouldVisitNextChild(IRuleNode node, IEnumerable<VBAPars
323323
{
324324
if (_qualifiedSelection.Selection.Contains(context))
325325
{
326-
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasOnGosubStatement));
326+
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, string.Format(RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement, "On...GoSub")));
327327
return null;
328328
}
329329

@@ -334,7 +334,7 @@ protected override bool ShouldVisitNextChild(IRuleNode node, IEnumerable<VBAPars
334334
{
335335
if (_qualifiedSelection.Selection.Contains(context))
336336
{
337-
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasOnGoToStatement));
337+
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, string.Format(RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement, "On...GoTo")));
338338
return null;
339339
}
340340

@@ -345,7 +345,7 @@ protected override bool ShouldVisitNextChild(IRuleNode node, IEnumerable<VBAPars
345345
{
346346
if (_qualifiedSelection.Selection.Contains(context))
347347
{
348-
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasResumeStatement));
348+
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, string.Format(RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement, "Resume")));
349349
return null;
350350
}
351351

@@ -356,7 +356,7 @@ protected override bool ShouldVisitNextChild(IRuleNode node, IEnumerable<VBAPars
356356
{
357357
if (_qualifiedSelection.Selection.Contains(context))
358358
{
359-
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasReturnStatement));
359+
InvalidContexts.Add(Tuple.Create(context as ParserRuleContext, string.Format(RefactoringsUI.ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement, "Return")));
360360
return null;
361361
}
362362

Rubberduck.Refactorings/RefactoringsUI.Designer.cs

Lines changed: 4 additions & 94 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Refactorings/RefactoringsUI.resx

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -655,38 +655,9 @@ Do you want to proceed?</value>
655655
<data name="ExtractMethod_InvalidMessageSelectionEndsOutsideProcedure" xml:space="preserve">
656656
<value>Selection does not end inside a recognised procedure</value>
657657
</data>
658-
<data name="ExtractMethod_InvalidMessageSelectionHasEndStatement" xml:space="preserve">
659-
<value>Extract method cannot extract code that contains an End statement.</value>
660-
</data>
661-
<data name="ExtractMethod_InvalidMessageSelectionHasErrorStatement" xml:space="preserve">
662-
<value>Extract method cannot extract code that contains an Error statement.</value>
663-
</data>
664-
<data name="ExtractMethod_InvalidMessageSelectionHasExitStatement" xml:space="preserve">
665-
<value>Extract method cannot extract code that contains an Exit statement.</value>
666-
</data>
667-
<data name="ExtractMethod_InvalidMessageSelectionHasGoSubStatement" xml:space="preserve">
668-
<value>Extract method cannot extract code that contains a GoSub statement.</value>
669-
</data>
670-
<data name="ExtractMethod_InvalidMessageSelectionHasGoToStatement" xml:space="preserve">
671-
<value>Extract method cannot extract code that contains a GoTo statement.</value>
672-
</data>
673-
<data name="ExtractMethod_InvalidMessageSelectionHasLineLabelStatement" xml:space="preserve">
674-
<value>Extract method cannot extract code that contains a line label.</value>
675-
</data>
676-
<data name="ExtractMethod_InvalidMessageSelectionHasOnErrorStatement" xml:space="preserve">
677-
<value>Extract method cannot extract code that contains an On Error statement.</value>
678-
</data>
679-
<data name="ExtractMethod_InvalidMessageSelectionHasOnGosubStatement" xml:space="preserve">
680-
<value>Extract method cannot extract code that contains an On ... GoSub statement.</value>
681-
</data>
682-
<data name="ExtractMethod_InvalidMessageSelectionHasOnGoToStatement" xml:space="preserve">
683-
<value>Extract method cannot extract code that contains an On ... GoTo statement.</value>
684-
</data>
685-
<data name="ExtractMethod_InvalidMessageSelectionHasResumeStatement" xml:space="preserve">
686-
<value>Extract method cannot extract code that contains a Resume statement.</value>
687-
</data>
688-
<data name="ExtractMethod_InvalidMessageSelectionHasReturnStatement" xml:space="preserve">
689-
<value>Extract method cannot extract code that contains a Return statement.</value>
658+
<data name="ExtractMethod_InvalidMessageSelectionHasUnsupportedStatement" xml:space="preserve">
659+
<value>Extract method cannot extract code that contains '{0}' statements.</value>
660+
<comment>0: statement type that cannot be refactored</comment>
690661
</data>
691662
<data name="ExtractMethod_InvalidMessageSelectionModifiesParentFunctionReturn" xml:space="preserve">
692663
<value>The selected code modifies the return value of the function it is in</value>

0 commit comments

Comments
 (0)