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)); }
public void Replace(AstNode node, AstNode replaceWith) { var segment = GetSegment(node); int startOffset = segment.Offset; int level = 0; if (!(replaceWith is Expression) && !(replaceWith is AstType)) { level = GetIndentLevelAt(startOffset); } NodeOutput output = OutputNode(level, replaceWith); output.TrimStart(); Replace(startOffset, segment.Length, output.Text); output.RegisterTrackedSegments(this, startOffset); }
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 CSharpOutputVisitor(formatter, Context.FormattingOptions); node.AcceptVisitor(visitor, null); result.Text = stringWriter.ToString().TrimEnd(); if (node is FieldDeclaration) { result.Text += Context.EolMarker; } return(result); }
public TestNodeOutputAction(int offset, int removedChars, NodeOutput output) : base(offset, removedChars, output) { }
public override NodeOutputAction CreateNodeOutputAction(int offset, int removedChars, NodeOutput output) { return new TestNodeOutputAction (offset, removedChars, output); }
public override NodeOutputAction CreateNodeOutputAction (int offset, int removedChars, NodeOutput output) { return new MdNodeOutputAction (Document, offset, removedChars, output); }
public MdNodeOutputAction (MonoDevelop.Ide.Gui.Document doc, int offset, int removedChars, NodeOutput output) : base (offset, removedChars, output) { if (doc == null) throw new ArgumentNullException ("doc"); if (output == null) throw new ArgumentNullException ("output"); this.doc = doc; }
public NodeOutputAction (int offset, int removedChars, NodeOutput output) : base (offset, removedChars) { if (output == null) throw new ArgumentNullException ("output"); this.NodeOutput = output; }
protected NodeOutput OutputNode(int indentLevel, AstNode node, bool startWithNewLine = false) { var result = new NodeOutput (); var stringWriter = new System.IO.StringWriter (); var formatter = new TextWriterOutputFormatter (stringWriter); formatter.Indentation = indentLevel; stringWriter.NewLine = Context.EolMarker; if (startWithNewLine) formatter.NewLine (); var visitor = new CSharpOutputVisitor (formatter, Context.FormattingOptions); visitor.OutputStarted += (sender, e) => { result.NodeSegments [e.AstNode] = new NodeOutput.Segment (stringWriter.GetStringBuilder ().Length); }; visitor.OutputFinished += (sender, e) => { result.NodeSegments [e.AstNode].EndOffset = stringWriter.GetStringBuilder ().Length; }; node.AcceptVisitor (visitor, null); result.Text = stringWriter.ToString ().TrimEnd (); if (node is FieldDeclaration) result.Text += Context.EolMarker; return result; }
public virtual NodeOutputAction CreateNodeOutputAction (int offset, int removedChars, NodeOutput output) { throw new NotImplementedException (); }
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(); }
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 CSharpOutputVisitor (formatter, Context.FormattingOptions); node.AcceptVisitor (visitor, null); result.Text = stringWriter.ToString ().TrimEnd (); if (node is FieldDeclaration) result.Text += Context.EolMarker; return result; }