Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
 public TestNodeOutputAction(int offset, int removedChars, NodeOutput output)
     : base(offset, removedChars, output)
 {
 }
Exemplo n.º 5
0
 public override NodeOutputAction CreateNodeOutputAction(int offset, int removedChars, NodeOutput output)
 {
     return new TestNodeOutputAction (offset, removedChars, output);
 }
Exemplo n.º 6
0
		public override NodeOutputAction CreateNodeOutputAction (int offset, int removedChars, NodeOutput output)
		{
			return new MdNodeOutputAction (Document, offset, removedChars, output);
		}
Exemplo n.º 7
0
			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;
			}
Exemplo n.º 8
0
		public NodeOutputAction (int offset, int removedChars, NodeOutput output) : base (offset, removedChars)
		{
			if (output == null)
				throw new ArgumentNullException ("output");
			this.NodeOutput = output;
		}
Exemplo n.º 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;
        }
Exemplo n.º 10
0
		public virtual NodeOutputAction CreateNodeOutputAction (int offset, int removedChars, NodeOutput output)
		{
			throw new NotImplementedException ();
		}
Exemplo n.º 11
0
 public SegmentTrackingOutputFormatter(NodeOutput result, StringWriter stringWriter)
     : base(stringWriter)
 {
     this.result       = result;
     this.stringWriter = stringWriter;
 }
Exemplo n.º 12
0
 public virtual NodeOutputAction CreateNodeOutputAction(int offset, int removedChars, NodeOutput output)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 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;
		}
Exemplo n.º 14
0
			public SegmentTrackingOutputFormatter(NodeOutput result, StringWriter stringWriter)
				: base(stringWriter)
			{
				this.result = result;
				this.stringWriter = stringWriter;
			}