Skip to content

Commit 4f8ac87

Browse files
authored
Merge pull request #3504 from MDoerner/SimplyfyShadowedDeclarationTests
Simplified unit tests for shadowed declaration inspection.
2 parents 7f2d123 + 85c925f commit 4f8ac87

File tree

3 files changed

+3993
-2117
lines changed

3 files changed

+3993
-2117
lines changed

RetailCoder.VBE/Root/RubberduckIoCInstaller.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ private static void RegisterQuickFixes(IWindsorContainer container, Assembly[] a
223223
{
224224
container.Register(Classes.FromAssembly(assembly)
225225
.BasedOn<IQuickFix>()
226+
.WithService.Base()
227+
.WithService.Self()
226228
.LifestyleSingleton());
227229
}
228230
}
@@ -245,6 +247,7 @@ private static void RegisterParseTreeInspections(IWindsorContainer container, As
245247
container.Register(Classes.FromAssembly(assembly)
246248
.BasedOn<IParseTreeInspection>()
247249
.WithService.Base()
250+
.WithService.Select(new[]{typeof(IInspection)})
248251
.LifestyleTransient());
249252
}
250253
}

Rubberduck.Inspections/Concrete/ShadowedDeclarationInspection.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,31 @@ private static bool DeclarationInAnotherComponentCanBeShadowed(Declaration origi
201201

202202
var originalDeclarationComponentType = originalDeclaration.QualifiedName.QualifiedModuleName.ComponentType;
203203

204-
// It is not possible to directly access a Parameter, UDT Member or Label declared in another component
204+
// It is not possible to directly access a Parameter, UDT Member or Label declared in another component.
205205
if (originalDeclaration.DeclarationType == DeclarationType.Parameter || originalDeclaration.DeclarationType == DeclarationType.UserDefinedTypeMember ||
206206
originalDeclaration.DeclarationType == DeclarationType.LineLabel)
207207
{
208208
return false;
209209
}
210210

211-
// It is not possible to directly access any declarations placed inside a Class Module
211+
// It is not possible to directly access any declarations placed inside a Class Module.
212212
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule && originalDeclarationComponentType == ComponentType.ClassModule)
213213
{
214214
return false;
215215
}
216216

217+
// It is not possible to directly access any declarations placed inside a Document Module. (Document Modules have DeclarationType ClassMoodule.)
218+
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule && originalDeclarationComponentType == ComponentType.Document)
219+
{
220+
return false;
221+
}
222+
223+
// It is not possible to directly access any declarations placed inside a User Form. (User Forms have DeclarationType ClassMoodule.)
224+
if (originalDeclaration.DeclarationType != DeclarationType.ClassModule && originalDeclarationComponentType == ComponentType.UserForm)
225+
{
226+
return false;
227+
}
228+
217229
if (originalDeclaration.DeclarationType == DeclarationType.ClassModule)
218230
{
219231
// Syntax of instantiating a new class makes it impossible to be shadowed
@@ -234,9 +246,15 @@ private static bool DeclarationInAnotherComponentCanBeShadowed(Declaration origi
234246
return false;
235247
}
236248
}
237-
else if (!OtherComponentTypeShadowingRelations[originalDeclaration.DeclarationType].Contains(userDeclaration.DeclarationType))
249+
else
238250
{
239-
return false;
251+
HashSet<DeclarationType> shadowedTypes;
252+
if (!OtherComponentTypeShadowingRelations.TryGetValue(originalDeclaration.DeclarationType,
253+
out shadowedTypes)
254+
|| !shadowedTypes.Contains(userDeclaration.DeclarationType))
255+
{
256+
return false;
257+
}
240258
}
241259

242260
// Events don't have a body, so their parameters can't be accessed

0 commit comments

Comments
 (0)