示例#1
0
 public DFormattingVisitor(DFormattingOptions policy, IDocumentAdapter document, DModule ast, ITextEditorOptions options = null)
 {
     if (policy == null)
     {
         throw new ArgumentNullException("policy");
     }
     if (document == null)
     {
         throw new ArgumentNullException("document");
     }
     this.ast      = ast;
     this.policy   = policy;
     this.document = document;
     this.options  = options ?? TextEditorOptions.Default;
     curIndent     = new FormattingIndentStack(this.options);
 }
示例#2
0
		public static string FormatCode(string code, DModule ast = null, IDocumentAdapter document = null, DFormattingOptions options = null, ITextEditorOptions textStyle = null)
		{
			options = options ?? DFormattingOptions.CreateDStandard();
			textStyle = textStyle ?? TextEditorOptions.Default;
			ast = ast ?? DParser.ParseString(code) as DModule;
			
			var formattingVisitor = new DFormattingVisitor(options, document ?? new TextDocument{ Text = code }, ast, textStyle);
			
			formattingVisitor.WalkThroughAst();
			
			var sb = new StringBuilder(code);
			
			formattingVisitor.ApplyChanges((int start, int length, string insertedText) => {
			                               	sb.Remove(start,length);
			                               	sb.Insert(start,insertedText);
			                               });
			
			return sb.ToString();
		}
示例#3
0
        public static string FormatCode(string code, DModule ast = null, IDocumentAdapter document = null, DFormattingOptions options = null, ITextEditorOptions textStyle = null)
        {
            options   = options ?? DFormattingOptions.CreateDStandard();
            textStyle = textStyle ?? TextEditorOptions.Default;
            ast       = ast ?? DParser.ParseString(code) as DModule;

            var formattingVisitor = new DFormattingVisitor(options, document ?? new TextDocument {
                Text = code
            }, ast, textStyle);

            formattingVisitor.WalkThroughAst();

            var sb = new StringBuilder(code);

            formattingVisitor.ApplyChanges((int start, int length, string insertedText) => {
                sb.Remove(start, length);
                sb.Insert(start, insertedText);
            });

            return(sb.ToString());
        }