Skip to content

Commit 7444a96

Browse files
committed
2 parents 7dee010 + 97dfdfc commit 7444a96

File tree

49 files changed

+3018
-887
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3018
-887
lines changed

RetailCoder.VBE/Inspections/ChangeParameterByRefByValQuickFix.cs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System;
12
using Antlr4.Runtime;
3+
using Rubberduck.Parsing.Grammar;
24
using Rubberduck.VBEditor;
35

46
namespace Rubberduck.Inspections
@@ -15,16 +17,38 @@ public ChangeParameterByRefByValQuickFix(ParserRuleContext context, QualifiedSel
1517

1618
public override void Fix()
1719
{
18-
var parameter = Context.GetText();
19-
var newContent = string.Concat(_newToken, " ", parameter);
20-
var selection = Selection.Selection;
21-
22-
var module = Selection.QualifiedName.Component.CodeModule;
20+
try
2321
{
24-
var lines = module.GetLines(selection.StartLine, selection.LineCount);
25-
var result = lines.Replace(parameter, newContent);
26-
module.ReplaceLine(selection.StartLine, result);
22+
dynamic context = Context;
23+
var parameter = Context.GetText();
24+
dynamic args = Context.parent;
25+
var argList = args.GetText();
26+
var module = Selection.QualifiedName.Component.CodeModule;
27+
{
28+
string result;
29+
if (context.OPTIONAL() != null)
30+
{
31+
result = parameter.Replace(Tokens.Optional, Tokens.Optional + ' ' + _newToken);
32+
}
33+
else
34+
{
35+
result = _newToken + ' ' + parameter;
36+
}
37+
38+
dynamic proc = args.parent;
39+
var startLine = proc.GetType().GetProperty("Start").GetValue(proc).Line;
40+
var stopLine = proc.GetType().GetProperty("Stop").GetValue(proc).Line;
41+
var code = module.GetLines(startLine, stopLine - startLine + 1);
42+
result = code.Replace(argList, argList.Replace(parameter, result));
43+
44+
foreach (var line in result.Split(new[] {"\r\n"}, StringSplitOptions.None))
45+
{
46+
module.ReplaceLine(startLine++, line);
47+
}
48+
}
2749
}
50+
// ReSharper disable once EmptyGeneralCatchClause
51+
catch { }
2852
}
2953
}
3054
}

RetailCoder.VBE/Inspections/InspectionsUI.de.resx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema
@@ -59,7 +59,7 @@
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
62-
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
62+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
6363
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
6464
<xsd:element name="root" msdata:IsDataSet="true">
6565
<xsd:complexType>
@@ -564,4 +564,31 @@ Falls der Parameter 'null' sein kann, bitte dieses Auftreten ignorieren. 'null'
564564
<data name="MalformedAnnotationInspectionMeta" xml:space="preserve">
565565
<value>Eine Annotation in einem Kommentar konnte nicht gelesen werden.</value>
566566
</data>
567-
</root>
567+
<data name="IntroduceLocalVariableQuickFix">
568+
<value>Introduce local variable</value>
569+
</data>
570+
<data name="UndeclaredVariableInspectionMeta">
571+
<value>Code that uses undeclared variables does not compile when Option Explicit is specified. Undeclared variables are always Variant, a data type that incurs unnecessary overhead and storage.</value>
572+
</data>
573+
<data name="WriteOnlyPropertyQuickFix">
574+
<value>Add property get</value>
575+
</data>
576+
<data name="ModuleScopeDimKeywordInspectionMeta">
577+
<value>The 'Public' keyword can only be used at module level; its counterpart 'Private' can also only be used at module level. 'Dim' however, can be used to declare both procedure and module scope variables. For consistency, it would be preferable to reserve 'Dim' for locals, and thus to use 'Private' instead of 'Dim' at module level.</value>
578+
</data>
579+
<data name="ChangeDimToPrivateQuickFix">
580+
<value>Replace 'Dim' with 'Private'</value>
581+
</data>
582+
<data name="UndeclaredVariableInspectionName">
583+
<value>Undeclared variable</value>
584+
</data>
585+
<data name="ModuleScopeDimKeywordInspectionName">
586+
<value>Use of 'Dim' keyword at module level</value>
587+
</data>
588+
<data name="UndeclaredVariableInspectionResultFormat">
589+
<value>Local variable '{0}' is not declared</value>
590+
</data>
591+
<data name="ModuleScopeDimKeywordInspectionResultFormat">
592+
<value>Module-level variable '{0}' is declared with the 'Dim' keyword.</value>
593+
</data>
594+
</root>

RetailCoder.VBE/Inspections/InspectionsUI.fr.resx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema
@@ -59,7 +59,7 @@
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
62-
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
62+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
6363
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
6464
<xsd:element name="root" msdata:IsDataSet="true">
6565
<xsd:complexType>
@@ -552,7 +552,8 @@
552552
<value>Remplacer la fonction '{0}' par la fonction typée équivalente</value>
553553
</data>
554554
<data name="UntypedFunctionUsageInspectionMeta" xml:space="preserve">
555-
<value />
555+
<value>Une fonction équivalente retourne une valeur 'String' et devrait préférablement être utilisée afin d'éviter les conversions implicites.
556+
Si le paramètre peut être nul, ignorer ce résultat; passer une valeur nulle à cette fonction causerait une erreur d'exécution 'type mismatch'.</value>
556557
</data>
557558
<data name="ChangeDimToPrivateQuickFix" xml:space="preserve">
558559
<value>Remplacer 'Dim' par 'Private'</value>
@@ -579,4 +580,16 @@
579580
<value>La variable locale '{0}' n'est pas déclarée</value>
580581
<comment>{0} variable name</comment>
581582
</data>
582-
</root>
583+
<data name="WriteOnlyPropertyQuickFix">
584+
<value>Ajouter un accesseur 'Property Get'</value>
585+
</data>
586+
<data name="MalformedAnnotationInspectionName">
587+
<value>Annotation incorrecte</value>
588+
</data>
589+
<data name="MalformedAnnotationInspectionResultFormat">
590+
<value>Annotation '{0}' incorrecte.</value>
591+
</data>
592+
<data name="MalformedAnnotationInspectionMeta">
593+
<value>Un commentaire contient une annotation spécifiée incorrectement.</value>
594+
</data>
595+
</root>

RetailCoder.VBE/Inspections/InspectionsUI.resx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema
@@ -59,7 +59,7 @@
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
62-
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
62+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
6363
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
6464
<xsd:element name="root" msdata:IsDataSet="true">
6565
<xsd:complexType>
@@ -557,16 +557,16 @@ If the parameter can be null, ignore this inspection result; passing a null valu
557557
<value>{0} '{1}' is implicitly 'Variant'</value>
558558
</data>
559559
<data name="MalformedAnnotationInspectionMeta" xml:space="preserve">
560-
<value>An annotation comment is malformed.</value>
560+
<value>An annotation comment is incorrectly specified.</value>
561561
</data>
562562
<data name="MalformedAnnotationInspectionName" xml:space="preserve">
563-
<value>Malformed annotation</value>
563+
<value>Incorrect annotation</value>
564564
</data>
565565
<data name="MalformedAnnotationInspectionResultFormat" xml:space="preserve">
566-
<value>Malformed '{0}' annotation.</value>
566+
<value>Incorrect '{0}' annotation.</value>
567567
</data>
568568
<data name="WriteOnlyPropertyQuickFix" xml:space="preserve">
569-
<value>Add property get</value>
569+
<value>Add property get accessor</value>
570570
</data>
571571
<data name="ChangeDimToPrivateQuickFix" xml:space="preserve">
572572
<value>Replace 'Dim' with 'Private'</value>
@@ -593,4 +593,4 @@ If the parameter can be null, ignore this inspection result; passing a null valu
593593
<data name="IntroduceLocalVariableQuickFix" xml:space="preserve">
594594
<value>Introduce local variable</value>
595595
</data>
596-
</root>
596+
</root>

RetailCoder.VBE/Inspections/PassParameterByValueQuickFix.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Linq;
23
using Antlr4.Runtime;
34
using Rubberduck.Common;
@@ -73,14 +74,42 @@ private void FixMethods()
7374

7475
private void FixMethod(VBAParser.ArgContext context, QualifiedSelection qualifiedSelection)
7576
{
76-
var selectionLength = context.BYREF() == null ? 0 : 6;
77+
var parameter = context.GetText();
78+
var argList = context.parent.GetText();
7779

7880
var module = qualifiedSelection.QualifiedName.Component.CodeModule;
7981
{
80-
var lines = module.GetLines(context.Start.Line, 1);
82+
string result;
83+
if (context.BYREF() != null)
84+
{
85+
result = parameter.Replace(Tokens.ByRef, Tokens.ByVal);
86+
}
87+
else if (context.OPTIONAL() != null)
88+
{
89+
result = parameter.Replace(Tokens.Optional, Tokens.Optional + ' ' + Tokens.ByVal);
90+
}
91+
else
92+
{
93+
result = Tokens.ByVal + ' ' + parameter;
94+
}
8195

82-
var result = lines.Remove(context.Start.Column, selectionLength).Insert(context.Start.Column, Tokens.ByVal + ' ');
83-
module.ReplaceLine(context.Start.Line, result);
96+
var startLine = 0;
97+
var stopLine = 0;
98+
try
99+
{
100+
dynamic proc = context.parent.parent;
101+
startLine = proc.GetType().GetProperty("Start").GetValue(proc).Line;
102+
stopLine = proc.GetType().GetProperty("Stop").GetValue(proc).Line;
103+
}
104+
catch { return; }
105+
106+
var code = module.GetLines(startLine, stopLine - startLine + 1);
107+
result = code.Replace(argList, argList.Replace(parameter, result));
108+
109+
foreach (var line in result.Split(new[] { "\r\n" }, StringSplitOptions.None))
110+
{
111+
module.ReplaceLine(startLine++, line);
112+
}
84113
}
85114
}
86115
}

RetailCoder.VBE/Root/RubberduckModule.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,9 @@ private IEnumerable<ICommandMenuItem> GetRubberduckCommandBarItems()
412412
KernelInstance.Get<ReparseCommandMenuItem>(),
413413
KernelInstance.Get<ShowParserErrorsCommandMenuItem>(),
414414
KernelInstance.Get<ContextSelectionLabelMenuItem>(),
415-
#if DEBUG
416-
KernelInstance.Get<SerializeDeclarationsCommandMenuItem>()
417-
#endif
415+
//#if DEBUG
416+
// KernelInstance.Get<SerializeDeclarationsCommandMenuItem>()
417+
//#endif
418418
};
419419
}
420420

RetailCoder.VBE/UI/Command/MenuItems/CommandBars/SerializeDeclarationsCommandMenuItem.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ public void Persist(string path, IEnumerable<SerializableDeclaration> items)
8181

8282
public IEnumerable<SerializableDeclaration> Load(string path)
8383
{
84-
if (string.IsNullOrEmpty(FullPath)) { throw new InvalidOperationException(); }
84+
if (string.IsNullOrEmpty(path)) { throw new InvalidOperationException(); }
8585
throw new NotImplementedException();
8686
}
87-
88-
public string FullPath { get; set; }
8987
}
9088
}

RetailCoder.VBE/UI/RubberduckUI.de.resx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1774,4 +1774,51 @@ Allen Sternguckern, Likern &amp; Followern, für das warme Kribbeln
17741774
<data name="RubberduckReloadFailure_Message">
17751775
<value>Werkzeugfenster wurden nicht korrekt entfernt und/oder konnten nicht wieder hergestellt werden; Die VBE könnte instabil sein. Rubberduck wird beim nächsten Start der VBE normal laden.</value>
17761776
</data>
1777-
</root>
1777+
<data name="IndenterSettings_PreviewCode">
1778+
<value>Public Enum ExampleEnum
1779+
' Enum comment.
1780+
Foo
1781+
Bar ' Member comment.
1782+
End Enum
1783+
1784+
' Example Procedure
1785+
Sub ExampleProc()
1786+
1787+
' SMART INDENTER
1788+
' Original VB6 code graciously offered to Rubberduck by Stephen Bullen &amp; Rob Bovey
1789+
' © 2016 by Rubberduck VBA.
1790+
1791+
Dim count As Integer
1792+
Static name As String
1793+
1794+
If YouLikeRubberduck Then
1795+
' Star us on GitHub http://github.com/rubberduck-vba/Rubberduck
1796+
' Follow us on Twitter @rubberduckvba
1797+
' Visit http://rubberduckvba.com for news and updates
1798+
1799+
Select Case X
1800+
Case "A"
1801+
' If you have any comments or suggestions, _
1802+
or find valid VBA code that isn't indented correctly,
1803+
1804+
#If VBA6 Then
1805+
MsgBox "Contact contact@rubberduck-vba.com"
1806+
#End If
1807+
1808+
Case "Continued strings and parameters can be" _
1809+
&amp; "lined up for easier reading, optionally ignoring" _
1810+
&amp; "any operators (&amp;+, etc) at the start of the line."
1811+
1812+
Debug.Print "X&lt;&gt;1"
1813+
End Select 'Case X
1814+
End If 'More Tools? Suggestions http://github.com/rubberduck-vba/Rubberduck/Issues/New
1815+
1816+
End Sub</value>
1817+
</data>
1818+
<data name="ParserErrorToolTipText">
1819+
<value>{0} module(s) failed to parse; click for details.</value>
1820+
</data>
1821+
<data name="ReparseToolTipText">
1822+
<value>{0}. Click to refresh.</value>
1823+
</data>
1824+
</root>

0 commit comments

Comments
 (0)