diff --git a/Design/Rule0044AnalyzeTransferField.cs b/Design/Rule0044AnalyzeTransferField.cs index 2eb54396..7acd7496 100644 --- a/Design/Rule0044AnalyzeTransferField.cs +++ b/Design/Rule0044AnalyzeTransferField.cs @@ -4,6 +4,7 @@ using System.Collections.Immutable; using System.Reflection; +#nullable enable namespace BusinessCentral.LinterCop.Design { public delegate bool Filter(IGrouping fieldGroup); @@ -64,8 +65,10 @@ private async void AnalyzeTransferFields(OperationAnalysisContext ctx) if (records == null) return; +#pragma warning disable CS8602 // Dereference of a possibly null reference. Task localVariablesTask = ctx.ContainingSymbol.DeclaringSyntaxReference.GetSyntaxAsync(); Task globalVariablesTask = ctx.ContainingSymbol.ContainingSymbol.DeclaringSyntaxReference.GetSyntaxAsync(); +#pragma warning restore CS8602 // Dereference of a possibly null reference. List variables = new List(); @@ -152,7 +155,7 @@ private void ReportFieldDiagnostics(SyntaxNodeAnalysisContext ctx, Table table, if (field.Location == null) continue; - foreach(Field fieldGroupValue in fieldGroupValues) + foreach (Field fieldGroupValue in fieldGroupValues) { if (fieldGroupValue.Equals(field)) continue; @@ -166,25 +169,25 @@ private void ReportFieldDiagnostics(SyntaxNodeAnalysisContext ctx, Table table, { Type nodeType = node.GetType(); - if(nodeType == typeof(TableSyntax)) + if (nodeType == typeof(TableSyntax)) { TableSyntax tableSyntax = (TableSyntax)node; return tableSyntax.Name.Identifier.ToString().Replace("\"", ""); } - if(nodeType == typeof(TableExtensionSyntax)) + if (nodeType == typeof(TableExtensionSyntax)) { TableExtensionSyntax tableExtensionSyntax = (TableExtensionSyntax)node; return GetIdentifierName(tableExtensionSyntax.BaseObject.Identifier); } - if(nodeType == typeof(PageSyntax)) + if (nodeType == typeof(PageSyntax)) { PageSyntax pageSyntax = (PageSyntax)node; - foreach(PropertySyntaxOrEmpty property in pageSyntax.PropertyList.Properties) + foreach (PropertySyntaxOrEmpty property in pageSyntax.PropertyList.Properties) { if (property.GetType() != typeof(PropertySyntax)) continue; @@ -197,7 +200,7 @@ private void ReportFieldDiagnostics(SyntaxNodeAnalysisContext ctx, Table table, if (propertySyntax.Value.GetType() != typeof(ObjectReferencePropertyValueSyntax)) continue; - ObjectReferencePropertyValueSyntax objectReferencePropertyValueSyntax = (ObjectReferencePropertyValueSyntax) propertySyntax.Value; + ObjectReferencePropertyValueSyntax objectReferencePropertyValueSyntax = (ObjectReferencePropertyValueSyntax)propertySyntax.Value; return GetIdentifierName(objectReferencePropertyValueSyntax.ObjectNameOrId.Identifier); } @@ -205,9 +208,9 @@ private void ReportFieldDiagnostics(SyntaxNodeAnalysisContext ctx, Table table, return null; } - if(nodeType == typeof(PageExtensionSyntax)) + if (nodeType == typeof(PageExtensionSyntax)) { - PageExtensionSyntax pageExtensionSyntax = (PageExtensionSyntax) node; + PageExtensionSyntax pageExtensionSyntax = (PageExtensionSyntax)node; string? pageExtensionName = GetIdentifierName(pageExtensionSyntax.BaseObject.Identifier); @@ -242,10 +245,10 @@ private void ReportFieldDiagnostics(SyntaxNodeAnalysisContext ctx, Table table, if (!memberAccessExpression.Name.ToString().Equals("TransferFields")) return null; - return new Tuple(memberAccessExpression.Expression.ToString(), invocationExpression.ArgumentList.Arguments[0].ToString()); + return new Tuple(memberAccessExpression.Expression.ToString(), invocationExpression.ArgumentList.Arguments[0].ToString()); } - - if(invocationExpression.Expression.GetType() == typeof(IdentifierNameSyntax)) + + if (invocationExpression.Expression.GetType() == typeof(IdentifierNameSyntax)) { IdentifierNameSyntax identifierNameSyntax = (IdentifierNameSyntax)invocationExpression.Expression; @@ -264,12 +267,12 @@ private Dictionary GetTableExtensions(Compilation foreach (SyntaxTree syntaxTree in compilation.SyntaxTrees) { - foreach(SyntaxNode node in syntaxTree.GetRoot().ChildNodes()) + foreach (SyntaxNode node in syntaxTree.GetRoot().ChildNodes()) { if (node.GetType() != typeof(TableExtensionSyntax)) continue; - TableExtensionSyntax tableExtension = (TableExtensionSyntax) node; + TableExtensionSyntax tableExtension = (TableExtensionSyntax)node; string? extendedTable = GetIdentifierName(tableExtension.BaseObject.Identifier); @@ -293,13 +296,13 @@ private Table GetTableWithFieldsByTableName(Compilation compilation, string tabl Table table = new Table(tableName); - if(tableSymbol != null) + if (tableSymbol != null) { SyntaxReference? syntaxReference = tableSymbol.DeclaringSyntaxReference; if (syntaxReference != null) { - TableSyntax tableSyntax = (TableSyntax) syntaxReference.GetSyntax(); + TableSyntax tableSyntax = (TableSyntax)syntaxReference.GetSyntax(); table.PopulateFields(tableSyntax.Fields); } @@ -366,7 +369,7 @@ private Table GetTableWithFieldsByTableName(Compilation compilation, string tabl method = type.GetMethod("get_Name", BindingFlags.Public | BindingFlags.Instance); - return (string) method.Invoke(obj, null); + return (string)method.Invoke(obj, null); } } @@ -386,7 +389,8 @@ private bool DifferentNameAndTypeFilter(IGrouping fieldGroup) string name = fieldGroup.First().Name; string type = fieldGroup.First().Type; - foreach(Field field in fieldGroup) { + foreach (Field field in fieldGroup) + { if (!(name.Equals(field.Name) && type.Equals(field.Type))) return true; } @@ -399,13 +403,13 @@ private bool DifferentNameAndTypeFilter(IGrouping fieldGroup) if (variable == null) return null; - SubtypedDataTypeSyntax subtypedData = (SubtypedDataTypeSyntax) variable.Type.DataType; + SubtypedDataTypeSyntax subtypedData = (SubtypedDataTypeSyntax)variable.Type.DataType; return GetIdentifierName(subtypedData.Subtype.Identifier); } private List FindLocalVariables(SyntaxNode node) { - VarSectionSyntax varSection = (VarSectionSyntax) node.DescendantNodes().FirstOrDefault(x => x.Kind == SyntaxKind.VarSection); + VarSectionSyntax varSection = (VarSectionSyntax)node.DescendantNodes().FirstOrDefault(x => x.Kind == SyntaxKind.VarSection); if (varSection == null) return new List(); @@ -448,7 +452,7 @@ private void LoadTablePairs() new Tuple("Item Reference", "Item Cross Reference"), new Tuple("Price List Line", "Price Worksheet Line"), new Tuple("Copy Item Buffer", "Copy Item Parameters"), - new Tuple("Item Templ.", "Item"), + new Tuple("Item Templ.", "Item"), new Tuple("Whse. Item Tracking Line", "Tracking Specification"), new Tuple("Whse. Item Tracking Line", "Reservation Entry"), @@ -459,7 +463,7 @@ private void LoadTablePairs() new Tuple("Detailed CV Ledg. Entry Buffer", "Detailed Employee Ledger Entry"), new Tuple("CV Ledger Entry Buffer", "Cust. Ledger Entry"), new Tuple("Vendor Ledger Entry", "Vendor Ledger Entry Buffer"), - new Tuple("Vendor Payment Buffer", "Payment Buffer"), + new Tuple("Vendor Payment Buffer", "Payment Buffer"), new Tuple("Tracking Specification", "Reservation Entry"), new Tuple("Assembly Line", "Posted Assembly Line"), @@ -524,7 +528,7 @@ private void LoadTablePairs() new Tuple("VAT Business Posting Group", "Tax Area Buffer"), new Tuple("Tax Area", "Tax Area Buffer"), new Tuple("VAT Product Posting Group", "Tax Group Buffer"), - new Tuple("Tax Group", "Tax Group Buffer"), + new Tuple("Tax Group", "Tax Group Buffer"), new Tuple("Phys. Invt. Order Header", "Pstd. Phys. Invt. Order Hdr"), new Tuple("Pstd. Phys. Invt. Order Line", "Phys. Invt. Comment Line"), @@ -535,13 +539,13 @@ private void LoadTablePairs() new Tuple("Invt. Document Header", "Invt. Receipt Header"), new Tuple("Invt. Document Header", "Invt. Shipment Header"), new Tuple("Invt. Document Line", "Invt. Receipt Line"), - new Tuple("Invt. Document Line", "Invt. Shipment Line"), + new Tuple("Invt. Document Line", "Invt. Shipment Line"), new Tuple("Prod. Order Rtng Comment Line", "Routing Comment Line"), new Tuple("Prod. Order Routing Personnel", "Routing Personnel"), new Tuple("Prod. Order Rtng Qlty Meas.", "Routing Quality Measure"), new Tuple("Prod. Order Routing Tool", "Routing Tool"), - new Tuple("Prod. Order Comp. Cmt Line", "Production BOM Comment Line"), + new Tuple("Prod. Order Comp. Cmt Line", "Production BOM Comment Line"), new Tuple("Warehouse Activity Header", "Registered Whse. Activity Hdr."), new Tuple("Warehouse Activity Header", "Registered Invt. Movement Hdr."), @@ -555,7 +559,7 @@ private void LoadTablePairs() new Tuple("Posted Whse. Receipt Header", "Warehouse Receipt Header"), new Tuple("Posted Whse. Shipment Line", "Warehouse Shipment Line"), - new Tuple("Whse. Item Entry Relation", "Item Entry Relation"), + new Tuple("Whse. Item Entry Relation", "Item Entry Relation"), new Tuple("Time Sheet Header", "Time Sheet Header Archive"), new Tuple("Time Sheet Line", "Time Sheet Line Archive"), @@ -571,11 +575,11 @@ private void LoadTablePairs() new Tuple("Service Cr.Memo Header", "Service Header"), new Tuple("Service Cr.Memo Line", "Service Line"), new Tuple("Filed Service Contract Header", "Service Contract Header"), - new Tuple("Filed Contract Line", "Service Contract Line"), + new Tuple("Filed Contract Line", "Service Contract Line"), new Tuple("Workflow Step Instance Archive", "Workflow Step Instance"), new Tuple("Workflow Record Change Archive", "Workflow - Record Change"), - new Tuple("Workflow Step Argument Archive", "Workflow Step Argument"), + new Tuple("Workflow Step Argument Archive", "Workflow Step Argument"), new Tuple("Purchase Header", "Purch. Inv. Entity Aggregate"), new Tuple("Purch. Inv. Header", "Purch. Inv. Entity Aggregate"), @@ -595,7 +599,7 @@ private void LoadTablePairs() new Tuple("Sales Cr. Memo Entity Buffer", "Sales Header"), new Tuple("Sales Cr. Memo Entity Buffer", "Sales Cr.Memo Header"), new Tuple("Sales Order Entity Buffer", "Sales Header"), - new Tuple("Sales Quote Entity Buffer", "Sales Header"), + new Tuple("Sales Quote Entity Buffer", "Sales Header"), new Tuple("IC Outbox Sales Header", "Sales Header"), new Tuple("IC Outbox Sales Line", "Sales Line"), @@ -632,16 +636,16 @@ private void LoadTablePairs() new Tuple("IC Inbox Sales Line", "Buffer IC Inbox Sales Line"), new Tuple("IC Inbox/Outbox Jnl. Line Dim.", "Buffer IC InOut Jnl. Line Dim."), new Tuple("IC Document Dimension", "Buffer IC Document Dimension"), - new Tuple("IC Comment Line", "Buffer IC Comment Line"), + new Tuple("IC Comment Line", "Buffer IC Comment Line"), new Tuple("Config. Setup", "Company Information"), new Tuple("Object Options", "Report Settings"), - - + + new Tuple("Analysis by Dim. Parameters", "Analysis by Dim. User Param."), new Tuple("G/L Account (Analysis View)", "G/L Account"), new Tuple("Acc. Schedule Line", "Acc. Sched. KPI Buffer"), - new Tuple("G/L Entry Posting Preview", "G/L Entry"), + new Tuple("G/L Entry Posting Preview", "G/L Entry"), new Tuple("Sales Invoice Header", "O365 Sales Document"), new Tuple("Sales Header", "O365 Sales Document"), @@ -649,7 +653,7 @@ private void LoadTablePairs() new Tuple("Incoming Document Attachment", "Inc. Doc. Attachment Overview"), new Tuple("Config. Field Mapping", "Config. Field Map"), - new Tuple("Onboarding Signal", "Onboarding Signal Buffer") + new Tuple("Onboarding Signal", "Onboarding Signal Buffer") }; } @@ -716,7 +720,7 @@ public void PopulateFields(FieldExtensionListSyntax fieldList) { foreach (FieldSyntax field in fieldList.Fields) { - if(!FieldIsObsolete(field)) + if (!FieldIsObsolete(field)) Fields.Add(new Field((int)field.No.Value, field.Name.Identifier.ToString().Replace("\"", ""), field.Type.ToString(), field.GetLocation(), this)); } } @@ -726,14 +730,14 @@ public void PopulateFields(FieldListSyntax fieldList) foreach (FieldSyntax field in fieldList.Fields) { - if(!FieldIsObsolete(field)) + if (!FieldIsObsolete(field)) Fields.Add(new Field((int)field.No.Value, field.Name.Identifier.ToString().Replace("\"", ""), field.Type.ToString(), field.GetLocation(), this)); } } private bool FieldIsObsolete(FieldSyntax field) { - foreach(PropertySyntax property in field.PropertyList.Properties) + foreach (PropertySyntax property in field.PropertyList.Properties) { if (!property.Name.Identifier.ToString().Equals("ObsoleteState")) continue;