Skip to content

Commit

Permalink
Merge pull request #576 from StefanMaron/InternalProcedureOfInterface…
Browse files Browse the repository at this point in the history
…OnRule0052

Exclude LC0052 and LC0053 on procedure which implements an interface #572
  • Loading branch information
Arthurvdv authored Apr 3, 2024
2 parents e46c4b5 + cc71455 commit e527189
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions Design/Rule0052and0053InternalProceduresNotReferenced.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
using Microsoft.Dynamics.Nav.CodeAnalysis.Symbols;
using Microsoft.Dynamics.Nav.CodeAnalysis.Syntax;
using Microsoft.Dynamics.Nav.CodeAnalysis.Packaging;



using System.Collections.Immutable;

namespace BusinessCentral.LinterCop.Design
Expand Down Expand Up @@ -40,13 +37,6 @@ public MethodSymbolAnalyzer(CompilationAnalysisContext compilationAnalysisContex
while (objectEnumerator.MoveNext())
{
IApplicationObjectTypeSymbol applicationSymbol = objectEnumerator.Current;

if (applicationSymbol.GetNavTypeKindSafe() == NavTypeKind.Codeunit)
{
// If the containing object is an codeunit and implements an interface, then we do not need to check for references for this procedure.
ICodeunitTypeSymbol codeunitSymbol = applicationSymbol as ICodeunitTypeSymbol;
if (codeunitSymbol != null && codeunitSymbol.ImplementedInterfaces.Any()) continue;
}
ImmutableArray<ISymbol>.Enumerator objectMemberEnumerator = applicationSymbol.GetMembers().GetEnumerator();
while (objectMemberEnumerator.MoveNext())
{
Expand Down Expand Up @@ -78,23 +68,22 @@ private bool MethodNeedsReferenceCheck(IMethodSymbol methodSymbol)
{
return false;
}
// If the procedure and implements an interface, then we do not need to check for references for this procedure
IApplicationObjectTypeSymbol objectSymbol = methodSymbol.GetContainingApplicationObjectTypeSymbol();
if (objectSymbol != null && HelperFunctions.MethodImplementsInterfaceMethod(objectSymbol, methodSymbol))
{
return false;
}
if (!methodSymbol.IsInternal)
{
// Check if public procedure in internal object
if (methodSymbol.DeclaredAccessibility == Accessibility.Public && methodSymbol.ContainingSymbol is IApplicationObjectTypeSymbol)
if (methodSymbol.DeclaredAccessibility == Accessibility.Public && objectSymbol != null)
{
var objectSymbol = methodSymbol.GetContainingApplicationObjectTypeSymbol();

// If the containing object is not an internal object, then we do not need to check for references for this public procedure.
if (objectSymbol.DeclaredAccessibility != Accessibility.Internal)
{
return false;
}

if (HelperFunctions.MethodImplementsInterfaceMethod(objectSymbol, methodSymbol))
{
return false;
}
}
else
{
Expand Down

0 comments on commit e527189

Please sign in to comment.