Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Hosch250 committed Jun 4, 2015
2 parents fb73040 + ba5f727 commit a1adda5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
using Microsoft.Vbe.Interop;
using Rubberduck.Parsing;
using Rubberduck.VBEditor;
using Rubberduck.VBEditor.Extensions;

namespace Rubberduck.Refactorings.ReorderParameters
{
public class ReorderParametersPresenterFactory : IRefactoringPresenterFactory<ReorderParametersPresenter>
{
private readonly VBE _vbe;
private readonly IActiveCodePaneEditor _editor;
private readonly IReorderParametersDialog _view;
private readonly VBProjectParseResult _parseResult;

public ReorderParametersPresenterFactory(VBE vbe, IReorderParametersDialog view,
public ReorderParametersPresenterFactory(IActiveCodePaneEditor editor, IReorderParametersDialog view,
VBProjectParseResult parseResult)
{
_vbe = vbe;
_editor = editor;
_view = view;
_parseResult = parseResult;
}

public ReorderParametersPresenter Create()
{
var selection = _vbe.ActiveCodePane.GetSelection();
var model = new ReorderParametersModel(_parseResult, selection);
var selection = _editor.GetSelection();
if (selection == null)
{
return null;
}

var model = new ReorderParametersModel(_parseResult, selection.Value);
return new ReorderParametersPresenter(_view, model);
}
}
Expand Down
6 changes: 0 additions & 6 deletions RetailCoder.VBE/UI/UnitTesting/TestExplorerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,6 @@ private void AddTestModuleButtonClicked(object sender, EventArgs e)
OnButtonClick(OnAddTestModuleButtonClick);
}

private void TestExplorerWindowFormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
Hide();
}

public void ClearProgress()
{
_completedCount = 0;
Expand Down
20 changes: 11 additions & 9 deletions Rubberduck.Parsing/Reflection/Member.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,26 @@ public MemberAttribute GetAttribute<TAttribute>() where TAttribute : MemberAttri
return GetAttribute(new TAttribute().Name);
}

private static readonly string[] _keywords =
new[] { "Dim ", "Private ", "Public ", "Friend ",
"Function ", "Sub ", "Property ",
"Static ", "Const ", "Global ", "Enum ", "Type ", "Declare " };
private static readonly string[] Keywords =
{
"Dim ", "Private ", "Public ", "Friend ",
"Function ", "Sub ", "Property ",
"Static ", "Const ", "Global ", "Enum ", "Type ", "Declare "
};

public static bool TryParse(string[] body, QualifiedModuleName qualifiedModuleName, out Member result)
{
var signature = body.FirstOrDefault(line => _keywords.Any(line.StartsWith));
var signature = body.FirstOrDefault(line => Keywords.Any(line.Trim().StartsWith));
if (signature == null)
{
result = null;
return false;
}

signature = signature.Replace("\r", string.Empty);
body = body.Select(line => line.Replace("\r", string.Empty)).ToArray();
signature = signature.Trim().Replace("\r", string.Empty);
body = body.Select(line => line.Trim().Replace("\r", string.Empty)).ToArray();

var withoutKeyword = signature.Substring((_keywords.First(keyword => signature.StartsWith(keyword))).Length);
var withoutKeyword = signature.Substring((Keywords.First(keyword => signature.StartsWith(keyword))).Length);
var name = withoutKeyword.Split(' ')[1]
.Split('(')[0];

Expand All @@ -102,7 +104,7 @@ public static bool TryParse(string[] body, QualifiedModuleName qualifiedModuleNa

var signatureLineIndex = body.ToList().IndexOf(signature);
var attributes = MemberAttribute.GetAttributes(body.Take(signatureLineIndex)
.Where(line => line.StartsWith("'@")));
.Where(line => line.Trim().StartsWith("'@")));

result = new Member(type, qualifiedModuleName.QualifyMemberName(name), signature, body, attributes);
return true;
Expand Down
4 changes: 2 additions & 2 deletions Rubberduck.Parsing/VBComponentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static bool HasAttribute<TAttribute>(this CodeModule code) where TAttribu
return HasAttribute(code, new TAttribute().Name);
}

public static bool HasAttribute(this CodeModule code, string name)
private static bool HasAttribute(this CodeModule code, string name)
{
if (code.CountOfDeclarationLines == 0)
{
Expand All @@ -31,7 +31,7 @@ public static IEnumerable<Member> GetMembers(this VBComponent component, vbext_P
return GetMembers(component.CodeModule, procedureKind);
}

public static IEnumerable<Member> GetMembers(this CodeModule module, vbext_ProcKind? procedureKind = null)
private static IEnumerable<Member> GetMembers(this CodeModule module, vbext_ProcKind? procedureKind = null)
{
var currentLine = module.CountOfDeclarationLines + 1;
while (currentLine < module.CountOfLines)
Expand Down

0 comments on commit a1adda5

Please sign in to comment.