コード例 #1
0
        private int GetContextStateIndex(int position)
        {
            // PositionComparer only checks the position, not the states
            var searchContext = new NullableContextState(
                position,
                warningsState: NullableContextState.State.Unknown,
                annotationsState: NullableContextState.State.Unknown
                );
            int index = _contexts.BinarySearch(searchContext, PositionComparer.Instance);

            if (index < 0)
            {
                // If no exact match, BinarySearch returns the complement
                // of the index of the next higher value.
                index = ~index - 1;
            }

            Debug.Assert(index >= -1);
            Debug.Assert(index < _contexts.Length);
#if DEBUG
            if (index >= 0)
            {
                Debug.Assert(_contexts[index].Position <= position);
                Debug.Assert(
                    index == _contexts.Length - 1 || position < _contexts[index + 1].Position
                    );
            }
#endif
            return(index);
        }
コード例 #2
0
        internal bool AreNullableAnnotationsEnabled(SyntaxTree syntaxTree, int position)
        {
            Syntax.NullableContextState context = ((CSharpSyntaxTree)syntaxTree).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 => AreNullableAnnotationsGloballyEnabled(),
                _ => throw ExceptionUtilities.UnexpectedValue(context.AnnotationsState)
            });
コード例 #3
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)
            });
コード例 #4
0
        internal NullableContextState GetContextState(int position)
        {
            // PositionComparer only checks the position, not the states
            var searchContext = new NullableContextState(position, warningsState: NullableContextState.State.Unknown, annotationsState: NullableContextState.State.Unknown);
            int index         = _contexts.BinarySearch(searchContext, PositionComparer.Instance);

            if (index < 0)
            {
                // If no exact match, BinarySearch returns the complement
                // of the index of the next higher value.
                index = ~index - 1;
            }

            var context = GetContextForFileStart(position, _isGeneratedCode);

            if (index >= 0)
            {
                Debug.Assert(_contexts[index].Position <= position);
                Debug.Assert(index == _contexts.Length - 1 || position < _contexts[index + 1].Position);
                context = _contexts[index];
            }

            return(context);
        }