コード例 #1
0
 private bool CheckBlock(Block block) {
     if (_typedChar == '}' && 
         block != null && 
         block.Braces != BraceState.None && 
         block.GetEndIndex(_tree.LocationResolver) == _position) {
         return true;
     }
     return false;
 }
コード例 #2
0
        public override bool Walk(Block node) {
            var prevScope = _scope;
            var prevSuite = _curSuite;
            _curSuite = node;

            try {
                // recursively walk the statements in the suite
                for (int i = 0; i < node.Count; i++) {
                    if (DDG.IsGwtCode(node, i)) {
                        return false;
                    }
                    node[i].Walk(this);
                }
            } finally {
                _curSuite = prevSuite;
                while (_scope != prevScope) {
                    StatementEnvironmentRecord stmtRec = _scope as StatementEnvironmentRecord;
                    if (stmtRec != null) {
                        stmtRec.EndIndex = node.GetEndIndex(_tree.LocationResolver);
                    }
                    _scope = _scope.Parent;
                }
            }
            return false;
        }
コード例 #3
0
        /// <summary>
        /// Reformats a block node.  If the block has braces then the formatting will be updated
        /// appropriately, if forceNewLine
        /// </summary>
        /// <param name="block"></param>
        /// <param name="braceOnNewline"></param>
        private void WalkBlock(Block block) {
            Debug.Assert(block == null || block.Braces != BraceState.None);
            if (block != null && block.Braces != BraceState.None) {
                bool isMultiLine = ContainsLineFeed(block.GetStartIndex(_tree.LocationResolver), block.GetEndIndex(_tree.LocationResolver));
                bool isComment = FollowedBySingleLineComment(block.GetStartIndex(_tree.LocationResolver), false);
                if (block.Count > 0 && isMultiLine && !isComment) {
                    // multiline block statement, make sure the 1st statement
                    // starts on a new line. If this is a comment it can stay on the same line as the brace
                    EnsureNewLineFollowing(block.GetStartIndex(_tree.LocationResolver) + "{".Length);
                }

                var parent = block.Parent;
                Indent();

                WalkStatements(block, block.Statements, isMultiLine);

                Dedent();

                if (block.Braces == BraceState.StartAndEnd) {
                    if (isMultiLine) {
                        EnsureNewLinePreceeding(block.GetEndIndex(_tree.LocationResolver) - 1);
                    } else {
                        ReplacePreceedingWhiteSpaceMaybeMultiline(block.GetEndIndex(_tree.LocationResolver) - 1);
                    }
                }
            }
        }