Browse Source

OutputVisitor: allow writing constructor declarations without writing their parent type declaration.

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
84a5ace4aa
  1. 7
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs
  2. 9
      ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs
  3. 8
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

7
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs

@ -33,6 +33,13 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
public static readonly Role<ConstructorInitializer> InitializerRole = new Role<ConstructorInitializer>("Initializer", ConstructorInitializer.Null); public static readonly Role<ConstructorInitializer> InitializerRole = new Role<ConstructorInitializer>("Initializer", ConstructorInitializer.Null);
/// <summary>
/// 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.
/// </summary>
public string Name { get; set; }
public CSharpTokenNode LParToken { public CSharpTokenNode LParToken {
get { return GetChildByRole (Roles.LPar); } get { return GetChildByRole (Roles.LPar); }
} }

9
ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs

@ -1,4 +1,4 @@
// //
// DestructorDeclaration.cs // DestructorDeclaration.cs
// //
// Author: // Author:
@ -34,6 +34,13 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (TildeRole); } get { return GetChildByRole (TildeRole); }
} }
/// <summary>
/// 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.
/// </summary>
public string Name { get; set; }
public CSharpTokenNode LParToken { public CSharpTokenNode LParToken {
get { return GetChildByRole (Roles.LPar); } get { return GetChildByRole (Roles.LPar); }
} }

8
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

@ -1626,9 +1626,7 @@ namespace ICSharpCode.NRefactory.CSharp
WriteAttributes(constructorDeclaration.Attributes); WriteAttributes(constructorDeclaration.Attributes);
WriteModifiers(constructorDeclaration.ModifierTokens); WriteModifiers(constructorDeclaration.ModifierTokens);
TypeDeclaration type = constructorDeclaration.Parent as TypeDeclaration; TypeDeclaration type = constructorDeclaration.Parent as TypeDeclaration;
if (type != null) { WriteIdentifier(type != null ? type.Name : constructorDeclaration.Name);
WriteIdentifier(type.Name);
}
Space(policy.BeforeConstructorDeclarationParentheses); Space(policy.BeforeConstructorDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(constructorDeclaration.Parameters, policy.WithinMethodDeclarationParentheses); WriteCommaSeparatedListInParenthesis(constructorDeclaration.Parameters, policy.WithinMethodDeclarationParentheses);
if (!constructorDeclaration.Initializer.IsNull) { if (!constructorDeclaration.Initializer.IsNull) {
@ -1661,9 +1659,7 @@ namespace ICSharpCode.NRefactory.CSharp
WriteModifiers(destructorDeclaration.ModifierTokens); WriteModifiers(destructorDeclaration.ModifierTokens);
WriteToken("~", DestructorDeclaration.TildeRole); WriteToken("~", DestructorDeclaration.TildeRole);
TypeDeclaration type = destructorDeclaration.Parent as TypeDeclaration; TypeDeclaration type = destructorDeclaration.Parent as TypeDeclaration;
if (type != null) { WriteIdentifier(type != null ? type.Name : destructorDeclaration.Name);
WriteIdentifier(type.Name);
}
Space(policy.BeforeConstructorDeclarationParentheses); Space(policy.BeforeConstructorDeclarationParentheses);
LPar(); LPar();
RPar(); RPar();

Loading…
Cancel
Save