PageRenderTime 16ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/NRefactory/ICSharpCode.NRefactory.VB/PrettyPrinter/SpecialNodesInserter.cs

http://github.com/icsharpcode/ILSpy
C# | 142 lines | 6 code | 2 blank | 134 comment | 0 complexity | 86202113e7dbe253aa05b89b2a4124a6 MD5 | raw file
  1// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
  2// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
  3
  4using System;
  5using System.Collections.Generic;
  6using ICSharpCode.NRefactory.VB.Ast;
  7
  8namespace ICSharpCode.NRefactory.VB.PrettyPrinter
  9{
 10//	public class SpecialOutputVisitor : ISpecialVisitor
 11//	{
 12//		readonly IOutputFormatter formatter;
 13//		
 14//		public SpecialOutputVisitor(IOutputFormatter formatter)
 15//		{
 16//			this.formatter = formatter;
 17//		}
 18//		
 19//		public bool ForceWriteInPreviousLine;
 20//		
 21//		public object Visit(ISpecial special, object data)
 22//		{
 23//			Console.WriteLine("Warning: SpecialOutputVisitor.Visit(ISpecial) called with " + special);
 24//			return data;
 25//		}
 26//		
 27//		public object Visit(BlankLine special, object data)
 28//		{
 29//			formatter.PrintBlankLine(ForceWriteInPreviousLine);
 30//			return data;
 31//		}
 32//		
 33//		public object Visit(Comment special, object data)
 34//		{
 35//			formatter.PrintComment(special, ForceWriteInPreviousLine);
 36//			return data;
 37//		}
 38//		
 39//		public object Visit(PreprocessingDirective special, object data)
 40//		{
 41//			formatter.PrintPreprocessingDirective(special, ForceWriteInPreviousLine);
 42//			return data;
 43//		}
 44//	}
 45//	
 46//	/// <summary>
 47//	/// This class inserts specials between INodes.
 48//	/// </summary>
 49//	public sealed class SpecialNodesInserter : IDisposable
 50//	{
 51//		IEnumerator<ISpecial> enumerator;
 52//		SpecialOutputVisitor visitor;
 53//		bool available; // true when more specials are available
 54//		
 55//		public SpecialNodesInserter(IEnumerable<ISpecial> specials, SpecialOutputVisitor visitor)
 56//		{
 57//			if (specials == null) throw new ArgumentNullException("specials");
 58//			if (visitor == null) throw new ArgumentNullException("visitor");
 59//			enumerator = specials.GetEnumerator();
 60//			this.visitor = visitor;
 61//			available = enumerator.MoveNext();
 62//		}
 63//		
 64//		void WriteCurrent()
 65//		{
 66//			enumerator.Current.AcceptVisitor(visitor, null);
 67//			available = enumerator.MoveNext();
 68//		}
 69//		
 70//		AttributedNode currentAttributedNode;
 71//		
 72//		/// <summary>
 73//		/// Writes all specials up to the start position of the node.
 74//		/// </summary>
 75//		public void AcceptNodeStart(INode node)
 76//		{
 77//			if (node is AttributedNode) {
 78//				currentAttributedNode = node as AttributedNode;
 79//				if (currentAttributedNode.Attributes.Count == 0) {
 80//					AcceptPoint(node.StartLocation);
 81//					currentAttributedNode = null;
 82//				}
 83//			} else {
 84//				AcceptPoint(node.StartLocation);
 85//			}
 86//		}
 87//		
 88//		/// <summary>
 89//		/// Writes all specials up to the end position of the node.
 90//		/// </summary>
 91//		public void AcceptNodeEnd(INode node)
 92//		{
 93//			visitor.ForceWriteInPreviousLine = true;
 94//			AcceptPoint(node.EndLocation);
 95//			visitor.ForceWriteInPreviousLine = false;
 96//			if (currentAttributedNode != null) {
 97//				if (node == currentAttributedNode.Attributes[currentAttributedNode.Attributes.Count - 1]) {
 98//					AcceptPoint(currentAttributedNode.StartLocation);
 99//					currentAttributedNode = null;
100//				}
101//			}
102//		}
103//		
104//		/// <summary>
105//		/// Writes all specials up to the specified location.
106//		/// </summary>
107//		public void AcceptPoint(Location loc)
108//		{
109//			while (available && enumerator.Current.StartPosition <= loc) {
110//				WriteCurrent();
111//			}
112//		}
113//		
114//		/// <summary>
115//		/// Outputs all missing specials to the writer.
116//		/// </summary>
117//		public void Finish()
118//		{
119//			while (available) {
120//				WriteCurrent();
121//			}
122//		}
123//		
124//		void IDisposable.Dispose()
125//		{
126//			Finish();
127//		}
128//		
129//		/// <summary>
130//		/// Registers a new SpecialNodesInserter with the output visitor.
131//		/// Make sure to call Finish() (or Dispose()) on the returned SpecialNodesInserter
132//		/// when the output is finished.
133//		/// </summary>
134//		public static SpecialNodesInserter Install(IEnumerable<ISpecial> specials, IOutputDomVisitor outputVisitor)
135//		{
136//			SpecialNodesInserter sni = new SpecialNodesInserter(specials, new SpecialOutputVisitor(outputVisitor.OutputFormatter));
137//			outputVisitor.BeforeNodeVisit += sni.AcceptNodeStart;
138//			outputVisitor.AfterNodeVisit  += sni.AcceptNodeEnd;
139//			return sni;
140//		}
141//	}
142}