Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Hosch250 committed Jun 6, 2016
1 parent f39821b commit c4aea62
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 156 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime;
using Antlr4.Runtime.Tree;
using Rubberduck.Parsing;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA.Nodes;
using Rubberduck.Parsing.VBA;
using Rubberduck.UI;
using Rubberduck.VBEditor;

Expand Down Expand Up @@ -51,16 +54,12 @@ public SetExplicitVariantReturnTypeQuickFix(ParserRuleContext context, Qualified

public override void Fix()
{
// note: turns a multiline signature into a one-liner signature.
// bug: removes all comments.

var node = GetNode(Context as VBAParser.FunctionStmtContext)
?? GetNode(Context as VBAParser.PropertyGetStmtContext);

var signature = node.Signature.TrimEnd();

var procedure = Context.GetText();
var result = procedure.Replace(signature, signature + ' ' + Tokens.As + ' ' + Tokens.Variant);
var indexOfLastClosingParen = procedure.LastIndexOf(')');

var result = indexOfLastClosingParen == procedure.Length
? procedure + ' ' + Tokens.As + ' ' + Tokens.Variant
: procedure.Insert(procedure.LastIndexOf(')') + 1, ' ' + Tokens.As + ' ' + Tokens.Variant);

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

private ProcedureNode GetNode(VBAParser.FunctionStmtContext context)
private string GetSignature(VBAParser.FunctionStmtContext context)
{
if (context == null)
{
return null;
}

var scope = Selection.QualifiedName.ToString();
var localScope = scope + "." + context.functionName().identifier().GetText();
return new ProcedureNode(context, scope, localScope);
var @static = context.STATIC() == null ? string.Empty : context.STATIC().GetText() + ' ';
var keyword = context.FUNCTION().GetText() + ' ';
var args = context.argList() == null ? "()" : context.argList().GetText() + ' ';
var asTypeClause = context.asTypeClause() == null ? string.Empty : context.asTypeClause().GetText();
var visibility = context.visibility() == null ? string.Empty : context.visibility().GetText() + ' ';

return visibility + @static + keyword + context.functionName().identifier().GetText() + args + asTypeClause;
}

private ProcedureNode GetNode(VBAParser.PropertyGetStmtContext context)
private string GetSignature(VBAParser.PropertyGetStmtContext context)
{
if (context == null)
{
return null;
}

var scope = Selection.QualifiedName.ToString();
var localScope = scope + "." + context.functionName().identifier().GetText();
return new ProcedureNode(context, scope, localScope);
var @static = context.STATIC() == null ? string.Empty : context.STATIC().GetText() + ' ';
var keyword = context.PROPERTY_GET().GetText() + ' ';
var args = context.argList() == null ? "()" : context.argList().GetText() + ' ';
var asTypeClause = context.asTypeClause() == null ? string.Empty : context.asTypeClause().GetText();
var visibility = context.visibility() == null ? string.Empty : context.visibility().GetText() + ' ';

return visibility + @static + keyword + context.functionName().identifier().GetText() + args + asTypeClause;
}

private string GetSignature(VBAParser.DeclareStmtContext context)
{
if (context == null)
{
return null;
}

var args = context.argList() == null ? "()" : context.argList().GetText() + ' ';
var asTypeClause = context.asTypeClause() == null ? string.Empty : context.asTypeClause().GetText();

return args + asTypeClause;
}
}
}
1 change: 0 additions & 1 deletion RetailCoder.VBE/Inspections/InspectionResultBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Linq;
using Antlr4.Runtime;
using Rubberduck.Parsing;
using Rubberduck.Parsing.Nodes;
using Rubberduck.Parsing.Symbols;
using Rubberduck.UI;
using Rubberduck.UI.Controls;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using Antlr4.Runtime;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Nodes;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.VBEditor;

Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/Inspections/OptionBaseInspectionResult.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Nodes;
using Rubberduck.Parsing.Symbols;
using Rubberduck.VBEditor;

namespace Rubberduck.Inspections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using Antlr4.Runtime;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Nodes;
using Rubberduck.Parsing.Symbols;
using Rubberduck.VBEditor;

namespace Rubberduck.Inspections
Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/ToDoItems/ToDoItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Rubberduck.Parsing.Nodes;
using Rubberduck.Parsing.Symbols;
using Rubberduck.UI;
using Rubberduck.UI.Controls;
using Rubberduck.VBEditor;
Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/UI/ToDoItems/ToDoExplorerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using Rubberduck.Parsing.Nodes;
using Rubberduck.Parsing.VBA;
using Rubberduck.Settings;
using Rubberduck.ToDoItems;
using Rubberduck.UI.Command;
using Rubberduck.UI.Controls;
using Rubberduck.UI.Settings;
using Rubberduck.Common;
using Rubberduck.Parsing.Symbols;

namespace Rubberduck.UI.ToDoItems
{
Expand Down
3 changes: 1 addition & 2 deletions Rubberduck.Parsing/Rubberduck.Parsing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<Compile Include="Preprocessing\VBAConditionalCompilationParserListener.cs" />
<Compile Include="Preprocessing\VBAConditionalCompilationParserVisitor.cs" />
<Compile Include="Symbols\ComInformation.cs" />
<Compile Include="Symbols\CommentNode.cs" />
<Compile Include="Symbols\ComParameter.cs" />
<Compile Include="Symbols\Identifier.cs" />
<Compile Include="Binding\IBindingContext.cs" />
Expand Down Expand Up @@ -256,7 +257,6 @@
<Compile Include="Symbols\ProjectReference.cs" />
<Compile Include="Symbols\ReferencedDeclarationsCollector.cs" />
<Compile Include="Symbols\SyntaxErrorException.cs" />
<Compile Include="Nodes\CommentNode.cs" />
<Compile Include="ParserRuleContextExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QualifiedContext.cs" />
Expand All @@ -277,7 +277,6 @@
<Compile Include="VBA\ModuleState.cs" />
<Compile Include="VBA\Nodes\INode.cs" />
<Compile Include="VBA\Nodes\Node.cs" />
<Compile Include="VBA\Nodes\ProcedureNode.cs" />
<Compile Include="VBA\ParseErrorEventArgs.cs" />
<Compile Include="VBA\ParserState.cs" />
<Compile Include="VBA\ReferencePriorityMap.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Rubberduck.VBEditor;

namespace Rubberduck.Parsing.Nodes
namespace Rubberduck.Parsing.Symbols
{
/// <summary>
/// Represents a comment.
Expand Down
1 change: 0 additions & 1 deletion Rubberduck.Parsing/Symbols/DeclarationFinder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using NLog;
using Rubberduck.Parsing.Annotations;
using Rubberduck.Parsing.Nodes;
using Rubberduck.VBEditor;
using System;
using System.Collections.Generic;
Expand Down
3 changes: 1 addition & 2 deletions Rubberduck.Parsing/Symbols/DeclarationSymbolsListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.Vbe.Interop.Forms;
using Rubberduck.Parsing.Annotations;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Nodes;
using Rubberduck.Parsing.VBA;
using Rubberduck.VBEditor;
using System;
Expand Down Expand Up @@ -247,7 +246,7 @@ private void DeclareControlsAsMembers(VBComponent form)
}
else if (declarationType == DeclarationType.LibraryProcedure || declarationType == DeclarationType.LibraryFunction)
{
result = new ExternalProcedureDeclaration(new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, declarationType, asTypeName, accessibility, context, selection, false, annotations);
result = new ExternalProcedureDeclaration(new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, declarationType, asTypeName, asTypeContext, accessibility, context, selection, false, annotations);
}
else if (declarationType == DeclarationType.PropertyGet)
{
Expand Down
4 changes: 3 additions & 1 deletion Rubberduck.Parsing/Symbols/ExternalProcedureDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Rubberduck.VBEditor;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Parsing.Grammar;

namespace Rubberduck.Parsing.Symbols
{
Expand All @@ -16,6 +17,7 @@ public sealed class ExternalProcedureDeclaration : Declaration, IDeclarationWith
Declaration parentScope,
DeclarationType declarationType,
string asTypeName,
VBAParser.AsTypeClauseContext asTypeContext,
Accessibility accessibility,
ParserRuleContext context,
Selection selection,
Expand All @@ -34,7 +36,7 @@ public sealed class ExternalProcedureDeclaration : Declaration, IDeclarationWith
context,
selection,
false,
null,
asTypeContext,
isBuiltIn,
annotations,
null)
Expand Down
1 change: 0 additions & 1 deletion Rubberduck.Parsing/VBA/ComponentParseTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using NLog;
using Rubberduck.Parsing.Annotations;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Nodes;
using Rubberduck.Parsing.Preprocessing;
using Rubberduck.Parsing.Symbols;
using Rubberduck.VBEditor;
Expand Down
1 change: 0 additions & 1 deletion Rubberduck.Parsing/VBA/ModuleState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Antlr4.Runtime;
using Antlr4.Runtime.Tree;
using Rubberduck.Parsing.Annotations;
using Rubberduck.Parsing.Nodes;
using Rubberduck.Parsing.Symbols;

namespace Rubberduck.Parsing.VBA
Expand Down
121 changes: 0 additions & 121 deletions Rubberduck.Parsing/VBA/Nodes/ProcedureNode.cs

This file was deleted.

1 change: 0 additions & 1 deletion Rubberduck.Parsing/VBA/RubberduckParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using System.Diagnostics;
using Rubberduck.Parsing.Annotations;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Nodes;
using Rubberduck.VBEditor.Extensions;
using System.IO;
using NLog;
Expand Down
1 change: 0 additions & 1 deletion Rubberduck.Parsing/VBA/RubberduckParserState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Antlr4.Runtime;
using Antlr4.Runtime.Tree;
using Microsoft.Vbe.Interop;
using Rubberduck.Parsing.Nodes;
using Rubberduck.Parsing.Symbols;
using Rubberduck.VBEditor;
using Rubberduck.Parsing.Annotations;
Expand Down

0 comments on commit c4aea62

Please sign in to comment.