Skip to content

Commit 2925035

Browse files
Vogel612MDoernerretailcoderInarion
authored
Merge pull request #4863 from rubberduck-vba/next
Release 2.4.1 Co-authored-by: <bgclothier@gmail.com> Co-authored-by: Max Dörner <maxdoerner@gmx.net> Co-authored-by: Mathieu Guindon <retailcoder@gmail.com> Co-authored-by: <brent.mckibbin@gmail.com> Co-authored-by: Jonas <Inarion@fastmail.fm>
2 parents 5d0eeb4 + ace6df1 commit 2925035

File tree

505 files changed

+23899
-11511
lines changed

Some content is hidden

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

505 files changed

+23899
-11511
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ assignees: ''
77

88
---
99
**Rubberduck version information**
10-
The info below can be copy-paste-completed from the first lines of Rubberduck's Log or the About box:
10+
The info below can be copy-paste-completed from the first lines of Rubberduck's log or the About box:
1111

1212
Rubberduck version [...]
1313
Operating System: [...]
@@ -33,7 +33,7 @@ A clear and concise description of what you expected to happen.
3333
If applicable, add screenshots to help explain your problem.
3434

3535
**Logfile**
36-
Rubberduck generates extensive logging in TRACE-Level. If no log was created at `%APP_DATA%\Rubberduck\Logs`, check your settings. Include this Log for bugreports about the behavior of Rubbberduck
36+
Rubberduck generates extensive logging in TRACE-Level. If no log was created at `%APPDATA%\Rubberduck\Logs`, check your settings. Include this log for bug reports about the behavior of Rubberduck.
3737

3838
**Additional context**
3939
Add any other context about the problem here.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,6 @@ CodeGraphData/
183183
/Rubberduck.Deployment/Properties/launchSettings.json
184184
/Rubberduck.Deployment/Rubberduck.API.idl
185185
/Rubberduck.Deployment/Rubberduck.idl
186+
187+
#Gradle
188+
/.gradle/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ If you like this project and would like to thank its contributors, you are welco
3838

3939
Rubberduck is a COM add-in for the VBA IDE (VBE).
4040

41-
Copyright (C) 2014-2018 Rubberduck project contributors
41+
Copyright (C) 2014-2019 Rubberduck project contributors
4242

4343
This program is free software: you can redistribute it and/or modify
4444
it under the terms of the GNU General Public License as published by

Rubberduck.CodeAnalysis/Inspections/Concrete/AssignmentNotUsedInspection.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
using Rubberduck.Parsing.Symbols;
77
using Rubberduck.Inspections.CodePathAnalysis.Extensions;
88
using System.Linq;
9-
using Rubberduck.Inspections.CodePathAnalysis.Nodes;
109
using Rubberduck.Inspections.Results;
11-
using Rubberduck.Parsing;
1210
using Rubberduck.Parsing.Grammar;
1311

1412
namespace Rubberduck.Inspections.Concrete
@@ -40,8 +38,11 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
4038

4139
var tree = _walker.GenerateTree(parentScopeDeclaration.Context, variable);
4240

43-
44-
nodes.AddRange(tree.GetIdentifierReferences());
41+
var references = tree.GetIdentifierReferences();
42+
// ignore set-assignments to 'Nothing'
43+
nodes.AddRange(references.Where(r =>
44+
!(r.Context.Parent is VBAParser.SetStmtContext setStmtContext &&
45+
setStmtContext.expression().GetText().Equals(Tokens.Nothing))));
4546
}
4647

4748
return nodes

Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueNotUsedInspection.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ private bool IsRecursive(Declaration function)
7575

7676
private bool IsReturnValueUsed(Declaration function)
7777
{
78+
// TODO: This is O(MG) at work here. Need to refactor the whole shebang.
7879
return (from usage in function.References
79-
where !IsAddressOfCall(usage)
80-
where !IsTypeOfExpression(usage)
81-
where !IsCallStmt(usage)
82-
where !IsLet(usage)
83-
where !IsSet(usage)
84-
select usage).Any(usage => !IsReturnStatement(function, usage));
80+
where !IsLet(usage)
81+
where !IsSet(usage)
82+
where !IsCallStmt(usage)
83+
where !IsTypeOfExpression(usage)
84+
where !IsAddressOfCall(usage)
85+
select usage).Any(usage => !IsReturnStatement(function, usage));
8586
}
8687

8788
private bool IsAddressOfCall(IdentifierReference usage)
@@ -93,7 +94,7 @@ private bool IsTypeOfExpression(IdentifierReference usage)
9394
{
9495
return usage.Context.IsDescendentOf<VBAParser.TypeofexprContext>();
9596
}
96-
97+
9798
private bool IsReturnStatement(Declaration function, IdentifierReference assignment)
9899
{
99100
return assignment.ParentScoping.Equals(function) && assignment.Declaration.Equals(function);
@@ -111,6 +112,19 @@ private bool IsCallStmt(IdentifierReference usage)
111112
{
112113
return false;
113114
}
115+
116+
var indexExpr = usage.Context.GetAncestor<VBAParser.IndexExprContext>();
117+
if (indexExpr != null)
118+
{
119+
var memberAccessStmt = usage.Context.GetAncestor<VBAParser.MemberAccessExprContext>();
120+
if (memberAccessStmt != null &&
121+
callStmt.SourceInterval.ProperlyContains(memberAccessStmt.SourceInterval) &&
122+
memberAccessStmt.SourceInterval.ProperlyContains(indexExpr.SourceInterval))
123+
{
124+
return false;
125+
}
126+
}
127+
114128
var argumentList = CallStatement.GetArgumentList(callStmt);
115129
if (argumentList == null)
116130
{

Rubberduck.CodeAnalysis/Inspections/Concrete/HungarianNotationInspection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public sealed class HungarianNotationInspection : InspectionBase
8585
DeclarationType.Constant,
8686
DeclarationType.Control,
8787
DeclarationType.ClassModule,
88+
DeclarationType.Document,
8889
DeclarationType.Member,
8990
DeclarationType.Module,
9091
DeclarationType.ProceduralModule,

Rubberduck.CodeAnalysis/Inspections/Concrete/MoveFieldCloserToUsageInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2020
.Where(declaration =>
2121
{
2222
if (declaration.IsWithEvents
23-
|| !new[] {DeclarationType.ClassModule, DeclarationType.ProceduralModule}.Contains(declaration.ParentDeclaration.DeclarationType)
23+
|| !new[] {DeclarationType.ClassModule, DeclarationType.Document, DeclarationType.ProceduralModule}.Contains(declaration.ParentDeclaration.DeclarationType)
2424
|| IsIgnoringInspectionResultFor(declaration, AnnotationName))
2525
{
2626
return false;

Rubberduck.CodeAnalysis/Inspections/Concrete/ParameterCanBeByValInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private bool CanBeChangedToBePassedByValIndividually(ParameterDeclaration parame
7070
&& (parameter.IsByRef || parameter.IsImplicitByRef)
7171
&& !IsParameterOfDeclaredLibraryFunction(parameter)
7272
&& (parameter.AsTypeDeclaration == null
73-
|| (parameter.AsTypeDeclaration.DeclarationType != DeclarationType.ClassModule
73+
|| (!parameter.AsTypeDeclaration.DeclarationType.HasFlag(DeclarationType.ClassModule)
7474
&& parameter.AsTypeDeclaration.DeclarationType != DeclarationType.UserDefinedType
7575
&& parameter.AsTypeDeclaration.DeclarationType != DeclarationType.Enumeration))
7676
&& !parameter.References.Any(reference => reference.IsAssignment)

Rubberduck.CodeAnalysis/Inspections/Concrete/ProcedureNotUsedInspection.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2929
{
3030
var declarations = UserDeclarations.ToList();
3131

32-
var classes = State.DeclarationFinder.UserDeclarations(DeclarationType.ClassModule).ToList(); // declarations.Where(item => item.DeclarationType == DeclarationType.ClassModule).ToList();
33-
var modules = State.DeclarationFinder.UserDeclarations(DeclarationType.ProceduralModule).ToList(); // declarations.Where(item => item.DeclarationType == DeclarationType.ProceduralModule).ToList();
32+
var classes = State.DeclarationFinder.UserDeclarations(DeclarationType.ClassModule)
33+
.Concat(State.DeclarationFinder.UserDeclarations(DeclarationType.Document))
34+
.ToList();
35+
var modules = State.DeclarationFinder.UserDeclarations(DeclarationType.ProceduralModule).ToList();
3436

3537
var handlers = State.DeclarationFinder.UserDeclarations(DeclarationType.Control)
3638
.SelectMany(control => declarations.FindEventHandlers(control)).ToList();

Rubberduck.CodeAnalysis/Inspections/Concrete/ShadowedDeclarationInspection.cs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ private static bool DeclarationInReferencedProjectCanBeShadowed(Declaration orig
119119
return false;
120120
}
121121

122-
var originalDeclarationComponentType = originalDeclaration.QualifiedName.QualifiedModuleName.ComponentType;
123-
var userDeclarationComponentType = userDeclaration.QualifiedName.QualifiedModuleName.ComponentType;
122+
var originalDeclarationEnclosingType = originalDeclaration.QualifiedName.QualifiedModuleName.ComponentType;
123+
var userDeclarationEnclosingType = userDeclaration.QualifiedName.QualifiedModuleName.ComponentType;
124124

125125
// It is not possible to directly access a Parameter, UDT Member or Label declared in another project
126126
if (originalDeclaration.DeclarationType == DeclarationType.Parameter || originalDeclaration.DeclarationType == DeclarationType.UserDefinedTypeMember ||
@@ -136,20 +136,20 @@ private static bool DeclarationInReferencedProjectCanBeShadowed(Declaration orig
136136
}
137137

138138
// It is not possible to directly access a UserForm or Document declared in another project, nor any declarations placed inside them
139-
if (originalDeclarationComponentType == ComponentType.UserForm || originalDeclarationComponentType == ComponentType.Document)
139+
if (originalDeclarationEnclosingType == ComponentType.UserForm || originalDeclarationEnclosingType == ComponentType.Document)
140140
{
141141
return false;
142142
}
143143

144144
// It is not possible to directly access any declarations placed inside a Class Module
145-
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule && originalDeclarationComponentType == ComponentType.ClassModule)
145+
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule && originalDeclarationEnclosingType == ComponentType.ClassModule)
146146
{
147147
return false;
148148
}
149149

150-
if (userDeclaration.DeclarationType == DeclarationType.ClassModule)
150+
if (userDeclaration.DeclarationType == DeclarationType.ClassModule || userDeclaration.DeclarationType == DeclarationType.Document)
151151
{
152-
switch (userDeclarationComponentType)
152+
switch (userDeclarationEnclosingType)
153153
{
154154
case ComponentType.UserForm when !ReferencedProjectTypeShadowingRelations[originalDeclaration.DeclarationType].Contains(DeclarationType.UserForm):
155155
return false;
@@ -158,8 +158,8 @@ private static bool DeclarationInReferencedProjectCanBeShadowed(Declaration orig
158158
}
159159
}
160160

161-
if (userDeclaration.DeclarationType != DeclarationType.ClassModule ||
162-
(userDeclarationComponentType != ComponentType.UserForm && userDeclarationComponentType != ComponentType.Document))
161+
if ((userDeclaration.DeclarationType != DeclarationType.ClassModule && userDeclaration.DeclarationType != DeclarationType.Document) ||
162+
(userDeclarationEnclosingType != ComponentType.UserForm && userDeclarationEnclosingType != ComponentType.Document))
163163
{
164164
if (!ReferencedProjectTypeShadowingRelations[originalDeclaration.DeclarationType].Contains(userDeclaration.DeclarationType))
165165
{
@@ -188,7 +188,7 @@ private static bool DeclarationInAnotherComponentCanBeShadowed(Declaration origi
188188
return false;
189189
}
190190

191-
var originalDeclarationComponentType = originalDeclaration.QualifiedName.QualifiedModuleName.ComponentType;
191+
var originalDeclarationEnclosingType = originalDeclaration.QualifiedName.QualifiedModuleName.ComponentType;
192192

193193
// It is not possible to directly access a Parameter, UDT Member or Label declared in another component.
194194
if (originalDeclaration.DeclarationType == DeclarationType.Parameter || originalDeclaration.DeclarationType == DeclarationType.UserDefinedTypeMember ||
@@ -198,27 +198,33 @@ private static bool DeclarationInAnotherComponentCanBeShadowed(Declaration origi
198198
}
199199

200200
// It is not possible to directly access any declarations placed inside a Class Module.
201-
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule && originalDeclarationComponentType == ComponentType.ClassModule)
201+
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule &&
202+
originalDeclaration.DeclarationType != DeclarationType.Document &&
203+
originalDeclarationEnclosingType == ComponentType.ClassModule)
202204
{
203205
return false;
204206
}
205207

206208
// It is not possible to directly access any declarations placed inside a Document Module. (Document Modules have DeclarationType ClassMoodule.)
207-
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule && originalDeclarationComponentType == ComponentType.Document)
209+
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule &&
210+
originalDeclaration.DeclarationType != DeclarationType.Document &&
211+
originalDeclarationEnclosingType == ComponentType.Document)
208212
{
209213
return false;
210214
}
211215

212216
// It is not possible to directly access any declarations placed inside a User Form. (User Forms have DeclarationType ClassMoodule.)
213-
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule && originalDeclarationComponentType == ComponentType.UserForm)
217+
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule &&
218+
originalDeclaration.DeclarationType != DeclarationType.Document &&
219+
originalDeclarationEnclosingType == ComponentType.UserForm)
214220
{
215221
return false;
216222
}
217223

218-
if (originalDeclaration.DeclarationType == DeclarationType.ClassModule)
224+
if (originalDeclaration.DeclarationType == DeclarationType.ClassModule || originalDeclaration.DeclarationType == DeclarationType.Document)
219225
{
220226
// Syntax of instantiating a new class makes it impossible to be shadowed
221-
switch (originalDeclarationComponentType)
227+
switch (originalDeclarationEnclosingType)
222228
{
223229
case ComponentType.ClassModule:
224230
return false;
@@ -250,8 +256,12 @@ private static bool DeclarationInAnotherComponentCanBeShadowed(Declaration origi
250256
private static bool DeclarationInTheSameComponentCanBeShadowed(Declaration originalDeclaration, Declaration userDeclaration)
251257
{
252258
// Shadowing the component containing the declaration is not a problem, because it is possible to directly access declarations inside that component
253-
if (originalDeclaration.DeclarationType == DeclarationType.ProceduralModule || originalDeclaration.DeclarationType == DeclarationType.ClassModule ||
254-
userDeclaration.DeclarationType == DeclarationType.ProceduralModule || userDeclaration.DeclarationType == DeclarationType.ClassModule)
259+
if (originalDeclaration.DeclarationType == DeclarationType.ProceduralModule ||
260+
originalDeclaration.DeclarationType == DeclarationType.ClassModule ||
261+
originalDeclaration.DeclarationType == DeclarationType.Document ||
262+
userDeclaration.DeclarationType == DeclarationType.ProceduralModule ||
263+
userDeclaration.DeclarationType == DeclarationType.ClassModule ||
264+
userDeclaration.DeclarationType == DeclarationType.Document)
255265
{
256266
return false;
257267
}
@@ -360,7 +370,7 @@ private static bool DeclarationIsLocal(Declaration declaration)
360370
}.ToHashSet(),
361371
[DeclarationType.ClassModule] = new[]
362372
{
363-
DeclarationType.Project, DeclarationType.ProceduralModule, DeclarationType.ClassModule, DeclarationType.UserForm
373+
DeclarationType.Project, DeclarationType.ProceduralModule, DeclarationType.ClassModule, DeclarationType.UserForm, DeclarationType.Document
364374
}.ToHashSet(),
365375
[DeclarationType.Procedure] = new[]
366376
{

0 commit comments

Comments
 (0)