private static AstNode FindIdentifier(AstNode declarationNode) { while (declarationNode.GetNextNode() != null && !(IsIdentifier(declarationNode))) { declarationNode = declarationNode.GetNextNode(); } return(declarationNode); }
static AstNode NextExpression(AstNode parent) { AstNode node = parent.GetNextNode(); if (node == null) { return(null); } while (node != null && !(node is Expression || node is Statement)) { node = node.GetNextNode(); } return(node); }
public static bool CausesAmbiguityWithGenerics(BinaryOperatorExpression binaryOperatorExpression) { if (binaryOperatorExpression.Operator != BinaryOperatorType.LessThan) { return(false); } var v = new GenericGrammarAmbiguityVisitor(); v.genericNestingLevel = 1; for (AstNode node = binaryOperatorExpression.Right; node != null; node = node.GetNextNode()) { if (node.AcceptVisitor(v)) { return(v.ambiguityFound); } } return(false); }
static void WalkTreeNonRecursive(AstNode root, List <IdentifierExpression> list) { AstNode pos = root; while (pos != null) { { IdentifierExpression id = pos as IdentifierExpression; if (id != null) { list.Add(id); } } if (pos.FirstChild != null) { pos = pos.FirstChild; } else { pos = pos.GetNextNode(); } } }
static void InsertComment(ref AstNode insertionPoint, AstNode newNode, Role role, bool isDocumentationComment, AstNode rootNode) { TextLocation insertAt = newNode.StartLocation; // Advance insertionPoint to the first node that has a start location >= insertAt while (insertionPoint != null && insertionPoint.StartLocation < insertAt) { // Enter the current node if insertAt is within while (insertAt < insertionPoint.EndLocation && insertionPoint.FirstChild != null) { insertionPoint = insertionPoint.FirstChild; } // Go to next node (insertionPoint.NextSibling if it exists; otherwise the next sibling of the parent node etc.) insertionPoint = insertionPoint.GetNextNode(); } // As a special case, XmlDoc gets inserted at the beginning of the entity declaration if (isDocumentationComment && insertionPoint is EntityDeclaration && insertionPoint.FirstChild != null) { insertionPoint = insertionPoint.FirstChild; } if (insertionPoint == null) { // we're at the end of the compilation unit rootNode.AddChildUnsafe(newNode, role); } else { insertionPoint.Parent.InsertChildBeforeUnsafe(insertionPoint, newNode, role); } }
void FixOpenBrace(BraceStyle braceStyle, AstNode lbrace) { if (lbrace.IsNull) return; switch (braceStyle) { case BraceStyle.DoNotChange: return; case BraceStyle.BannerStyle: case BraceStyle.EndOfLine: var prev = lbrace.GetPrevNode (NoWhitespacePredicate); if (prev is PreProcessorDirective) return; int prevOffset = document.GetOffset(prev.EndLocation); if (prev is Comment || prev is PreProcessorDirective) { int next = document.GetOffset(lbrace.GetNextNode ().StartLocation); AddChange(prevOffset, next - prevOffset, ""); while (prev is Comment || prev is PreProcessorDirective) prev = prev.GetPrevNode(); prevOffset = document.GetOffset(prev.EndLocation); AddChange(prevOffset, 0, " {"); } else { int braceOffset2 = document.GetOffset(lbrace.StartLocation); AddChange(prevOffset, braceOffset2 - prevOffset, " "); } break; case BraceStyle.EndOfLineWithoutSpace: prev = lbrace.GetPrevNode (NoWhitespacePredicate); if (prev is PreProcessorDirective) return; prevOffset = document.GetOffset(prev.EndLocation); int braceOffset = document.GetOffset(lbrace.StartLocation); AddChange(prevOffset, braceOffset - prevOffset, ""); break; case BraceStyle.NextLine: prev = lbrace.GetPrevNode (NoWhitespacePredicate); if (prev is PreProcessorDirective) return; prevOffset = document.GetOffset(prev.EndLocation); braceOffset = document.GetOffset(lbrace.StartLocation); AddChange(prevOffset, braceOffset - prevOffset, options.EolMarker + curIndent.IndentString); break; case BraceStyle.NextLineShifted: prev = lbrace.GetPrevNode (NoWhitespacePredicate); if (prev is PreProcessorDirective) return; prevOffset = document.GetOffset(prev.EndLocation); braceOffset = document.GetOffset(lbrace.StartLocation); curIndent.Push(IndentType.Block); AddChange(prevOffset, braceOffset - prevOffset, options.EolMarker + curIndent.IndentString); curIndent.Pop(); break; case BraceStyle.NextLineShifted2: prev = lbrace.GetPrevNode (NoWhitespacePredicate); if (prev is PreProcessorDirective) return; prevOffset = document.GetOffset(prev.EndLocation); braceOffset = document.GetOffset(lbrace.StartLocation); curIndent.Push(IndentType.Block); AddChange(prevOffset, braceOffset - prevOffset, options.EolMarker + curIndent.IndentString); curIndent.Pop(); break; } }
public void EnsureNewLinesAfter(AstNode node, int blankLines) { if (formatter.FormattingMode != FormattingMode.Intrusive) blankLines = 1; int foundBlankLines = 0; var nextNode = node.GetNextNode (); AstNode lastNewLine = null; while (nextNode != null) { if (!(nextNode is NewLineNode)) break; lastNewLine = nextNode; foundBlankLines++; nextNode = nextNode.GetNextNode (); } if (nextNode == null) return; var start = document.GetOffset(node.EndLocation); var end = document.GetOffset((lastNewLine ?? nextNode).StartLocation); var sb = new StringBuilder(options.EolMarker.Length * blankLines); for (int i = 0; i < blankLines + (lastNewLine != null ? -1 : 0); i++) { sb.Append(options.EolMarker); } AddChange(start, end - start, sb.ToString()); }
static AstNode NextExpression (AstNode parent) { AstNode node = parent.GetNextNode (); if (node == null) return null; while (node != null && !(node is Expression || node is Statement)) { node = node.GetNextNode (); } return node; }
static TextLocation GetNextStart(AstNode node) { var next = node.GetNextNode(n => !(n is NewLineNode)); return(next != null ? next.StartLocation : node.EndLocation); }