Skip to content

Commit 6aedd33

Browse files
committed
Merge pull request #1130 from Hosch250/BugBlipper
Obsolete Type Hint Tests
2 parents eefaafb + 57795ad commit 6aedd33

File tree

7 files changed

+785
-5
lines changed

7 files changed

+785
-5
lines changed

RetailCoder.VBE/Inspections/FunctionReturnValueNotUsedInspectionResult.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public override string Description
4242
{
4343
get
4444
{
45+
// bug NullReferenceException thrown here - null Target
4546
return string.Format(InspectionsUI.FunctionReturnValueNotUsedInspectionResultFormat, Target.IdentifierName);
4647
}
4748
}

RetailCoder.VBE/Inspections/NonReturningFunctionInspectionResult.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public override string Description
2727
{
2828
get
2929
{
30+
// bug NullReferenceException thrown here - null Target
3031
return string.Format(InspectionsUI.NonReturningFunctionInspectionResultFormat, Target.IdentifierName);
3132
}
3233
}

RetailCoder.VBE/Inspections/ObsoleteTypeHintInspectionResult.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.RegularExpressions;
45
using Antlr4.Runtime;
56
using Microsoft.Vbe.Interop;
@@ -78,13 +79,30 @@ public override void Fix()
7879

7980
private void FixTypeHintUsage(string hint, CodeModule module, Selection selection, bool isDeclaration = false)
8081
{
81-
var line = module.get_Lines(selection.StartLine, 1);
82+
var line = module.Lines[selection.StartLine, 1];
8283

8384
var asTypeClause = ' ' + Tokens.As + ' ' + TypeHints[hint];
84-
var pattern = "\\b" + _declaration.IdentifierName + "\\" + hint;
85-
var fix = Regex.Replace(line, pattern, _declaration.IdentifierName + (isDeclaration ? asTypeClause : String.Empty));
8685

87-
module.ReplaceLine(selection.StartLine, fix);
86+
string fix;
87+
88+
if (isDeclaration && (Context is VBAParser.FunctionStmtContext || Context is VBAParser.PropertyGetStmtContext))
89+
{
90+
var typeHint = (ParserRuleContext)Context.children.First(c => c is VBAParser.TypeHintContext);
91+
var argList = (ParserRuleContext) Context.children.First(c => c is VBAParser.ArgListContext);
92+
var endLine = argList.Stop.Line;
93+
var endColumn = argList.Stop.Column;
94+
95+
var oldLine = module.Lines[endLine, selection.LineCount];
96+
fix = oldLine.Insert(endColumn + 1, asTypeClause).Remove(typeHint.Start.Column, 1); // adjust for VBA 0-based indexing
97+
98+
module.ReplaceLine(endLine, fix);
99+
}
100+
else
101+
{
102+
var pattern = "\\b" + _declaration.IdentifierName + "\\" + hint;
103+
fix = Regex.Replace(line, pattern, _declaration.IdentifierName + (isDeclaration ? asTypeClause : string.Empty));
104+
module.ReplaceLine(selection.StartLine, fix);
105+
}
88106
}
89107
}
90108
}

RetailCoder.VBE/Inspections/ParameterNotUsedInspectionResult.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public ParameterNotUsedInspectionResult(IInspection inspection, string result,
2626

2727
public override string Description
2828
{
29+
// bug NullReferenceException thrown here - null Target
2930
get { return string.Format(InspectionsUI.ParameterNotUsedInspectionResultFormat, Target.IdentifierName); }
3031
}
3132
}

Rubberduck.Parsing/Grammar/VBA.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ dictionaryCallStmt : '!' ambiguousIdentifier typeHint?;
637637

638638
argList : LPAREN (WS? arg (WS? ',' WS? arg)*)? WS? RPAREN;
639639

640-
arg : (OPTIONAL WS)? ((BYVAL | BYREF) WS)? (PARAMARRAY WS)? ambiguousIdentifier (WS? LPAREN WS? RPAREN)? (WS? asTypeClause)? (WS? argDefaultValue)?;
640+
arg : (OPTIONAL WS)? ((BYVAL | BYREF) WS)? (PARAMARRAY WS)? ambiguousIdentifier typeHint? (WS? LPAREN WS? RPAREN)? (WS? asTypeClause)? (WS? argDefaultValue)?;
641641

642642
argDefaultValue : EQ WS? valueStmt;
643643

0 commit comments

Comments
 (0)