Example #1
0
        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));
        }
Example #2
0
        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);
        }
Example #3
0
        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;
		}
Example #9
0
        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;
        }
Example #10
0
		public virtual NodeOutputAction CreateNodeOutputAction (int offset, int removedChars, NodeOutput output)
		{
			throw new NotImplementedException ();
		}
Example #11
0
 public SegmentTrackingOutputFormatter(NodeOutput result, StringWriter stringWriter)
     : base(stringWriter)
 {
     this.result       = result;
     this.stringWriter = stringWriter;
 }
Example #12
0
 public virtual NodeOutputAction CreateNodeOutputAction(int offset, int removedChars, NodeOutput output)
 {
     throw new NotImplementedException();
 }
Example #13
0
		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;
		}
Example #14
0
			public SegmentTrackingOutputFormatter(NodeOutput result, StringWriter stringWriter)
				: base(stringWriter)
			{
				this.result = result;
				this.stringWriter = stringWriter;
			}