Skip to content

Commit 59e0fa7

Browse files
committed
removed unused VbComponentExtensions
1 parent e7264b3 commit 59e0fa7

File tree

8 files changed

+17
-71
lines changed

8 files changed

+17
-71
lines changed

RetailCoder.VBE/Extensions/CodePaneExtensions.cs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,7 @@ public static QualifiedSelection GetSelection(this CodePane code)
2828
}
2929

3030
var selection = new Selection(startLine, startColumn, endLine, endColumn);
31-
return new QualifiedSelection(code.CodeModule.Parent.QualifiedName(), selection);
32-
}
33-
34-
/// <summary>
35-
/// Returns a <see cref="Selection"/> representing the position
36-
/// </summary>
37-
///
38-
/// <param name="selection"> The selection. </param>
39-
/// <returns> A QualifiedSelection object representing the procedure the cursor is currently in. </returns>
40-
public static Selection SelectedProcedure(this CodePane code, Selection selection)
41-
{
42-
vbext_ProcKind kind;
43-
var procedure = code.CodeModule.get_ProcOfLine(selection.StartLine, out kind);
44-
var startLine = code.CodeModule.get_ProcStartLine(procedure, kind);
45-
var endLine = startLine + code.CodeModule.get_ProcCountLines(procedure, kind) + 1;
46-
47-
return new Selection(startLine, 1, endLine, 1);
48-
}
49-
50-
/// <summary>
51-
/// Sets the cursor to the first position of the given line.
52-
/// </summary>
53-
/// <param name="codePane"></param>
54-
/// <param name="lineNumber"></param>
55-
public static void SetSelection(this CodePane codePane, int lineNumber)
56-
{
57-
var line = codePane.CodeModule.Lines[lineNumber, 1];
58-
var selection = new Selection(lineNumber, 1, lineNumber, line.Length);
59-
codePane.SetSelection(selection);
31+
return new QualifiedSelection(new QualifiedModuleName(code.CodeModule.Parent), selection);
6032
}
6133

6234
/// <summary>

RetailCoder.VBE/UI/CodeInspections/CodeInspectionsDockablePresenter.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,10 @@ private void OnNavigateCodeIssue(object sender, NavigateCodeEventArgs e)
7474
{
7575
try
7676
{
77-
var location = VBE.FindInstruction(e.QualifiedName, e.Selection);
78-
location.CodeModule.CodePane.SetSelection(e.Selection);
79-
80-
var codePane = location.CodeModule.CodePane;
81-
var selection = location.Selection;
82-
codePane.SetSelection(selection);
77+
e.QualifiedName.Component.CodeModule.CodePane.SetSelection(e.Selection);
8378
}
84-
catch (Exception exception)
79+
catch (COMException)
8580
{
86-
Debug.Assert(false, exception.ToString());
8781
}
8882
}
8983

RetailCoder.VBE/VBA/RubberduckParser.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private VBComponentParseResult Parse(VBComponent component)
5050
try
5151
{
5252
VBComponentParseResult cachedValue;
53-
var name = component.QualifiedName();
53+
var name = new QualifiedModuleName(component); // already a performance hit
5454
if (ParseResultCache.TryGetValue(name, out cachedValue))
5555
{
5656
return cachedValue;
@@ -61,7 +61,7 @@ private VBComponentParseResult Parse(VBComponent component)
6161

6262
TokenStreamRewriter rewriter;
6363
var parseTree = Parse(lines, out rewriter);
64-
var comments = ParseComments(component);
64+
var comments = ParseComments(name);
6565
var result = new VBComponentParseResult(component, parseTree, comments, rewriter);
6666

6767
ParseResultCache.AddOrUpdate(name, module => result, (qName, module) => result);
@@ -73,11 +73,9 @@ private VBComponentParseResult Parse(VBComponent component)
7373
}
7474
}
7575

76-
private IEnumerable<CommentNode> ParseComments(VBComponent component)
76+
private IEnumerable<CommentNode> ParseComments(QualifiedModuleName qualifiedName)
7777
{
78-
var code = component.CodeModule.Code();
79-
var qualifiedName = component.QualifiedName();
80-
78+
var code = qualifiedName.Component.CodeModule.Code();
8179
var commentBuilder = new StringBuilder();
8280
var continuing = false;
8381

Rubberduck.Parsing/ParserRuleContextExtensions.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ public static IEnumerable<QualifiedContext<TContext>> GetContexts<TListener, TCo
4343
return listener.Members;
4444
}
4545

46-
public static QualifiedContext<TContext> ToQualifiedContext<TContext>(this TContext context, QualifiedModuleName name) where TContext : ParserRuleContext
47-
{
48-
return new QualifiedContext<TContext>(name, context);
49-
}
50-
51-
public static QualifiedSelection GetQualifiedSelection(this ParserRuleContext context, QualifiedModuleName name)
52-
{
53-
var selection = context.GetSelection();
54-
return new QualifiedSelection(name, selection);
55-
}
56-
5746
public static Selection GetSelection(this ParserRuleContext context)
5847
{
5948
if (context == null)

Rubberduck.Parsing/QualifiedModuleName.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ public struct QualifiedModuleName
88
public QualifiedModuleName(VBComponent component)
99
{
1010
_component = component;
11+
12+
var module = _component.CodeModule;
13+
_contentHashCode = module.CountOfLines > 0
14+
? module.get_Lines(1, module.CountOfLines).GetHashCode()
15+
: 0;
1116
}
1217

1318
public QualifiedMemberName QualifyMemberName(string member)
@@ -17,25 +22,26 @@ public QualifiedMemberName QualifyMemberName(string member)
1722

1823
private readonly VBComponent _component;
1924
public VBComponent Component { get { return _component; } }
20-
2125
public VBProject Project { get { return _component == null ? null : _component.Collection.Parent; } }
2226

27+
private readonly int _contentHashCode;
28+
2329
public override string ToString()
2430
{
2531
return _component == null ? string.Empty : Project.Name + "." + _component.Name;
2632
}
2733

2834
public override int GetHashCode()
2935
{
30-
return _component.GetHashCode();
36+
return _component == null ? 0 : _component.GetHashCode();
3137
}
3238

3339
public override bool Equals(object obj)
3440
{
3541
try
3642
{
3743
var other = (QualifiedModuleName)obj;
38-
return other.Component == Component;
44+
return other.Component == Component && other._contentHashCode == _contentHashCode;
3945
}
4046
catch (InvalidCastException)
4147
{

Rubberduck.Parsing/Rubberduck.Parsing.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
</Compile>
8282
<Compile Include="Symbols\IdentifierReference.cs" />
8383
<Compile Include="Symbols\IdentifierReferenceListener.cs" />
84-
<Compile Include="VBComponentExtensions.cs" />
8584
<Compile Include="VBComponentParseResult.cs" />
8685
<Compile Include="VBProjectParseResult.cs" />
8786
</ItemGroup>

Rubberduck.Parsing/VBComponentExtensions.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

Rubberduck.Parsing/VBComponentParseResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class VBComponentParseResult
1111
public VBComponentParseResult(VBComponent component, IParseTree parseTree, IEnumerable<CommentNode> comments, TokenStreamRewriter rewriter)
1212
{
1313
_component = component;
14-
_qualifiedName = component.QualifiedName();
14+
_qualifiedName = new QualifiedModuleName(component);
1515
_parseTree = parseTree;
1616
_comments = comments;
1717
_rewriter = rewriter;

0 commit comments

Comments
 (0)