protected virtual void ReportKeyDeclarationWithWrongName(SymbolAnalysisContext symbolContext, PXContext context, DacSemanticModel dac, INamedTypeSymbol keyDeclaration, RefIntegrityDacKeyType dacKeyType) { var keyDeclarationNode = keyDeclaration.GetSyntax(symbolContext.CancellationToken); Location location = (keyDeclarationNode as ClassDeclarationSyntax)?.Identifier.GetLocation() ?? keyDeclarationNode?.GetLocation(); Location dacLocation = dac.Node.GetLocation(); DiagnosticDescriptor px1036Descriptor = GetWrongKeyNameDiagnosticDescriptor(dacKeyType); if (location == null || dacLocation == null || px1036Descriptor == null) { return; } var additionalLocations = new[] { dacLocation }; var diagnosticProperties = new Dictionary <string, string> { { nameof(RefIntegrityDacKeyType), dacKeyType.ToString() } }; if (dacKeyType == RefIntegrityDacKeyType.UniqueKey) { diagnosticProperties.Add(nameof(UniqueKeyCodeFixType), UniqueKeyCodeFixType.SingleUniqueKey.ToString()); } symbolContext.ReportDiagnosticWithSuppressionCheck( Diagnostic.Create(px1036Descriptor, location, additionalLocations, diagnosticProperties.ToImmutableDictionary()), context.CodeAnalysisSettings); }
protected DiagnosticDescriptor GetWrongKeyNameDiagnosticDescriptor(RefIntegrityDacKeyType dacKeyType) => dacKeyType switch {
private async Task <Document> MultipleKeyNotInContainerDeclarationsFixAsync(Document document, SyntaxNode root, List <ClassDeclarationSyntax> keyNodesNotInContainer, ClassDeclarationSyntax dacNode, RefIntegrityDacKeyType keyType, CancellationToken cancellation) { string containerName = keyType switch { RefIntegrityDacKeyType.ForeignKey => ReferentialIntegrity.ForeignKeyClassName, RefIntegrityDacKeyType.UniqueKey => ReferentialIntegrity.UniqueKeyClassName, _ => null }; if (containerName == null) { return(document); } var keysContainerNode = dacNode.Members.OfType <ClassDeclarationSyntax>() .FirstOrDefault(nestedType => nestedType.Identifier.Text == containerName); SyntaxNode changedRoot = keysContainerNode != null ? PlaceKeysIntoExistingContainer(root, keyNodesNotInContainer, keysContainerNode, cancellation) : PlaceKeysIntoNewKeysContainer(document, root, keyNodesNotInContainer, containerName, dacNode, cancellation); var newDocument = document.WithSyntaxRoot(changedRoot); var formattedDocument = await Formatter.FormatAsync(newDocument, Formatter.Annotation, cancellationToken : cancellation) .ConfigureAwait(false); return(formattedDocument); }