diff --git a/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs b/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs index c84f4cdbf2..114cb780c6 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs @@ -877,14 +877,19 @@ namespace ICSharpCode.NRefactory.CSharp node = next; } } - + [Obsolete("Use ToString(options).")] + public string GetText (CSharpFormattingOptions formattingOptions = null) + { + return ToString(formattingOptions); + } + /// /// Gets the node as formatted C# output. /// /// /// Formatting options. /// - public virtual string GetText (CSharpFormattingOptions formattingOptions = null) + public virtual string ToString (CSharpFormattingOptions formattingOptions) { if (IsNull) return ""; @@ -892,7 +897,12 @@ namespace ICSharpCode.NRefactory.CSharp AcceptVisitor (new CSharpOutputVisitor (w, formattingOptions ?? FormattingOptionsFactory.CreateMono ())); return w.ToString (); } - + + public sealed override string ToString() + { + return ToString(null); + } + /// /// Returns true, if the given coordinates (line, column) are in the node. /// diff --git a/ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs b/ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs index 3f38eaf3a6..ddcd3ff3a9 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs @@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp } } - public override string GetText (CSharpFormattingOptions formattingOptions = null) + public override string ToString(CSharpFormattingOptions formattingOptions) { return GetModifierName (Modifier); } diff --git a/ICSharpCode.NRefactory.CSharp/Ast/CSharpTokenNode.cs b/ICSharpCode.NRefactory.CSharp/Ast/CSharpTokenNode.cs index 3de564d78e..725cb6d493 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/CSharpTokenNode.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/CSharpTokenNode.cs @@ -99,8 +99,8 @@ namespace ICSharpCode.NRefactory.CSharp if (role != null) this.flags |= role.TokenIndex << AstNodeFlagsUsedBits; } - - public override string GetText (CSharpFormattingOptions formattingOptions = null) + + public override string ToString(CSharpFormattingOptions formattingOptions) { return TokenRole.Tokens [(int)(this.flags >> AstNodeFlagsUsedBits)]; } @@ -125,11 +125,6 @@ namespace ICSharpCode.NRefactory.CSharp CSharpTokenNode o = other as CSharpTokenNode; return o != null && !o.IsNull && !(o is CSharpModifierToken); } - - public override string ToString () - { - return string.Format ("[CSharpTokenNode: StartLocation={0}, EndLocation={1}, Role={2}]", StartLocation, EndLocation, Role); - } } } diff --git a/ICSharpCode.NRefactory.CSharp/Ast/ComposedType.cs b/ICSharpCode.NRefactory.CSharp/Ast/ComposedType.cs index 2b274fa308..99ffe73d29 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/ComposedType.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/ComposedType.cs @@ -96,8 +96,8 @@ namespace ICSharpCode.NRefactory.CSharp && this.BaseType.DoMatch(o.BaseType, match) && this.ArraySpecifiers.DoMatch(o.ArraySpecifiers, match); } - - public override string ToString() + + public override string ToString(CSharpFormattingOptions formattingOptions) { StringBuilder b = new StringBuilder(); b.Append(this.BaseType.ToString()); @@ -210,8 +210,8 @@ namespace ICSharpCode.NRefactory.CSharp ArraySpecifier o = other as ArraySpecifier; return o != null && this.Dimensions == o.Dimensions; } - - public override string ToString() + + public override string ToString(CSharpFormattingOptions formattingOptions) { return "[" + new string(',', this.Dimensions - 1) + "]"; } diff --git a/ICSharpCode.NRefactory.CSharp/Ast/ErrorNode.cs b/ICSharpCode.NRefactory.CSharp/Ast/ErrorNode.cs index ee5f885215..e402a80471 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/ErrorNode.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/ErrorNode.cs @@ -78,8 +78,8 @@ namespace ICSharpCode.NRefactory.CSharp var o = other as ErrorNode; return o != null; } - - public override string ToString () + + public override string ToString(CSharpFormattingOptions formattingOptions) { return "[ErrorNode]"; } diff --git a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/Expression.cs b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/Expression.cs index 768f3bd79f..212aecdb5d 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/Expression.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/Expression.cs @@ -118,13 +118,7 @@ namespace ICSharpCode.NRefactory.CSharp { return (Expression)base.Clone(); } - - // Make debugging easier by giving Expressions a ToString() implementation - public override string ToString() - { - return DebugToString(); - } - + public Expression ReplaceWith(Func replaceFunction) { if (replaceFunction == null) diff --git a/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Attribute.cs b/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Attribute.cs index 74fd9d7e30..5a3b8985a7 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Attribute.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Attribute.cs @@ -74,13 +74,12 @@ namespace ICSharpCode.NRefactory.CSharp Attribute o = other as Attribute; return o != null && this.Type.DoMatch (o.Type, match) && this.Arguments.DoMatch (o.Arguments, match); } - - public override string ToString () + + public override string ToString(CSharpFormattingOptions formattingOptions) { if (IsNull) return "Null"; - else - return GetText(); + return base.ToString(formattingOptions); } } } diff --git a/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NewLineNode.cs b/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NewLineNode.cs index 0ddfb50a13..5eb148694b 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NewLineNode.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NewLineNode.cs @@ -76,7 +76,7 @@ namespace ICSharpCode.NRefactory.CSharp { } - public override string GetText(CSharpFormattingOptions formattingOptions) + public override string ToString(CSharpFormattingOptions formattingOptions) { return "\n"; } @@ -104,7 +104,7 @@ namespace ICSharpCode.NRefactory.CSharp { } - public override string GetText(CSharpFormattingOptions formattingOptions) + public override string ToString(CSharpFormattingOptions formattingOptions) { return "\r\n"; } @@ -132,7 +132,7 @@ namespace ICSharpCode.NRefactory.CSharp { } - public override string GetText(CSharpFormattingOptions formattingOptions) + public override string ToString(CSharpFormattingOptions formattingOptions) { return "\r"; } diff --git a/ICSharpCode.NRefactory.CSharp/Ast/MemberType.cs b/ICSharpCode.NRefactory.CSharp/Ast/MemberType.cs index d2a06d5175..2045d00edb 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/MemberType.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/MemberType.cs @@ -119,24 +119,7 @@ namespace ICSharpCode.NRefactory.CSharp && MatchString(this.MemberName, o.MemberName) && this.Target.DoMatch(o.Target, match) && this.TypeArguments.DoMatch(o.TypeArguments, match); } - - public override string ToString() - { - StringBuilder b = new StringBuilder(); - b.Append(this.Target); - if (IsDoubleColon) - b.Append("::"); - else - b.Append('.'); - b.Append(this.MemberName); - if (this.TypeArguments.Any()) { - b.Append('<'); - b.Append(string.Join(", ", this.TypeArguments)); - b.Append('>'); - } - return b.ToString(); - } - + public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null) { if (interningProvider == null) diff --git a/ICSharpCode.NRefactory.CSharp/Ast/PrimitiveType.cs b/ICSharpCode.NRefactory.CSharp/Ast/PrimitiveType.cs index c21df9b313..8861e32ee0 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/PrimitiveType.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/PrimitiveType.cs @@ -97,8 +97,8 @@ namespace ICSharpCode.NRefactory.CSharp PrimitiveType o = other as PrimitiveType; return o != null && MatchString(this.Keyword, o.Keyword); } - - public override string ToString() + + public override string ToString(CSharpFormattingOptions formattingOptions) { return Keyword; } diff --git a/ICSharpCode.NRefactory.CSharp/Ast/SimpleType.cs b/ICSharpCode.NRefactory.CSharp/Ast/SimpleType.cs index 5eb2832224..4001a9ea60 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/SimpleType.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/SimpleType.cs @@ -147,17 +147,6 @@ namespace ICSharpCode.NRefactory.CSharp return o != null && MatchString(this.Identifier, o.Identifier) && this.TypeArguments.DoMatch(o.TypeArguments, match); } - public override string ToString() - { - StringBuilder b = new StringBuilder(this.Identifier); - if (this.TypeArguments.Any()) { - b.Append('<'); - b.Append(string.Join(", ", this.TypeArguments)); - b.Append('>'); - } - return b.ToString(); - } - public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null) { if (interningProvider == null) diff --git a/ICSharpCode.NRefactory.CSharp/Ast/Statements/Statement.cs b/ICSharpCode.NRefactory.CSharp/Ast/Statements/Statement.cs index 593207c85a..c7046dab7e 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/Statements/Statement.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/Statements/Statement.cs @@ -122,11 +122,5 @@ namespace ICSharpCode.NRefactory.CSharp public override NodeType NodeType { get { return NodeType.Statement; } } - - // Make debugging easier by giving Statements a ToString() implementation - public override string ToString() - { - return DebugToString(); - } } } diff --git a/ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/VariableInitializer.cs b/ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/VariableInitializer.cs index 8b0c3fff2d..1d50928ddd 100644 --- a/ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/VariableInitializer.cs +++ b/ICSharpCode.NRefactory.CSharp/Ast/TypeMembers/VariableInitializer.cs @@ -163,15 +163,7 @@ namespace ICSharpCode.NRefactory.CSharp { return visitor.VisitVariableInitializer (this, data); } - - public override string ToString() - { - if (this.Initializer.IsNull) - return "[VariableInitializer " + this.Name + "]"; - else - return "[VariableInitializer " + this.Name + " = " + this.Initializer.ToString() + "]"; - } - + protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { VariableInitializer o = other as VariableInitializer;