Skip to content

Commit

Permalink
Update for special exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanbekkum authored and Rob van Bekkum committed Jan 18, 2024
1 parent 8efe810 commit b458e12
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Design/Rule0052and0053InternalProceduresNotReferenced.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using BusinessCentral.LinterCop.Helpers;
using Microsoft.Dynamics.Nav.CodeAnalysis;
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics;
using Microsoft.Dynamics.Nav.CodeAnalysis.InternalSyntax;
using Microsoft.Dynamics.Nav.CodeAnalysis.Symbols;
using Microsoft.Dynamics.Nav.CodeAnalysis.Syntax;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;

namespace BusinessCentral.LinterCop.Design {
[DiagnosticAnalyzer]
Expand All @@ -16,6 +20,8 @@ private class MethodSymbolAnalyzer : IDisposable {
private readonly PooledDictionary<IMethodSymbol, string> internalMethodsUsedInCurrentObject = PooledDictionary<IMethodSymbol, string>.GetInstance();
private readonly PooledDictionary<IMethodSymbol, string> internalMethodsUsedInOtherObjects = PooledDictionary<IMethodSymbol, string>.GetInstance();

private readonly AttributeKind[] attributeKindsOfMethodsToSkip = new AttributeKind[] { AttributeKind.ConfirmHandler, AttributeKind.FilterPageHandler, AttributeKind.HyperlinkHandler, AttributeKind.MessageHandler, AttributeKind.ModalPageHandler, AttributeKind.PageHandler, AttributeKind.RecallNotificationHandler, AttributeKind.ReportHandler, AttributeKind.RequestPageHandler, AttributeKind.SendNotificationHandler, AttributeKind.SessionSettingsHandler, AttributeKind.StrMenuHandler, AttributeKind.Test };

public MethodSymbolAnalyzer(CompilationAnalysisContext compilationAnalysisContext)
{
ImmutableArray<IApplicationObjectTypeSymbol>.Enumerator objectEnumerator = compilationAnalysisContext.Compilation.GetDeclaredApplicationObjectSymbols().GetEnumerator();
Expand Down Expand Up @@ -49,6 +55,10 @@ private bool MethodNeedsReferenceCheck(IMethodSymbol methodSymbol)
{
return false;
}
if (methodSymbol.Attributes.Any(attr => attributeKindsOfMethodsToSkip.Contains(attr.AttributeKind)))
{
return false;
}
if (!methodSymbol.IsInternal)
{
// Check if public procedure in internal object
Expand All @@ -73,11 +83,11 @@ private bool MethodNeedsReferenceCheck(IMethodSymbol methodSymbol)
}
}

// If the procedure has signature ProcedureName(HostNotification: Notification), then the procedure does not need a reference check
// If the procedure has signature ProcedureName(HostNotification: Notification) or ProcedureName(ErrorInfo: ErrorInfo), then the procedure does not need a reference check
if (methodSymbol.Parameters.Length == 1)
{
ITypeSymbol firstParameterTypeSymbol = methodSymbol.Parameters[0].ParameterType;
if (firstParameterTypeSymbol.GetNavTypeKindSafe() == NavTypeKind.Notification)
if (firstParameterTypeSymbol.GetNavTypeKindSafe() == NavTypeKind.Notification || firstParameterTypeSymbol.GetNavTypeKindSafe() == NavTypeKind.ErrorInfo)
{
return false;
}
Expand Down

0 comments on commit b458e12

Please sign in to comment.