private void AnalyzeNode(SyntaxNodeAnalysisContext context) { var cancellationToken = context.CancellationToken; var node = (TThisExpressionSyntax)context.Node; if (node.Parent is not TMemberAccessExpressionSyntax expr) { return; } var analyzerOptions = context.Options; var syntaxTree = node.SyntaxTree; var optionSet = analyzerOptions.GetAnalyzerOptionSet(syntaxTree, cancellationToken); var model = context.SemanticModel; if (!CanSimplifyTypeNameExpression( model, expr, optionSet, out var issueSpan, cancellationToken)) { return; } if (model.SyntaxTree.OverlapsHiddenPosition(issueSpan, cancellationToken)) { return; } var symbolInfo = model.GetSymbolInfo(expr, cancellationToken); if (symbolInfo.Symbol == null) { return; } var applicableOption = QualifyMembersHelpers.GetApplicableOptionFromSymbolKind(symbolInfo.Symbol.Kind); var optionValue = optionSet.GetOption(applicableOption, model.Language); if (optionValue == null) { return; } var severity = optionValue.Notification.Severity; var builder = ImmutableDictionary.CreateBuilder <string, string?>(); // used so we can provide a link in the preview to the options page. This value is // hard-coded there to be the one that will go to the code-style page. builder["OptionName"] = nameof(CodeStyleOptions2.PreferIntrinsicPredefinedTypeKeywordInDeclaration); builder["OptionLanguage"] = model.Language; var diagnostic = DiagnosticHelper.Create( Descriptor, syntaxTree.GetLocation(issueSpan), severity, ImmutableArray.Create(expr.GetLocation()), builder.ToImmutable()); context.ReportDiagnostic(diagnostic); }
private DiagnosticDescriptor GetRemoveQualificationDiagnosticDescriptor(SemanticModel model, SyntaxNode node, OptionSet optionSet, CancellationToken cancellationToken) { var symbolInfo = model.GetSymbolInfo(node, cancellationToken); if (symbolInfo.Symbol == null) { return(null); } var applicableOption = QualifyMembersHelpers.GetApplicableOptionFromSymbolKind(symbolInfo.Symbol.Kind); var optionValue = optionSet.GetOption(applicableOption, GetLanguageName()); var severity = optionValue.Notification.Value; return(new DiagnosticDescriptor( IDEDiagnosticIds.RemoveQualificationDiagnosticId, s_localizableTitleRemoveThisOrMe, s_localizableMessage, DiagnosticCategory.Style, severity, isEnabledByDefault: true, customTags: DiagnosticCustomTags.Unnecessary)); }