Skip to content

Commit f958960

Browse files
committed
minor tweaks
1 parent 2388b6a commit f958960

File tree

8 files changed

+52
-24
lines changed

8 files changed

+52
-24
lines changed

RetailCoder.VBE/Common/DeclarationExtensions.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Reflection;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.Diagnostics.CodeAnalysis;
@@ -449,12 +450,16 @@ public static Declaration FindTarget(this IEnumerable<Declaration> declarations,
449450
foreach (var reference in declaration.References)
450451
{
451452
var proc = (dynamic)reference.Context.Parent;
452-
VBAParser.ArgsCallContext paramList;
453+
var paramList = proc ;
453454

454455
// This is to prevent throws when this statement fails:
455456
// (VBAParser.ArgsCallContext)proc.argsCall();
456-
try { paramList = (VBAParser.ArgsCallContext)proc.argsCall(); }
457-
catch { continue; }
457+
var method = ((Type) proc.GetType()).GetMethod("argsCall");
458+
if (method != null)
459+
{
460+
try { paramList = method.Invoke(proc, null); }
461+
catch { continue; }
462+
}
458463

459464
if (paramList == null) { continue; }
460465

RetailCoder.VBE/Inspections/UntypedFunctionUsageInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
4444
{
4545
var declarations = BuiltInDeclarations
4646
// note: these *should* be functions, but somehow they're not defined as such
47-
.Where(item => _tokens.Any(token => item.References.Any() && (item.IdentifierName == token || item.IdentifierName == "_B_var_" + token)));
47+
.Where(item => _tokens.Any(token => (item.IdentifierName == token || item.IdentifierName == "_B_var_" + token)) && item.References.Any());
4848

4949
return declarations.SelectMany(declaration => declaration.References
5050
.Select(item => new UntypedFunctionUsageInspectionResult(this, string.Format(Description, declaration.IdentifierName), item.QualifiedModuleName, item.Context)));

RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
2121
var issues = from item in UserDeclarations
2222
where (item.DeclarationType == DeclarationType.Variable
2323
|| item.DeclarationType == DeclarationType.Constant
24-
|| item.DeclarationType == DeclarationType.Parameter)
24+
|| (item.DeclarationType == DeclarationType.Parameter && !item.IsArray()))
2525
&& !item.IsTypeSpecified()
2626
select new VariableTypeNotDeclaredInspectionResult(this, item);
2727

RetailCoder.VBE/UI/Command/MenuItems/RubberduckCommandBar.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ private void _statusButton_Click(CommandBarButton Ctrl, ref bool CancelDefault)
4141

4242
public void SetStatusText(string value = null)
4343
{
44+
Debug.WriteLine(string.Format("RubberduckCommandBar status text changes to '{0}'.", value));
4445
UiDispatcher.Invoke(() => _statusButton.Caption = value ?? RubberduckUI.ResourceManager.GetString("ParserState_" + _state.Status));
4546
}
4647

@@ -50,6 +51,7 @@ public void SetSelectionText(Declaration declaration)
5051
{
5152
var selection = _vbe.ActiveCodePane.GetSelection();
5253
SetSelectionText(selection);
54+
_selectionButton.TooltipText = _selectionButton.Caption;
5355
}
5456
else if (declaration != null && !declaration.IsBuiltIn && declaration.DeclarationType != DeclarationType.Class && declaration.DeclarationType != DeclarationType.Module)
5557
{
@@ -58,6 +60,9 @@ public void SetSelectionText(Declaration declaration)
5860
declaration.QualifiedSelection.Selection,
5961
declaration.IdentifierName,
6062
RubberduckUI.ResourceManager.GetString("DeclarationType_" + declaration.DeclarationType));
63+
_selectionButton.TooltipText = string.IsNullOrEmpty(declaration.DescriptionString)
64+
? _selectionButton.Caption
65+
: declaration.DescriptionString;
6166
}
6267
else if (declaration != null)
6368
{
@@ -67,6 +72,9 @@ public void SetSelectionText(Declaration declaration)
6772
declaration.IdentifierName,
6873
RubberduckUI.ResourceManager.GetString("DeclarationType_" + declaration.DeclarationType),
6974
selection.Selection);
75+
_selectionButton.TooltipText = string.IsNullOrEmpty(declaration.DescriptionString)
76+
? _selectionButton.Caption
77+
: declaration.DescriptionString;
7078
}
7179
}
7280

RetailCoder.VBE/UI/Command/Refactorings/FormDesignerRefactorRenameCommand.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ private Declaration GetTarget()
5959
}
6060

6161
return _state.AllUserDeclarations
62-
.FirstOrDefault(item => item.IdentifierName == control.Name &&
63-
item.ComponentName == Vbe.SelectedVBComponent.Name &&
64-
Vbe.ActiveVBProject.HelpFile == item.ProjectId);
62+
.FirstOrDefault(item => item.DeclarationType == DeclarationType.Control
63+
&& Vbe.ActiveVBProject.HelpFile == item.ProjectId
64+
&& item.ComponentName == Vbe.SelectedVBComponent.Name
65+
&& item.IdentifierName == control.Name);
6566
}
6667
}
6768

Rubberduck.Parsing/VBA/AttributeParser.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using Antlr4.Runtime;
6+
using Antlr4.Runtime.Tree;
67
using Microsoft.Vbe.Interop;
78
using Rubberduck.Parsing.Grammar;
89
using Rubberduck.Parsing.Symbols;
@@ -43,12 +44,12 @@ public IDictionary<Tuple<string, DeclarationType>, Attributes> Parse(VBComponent
4344
var lexer = new VBALexer(stream);
4445
var tokens = new CommonTokenStream(lexer);
4546
var parser = new VBAParser(tokens);
46-
parser.AddParseListener(listener);
4747

4848
// parse tree isn't usable for declarations because
4949
// line numbers are offset due to module header and attributes
5050
// (these don't show up in the VBE, that's why we're parsing an exported file)
5151
var tree = parser.startRule();
52+
ParseTreeWalker.Default.Walk(listener, tree);
5253

5354
return listener.Attributes;
5455
}
@@ -101,11 +102,12 @@ public override void EnterAmbiguousIdentifier(VBAParser.AmbiguousIdentifierConte
101102
public override void EnterSubStmt(VBAParser.SubStmtContext context)
102103
{
103104
_currentScopeAttributes = new Attributes();
105+
_currentScope = Tuple.Create(context.ambiguousIdentifier().GetText(), DeclarationType.Procedure);
104106
}
105107

106108
public override void ExitSubStmt(VBAParser.SubStmtContext context)
107109
{
108-
if (_currentScopeAttributes.Any())
110+
if (!string.IsNullOrEmpty(_currentScope.Item1) && _currentScopeAttributes.Any())
109111
{
110112
_attributes.Add(_currentScope, _currentScopeAttributes);
111113
}
@@ -114,11 +116,12 @@ public override void ExitSubStmt(VBAParser.SubStmtContext context)
114116
public override void EnterFunctionStmt(VBAParser.FunctionStmtContext context)
115117
{
116118
_currentScopeAttributes = new Attributes();
119+
_currentScope = Tuple.Create(context.ambiguousIdentifier().GetText(), DeclarationType.Function);
117120
}
118121

119122
public override void ExitFunctionStmt(VBAParser.FunctionStmtContext context)
120123
{
121-
if (_currentScopeAttributes.Any())
124+
if (!string.IsNullOrEmpty(_currentScope.Item1) && _currentScopeAttributes.Any())
122125
{
123126
_attributes.Add(_currentScope, _currentScopeAttributes);
124127
}
@@ -127,11 +130,12 @@ public override void ExitFunctionStmt(VBAParser.FunctionStmtContext context)
127130
public override void EnterPropertyGetStmt(VBAParser.PropertyGetStmtContext context)
128131
{
129132
_currentScopeAttributes = new Attributes();
133+
_currentScope = Tuple.Create(context.ambiguousIdentifier().GetText(), DeclarationType.PropertyGet);
130134
}
131135

132136
public override void ExitPropertyGetStmt(VBAParser.PropertyGetStmtContext context)
133137
{
134-
if (_currentScopeAttributes.Any())
138+
if (!string.IsNullOrEmpty(_currentScope.Item1) && _currentScopeAttributes.Any())
135139
{
136140
_attributes.Add(_currentScope, _currentScopeAttributes);
137141
}
@@ -140,11 +144,12 @@ public override void ExitPropertyGetStmt(VBAParser.PropertyGetStmtContext contex
140144
public override void EnterPropertyLetStmt(VBAParser.PropertyLetStmtContext context)
141145
{
142146
_currentScopeAttributes = new Attributes();
147+
_currentScope = Tuple.Create(context.ambiguousIdentifier().GetText(), DeclarationType.PropertyLet);
143148
}
144149

145150
public override void ExitPropertyLetStmt(VBAParser.PropertyLetStmtContext context)
146151
{
147-
if (_currentScopeAttributes.Any())
152+
if (!string.IsNullOrEmpty(_currentScope.Item1) && _currentScopeAttributes.Any())
148153
{
149154
_attributes.Add(_currentScope, _currentScopeAttributes);
150155
}
@@ -153,20 +158,21 @@ public override void ExitPropertyLetStmt(VBAParser.PropertyLetStmtContext contex
153158
public override void EnterPropertySetStmt(VBAParser.PropertySetStmtContext context)
154159
{
155160
_currentScopeAttributes = new Attributes();
161+
_currentScope = Tuple.Create(context.ambiguousIdentifier().GetText(), DeclarationType.PropertySet);
156162
}
157163

158164
public override void ExitPropertySetStmt(VBAParser.PropertySetStmtContext context)
159165
{
160-
if (_currentScopeAttributes.Any())
166+
if (!string.IsNullOrEmpty(_currentScope.Item1) && _currentScopeAttributes.Any())
161167
{
162168
_attributes.Add(_currentScope, _currentScopeAttributes);
163169
}
164170
}
165171

166172
public override void ExitAttributeStmt(VBAParser.AttributeStmtContext context)
167173
{
168-
var name = context.implicitCallStmt_InStmt().GetText();
169-
var values = context.literal().Select(e => e.GetText()).ToList();
174+
var name = context.implicitCallStmt_InStmt().GetText().Trim();
175+
var values = context.literal().Select(e => e.GetText().Replace("\"", string.Empty)).ToList();
170176
_currentScopeAttributes.Add(name, values);
171177
}
172178

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public void Parse()
128128
private void ParseAll()
129129
{
130130
var projects = _state.Projects
131+
// accessing the code of a protected VBComponent throws a COMException:
131132
.Where(project => project.Protection == vbext_ProjectProtection.vbext_pp_none)
132133
.ToList();
133134

@@ -293,12 +294,12 @@ private void ParseAsyncInternal(VBComponent component, CancellationToken token,
293294
parser.Start(token);
294295
}
295296

296-
public void ParseComponent(VBComponent component, TokenStreamRewriter rewriter = null)
297+
private void ParseComponent(VBComponent component, TokenStreamRewriter rewriter = null)
297298
{
298299
ParseAsync(component, CancellationToken.None, rewriter).Wait();
299300
}
300301

301-
public void Resolve(CancellationToken token)
302+
private void Resolve(CancellationToken token)
302303
{
303304
var sharedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_resolverTokenSource.Token, token);
304305
// tests expect this to be synchronous :/
@@ -319,7 +320,7 @@ private void ResolveInternal(CancellationToken token)
319320
foreach (var kvp in _state.ParseTrees)
320321
{
321322
var qualifiedName = kvp.Key;
322-
if (/*_force || _state.IsModified(qualifiedName)*/ true)
323+
if (true /*_state.IsModified(qualifiedName)*/)
323324
{
324325
Debug.WriteLine("Module '{0}' {1}", qualifiedName.ComponentName, _state.IsModified(qualifiedName) ? "was modified" : "was NOT modified");
325326
// modified module; walk parse tree and re-acquire all declarations
@@ -364,7 +365,7 @@ private void ResolveDeclarations(VBComponent component, IParseTree tree)
364365
emptyStringLiteralListener,
365366
argListWithOneByRefParamListener,
366367
}), tree);
367-
// FIXME these are actually (almost) isnpection results.. we should handle them as such
368+
// TODO: these are actually (almost) isnpection results.. we should handle them as such
368369
_state.ArgListsWithOneByRefParam = argListWithOneByRefParamListener.Contexts.Select(context => new QualifiedContext(qualifiedModuleName, context));
369370
_state.EmptyStringLiterals = emptyStringLiteralListener.Contexts.Select(context => new QualifiedContext(qualifiedModuleName, context));
370371
_state.ObsoleteLetContexts = obsoleteLetStatementListener.Contexts.Select(context => new QualifiedContext(qualifiedModuleName, context));
@@ -390,11 +391,11 @@ private void ResolveDeclarations(VBComponent component, IParseTree tree)
390391
private void ResolveReferences(DeclarationFinder finder, VBComponent component, IParseTree tree)
391392
{
392393
var state = _state.GetModuleState(component);
393-
if (_state.Status == ParserState.ResolverError || state != ParserState.Parsed)
394+
if (_state.Status == ParserState.ResolverError || (state != ParserState.Parsed))
394395
{
395396
return;
396397
}
397-
_state.SetModuleState(component, ParserState.Resolving);
398+
398399
Debug.WriteLine("Resolving '{0}'... (thread {1})", component.Name, Thread.CurrentThread.ManagedThreadId);
399400
var qualifiedName = new QualifiedModuleName(component);
400401
var resolver = new IdentifierReferenceResolver(qualifiedName, finder);

Rubberduck.VBEEditor/QualifiedModuleName.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public QualifiedModuleName(VBProject project)
3131
_componentName = null;
3232
_project = project;
3333
_projectName = project.Name;
34+
_projectPath = string.Empty;
3435
_projectId = GetProjectId(project);
3536
_contentHashCode = 0;
3637
}
@@ -43,6 +44,7 @@ public QualifiedModuleName(VBComponent component)
4344
_componentName = component == null ? string.Empty : component.Name;
4445
_project = component == null ? null : component.Collection.Parent;
4546
_projectName = _project == null ? string.Empty : _project.Name;
47+
_projectPath = string.Empty;
4648
_projectId = GetProjectId(_project);
4749

4850
_contentHashCode = 0;
@@ -65,7 +67,8 @@ public QualifiedModuleName(VBComponent component)
6567
public QualifiedModuleName(string projectName, string projectPath, string componentName)
6668
{
6769
_project = null;
68-
_projectName = projectName + ";" + projectPath;
70+
_projectName = projectName;
71+
_projectPath = projectPath;
6972
_projectId = _projectName.GetHashCode().ToString();
7073
_componentName = componentName;
7174
_component = null;
@@ -94,10 +97,14 @@ public QualifiedMemberName QualifyMemberName(string member)
9497

9598
public string Name { get { return ToString(); } }
9699
private readonly string _projectName;
100+
private readonly string _projectPath;
97101

98102
public override string ToString()
99103
{
100-
return _component == null && string.IsNullOrEmpty(_projectName) ? string.Empty : _projectName + "." + _componentName;
104+
return _component == null && string.IsNullOrEmpty(_projectName)
105+
? string.Empty
106+
: (string.IsNullOrEmpty(_projectPath) ? string.Empty : _projectPath + ";")
107+
+ _projectName + "." + _componentName;
101108
}
102109

103110
public override int GetHashCode()

0 commit comments

Comments
 (0)