Skip to content

Commit 1323394

Browse files
committed
Merge branch 'next' of https://github.com/rubberduck-vba/Rubberduck into ExtractMethod
# Conflicts: # Rubberduck.Refactorings/Rename/RenameRefactoring.cs # Rubberduck.Refactorings/ReorderParameters/ReorderParametersModel.cs # Rubberduck.Refactorings/ReorderParameters/ReorderParametersRefactoring.cs
2 parents cf40221 + 117639d commit 1323394

File tree

429 files changed

+13504
-5481
lines changed

Some content is hidden

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

429 files changed

+13504
-5481
lines changed

Rubberduck.API/VBA/Parser.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Runtime.InteropServices;
77
using System.Threading;
88
using Rubberduck.Common;
9+
using Rubberduck.Parsing.ComReflection;
910
using Rubberduck.Parsing.PreProcessing;
1011
using Rubberduck.Parsing.Rewriter;
1112
using Rubberduck.Parsing.Symbols.DeclarationLoaders;
@@ -116,7 +117,9 @@ internal Parser(object vbe) : this()
116117
var parserStateManager = new ParserStateManager(_state);
117118
var referenceRemover = new ReferenceRemover(_state, moduleToModuleReferenceManager);
118119
var supertypeClearer = new SupertypeClearer(_state);
119-
var comSynchronizer = new COMReferenceSynchronizer(_state, parserStateManager);
120+
var comLibraryProvider = new ComLibraryProvider();
121+
var referencedDeclarationsCollector = new LibraryReferencedDeclarationsCollector(comLibraryProvider);
122+
var comSynchronizer = new COMReferenceSynchronizer(_state, parserStateManager, projectRepository, referencedDeclarationsCollector);
120123
var builtInDeclarationLoader = new BuiltInDeclarationLoader(
121124
_state,
122125
new List<ICustomDeclarationLoader>

Rubberduck.CodeAnalysis/Inspections/Abstract/InspectionResultBase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
using Rubberduck.Parsing.Inspections.Abstract;
66
using Rubberduck.Resources.Inspections;
77
using Rubberduck.Parsing.Symbols;
8-
using Rubberduck.UI;
9-
using Rubberduck.UI.Controls;
108
using Rubberduck.VBEditor;
9+
using Rubberduck.Interaction.Navigation;
1110

1211
namespace Rubberduck.Inspections.Abstract
1312
{
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Rubberduck.Inspections.Abstract;
4+
using Rubberduck.Inspections.Results;
5+
using Rubberduck.Parsing.Inspections.Abstract;
6+
using Rubberduck.Parsing.VBA;
7+
using Rubberduck.Resources.Inspections;
8+
9+
namespace Rubberduck.Inspections.Concrete
10+
{
11+
public sealed class DuplicatedAnnotationInspection : InspectionBase
12+
{
13+
public DuplicatedAnnotationInspection(RubberduckParserState state) : base(state)
14+
{
15+
}
16+
17+
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
18+
{
19+
var issues = new List<DeclarationInspectionResult>();
20+
21+
foreach (var declaration in State.AllUserDeclarations)
22+
{
23+
var duplicateAnnotations = declaration.Annotations
24+
.GroupBy(annotation => annotation.AnnotationType)
25+
.Where(group => !group.First().AllowMultiple && group.Count() > 1);
26+
27+
issues.AddRange(duplicateAnnotations.Select(duplicate =>
28+
{
29+
var result = new DeclarationInspectionResult(
30+
this,
31+
string.Format(InspectionResults.DuplicatedAnnotationInspection, duplicate.Key.ToString()),
32+
declaration);
33+
34+
result.Properties.AnnotationType = duplicate.Key;
35+
36+
return result;
37+
}));
38+
}
39+
40+
return issues;
41+
}
42+
}
43+
}

Rubberduck.CodeAnalysis/Inspections/Concrete/EmptyModuleInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public override bool VisitModuleDeclarations(VBAParser.ModuleDeclarationsContext
8787

8888
public override bool VisitModuleDeclarationsElement(VBAParser.ModuleDeclarationsElementContext context)
8989
{
90-
return context.variableStmt() == null
90+
return context.moduleVariableStmt() == null
9191
&& context.constStmt() == null
9292
&& context.enumerationStmt() == null
9393
&& context.udtDeclaration() == null

Rubberduck.CodeAnalysis/Inspections/Concrete/FunctionReturnValueNotUsedInspection.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using Rubberduck.Common;
54
using Rubberduck.Inspections.Abstract;
65
using Rubberduck.Inspections.Results;
76
using Rubberduck.Parsing;
@@ -25,8 +24,8 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2524
{
2625
// Note: This inspection does not find dictionary calls (e.g. foo!bar) since we do not know what the
2726
// default member is of a class.
28-
var interfaceMembers = UserDeclarations.FindInterfaceMembers().ToList();
29-
var interfaceImplementationMembers = UserDeclarations.FindInterfaceImplementationMembers();
27+
var interfaceMembers = State.DeclarationFinder.FindAllInterfaceMembers().ToList();
28+
var interfaceImplementationMembers = State.DeclarationFinder.FindAllInterfaceImplementingMembers();
3029
var functions = State.DeclarationFinder
3130
.UserDeclarations(DeclarationType.Function)
3231
.Where(item => !IsIgnoringInspectionResultFor(item, AnnotationName))
@@ -41,7 +40,7 @@ private IEnumerable<IInspectionResult> GetInterfaceMemberIssues(IEnumerable<Decl
4140
{
4241
return from interfaceMember in interfaceMembers
4342
let implementationMembers =
44-
UserDeclarations.FindInterfaceImplementationMembers(interfaceMember.IdentifierName).ToList()
43+
State.DeclarationFinder.FindInterfaceImplementationMembers(interfaceMember).ToList()
4544
where interfaceMember.DeclarationType == DeclarationType.Function &&
4645
!IsReturnValueUsed(interfaceMember) &&
4746
implementationMembers.All(member => !IsReturnValueUsed(member))

Rubberduck.CodeAnalysis/Inspections/Concrete/IllegalAnnotationInspection.cs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
3535

3636
public class IllegalAttributeAnnotationsListener : VBAParserBaseListener, IInspectionListener
3737
{
38-
private static readonly AnnotationType[] AnnotationTypes = Enum.GetValues(typeof(AnnotationType)).Cast<AnnotationType>().ToArray();
39-
40-
private IDictionary<Tuple<QualifiedModuleName, AnnotationType>, int> _annotationCounts =
41-
new Dictionary<Tuple<QualifiedModuleName, AnnotationType>, int>();
42-
4338
private readonly RubberduckParserState _state;
4439

4540
private Lazy<Declaration> _module;
@@ -55,32 +50,19 @@ public IllegalAttributeAnnotationsListener(RubberduckParserState state)
5550

5651
public IReadOnlyList<QualifiedContext<ParserRuleContext>> Contexts => _contexts;
5752

58-
public QualifiedModuleName CurrentModuleName
59-
{
60-
get => _currentModuleName;
61-
set
62-
{
63-
_currentModuleName = value;
64-
foreach (var type in AnnotationTypes)
65-
{
66-
_annotationCounts.Add(Tuple.Create(value, type), 0);
67-
}
68-
}
69-
}
53+
public QualifiedModuleName CurrentModuleName { get; set; }
7054

7155
private bool _isFirstMemberProcessed;
7256

7357
public void ClearContexts()
7458
{
75-
_annotationCounts = new Dictionary<Tuple<QualifiedModuleName, AnnotationType>, int>();
7659
_contexts.Clear();
7760
_isFirstMemberProcessed = false;
7861
}
7962

8063
#region scoping
8164
private Declaration _currentScopeDeclaration;
8265
private bool _hasMembers;
83-
private QualifiedModuleName _currentModuleName;
8466

8567
private void SetCurrentScope(string memberName = null)
8668
{
@@ -168,8 +150,6 @@ public override void ExitAnnotation(VBAParser.AnnotationContext context)
168150
{
169151
var name = Identifier.GetName(context.annotationName().unrestrictedIdentifier());
170152
var annotationType = (AnnotationType) Enum.Parse(typeof (AnnotationType), name, true);
171-
var key = Tuple.Create(_currentModuleName, annotationType);
172-
_annotationCounts[key]++;
173153

174154
var moduleHasMembers = _members.Value.Any();
175155

@@ -183,9 +163,7 @@ public override void ExitAnnotation(VBAParser.AnnotationContext context)
183163
&& (_currentScopeDeclaration?.DeclarationType.HasFlag(DeclarationType.Member) ?? false);
184164

185165
var isIllegal = !(isMemberAnnotation && moduleHasMembers && !_isFirstMemberProcessed) &&
186-
(isModuleAnnotation && _annotationCounts[key] > 1
187-
|| isMemberAnnotatedForModuleAnnotation
188-
|| isModuleAnnotatedForMemberAnnotation);
166+
(isMemberAnnotatedForModuleAnnotation || isModuleAnnotatedForMemberAnnotation);
189167

190168
if (isIllegal)
191169
{

Rubberduck.CodeAnalysis/Inspections/Concrete/ImplicitByRefModifierInspection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using Antlr4.Runtime;
4-
using Rubberduck.Common;
54
using Rubberduck.Inspections.Abstract;
65
using Rubberduck.Inspections.Results;
76
using Rubberduck.Parsing;
@@ -26,7 +25,7 @@ public ImplicitByRefModifierInspection(RubberduckParserState state)
2625
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2726
{
2827
var builtInEventHandlerContexts = State.DeclarationFinder.FindEventHandlers().Select(handler => handler.Context).ToHashSet();
29-
var interfaceImplementationMemberContexts = UserDeclarations.FindInterfaceImplementationMembers().Select(member => member.Context).ToHashSet();
28+
var interfaceImplementationMemberContexts = State.DeclarationFinder.FindAllInterfaceImplementingMembers().Select(member => member.Context).ToHashSet();
3029

3130
var issues = Listener.Contexts.Where(context =>
3231
!IsIgnoringInspectionResultFor(context.ModuleName, context.Context.Start.Line) &&

Rubberduck.CodeAnalysis/Inspections/Concrete/IntegerDataTypeInspection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Collections.Generic;
22
using System.Globalization;
33
using System.Linq;
4-
using Rubberduck.Common;
54
using Rubberduck.Inspections.Abstract;
65
using Rubberduck.Inspections.Results;
76
using Rubberduck.Parsing.Grammar;
@@ -21,7 +20,7 @@ public IntegerDataTypeInspection(RubberduckParserState state) : base(state)
2120

2221
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2322
{
24-
var interfaceImplementationMembers = UserDeclarations.FindInterfaceImplementationMembers().ToHashSet();
23+
var interfaceImplementationMembers = State.DeclarationFinder.FindAllInterfaceImplementingMembers().ToHashSet();
2524

2625
var excludeParameterMembers = State.DeclarationFinder.FindEventHandlers().ToHashSet();
2726
excludeParameterMembers.UnionWith(interfaceImplementationMembers);

Rubberduck.CodeAnalysis/Inspections/Concrete/ModuleScopeDimKeywordInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void ClearContexts()
4545

4646
public override void ExitVariableStmt([NotNull] VBAParser.VariableStmtContext context)
4747
{
48-
if (context.DIM() != null && context.Parent is VBAParser.ModuleDeclarationsElementContext)
48+
if (context.DIM() != null && context.TryGetAncestor<VBAParser.ModuleDeclarationsElementContext>(out _))
4949
{
5050
_contexts.Add(new QualifiedContext<ParserRuleContext>(CurrentModuleName, context));
5151
}

Rubberduck.CodeAnalysis/Inspections/Concrete/NonReturningFunctionInspection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using Rubberduck.Common;
43
using Rubberduck.Inspections.Abstract;
54
using Rubberduck.Inspections.Results;
65
using Rubberduck.Parsing.Grammar;
@@ -26,7 +25,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2625
{
2726
var declarations = UserDeclarations.ToList();
2827

29-
var interfaceMembers = declarations.FindInterfaceMembers();
28+
var interfaceMembers = State.DeclarationFinder.FindAllInterfaceMembers();
3029

3130
var functions = declarations
3231
.Where(declaration => ReturningMemberTypes.Contains(declaration.DeclarationType)

0 commit comments

Comments
 (0)