public void Replace(AstNode node, AstNode replaceWith) { var startOffset = Context.GetOffset(node.StartLocation); var endOffset = Context.GetOffset(node.EndLocation); int level = 0; if (!(replaceWith is Expression) && !(replaceWith is AstType)) { level = GetIndentLevelAt(startOffset); } NodeOutput output = OutputNode(level, replaceWith); output.Trim(); Queue(Context.CreateNodeOutputAction(startOffset, endOffset - startOffset, output)); }
protected NodeOutput OutputNode(int indentLevel, AstNode node, bool startWithNewLine = false) { var result = new NodeOutput(); var stringWriter = new StringWriter(); var formatter = new SegmentTrackingOutputFormatter(result, stringWriter); formatter.Indentation = indentLevel; stringWriter.NewLine = Context.EolMarker; if (startWithNewLine) { formatter.NewLine(); } var visitor = new CppOutputVisitor(formatter, Context.FormattingOptions); node.AcceptVisitor(visitor, null); result.Text = stringWriter.ToString().TrimEnd(); if (node is FieldDeclaration) { result.Text += Context.EolMarker; } return(result); }
public NodeOutputAction (int offset, int removedChars, NodeOutput output) : base (offset, removedChars) { if (output == null) throw new ArgumentNullException ("output"); this.NodeOutput = output; }
public SegmentTrackingOutputFormatter(NodeOutput result, StringWriter stringWriter) : base(stringWriter) { this.result = result; this.stringWriter = stringWriter; }
public virtual NodeOutputAction CreateNodeOutputAction (int offset, int removedChars, NodeOutput output) { throw new NotImplementedException (); }
public virtual NodeOutputAction CreateNodeOutputAction(int offset, int removedChars, NodeOutput output) { throw new NotImplementedException(); }
protected NodeOutput OutputNode (int indentLevel, AstNode node, bool startWithNewLine = false) { var result = new NodeOutput (); var stringWriter = new StringWriter (); var formatter = new SegmentTrackingOutputFormatter (result, stringWriter); formatter.Indentation = indentLevel; stringWriter.NewLine = Context.EolMarker; if (startWithNewLine) formatter.NewLine (); var visitor = new CppOutputVisitor (formatter, Context.FormattingOptions); node.AcceptVisitor (visitor, null); result.Text = stringWriter.ToString ().TrimEnd (); if (node is FieldDeclaration) result.Text += Context.EolMarker; return result; }