From cc714556633a9de5642cb95e07a5895dc0f4a660 Mon Sep 17 00:00:00 2001 From: Arthur van de Vondervoort Date: Mon, 1 Apr 2024 14:04:53 +0200 Subject: [PATCH] Exclude method which implements an interface --- ...2and0053InternalProceduresNotReferenced.cs | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/Design/Rule0052and0053InternalProceduresNotReferenced.cs b/Design/Rule0052and0053InternalProceduresNotReferenced.cs index 0dbd22a0..7a37150d 100644 --- a/Design/Rule0052and0053InternalProceduresNotReferenced.cs +++ b/Design/Rule0052and0053InternalProceduresNotReferenced.cs @@ -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 @@ -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.Enumerator objectMemberEnumerator = applicationSymbol.GetMembers().GetEnumerator(); while (objectMemberEnumerator.MoveNext()) { @@ -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 {