public DocumentScript(IDocument document, CSharpFormattingOptions formattingOptions, TextEditorOptions options) : base(formattingOptions, options) { this.originalDocument = document.CreateDocumentSnapshot(); this.currentDocument = document; Debug.Assert(currentDocument.Version.CompareAge(originalDocument.Version) == 0); this.undoGroup = document.OpenUndoGroup(); }
protected Script(CSharpFormattingOptions formattingOptions, TextEditorOptions options) { if (formattingOptions == null) throw new ArgumentNullException("formattingOptions"); if (options == null) throw new ArgumentNullException("options"); this.formattingOptions = formattingOptions; this.options = options; }
protected CSharpFormattingPolicy(CSharpFormattingOptions options) { this.options = options; }
public CSharpFormattingPolicy() { this.options = FormattingOptionsFactory.CreateMono(); }
public AstAmbience(ICSharpCode.NRefactory.CSharp.CSharpFormattingOptions options) { this.options = options; }
public void TestUsingAliasDeclarations() { CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono(); Test(policy, @" using Foo = Bar;", @"using Foo = Bar;"); }
void WriteMemberDeclarationName(IMember member, TextWriterTokenWriter formatter, CSharpFormattingOptions formattingPolicy) { TypeSystemAstBuilder astBuilder = CreateAstBuilder(); if ((ConversionFlags & ConversionFlags.ShowDeclaringType) == ConversionFlags.ShowDeclaringType) { ConvertType(member.DeclaringType, formatter, formattingPolicy); formatter.WriteToken(Roles.Dot, "."); } switch (member.SymbolKind) { case SymbolKind.Indexer: formatter.WriteKeyword(IndexerDeclaration.ThisKeywordRole, "this"); break; case SymbolKind.Constructor: formatter.WriteIdentifier(Identifier.Create(member.DeclaringType.Name)); break; case SymbolKind.Destructor: formatter.WriteToken(DestructorDeclaration.TildeRole, "~"); formatter.WriteIdentifier(Identifier.Create(member.DeclaringType.Name)); break; case SymbolKind.Operator: switch (member.Name) { case "op_Implicit": formatter.WriteKeyword(OperatorDeclaration.ImplicitRole, "implicit"); formatter.Space(); formatter.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator"); formatter.Space(); ConvertType(member.ReturnType, formatter, formattingPolicy); break; case "op_Explicit": formatter.WriteKeyword(OperatorDeclaration.ExplicitRole, "explicit"); formatter.Space(); formatter.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator"); formatter.Space(); ConvertType(member.ReturnType, formatter, formattingPolicy); break; default: formatter.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator"); formatter.Space(); var operatorType = OperatorDeclaration.GetOperatorType(member.Name); if (operatorType.HasValue) { formatter.WriteToken(OperatorDeclaration.GetRole(operatorType.Value), OperatorDeclaration.GetToken(operatorType.Value)); } else { formatter.WriteIdentifier(Identifier.Create(member.Name)); } break; } break; default: formatter.WriteIdentifier(Identifier.Create(member.Name)); break; } if ((ConversionFlags & ConversionFlags.ShowTypeParameterList) == ConversionFlags.ShowTypeParameterList && member.SymbolKind == SymbolKind.Method) { var outputVisitor = new CSharpOutputVisitor(formatter, formattingPolicy); outputVisitor.WriteTypeParameters(astBuilder.ConvertEntity(member).GetChildrenByRole(Roles.TypeParameter)); } }
public override string ToString(CSharpFormattingOptions formattingOptions) { return("[ErrorNode]"); }
public sealed override string ToString(CSharpFormattingOptions formattingOptions) { return(NewLine.GetString(NewLineType)); }
public override string ToString(CSharpFormattingOptions formattingOptions) { return(Keyword); }
public void TestParseLabelPositioning(string rawValue, LabelPositionOptions parsedValue) { Assert.Equal(parsedValue, CSharpFormattingOptions.ParseEditorConfigLabelPositioning(rawValue)); }
public void TestParseSpacingAroundBinaryOperator(string rawValue, BinaryOperatorSpacingOptions parsedValue) { Assert.Equal(parsedValue, CSharpFormattingOptions.ParseEditorConfigSpacingAroundBinaryOperator(rawValue)); }
public void TestAllowIfBlockInline() { CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono(); policy.StatementBraceStyle = BraceStyle.EndOfLine; policy.AllowIfBlockInline = true; Test(policy, @"class Test { Test TestMethod () { if (true) {} } }", @"class Test { Test TestMethod () { if (true) {} } }"); Test(policy, @"class Test { Test TestMethod () { if (true) { Foo (); } } }", @"class Test { Test TestMethod () { if (true) { Foo (); } } }"); Test(policy, @"class Test { Test TestMethod () { if (true) Foo (); } }", @"class Test { Test TestMethod () { if (true) Foo (); } }"); Test(policy, @"class Test { Test TestMethod () { if (true) Foo (); } }", @"class Test { Test TestMethod () { if (true) Foo (); } }"); }
public void TestSwitchIndentBreak() { CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono(); policy.IndentSwitchBody = true; policy.IndentBreakStatements = true; Test(policy, @"class Test { Test TestMethod () { switch (a) { case 1: case 2: DoSomething (); break; default: Foo (); break; } } }", @"class Test { Test TestMethod () { switch (a) { case 1: case 2: DoSomething (); break; default: Foo (); break; } } }"); policy.IndentSwitchBody = true; policy.IndentBreakStatements = false; Test(policy, @"class Test { Test TestMethod () { switch (a) { case 1: case 2: DoSomething (); break; default: Foo (); break; } } }", @"class Test { Test TestMethod () { switch (a) { case 1: case 2: DoSomething (); break; default: Foo (); break; } } }"); }
public virtual void SetUp() { formattingOptions = FormattingOptionsFactory.CreateMono(); }
public MDRefactoringScript(MDRefactoringContext context, CSharpFormattingOptions formattingOptions) : base(context.TextEditor.Document, formattingOptions, context.TextEditor.CreateNRefactoryTextEditorOptions()) { this.context = context; undoGroup = this.context.TextEditor.OpenUndoGroup(); this.startVersion = this.context.TextEditor.Version; }
public void ConvertEntity(IEntity entity, TextWriterTokenWriter formatter, CSharpFormattingOptions formattingPolicy) { if (entity == null) { throw new ArgumentNullException("entity"); } if (formatter == null) { throw new ArgumentNullException("formatter"); } if (formattingPolicy == null) { throw new ArgumentNullException("options"); } TypeSystemAstBuilder astBuilder = CreateAstBuilder(); EntityDeclaration node = astBuilder.ConvertEntity(entity); PrintModifiers(node.Modifiers, formatter); if ((ConversionFlags & ConversionFlags.ShowDefinitionKeyword) == ConversionFlags.ShowDefinitionKeyword) { if (node is TypeDeclaration) { switch (((TypeDeclaration)node).ClassType) { case ClassType.Class: formatter.WriteKeyword(Roles.ClassKeyword, "class"); break; case ClassType.Struct: formatter.WriteKeyword(Roles.StructKeyword, "struct"); break; case ClassType.Interface: formatter.WriteKeyword(Roles.InterfaceKeyword, "interface"); break; case ClassType.Enum: formatter.WriteKeyword(Roles.EnumKeyword, "enum"); break; default: throw new Exception("Invalid value for ClassType"); } formatter.Space(); } else if (node is DelegateDeclaration) { formatter.WriteKeyword(Roles.DelegateKeyword, "delegate"); formatter.Space(); } else if (node is EventDeclaration) { formatter.WriteKeyword(EventDeclaration.EventKeywordRole, "event"); formatter.Space(); } } if ((ConversionFlags & ConversionFlags.ShowReturnType) == ConversionFlags.ShowReturnType) { var rt = node.GetChildByRole(Roles.Type); if (!rt.IsNull) { rt.AcceptVisitor(new CSharpOutputVisitor(formatter, formattingPolicy)); formatter.Space(); } } if (entity is ITypeDefinition) { WriteTypeDeclarationName((ITypeDefinition)entity, formatter, formattingPolicy); } else { WriteMemberDeclarationName((IMember)entity, formatter, formattingPolicy); } if ((ConversionFlags & ConversionFlags.ShowParameterList) == ConversionFlags.ShowParameterList && HasParameters(entity)) { if (entity.SymbolKind == SymbolKind.Indexer) { formatter.WriteToken(Roles.LBracket, "["); } else { formatter.WriteToken(Roles.LBrace, "("); } bool first = true; foreach (var param in node.GetChildrenByRole(Roles.Parameter)) { if (first) { first = false; } else { formatter.WriteToken(Roles.Comma, ","); formatter.Space(); } param.AcceptVisitor(new CSharpOutputVisitor(formatter, formattingPolicy)); } if (entity.SymbolKind == SymbolKind.Indexer) { formatter.WriteToken(Roles.RBracket, "]"); } else { formatter.WriteToken(Roles.RBrace, ")"); } } if ((ConversionFlags & ConversionFlags.ShowBody) == ConversionFlags.ShowBody && !(node is TypeDeclaration)) { IProperty property = entity as IProperty; if (property != null) { formatter.Space(); formatter.WriteToken(Roles.LBrace, "{"); formatter.Space(); if (property.CanGet) { formatter.WriteKeyword(PropertyDeclaration.GetKeywordRole, "get"); formatter.WriteToken(Roles.Semicolon, ";"); formatter.Space(); } if (property.CanSet) { formatter.WriteKeyword(PropertyDeclaration.SetKeywordRole, "set"); formatter.WriteToken(Roles.Semicolon, ";"); formatter.Space(); } formatter.WriteToken(Roles.RBrace, "}"); } else { formatter.WriteToken(Roles.Semicolon, ";"); } } }
void WriteTypeDeclarationName(ITypeDefinition typeDef, TextWriterTokenWriter formatter, CSharpFormattingOptions formattingPolicy) { TypeSystemAstBuilder astBuilder = CreateAstBuilder(); if (typeDef.DeclaringTypeDefinition != null) { WriteTypeDeclarationName(typeDef.DeclaringTypeDefinition, formatter, formattingPolicy); formatter.WriteToken(Roles.Dot, "."); } else if ((ConversionFlags & ConversionFlags.UseFullyQualifiedTypeNames) == ConversionFlags.UseFullyQualifiedTypeNames) { formatter.WriteIdentifier(Identifier.Create(typeDef.Namespace)); formatter.WriteToken(Roles.Dot, "."); } formatter.WriteIdentifier(Identifier.Create(typeDef.Name)); if ((ConversionFlags & ConversionFlags.ShowTypeParameterList) == ConversionFlags.ShowTypeParameterList) { var outputVisitor = new CSharpOutputVisitor(formatter, formattingPolicy); outputVisitor.WriteTypeParameters(astBuilder.ConvertEntity(typeDef).GetChildrenByRole(Roles.TypeParameter)); } }
protected Script(CSharpFormattingOptions formattingOptions) { if (formattingOptions == null) throw new ArgumentNullException("formattingOptions"); this.formattingOptions = formattingOptions; }