Skip to content

Commit a6fe019

Browse files
committed
Merge branch 'rubberduck-vba/next' into 1584_UnreachableSelectCase
2 parents 5c4fe62 + 4cb8c51 commit a6fe019

File tree

4 files changed

+71
-8
lines changed

4 files changed

+71
-8
lines changed

Rubberduck.Core/Refactorings/MoveCloserToUsage/MoveCloserToUsageRefactoring.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Windows.Forms;
55
using Antlr4.Runtime;
6+
using Antlr4.Runtime.Misc;
67
using Rubberduck.Common;
78
using Rubberduck.Parsing.Grammar;
89
using Rubberduck.Parsing.Rewriter;
@@ -198,7 +199,8 @@ private void UpdateCallsToOtherModule(IEnumerable<IdentifierReference> reference
198199
}
199200

200201
var rewriter = _state.GetRewriter(reference.QualifiedModuleName);
201-
rewriter.Replace(parent as ParserRuleContext, reference.IdentifierName);
202+
var tokenInterval = Interval.Of(parent.SourceInterval.a, reference.Context.SourceInterval.b);
203+
rewriter.Replace(tokenInterval, reference.IdentifierName);
202204

203205
_rewriters.Add(rewriter);
204206
}

Rubberduck.Deployment/BuildRegistryScript.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,17 @@ try
9595
if (Test-Path -Path $regFile -PathType Leaf)
9696
{
9797
$datetime = Get-Date;
98-
& reg.exe import $regFile;
98+
if ([Environment]::Is64BitOperatingSystem)
99+
{
100+
& reg.exe import $regFile /reg:32;
101+
& reg.exe import $regFile /reg:64;
102+
}
103+
else
104+
{
105+
& reg.exe import $regFile;
106+
}
99107
& reg.exe import ($dir + "\RubberduckAddinRegistry.reg");
100-
Move-Item -Path $regFile -Destination ($regFile + ".imported_" + $datetime.ToUniversalTime().ToString("yyyyMMddhhmmss") + ".txt" )
108+
Move-Item -Path $regFile -Destination ($regFile + ".imported_" + $datetime.ToUniversalTime().ToString("yyyyMMddHHmmss") + ".txt" )
101109
}
102110
}
103111
else

Rubberduck.Deployment/Writers/LocalDebugRegistryWriter.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class LocalDebugRegistryWriter : IRegistryWriter
1313
{
1414
public string Write(IOrderedEnumerable<RegistryEntry> entries)
1515
{
16+
//System.Diagnostics.Debugger.Launch(); //uncomment if need to debug
1617
var sb = new StringBuilder("Windows Registry Editor Version 5.00" + Environment.NewLine + Environment.NewLine);
1718
var distinctKeys = new List<string>();
1819

@@ -30,12 +31,14 @@ public string Write(IOrderedEnumerable<RegistryEntry> entries)
3031
throw new InvalidOperationException("Unexpected registry entry: " + entry.Key);
3132
}
3233

33-
var value = ReplacePlaceholder(entry.Value, entry.Bitness);
34-
35-
var key = Registry.CurrentUser.CreateSubKey(entry.Key);
36-
if (!(string.IsNullOrWhiteSpace(entry.Name) && string.IsNullOrWhiteSpace(value)))
34+
if (Environment.Is64BitOperatingSystem)
35+
{
36+
MakeRegistryEntries(entry, RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32));
37+
MakeRegistryEntries(entry, RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64));
38+
}
39+
else
3740
{
38-
key.SetValue(entry.Name, value);
41+
MakeRegistryEntries(entry, Registry.CurrentUser);
3942
}
4043

4144
if (!distinctKeys.Contains(entry.Key))
@@ -53,6 +56,18 @@ public string Write(IOrderedEnumerable<RegistryEntry> entries)
5356
return sb.ToString();
5457
}
5558

59+
private void MakeRegistryEntries(RegistryEntry entry, RegistryKey hKey)
60+
{
61+
var key = hKey.CreateSubKey(entry.Key);
62+
63+
var value = ReplacePlaceholder(entry.Value, entry.Bitness);
64+
65+
if (!(string.IsNullOrWhiteSpace(entry.Name) && string.IsNullOrWhiteSpace(value)))
66+
{
67+
key.SetValue(entry.Name, value);
68+
}
69+
}
70+
5671
//Cache the string so we call the AssemblyDirectory only once
5772
private string _currentPath;
5873
private string ReplacePlaceholder(string value, Bitness bitness)

RubberduckTests/Refactoring/MoveCloserToUsageTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,5 +880,43 @@ Private Sub Foo()
880880
Assert.AreEqual(inputCode, rewriter.GetText());
881881
}
882882
}
883+
884+
[Test]
885+
[Category("Move Closer")]
886+
[Category("Refactorings")]
887+
public void MoveCloser_RespectsObjectProperties_InUsages()
888+
{
889+
const string input = @"Option Explicit
890+
891+
Public Sub Test()
892+
Dim foo As Object
893+
Debug.Print ""Some statements between""
894+
Debug.Print ""Declaration and first usage!""
895+
Set foo = CreateObject(""Some.Object"")
896+
foo.Name = ""FooName""
897+
foo.OtherProperty = 1626
898+
End Sub";
899+
900+
const string expected = @"Option Explicit
901+
902+
Public Sub Test()
903+
Debug.Print ""Some statements between""
904+
Debug.Print ""Declaration and first usage!""
905+
Dim foo As Object
906+
Set foo = CreateObject(""Some.Object"")
907+
foo.Name = ""FooName""
908+
foo.OtherProperty = 1626
909+
End Sub";
910+
911+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(input, out var component);
912+
using (var state = MockParser.CreateAndParse(vbe.Object))
913+
{
914+
var messageBox = new Mock<IMessageBox>();
915+
var refactoring = new MoveCloserToUsageRefactoring(vbe.Object, state, messageBox.Object);
916+
refactoring.Refactor(state.AllUserDeclarations.First(d => d.DeclarationType == DeclarationType.Variable));
917+
var rewriter = state.GetRewriter(component);
918+
Assert.AreEqual(expected, rewriter.GetText());
919+
}
920+
}
883921
}
884922
}

0 commit comments

Comments
 (0)