Indentation engine based on a state machine. Supports only pushing new chars to the end.
Represents the context for transitions between IndentState. Delegates the responsibility for pushing a new char to the current state and changes between states depending on the pushed chars.
Inheritance: IStateMachineIndentEngine
        /// <summary>
        ///     Creates a new CSharpIndentEngine instance from the given prototype.
        /// </summary>
        /// <param name="prototype">
        ///     An CSharpIndentEngine instance.
        /// </param>
        public CSharpIndentEngine(CSharpIndentEngine prototype)
        {
            this.formattingOptions = prototype.formattingOptions;
            this.textEditorOptions = prototype.textEditorOptions;
            this.document          = prototype.document;

            this.newLineChar              = prototype.newLineChar;
            this.currentState             = prototype.currentState.Clone(this);
            this.conditionalSymbols       = new HashSet <string>(prototype.conditionalSymbols);
            this.customConditionalSymbols = new HashSet <string>(prototype.customConditionalSymbols);

            this.wordToken       = new StringBuilder(prototype.wordToken.ToString());
            this.previousKeyword = string.Copy(prototype.previousKeyword);

            this.offset      = prototype.offset;
            this.line        = prototype.line;
            this.column      = prototype.column;
            this.isLineStart = prototype.isLineStart;
            this.isLineStartBeforeWordToken = prototype.isLineStartBeforeWordToken;
            this.currentChar     = prototype.currentChar;
            this.previousChar    = prototype.previousChar;
            this.previousNewline = prototype.previousNewline;
            this.currentIndent   = new StringBuilder(prototype.CurrentIndent.ToString());
            this.lineBeganInsideMultiLineComment = prototype.lineBeganInsideMultiLineComment;
            this.lineBeganInsideVerbatimString   = prototype.lineBeganInsideVerbatimString;
            this.ifDirectiveEvalResults          = prototype.ifDirectiveEvalResults.Clone();
            this.ifDirectiveIndents = prototype.ifDirectiveIndents.Clone();

            this.EnableCustomIndentLevels = prototype.EnableCustomIndentLevels;
        }
		static CacheIndentEngine CreateIndentEngine(IDocument document, TextEditorOptions options)
		{
			IProject currentProject = null;
			var projectService = SD.GetService<IProjectService>();
			if (projectService != null) {
				currentProject = projectService.FindProjectContainingFile(new FileName(document.FileName));
			}
			var formattingOptions = CSharpFormattingOptionsPersistence.GetProjectOptions(currentProject);
			var engine = new CSharpIndentEngine(document, options, formattingOptions.OptionsContainer.GetEffectiveOptions());
			return new CacheIndentEngine(engine);
		}
 CSharpIndentEngine(CSharpIndentEngine prototype)
 {
     this.document = prototype.document;
     this.options = prototype.options;
     this.textEditorOptions = prototype.textEditorOptions;
     this.indent = prototype.indent.Clone();
     this.thisLineindent = prototype.thisLineindent.Clone();
     this.offset = prototype.offset;
     this.inside = prototype.inside;
     this.IsLineStart = prototype.IsLineStart;
     this.pc = prototype.pc;
     this.parenStack = new Stack<TextLocation>(prototype.parenStack.Reverse ());
     this.currentBody = prototype.currentBody;
     this.nextBody = prototype.nextBody;
     this.addContinuation = prototype.addContinuation;
     this.line = prototype.line;
     this.col = prototype.col;
     this.popNextParenBlock = prototype.popNextParenBlock;
 }
 CSharpIndentEngine(CSharpIndentEngine prototype)
 {
     this.document          = prototype.document;
     this.options           = prototype.options;
     this.textEditorOptions = prototype.textEditorOptions;
     this.indent            = prototype.indent.Clone();
     this.indentDelta       = prototype.indentDelta.Clone();
     this.thisLineindent    = prototype.thisLineindent.Clone();
     this.offset            = prototype.offset;
     this.inside            = prototype.inside;
     this.IsLineStart       = prototype.IsLineStart;
     this.pc                = prototype.pc;
     this.parenStack        = new Stack <TextLocation>(prototype.parenStack.Reverse());
     this.currentBody       = prototype.currentBody;
     this.nextBody          = prototype.nextBody;
     this.addContinuation   = prototype.addContinuation;
     this.line              = prototype.line;
     this.col               = prototype.col;
     this.popNextParenBlock = prototype.popNextParenBlock;
 }
Beispiel #5
0
		public static IDocumentIndentEngine CreateEngine(string text, CSharpFormattingOptions formatOptions = null, IEnumerable<string> symbols = null)
		{
			var policy = formatOptions;
			if ( policy == null) {
				policy = FormattingOptionsFactory.CreateMono();
				policy.IndentPreprocessorDirectives = false;
				policy.AlignToFirstMethodCallArgument = policy.AlignToFirstIndexerArgument = true;

			}

			var sb = new StringBuilder();
			int offset = 0;
			for (int i = 0; i < text.Length; i++)
			{
				var ch = text[i];
				if (ch == '$')
				{
					offset = i;
					continue;
				}
				sb.Append(ch);
			}

			var document = new ReadOnlyDocument(sb.ToString());
			var options = new TextEditorOptions();

			var csi = new CSharpIndentEngine(document, options, policy) {
				EnableCustomIndentLevels = true
			};
			if (symbols != null) {
				foreach (var sym in symbols) {
					csi.DefineSymbol(sym);
				}
			}
			var result = new CacheIndentEngine(csi);
			result.Update(offset);
			return result;
		}
Beispiel #6
0
		/// <summary>
		///     Creates a new CSharpIndentEngine instance from the given prototype.
		/// </summary>
		/// <param name="prototype">
		///     An CSharpIndentEngine instance.
		/// </param>
		public CSharpIndentEngine(CSharpIndentEngine prototype)
		{
			this.formattingOptions = prototype.formattingOptions;
			this.textEditorOptions = prototype.textEditorOptions;
			this.document = prototype.document;

			this.newLineChar = prototype.newLineChar;
			this.currentState = prototype.currentState.Clone(this);
			this.conditionalSymbols = new HashSet<string>(prototype.conditionalSymbols);
			this.customConditionalSymbols = new HashSet<string>(prototype.customConditionalSymbols);

			this.wordToken = new StringBuilder(prototype.wordToken.ToString());
			this.previousKeyword = string.Copy(prototype.previousKeyword);

			this.offset = prototype.offset;
			this.line = prototype.line;
			this.column = prototype.column;
			this.isLineStart = prototype.isLineStart;
			this.isLineStartBeforeWordToken = prototype.isLineStartBeforeWordToken;
			this.currentChar = prototype.currentChar;
			this.previousChar = prototype.previousChar;
			this.previousNewline = prototype.previousNewline;
			this.currentIndent = new StringBuilder(prototype.CurrentIndent.ToString());
			this.lineBeganInsideMultiLineComment = prototype.lineBeganInsideMultiLineComment;
			this.lineBeganInsideVerbatimString = prototype.lineBeganInsideVerbatimString;
			this.ifDirectiveEvalResults = prototype.ifDirectiveEvalResults.Clone();
			this.ifDirectiveIndents = prototype.ifDirectiveIndents.Clone();

			this.EnableCustomIndentLevels = prototype.EnableCustomIndentLevels;
		}
        static CSharpIndentEngine CreateEngine(string text)
        {
            var policy = FormattingOptionsFactory.CreateMono ();

            var sb = new StringBuilder();
            int offset = 0;
            for (int i = 0; i < text.Length; i++) {
                var ch = text [i];
                if (ch == '$') {
                    offset = i;
                    continue;
                }
                sb.Append (ch);
            }
            var document = new ReadOnlyDocument(sb.ToString ());

            var options = new TextEditorOptions();

            var result = new CSharpIndentEngine(document, options, policy);
            result.UpdateToOffset(offset);
            return result;
        }
		static CacheIndentEngine CreateIndentEngine(IDocument document, TextEditorOptions options)
		{
			var engine = new CSharpIndentEngine(document, options, FormattingOptionsFactory.CreateSharpDevelop());
			return new CacheIndentEngine(engine);
		}