Skip to content

Commit

Permalink
fixed DeclareAsExplicitVariantQuickFix
Browse files Browse the repository at this point in the history
  • Loading branch information
retailcoder committed Sep 27, 2015
1 parent a437a78 commit 4fa4dc2
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 52 deletions.
Expand Up @@ -37,7 +37,8 @@ public override void Fix()

// methods return empty string if soft-cast context is null - just concat results:
string originalInstruction;
var fix = DeclareExplicitVariant(Context.Parent as VBAParser.VariableSubStmtContext, out originalInstruction);

var fix = DeclareExplicitVariant(Context as VBAParser.VariableSubStmtContext, out originalInstruction);

if (string.IsNullOrEmpty(originalInstruction))
{
Expand All @@ -46,7 +47,12 @@ public override void Fix()

if (string.IsNullOrEmpty(originalInstruction))
{
fix = DeclareExplicitVariant(Context.Parent as VBAParser.ArgContext, out originalInstruction);
fix = DeclareExplicitVariant(Context as VBAParser.ArgContext, out originalInstruction);
}

if (string.IsNullOrEmpty(originalInstruction))
{
return;
}

var fixedCodeLine = codeLine.Replace(originalInstruction, fix);
Expand Down
8 changes: 4 additions & 4 deletions RetailCoder.VBE/Rubberduck.csproj
Expand Up @@ -400,10 +400,10 @@
<DesignTime>True</DesignTime>
<DependentUpon>RubberduckUI.de.resx</DependentUpon>
</Compile>
<Compile Include="UI\RubberduckUI.jp.Designer.cs">
<Compile Include="UI\RubberduckUI.ja.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>RubberduckUI.jp.resx</DependentUpon>
<DependentUpon>RubberduckUI.ja.resx</DependentUpon>
</Compile>
<Compile Include="UI\RubberduckUI.sv.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -756,9 +756,9 @@
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>RubberduckUI.de.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="UI\RubberduckUI.jp.resx">
<EmbeddedResource Include="UI\RubberduckUI.ja.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>RubberduckUI.jp.Designer.cs</LastGenOutput>
<LastGenOutput>RubberduckUI.ja.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="UI\RubberduckUI.sv.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Expand Down Expand Up @@ -59,7 +59,7 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
Expand Down Expand Up @@ -623,7 +623,7 @@
<data name="Language_FR" xml:space="preserve">
<value>フランス語</value>
</data>
<data name="Language_JP" xml:space="preserve">
<data name="Language_JA" xml:space="preserve">
<value>日本語</value>
</data>
<data name="RemoveParamsDialog_Caption" xml:space="preserve">
Expand Down Expand Up @@ -1113,7 +1113,7 @@
<data name="RubberduckMenu_Navigate" xml:space="preserve">
<value>&amp;vナビゲート</value>
</data>
<data name="Language_DE">
<data name="Language_DE" xml:space="preserve">
<value />
</data>
</root>
</root>
9 changes: 3 additions & 6 deletions Rubberduck.Parsing/Symbols/DeclarationSymbolsListener.cs
Expand Up @@ -3,7 +3,6 @@
using Microsoft.Vbe.Interop;
using Rubberduck.Parsing.Grammar;
using Rubberduck.VBEditor;
using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodePane;

namespace Rubberduck.Parsing.Symbols
{
Expand All @@ -13,21 +12,19 @@ public class DeclarationSymbolsListener : VBABaseListener
public Declarations Declarations { get { return _declarations; } }

private readonly QualifiedModuleName _qualifiedName;
private readonly ICodePaneWrapperFactory _wrapperFactory;
private readonly Declaration _moduleDeclaration;

private string _currentScope;
private Declaration _parentDeclaration;

public DeclarationSymbolsListener(VBComponentParseResult result, ICodePaneWrapperFactory wrapperFactory)
: this(result.QualifiedName, Accessibility.Implicit, result.Component.Type, wrapperFactory)
public DeclarationSymbolsListener(VBComponentParseResult result)
: this(result.QualifiedName, Accessibility.Implicit, result.Component.Type)
{
}

public DeclarationSymbolsListener(QualifiedModuleName qualifiedName, Accessibility componentAccessibility, vbext_ComponentType type, ICodePaneWrapperFactory wrapperFactory)
public DeclarationSymbolsListener(QualifiedModuleName qualifiedName, Accessibility componentAccessibility, vbext_ComponentType type)
{
_qualifiedName = qualifiedName;
_wrapperFactory = wrapperFactory;

var declarationType = type == vbext_ComponentType.vbext_ct_StdModule
? DeclarationType.Module
Expand Down
2 changes: 0 additions & 2 deletions Rubberduck.Parsing/Symbols/VbaStandardLib.cs
Expand Up @@ -2,7 +2,6 @@
using System.Linq;
using System.Reflection;
using Rubberduck.VBEditor;
using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodePane;

namespace Rubberduck.Parsing.Symbols
{
Expand All @@ -13,7 +12,6 @@ internal static class VbaStandardLib
{
private static IEnumerable<Declaration> _standardLibDeclarations;
private static readonly QualifiedModuleName VbaModuleName = new QualifiedModuleName("VBA", "VBA");
private static readonly ICodePaneWrapperFactory WrapperFactory = new CodePaneWrapperFactory();

public static IEnumerable<Declaration> Declarations
{
Expand Down
2 changes: 1 addition & 1 deletion Rubberduck.Parsing/VBComponentParseResult.cs
Expand Up @@ -19,7 +19,7 @@ public VBComponentParseResult(VBComponent component, IParseTree parseTree, IEnum
_comments = comments;
_tokenStream = tokenStream;

var listener = new DeclarationSymbolsListener(_qualifiedName, Accessibility.Implicit, _component.Type, wrapperFactory);
var listener = new DeclarationSymbolsListener(_qualifiedName, Accessibility.Implicit, _component.Type);
var walker = new ParseTreeWalker();
walker.Walk(listener, _parseTree);

Expand Down
2 changes: 1 addition & 1 deletion Rubberduck.Parsing/VBProjectParseResult.cs
Expand Up @@ -18,7 +18,7 @@ public VBProjectParseResult(VBProject project, IEnumerable<VBComponentParseResul

var projectIdentifier = project.Name;
var memberName = new QualifiedMemberName(new QualifiedModuleName(project), projectIdentifier);
var projectDeclaration = new Declaration(memberName, null, null, projectIdentifier, false, false, Accessibility.Global, DeclarationType.Project);
var projectDeclaration = new Declaration(memberName, null, null, projectIdentifier, false, false, Accessibility.Global, DeclarationType.Project, false);
_declarations.Add(projectDeclaration);

foreach (var declaration in VbaStandardLib.Declarations)
Expand Down
Expand Up @@ -180,35 +180,6 @@ public void ImplicitByRefParameter_QuickFixWorks_PassByRef()
Assert.AreEqual(expectedCode, module.Lines());
}

[TestMethod]
public void ImplicitByRefParameter_QuickFixWorks_PassByVal()
{
const string inputCode =
@"Sub Foo(arg1 As Integer)
End Sub";

const string expectedCode =
@"Sub Foo(ByVal arg1 As Integer)
End Sub";

//Arrange
var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none)
.AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputCode)
.Build().Object;
var module = project.VBComponents.Item(0).CodeModule;

var codePaneFactory = new CodePaneWrapperFactory();
var parseResult = new RubberduckParser(codePaneFactory).Parse(project);

var inspection = new ImplicitByRefParameterInspection();
var inspectionResults = inspection.GetInspectionResults(parseResult);

inspectionResults.First().QuickFixes.ElementAt(1).Fix();

Assert.AreEqual(expectedCode, module.Lines());
}

[TestMethod]
public void ImplicitByRefParameter_QuickFixWorks_ParamArrayMustBePassedByRef()
{
Expand Down
Expand Up @@ -124,7 +124,8 @@ public void VariableTypeNotDeclared_ReturnsResult_QuickFixWorks_Parameter()
var inspection = new VariableTypeNotDeclaredInspection();
inspection.GetInspectionResults(parseResult).First().QuickFixes.First().Fix();

Assert.AreEqual(expectedCode, module.Lines());
var actual = module.Lines();
Assert.AreEqual(expectedCode, actual);
}

[TestMethod]
Expand Down

0 comments on commit 4fa4dc2

Please sign in to comment.