Skip to content

Commit

Permalink
Merge pull request #4863 from rubberduck-vba/next
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
4 people committed Mar 25, 2019
2 parents 5d0eeb4 + ace6df1 commit 2925035
Show file tree
Hide file tree
Showing 505 changed files with 23,899 additions and 11,511 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Expand Up @@ -7,7 +7,7 @@ assignees: ''

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

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

**Logfile**
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
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.

**Additional context**
Add any other context about the problem here.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -183,3 +183,6 @@ CodeGraphData/
/Rubberduck.Deployment/Properties/launchSettings.json
/Rubberduck.Deployment/Rubberduck.API.idl
/Rubberduck.Deployment/Rubberduck.idl

#Gradle
/.gradle/
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -38,7 +38,7 @@ If you like this project and would like to thank its contributors, you are welco

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

Copyright (C) 2014-2018 Rubberduck project contributors
Copyright (C) 2014-2019 Rubberduck project contributors

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
Expand Up @@ -6,9 +6,7 @@
using Rubberduck.Parsing.Symbols;
using Rubberduck.Inspections.CodePathAnalysis.Extensions;
using System.Linq;
using Rubberduck.Inspections.CodePathAnalysis.Nodes;
using Rubberduck.Inspections.Results;
using Rubberduck.Parsing;
using Rubberduck.Parsing.Grammar;

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

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


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

return nodes
Expand Down
Expand Up @@ -75,13 +75,14 @@ private bool IsRecursive(Declaration function)

private bool IsReturnValueUsed(Declaration function)
{
// TODO: This is O(MG) at work here. Need to refactor the whole shebang.
return (from usage in function.References
where !IsAddressOfCall(usage)
where !IsTypeOfExpression(usage)
where !IsCallStmt(usage)
where !IsLet(usage)
where !IsSet(usage)
select usage).Any(usage => !IsReturnStatement(function, usage));
where !IsLet(usage)
where !IsSet(usage)
where !IsCallStmt(usage)
where !IsTypeOfExpression(usage)
where !IsAddressOfCall(usage)
select usage).Any(usage => !IsReturnStatement(function, usage));
}

private bool IsAddressOfCall(IdentifierReference usage)
Expand All @@ -93,7 +94,7 @@ private bool IsTypeOfExpression(IdentifierReference usage)
{
return usage.Context.IsDescendentOf<VBAParser.TypeofexprContext>();
}

private bool IsReturnStatement(Declaration function, IdentifierReference assignment)
{
return assignment.ParentScoping.Equals(function) && assignment.Declaration.Equals(function);
Expand All @@ -111,6 +112,19 @@ private bool IsCallStmt(IdentifierReference usage)
{
return false;
}

var indexExpr = usage.Context.GetAncestor<VBAParser.IndexExprContext>();
if (indexExpr != null)
{
var memberAccessStmt = usage.Context.GetAncestor<VBAParser.MemberAccessExprContext>();
if (memberAccessStmt != null &&
callStmt.SourceInterval.ProperlyContains(memberAccessStmt.SourceInterval) &&
memberAccessStmt.SourceInterval.ProperlyContains(indexExpr.SourceInterval))
{
return false;
}
}

var argumentList = CallStatement.GetArgumentList(callStmt);
if (argumentList == null)
{
Expand Down
Expand Up @@ -85,6 +85,7 @@ public sealed class HungarianNotationInspection : InspectionBase
DeclarationType.Constant,
DeclarationType.Control,
DeclarationType.ClassModule,
DeclarationType.Document,
DeclarationType.Member,
DeclarationType.Module,
DeclarationType.ProceduralModule,
Expand Down
Expand Up @@ -20,7 +20,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
.Where(declaration =>
{
if (declaration.IsWithEvents
|| !new[] {DeclarationType.ClassModule, DeclarationType.ProceduralModule}.Contains(declaration.ParentDeclaration.DeclarationType)
|| !new[] {DeclarationType.ClassModule, DeclarationType.Document, DeclarationType.ProceduralModule}.Contains(declaration.ParentDeclaration.DeclarationType)
|| IsIgnoringInspectionResultFor(declaration, AnnotationName))
{
return false;
Expand Down
Expand Up @@ -70,7 +70,7 @@ private bool CanBeChangedToBePassedByValIndividually(ParameterDeclaration parame
&& (parameter.IsByRef || parameter.IsImplicitByRef)
&& !IsParameterOfDeclaredLibraryFunction(parameter)
&& (parameter.AsTypeDeclaration == null
|| (parameter.AsTypeDeclaration.DeclarationType != DeclarationType.ClassModule
|| (!parameter.AsTypeDeclaration.DeclarationType.HasFlag(DeclarationType.ClassModule)
&& parameter.AsTypeDeclaration.DeclarationType != DeclarationType.UserDefinedType
&& parameter.AsTypeDeclaration.DeclarationType != DeclarationType.Enumeration))
&& !parameter.References.Any(reference => reference.IsAssignment)
Expand Down
Expand Up @@ -29,8 +29,10 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
{
var declarations = UserDeclarations.ToList();

var classes = State.DeclarationFinder.UserDeclarations(DeclarationType.ClassModule).ToList(); // declarations.Where(item => item.DeclarationType == DeclarationType.ClassModule).ToList();
var modules = State.DeclarationFinder.UserDeclarations(DeclarationType.ProceduralModule).ToList(); // declarations.Where(item => item.DeclarationType == DeclarationType.ProceduralModule).ToList();
var classes = State.DeclarationFinder.UserDeclarations(DeclarationType.ClassModule)
.Concat(State.DeclarationFinder.UserDeclarations(DeclarationType.Document))
.ToList();
var modules = State.DeclarationFinder.UserDeclarations(DeclarationType.ProceduralModule).ToList();

var handlers = State.DeclarationFinder.UserDeclarations(DeclarationType.Control)
.SelectMany(control => declarations.FindEventHandlers(control)).ToList();
Expand Down
Expand Up @@ -119,8 +119,8 @@ private static bool DeclarationInReferencedProjectCanBeShadowed(Declaration orig
return false;
}

var originalDeclarationComponentType = originalDeclaration.QualifiedName.QualifiedModuleName.ComponentType;
var userDeclarationComponentType = userDeclaration.QualifiedName.QualifiedModuleName.ComponentType;
var originalDeclarationEnclosingType = originalDeclaration.QualifiedName.QualifiedModuleName.ComponentType;
var userDeclarationEnclosingType = userDeclaration.QualifiedName.QualifiedModuleName.ComponentType;

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

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

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

if (userDeclaration.DeclarationType == DeclarationType.ClassModule)
if (userDeclaration.DeclarationType == DeclarationType.ClassModule || userDeclaration.DeclarationType == DeclarationType.Document)
{
switch (userDeclarationComponentType)
switch (userDeclarationEnclosingType)
{
case ComponentType.UserForm when !ReferencedProjectTypeShadowingRelations[originalDeclaration.DeclarationType].Contains(DeclarationType.UserForm):
return false;
Expand All @@ -158,8 +158,8 @@ private static bool DeclarationInReferencedProjectCanBeShadowed(Declaration orig
}
}

if (userDeclaration.DeclarationType != DeclarationType.ClassModule ||
(userDeclarationComponentType != ComponentType.UserForm && userDeclarationComponentType != ComponentType.Document))
if ((userDeclaration.DeclarationType != DeclarationType.ClassModule && userDeclaration.DeclarationType != DeclarationType.Document) ||
(userDeclarationEnclosingType != ComponentType.UserForm && userDeclarationEnclosingType != ComponentType.Document))
{
if (!ReferencedProjectTypeShadowingRelations[originalDeclaration.DeclarationType].Contains(userDeclaration.DeclarationType))
{
Expand Down Expand Up @@ -188,7 +188,7 @@ private static bool DeclarationInAnotherComponentCanBeShadowed(Declaration origi
return false;
}

var originalDeclarationComponentType = originalDeclaration.QualifiedName.QualifiedModuleName.ComponentType;
var originalDeclarationEnclosingType = originalDeclaration.QualifiedName.QualifiedModuleName.ComponentType;

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

// It is not possible to directly access any declarations placed inside a Class Module.
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule && originalDeclarationComponentType == ComponentType.ClassModule)
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule &&
originalDeclaration.DeclarationType != DeclarationType.Document &&
originalDeclarationEnclosingType == ComponentType.ClassModule)
{
return false;
}

// It is not possible to directly access any declarations placed inside a Document Module. (Document Modules have DeclarationType ClassMoodule.)
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule && originalDeclarationComponentType == ComponentType.Document)
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule &&
originalDeclaration.DeclarationType != DeclarationType.Document &&
originalDeclarationEnclosingType == ComponentType.Document)
{
return false;
}

// It is not possible to directly access any declarations placed inside a User Form. (User Forms have DeclarationType ClassMoodule.)
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule && originalDeclarationComponentType == ComponentType.UserForm)
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule &&
originalDeclaration.DeclarationType != DeclarationType.Document &&
originalDeclarationEnclosingType == ComponentType.UserForm)
{
return false;
}

if (originalDeclaration.DeclarationType == DeclarationType.ClassModule)
if (originalDeclaration.DeclarationType == DeclarationType.ClassModule || originalDeclaration.DeclarationType == DeclarationType.Document)
{
// Syntax of instantiating a new class makes it impossible to be shadowed
switch (originalDeclarationComponentType)
switch (originalDeclarationEnclosingType)
{
case ComponentType.ClassModule:
return false;
Expand Down Expand Up @@ -250,8 +256,12 @@ private static bool DeclarationInAnotherComponentCanBeShadowed(Declaration origi
private static bool DeclarationInTheSameComponentCanBeShadowed(Declaration originalDeclaration, Declaration userDeclaration)
{
// Shadowing the component containing the declaration is not a problem, because it is possible to directly access declarations inside that component
if (originalDeclaration.DeclarationType == DeclarationType.ProceduralModule || originalDeclaration.DeclarationType == DeclarationType.ClassModule ||
userDeclaration.DeclarationType == DeclarationType.ProceduralModule || userDeclaration.DeclarationType == DeclarationType.ClassModule)
if (originalDeclaration.DeclarationType == DeclarationType.ProceduralModule ||
originalDeclaration.DeclarationType == DeclarationType.ClassModule ||
originalDeclaration.DeclarationType == DeclarationType.Document ||
userDeclaration.DeclarationType == DeclarationType.ProceduralModule ||
userDeclaration.DeclarationType == DeclarationType.ClassModule ||
userDeclaration.DeclarationType == DeclarationType.Document)
{
return false;
}
Expand Down Expand Up @@ -360,7 +370,7 @@ private static bool DeclarationIsLocal(Declaration declaration)
}.ToHashSet(),
[DeclarationType.ClassModule] = new[]
{
DeclarationType.Project, DeclarationType.ProceduralModule, DeclarationType.ClassModule, DeclarationType.UserForm
DeclarationType.Project, DeclarationType.ProceduralModule, DeclarationType.ClassModule, DeclarationType.UserForm, DeclarationType.Document
}.ToHashSet(),
[DeclarationType.Procedure] = new[]
{
Expand Down

0 comments on commit 2925035

Please sign in to comment.