Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion RetailCoder.VBE/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ private void RefreshSelection()

private bool ShouldEvaluateCanExecute(Declaration selectedDeclaration, ParserState currentStatus)
{
return _lastStatus != currentStatus || (selectedDeclaration != null && !selectedDeclaration.Equals(_lastSelectedDeclaration));
return _lastStatus != currentStatus ||
(selectedDeclaration != null && !selectedDeclaration.Equals(_lastSelectedDeclaration)) ||
(selectedDeclaration == null && _lastSelectedDeclaration != null);
}

private void _configService_SettingsChanged(object sender, EventArgs e)
Expand Down
8 changes: 4 additions & 4 deletions RetailCoder.VBE/Inspections/InspectionsUI.de.resx
Original file line number Diff line number Diff line change
@@ -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 @@ -453,7 +453,7 @@
<value>Übergebe Parameter als Wert</value>
</data>
<data name="QuickFixUseTypedFunction_" xml:space="preserve">
<value>Ändere '{0}$' zu '{0}'</value>
<value>Ändere '{0}' zu '{1}'</value>
</data>
<data name="QuickFix_ThisModule" xml:space="preserve">
<value>Verarbeite alle Vorkommen im Modul</value>
Expand Down Expand Up @@ -521,4 +521,4 @@
<data name="ObjectVariableNotSetInspectionName" xml:space="preserve">
<value>Zuweisung in eine Objektvariable benötigt das 'Set'-Schlüsselwort.</value>
</data>
</root>
</root>
8 changes: 4 additions & 4 deletions RetailCoder.VBE/Inspections/InspectionsUI.resx
Original file line number Diff line number Diff line change
@@ -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 @@ -453,7 +453,7 @@
<value>Pass parameter by value</value>
</data>
<data name="QuickFixUseTypedFunction_" xml:space="preserve">
<value>Change '{0}' to '{0}$'</value>
<value>Change '{0}' to '{1}'</value>
</data>
<data name="QuickFix_ThisModule" xml:space="preserve">
<value>Fix all occurrences in module</value>
Expand Down Expand Up @@ -522,4 +522,4 @@
<data name="ObjectVariableNotSetInspectionName" xml:space="preserve">
<value>Object variable assignment requires 'Set' keyword</value>
</data>
</root>
</root>
5 changes: 2 additions & 3 deletions RetailCoder.VBE/Inspections/ObjectVariableNotSetInspection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public ObjectVariableNotSetInspection(RubberduckParserState state)
Tokens.Long,
Tokens.LongLong,
Tokens.Single,
Tokens.String
Tokens.String,
Tokens.Variant
};

public override IEnumerable<InspectionResultBase> GetInspectionResults()
Expand All @@ -97,8 +98,6 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
return setStmtContext != null && setStmtContext.LET() == null;
}))
.Select(reference => new ObjectVariableNotSetInspectionResult(this, reference));


}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override string Description
public class UntypedFunctionUsageQuickFix : CodeInspectionQuickFix
{
public UntypedFunctionUsageQuickFix(ParserRuleContext context, QualifiedSelection selection)
: base(context, selection, string.Format(InspectionsUI.QuickFixUseTypedFunction_, context.GetText()))
: base(context, selection, string.Format(InspectionsUI.QuickFixUseTypedFunction_, context.GetText(), context.GetText() + "$"))
{
}

Expand All @@ -49,6 +49,7 @@ public override void Fix()

var result = lines.Replace(originalInstruction, newInstruction);
module.ReplaceLine(selection.StartLine, result);
// FIXME trigger reparse
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ public EncapsulateFieldRefactoring(VBE vbe, IRefactoringPresenterFactory<IEncaps
_factory = factory;
}

public bool CanExecute(QualifiedSelection selection)
{
return false;
}

public void Refactor()
{
var presenter = _factory.Create();
Expand Down
2 changes: 0 additions & 2 deletions RetailCoder.VBE/Refactorings/IRefactoring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ public interface IRefactoring
void Refactor();
void Refactor(QualifiedSelection target);
void Refactor(Declaration target);

bool CanExecute(QualifiedSelection selection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,23 @@ namespace Rubberduck.Refactorings.IntroduceField
{
public class IntroduceFieldRefactoring : IRefactoring
{
private readonly IList<Declaration> _declarations;
private readonly VBE _vbe;
private readonly RubberduckParserState _parserState;
private readonly IMessageBox _messageBox;

private IList<Declaration> _declarations;
private Declaration _target;

public IntroduceFieldRefactoring(VBE vbe, RubberduckParserState parserState, IMessageBox messageBox)
{
_declarations =
parserState.AllDeclarations.Where(i => !i.IsBuiltIn && i.DeclarationType == DeclarationType.Variable)
.ToList();
_vbe = vbe;
_parserState = parserState;
_messageBox = messageBox;
}

public bool CanExecute(QualifiedSelection selection)
{
_declarations = _parserState.AllUserDeclarations.ToList();

_target = _declarations.FindVariable(selection);
return _target != null;
}

public void Refactor()
{
var selection = _vbe.ActiveCodePane.GetQualifiedSelection();

if (!selection.HasValue)
{
_messageBox.Show(RubberduckUI.PromoteVariable_InvalidSelection, RubberduckUI.IntroduceField_Caption,
Expand All @@ -52,14 +43,16 @@ public void Refactor()

public void Refactor(QualifiedSelection selection)
{
if (!CanExecute(selection))
var target = _declarations.FindVariable(selection);

if (target == null)
{
_messageBox.Show(RubberduckUI.PromoteVariable_InvalidSelection, RubberduckUI.IntroduceParameter_Caption,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}

PromoteVariable(_target);
PromoteVariable(target);
}

public void Refactor(Declaration target)
Expand All @@ -85,35 +78,33 @@ private void PromoteVariable(Declaration target)
return;
}

_target = target;

RemoveVariable();
AddField();
RemoveVariable(target);
AddField(target);
}

private void AddField()
private void AddField(Declaration target)
{
var module = _target.QualifiedName.QualifiedModuleName.Component.CodeModule;
module.InsertLines(module.CountOfDeclarationLines + 1, GetFieldDefinition());
var module = target.QualifiedName.QualifiedModuleName.Component.CodeModule;
module.InsertLines(module.CountOfDeclarationLines + 1, GetFieldDefinition(target));
}

private void RemoveVariable()
private void RemoveVariable(Declaration target)
{
Selection selection;
var declarationText = _target.Context.GetText();
var multipleDeclarations = _target.HasMultipleDeclarationsInStatement();
var declarationText = target.Context.GetText();
var multipleDeclarations = target.HasMultipleDeclarationsInStatement();

var variableStmtContext = _target.GetVariableStmtContext();
var variableStmtContext = target.GetVariableStmtContext();

if (!multipleDeclarations)
{
declarationText = variableStmtContext.GetText();
selection = _target.GetVariableStmtContextSelection();
selection = target.GetVariableStmtContextSelection();
}
else
{
selection = new Selection(_target.Context.Start.Line, _target.Context.Start.Column,
_target.Context.Stop.Line, _target.Context.Stop.Column);
selection = new Selection(target.Context.Start.Line, target.Context.Start.Column,
target.Context.Stop.Line, target.Context.Stop.Column);
}

var oldLines = _vbe.ActiveCodePane.CodeModule.GetLines(selection);
Expand All @@ -123,9 +114,9 @@ private void RemoveVariable()

if (multipleDeclarations)
{
selection = _target.GetVariableStmtContextSelection();
selection = target.GetVariableStmtContextSelection();
newLines = RemoveExtraComma(_vbe.ActiveCodePane.CodeModule.GetLines(selection).Replace(oldLines, newLines),
_target.CountOfDeclarationsInStatement(), _target.IndexOfVariableDeclarationInStatement());
target.CountOfDeclarationsInStatement(), target.IndexOfVariableDeclarationInStatement());
}

var newLinesWithoutExcessSpaces = newLines.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
Expand Down Expand Up @@ -189,9 +180,9 @@ private string RemoveExtraComma(string str, int numParams, int indexRemoved)
return str.Remove(str.NthIndexOf(',', commaToRemove), 1);
}

private string GetFieldDefinition()
private string GetFieldDefinition(Declaration target)
{
return "Private " + _target.IdentifierName + " As " + _target.AsTypeName;
return "Private " + target.IdentifierName + " As " + target.AsTypeName;
}
}
}
Loading