From 84a5ace4aa0718ffe9ca419c503144edcdf35c6f Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 20 Feb 2011 00:15:20 +0100 Subject: [PATCH] OutputVisitor: allow writing constructor declarations without writing their parent type declaration. --- .../CSharp/Ast/TypeMembers/ConstructorDeclaration.cs | 7 +++++++ .../CSharp/Ast/TypeMembers/DestructorDeclaration.cs | 9 ++++++++- .../CSharp/OutputVisitor/OutputVisitor.cs | 8 ++------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs index 8960dd0ad7..97f808051d 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs @@ -33,6 +33,13 @@ namespace ICSharpCode.NRefactory.CSharp { public static readonly Role InitializerRole = new Role("Initializer", ConstructorInitializer.Null); + /// + /// Gets/Sets the name of the class containing the constructor. + /// This property can be used to inform the output visitor about the class name when writing a constructor declaration + /// without writing the complete type declaration. It is ignored when the constructor has a type declaration as parent. + /// + public string Name { get; set; } + public CSharpTokenNode LParToken { get { return GetChildByRole (Roles.LPar); } } diff --git a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs index 2336d46d28..2798d0660c 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs @@ -1,4 +1,4 @@ -// +// // DestructorDeclaration.cs // // Author: @@ -34,6 +34,13 @@ namespace ICSharpCode.NRefactory.CSharp get { return GetChildByRole (TildeRole); } } + /// + /// Gets/Sets the name of the class containing the destructor. + /// This property can be used to inform the output visitor about the class name when writing a destructor declaration + /// without writing the complete type declaration. It is ignored when the destructor has a type declaration as parent. + /// + public string Name { get; set; } + public CSharpTokenNode LParToken { get { return GetChildByRole (Roles.LPar); } } diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs index 80f0b03a2a..42f049978b 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs @@ -1626,9 +1626,7 @@ namespace ICSharpCode.NRefactory.CSharp WriteAttributes(constructorDeclaration.Attributes); WriteModifiers(constructorDeclaration.ModifierTokens); TypeDeclaration type = constructorDeclaration.Parent as TypeDeclaration; - if (type != null) { - WriteIdentifier(type.Name); - } + WriteIdentifier(type != null ? type.Name : constructorDeclaration.Name); Space(policy.BeforeConstructorDeclarationParentheses); WriteCommaSeparatedListInParenthesis(constructorDeclaration.Parameters, policy.WithinMethodDeclarationParentheses); if (!constructorDeclaration.Initializer.IsNull) { @@ -1661,9 +1659,7 @@ namespace ICSharpCode.NRefactory.CSharp WriteModifiers(destructorDeclaration.ModifierTokens); WriteToken("~", DestructorDeclaration.TildeRole); TypeDeclaration type = destructorDeclaration.Parent as TypeDeclaration; - if (type != null) { - WriteIdentifier(type.Name); - } + WriteIdentifier(type != null ? type.Name : destructorDeclaration.Name); Space(policy.BeforeConstructorDeclarationParentheses); LPar(); RPar();