Browse Source

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

pull/37/head
Daniel Grunwald 14 years ago
parent
commit
1a9a65d7a9
  1. 1
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 1
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  3. 7
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/ConstructorDeclaration.cs
  4. 9
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/TypeMembers/DestructorDeclaration.cs
  5. 8
      NRefactory/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

1
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -458,6 +458,7 @@ namespace Decompiler
// don't show visibility for static ctors // don't show visibility for static ctors
astMethod.Modifiers &= ~Modifiers.VisibilityMask; astMethod.Modifiers &= ~Modifiers.VisibilityMask;
} }
astMethod.Name = methodDef.DeclaringType.Name;
astMethod.Parameters.AddRange(MakeParameters(methodDef.Parameters)); astMethod.Parameters.AddRange(MakeParameters(methodDef.Parameters));
astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context); astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context);
return astMethod; return astMethod;

1
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -114,7 +114,6 @@
<Folder Include="Ast\Transforms" /> <Folder Include="Ast\Transforms" />
<Folder Include="Disassembler" /> <Folder Include="Disassembler" />
<Folder Include="ILAst" /> <Folder Include="ILAst" />
<Folder Include="Mono.Cecil.Rocks" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">

7
NRefactory/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
NRefactory/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
NRefactory/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