public override void CompleteStatement (MonoDevelop.Ide.Gui.Document doc) { var fixer = new ConstructFixer (doc.GetFormattingOptions (), doc.Editor.CreateNRefactoryTextEditorOptions ()); int newOffset; if (fixer.TryFix (doc.Editor.Document, doc.Editor.Caret.Offset, out newOffset)) { doc.Editor.Caret.Offset = newOffset; } }
static string OutputNode (MonoDevelop.Ide.Gui.Document doc, AstNode node) { using (var stringWriter = new System.IO.StringWriter ()) { // formatter.Indentation = indentLevel; var formatter = new TextWriterOutputFormatter (stringWriter); stringWriter.NewLine = doc.Editor.EolMarker; var visitor = new CSharpOutputVisitor (formatter, doc.GetFormattingOptions ()); node.AcceptVisitor (visitor); return stringWriter.ToString (); } }
//// public override string CreateFieldEncapsulation (IUnresolvedTypeDefinition implementingType, IField field, string propertyName, Accessibility modifiers, bool readOnly) //// { //// SetIndentTo (implementingType); //// StringBuilder result = new StringBuilder (); //// AppendIndent (result); //// ////// if (modifiers != MonoDevelop.Projects.Dom.Modifiers.None) { ////// switch (modifiers) { ////// } ////// result.Append (ambience.GetString (modifiers)); ////// result.Append (" "); ////// } //// var options = new CodeGenerationOptions () { //// ImplementingType = field.DeclaringTypeDefinition, //// Part = implementingType //// }; //// result.Append ("public "); //// AppendReturnType (result, options, field.ReturnType); //// result.Append (" "); //// result.Append (propertyName); //// AppendBraceStart (result, Policy.PropertyBraceStyle); //// AppendIndent (result); //// //// result.Append ("get"); //// AppendBraceStart (result, Policy.PropertyGetBraceStyle); //// AppendIndent (result); //// result.Append ("return this."); //// result.Append (CSharpAmbience.FilterName (field.Name)); //// result.Append (";"); //// AppendLine (result); //// AppendBraceEnd (result, Policy.PropertyGetBraceStyle); //// AppendLine (result); //// //// if (!readOnly) { //// AppendIndent (result); //// result.Append ("set"); //// AppendBraceStart (result, Policy.PropertyGetBraceStyle); //// AppendIndent (result); //// result.Append (CSharpAmbience.FilterName (field.Name)); //// result.Append (" = value;"); //// AppendLine (result); //// AppendBraceEnd (result, Policy.PropertyGetBraceStyle); //// AppendLine (result); //// } //// //// AppendBraceEnd (result, Policy.PropertyBraceStyle); //// return result.ToString (); //// } // // int CountBlankLines (IReadonlyTextDocument doc, int startLine) // { // int result = 0; // IDocumentLine line; // while ((line = doc.GetLine (startLine + result)) != null && doc.GetLineIndent (line).Length == line.Length) { // result++; // } // // return result; // } // // static bool InsertUsingAfter (AstNode node) // { // return node is NewLineNode && IsCommentOrUsing (node.GetNextSibling (s => !(s is NewLineNode))) || // IsCommentOrUsing (node) || (node is PreProcessorDirective); // } // // static bool IsCommentOrUsing (AstNode node) // { // return node is ICSharpCode.NRefactory.CSharp.Comment || // node is UsingDeclaration || // node is UsingAliasDeclaration; // } // // // static string OutputNode (TextEditor editor, DocumentContext context, AstNode node) // { // using (var stringWriter = new System.IO.StringWriter ()) { //// formatter.Indentation = indentLevel; // var formatter = new TextWriterTokenWriter (stringWriter); // stringWriter.NewLine = editor.EolMarker; // // var visitor = new CSharpOutputVisitor (formatter, null /* TODO: BROKEN DUE ROSLYN PORT (note: that code should be unused) */ ); // node.AcceptVisitor (visitor); // return stringWriter.ToString (); // } // } // // // public AstType CreateShortType (ICompilation compilation, CSharpUnresolvedFile parsedFile, TextLocation loc, IType fullType) // { // var csResolver = parsedFile.GetResolver (compilation, loc); // var builder = new ICSharpCode.NRefactory.CSharp.Refactoring.TypeSystemAstBuilder (csResolver); // return builder.ConvertType (fullType); // } // public override async void CompleteStatement (MonoDevelop.Ide.Gui.Document doc) { var fixer = new ConstructFixer (doc.GetFormattingOptions ()); int newOffset = await fixer.TryFix (doc, doc.Editor.CaretOffset, default(CancellationToken)); if (newOffset != -1) { doc.Editor.CaretOffset = newOffset; } }