예제 #1
0
        internal bool AreNullableAnnotationsEnabled(SyntaxTree syntaxTree, int position)
        {
            CSharpSyntaxTree csTree = (CSharpSyntaxTree)syntaxTree;

            Syntax.NullableContextState context = csTree.GetNullableContextState(position);

            return(context.AnnotationsState switch
            {
                Syntax.NullableContextState.State.Enabled => true,
                Syntax.NullableContextState.State.Disabled => false,
                Syntax.NullableContextState.State.ExplicitlyRestored => GetGlobalAnnotationState(),
                Syntax.NullableContextState.State.Unknown =>
                !csTree.IsGeneratedCode(this.Compilation.Options.SyntaxTreeOptionsProvider, CancellationToken.None) &&
                AreNullableAnnotationsGloballyEnabled(),
                _ => throw ExceptionUtilities.UnexpectedValue(context.AnnotationsState)
            });
예제 #2
0
        private static void GetRawDiagnosticInfos(bool isNullableEnabled, CSharpSyntaxTree tree, ArrayBuilder <DiagnosticInfo> infos)
        {
            const MessageID featureId = MessageID.IDS_FeatureNullableReferenceTypes;
            var             info      = featureId.GetFeatureAvailabilityDiagnosticInfoOpt(tree.Options);

            if (info is object)
            {
                infos.Add(info);
            }

            if (!isNullableEnabled && info?.Severity != DiagnosticSeverity.Error)
            {
                var code = tree.IsGeneratedCode() ? ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode : ErrorCode.WRN_MissingNonNullTypesContextForAnnotation;
                infos.Add(new CSDiagnosticInfo(code));
            }
        }