Skip to content

Commit aeb361d

Browse files
committed
Merge pull request #1715 from Hosch250/Issue1712
Fix Implicit Variant Function Return Type
2 parents f39821b + c4aea62 commit aeb361d

18 files changed

+201
-156
lines changed

RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspectionResult.cs

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
using System;
12
using System.Collections.Generic;
3+
using System.Linq;
24
using Antlr4.Runtime;
5+
using Antlr4.Runtime.Tree;
36
using Rubberduck.Parsing;
47
using Rubberduck.Parsing.Grammar;
58
using Rubberduck.Parsing.Symbols;
6-
using Rubberduck.Parsing.VBA.Nodes;
9+
using Rubberduck.Parsing.VBA;
710
using Rubberduck.UI;
811
using Rubberduck.VBEditor;
912

@@ -51,16 +54,12 @@ public SetExplicitVariantReturnTypeQuickFix(ParserRuleContext context, Qualified
5154

5255
public override void Fix()
5356
{
54-
// note: turns a multiline signature into a one-liner signature.
55-
// bug: removes all comments.
56-
57-
var node = GetNode(Context as VBAParser.FunctionStmtContext)
58-
?? GetNode(Context as VBAParser.PropertyGetStmtContext);
59-
60-
var signature = node.Signature.TrimEnd();
61-
6257
var procedure = Context.GetText();
63-
var result = procedure.Replace(signature, signature + ' ' + Tokens.As + ' ' + Tokens.Variant);
58+
var indexOfLastClosingParen = procedure.LastIndexOf(')');
59+
60+
var result = indexOfLastClosingParen == procedure.Length
61+
? procedure + ' ' + Tokens.As + ' ' + Tokens.Variant
62+
: procedure.Insert(procedure.LastIndexOf(')') + 1, ' ' + Tokens.As + ' ' + Tokens.Variant);
6463

6564
var module = Selection.QualifiedName.Component.CodeModule;
6665
var selection = Context.GetSelection();
@@ -69,28 +68,49 @@ public override void Fix()
6968
module.InsertLines(selection.StartLine, result);
7069
}
7170

72-
private ProcedureNode GetNode(VBAParser.FunctionStmtContext context)
71+
private string GetSignature(VBAParser.FunctionStmtContext context)
7372
{
7473
if (context == null)
7574
{
7675
return null;
7776
}
7877

79-
var scope = Selection.QualifiedName.ToString();
80-
var localScope = scope + "." + context.functionName().identifier().GetText();
81-
return new ProcedureNode(context, scope, localScope);
78+
var @static = context.STATIC() == null ? string.Empty : context.STATIC().GetText() + ' ';
79+
var keyword = context.FUNCTION().GetText() + ' ';
80+
var args = context.argList() == null ? "()" : context.argList().GetText() + ' ';
81+
var asTypeClause = context.asTypeClause() == null ? string.Empty : context.asTypeClause().GetText();
82+
var visibility = context.visibility() == null ? string.Empty : context.visibility().GetText() + ' ';
83+
84+
return visibility + @static + keyword + context.functionName().identifier().GetText() + args + asTypeClause;
8285
}
8386

84-
private ProcedureNode GetNode(VBAParser.PropertyGetStmtContext context)
87+
private string GetSignature(VBAParser.PropertyGetStmtContext context)
8588
{
8689
if (context == null)
8790
{
8891
return null;
8992
}
9093

91-
var scope = Selection.QualifiedName.ToString();
92-
var localScope = scope + "." + context.functionName().identifier().GetText();
93-
return new ProcedureNode(context, scope, localScope);
94+
var @static = context.STATIC() == null ? string.Empty : context.STATIC().GetText() + ' ';
95+
var keyword = context.PROPERTY_GET().GetText() + ' ';
96+
var args = context.argList() == null ? "()" : context.argList().GetText() + ' ';
97+
var asTypeClause = context.asTypeClause() == null ? string.Empty : context.asTypeClause().GetText();
98+
var visibility = context.visibility() == null ? string.Empty : context.visibility().GetText() + ' ';
99+
100+
return visibility + @static + keyword + context.functionName().identifier().GetText() + args + asTypeClause;
101+
}
102+
103+
private string GetSignature(VBAParser.DeclareStmtContext context)
104+
{
105+
if (context == null)
106+
{
107+
return null;
108+
}
109+
110+
var args = context.argList() == null ? "()" : context.argList().GetText() + ' ';
111+
var asTypeClause = context.asTypeClause() == null ? string.Empty : context.asTypeClause().GetText();
112+
113+
return args + asTypeClause;
94114
}
95115
}
96116
}

RetailCoder.VBE/Inspections/InspectionResultBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Linq;
33
using Antlr4.Runtime;
44
using Rubberduck.Parsing;
5-
using Rubberduck.Parsing.Nodes;
65
using Rubberduck.Parsing.Symbols;
76
using Rubberduck.UI;
87
using Rubberduck.UI.Controls;

RetailCoder.VBE/Inspections/ObsoleteCommentSyntaxInspectionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Collections.Generic;
22
using Antlr4.Runtime;
33
using Rubberduck.Parsing.Grammar;
4-
using Rubberduck.Parsing.Nodes;
4+
using Rubberduck.Parsing.Symbols;
55
using Rubberduck.Parsing.VBA;
66
using Rubberduck.VBEditor;
77

RetailCoder.VBE/Inspections/OptionBaseInspectionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Rubberduck.Parsing.Grammar;
2-
using Rubberduck.Parsing.Nodes;
2+
using Rubberduck.Parsing.Symbols;
33
using Rubberduck.VBEditor;
44

55
namespace Rubberduck.Inspections

RetailCoder.VBE/Inspections/OptionExplicitInspectionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using Antlr4.Runtime;
44
using Rubberduck.Parsing.Grammar;
5-
using Rubberduck.Parsing.Nodes;
5+
using Rubberduck.Parsing.Symbols;
66
using Rubberduck.VBEditor;
77

88
namespace Rubberduck.Inspections

RetailCoder.VBE/ToDoItems/ToDoItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Rubberduck.Parsing.Nodes;
1+
using Rubberduck.Parsing.Symbols;
22
using Rubberduck.UI;
33
using Rubberduck.UI.Controls;
44
using Rubberduck.VBEditor;

RetailCoder.VBE/UI/ToDoItems/ToDoExplorerViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
using System.Collections.ObjectModel;
44
using System.Linq;
55
using System.Windows.Input;
6-
using Rubberduck.Parsing.Nodes;
76
using Rubberduck.Parsing.VBA;
87
using Rubberduck.Settings;
98
using Rubberduck.ToDoItems;
109
using Rubberduck.UI.Command;
1110
using Rubberduck.UI.Controls;
1211
using Rubberduck.UI.Settings;
1312
using Rubberduck.Common;
13+
using Rubberduck.Parsing.Symbols;
1414

1515
namespace Rubberduck.UI.ToDoItems
1616
{

Rubberduck.Parsing/Rubberduck.Parsing.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
<Compile Include="Preprocessing\VBAConditionalCompilationParserListener.cs" />
129129
<Compile Include="Preprocessing\VBAConditionalCompilationParserVisitor.cs" />
130130
<Compile Include="Symbols\ComInformation.cs" />
131+
<Compile Include="Symbols\CommentNode.cs" />
131132
<Compile Include="Symbols\ComParameter.cs" />
132133
<Compile Include="Symbols\Identifier.cs" />
133134
<Compile Include="Binding\IBindingContext.cs" />
@@ -256,7 +257,6 @@
256257
<Compile Include="Symbols\ProjectReference.cs" />
257258
<Compile Include="Symbols\ReferencedDeclarationsCollector.cs" />
258259
<Compile Include="Symbols\SyntaxErrorException.cs" />
259-
<Compile Include="Nodes\CommentNode.cs" />
260260
<Compile Include="ParserRuleContextExtensions.cs" />
261261
<Compile Include="Properties\AssemblyInfo.cs" />
262262
<Compile Include="QualifiedContext.cs" />
@@ -277,7 +277,6 @@
277277
<Compile Include="VBA\ModuleState.cs" />
278278
<Compile Include="VBA\Nodes\INode.cs" />
279279
<Compile Include="VBA\Nodes\Node.cs" />
280-
<Compile Include="VBA\Nodes\ProcedureNode.cs" />
281280
<Compile Include="VBA\ParseErrorEventArgs.cs" />
282281
<Compile Include="VBA\ParserState.cs" />
283282
<Compile Include="VBA\ReferencePriorityMap.cs" />

Rubberduck.Parsing/Nodes/CommentNode.cs renamed to Rubberduck.Parsing/Symbols/CommentNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Rubberduck.VBEditor;
22

3-
namespace Rubberduck.Parsing.Nodes
3+
namespace Rubberduck.Parsing.Symbols
44
{
55
/// <summary>
66
/// Represents a comment.

Rubberduck.Parsing/Symbols/DeclarationFinder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using NLog;
22
using Rubberduck.Parsing.Annotations;
3-
using Rubberduck.Parsing.Nodes;
43
using Rubberduck.VBEditor;
54
using System;
65
using System.Collections.Generic;

0 commit comments

Comments
 (0)