Browse Source

Add support for expression bodies to IndexerDeclaration.

pull/1440/head
Siegfried Pammer 7 years ago
parent
commit
78cf5f0ec0
  1. 23
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  2. 13
      ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/IndexerDeclaration.cs

23
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -2096,15 +2096,24 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
WriteKeyword(IndexerDeclaration.ThisKeywordRole); WriteKeyword(IndexerDeclaration.ThisKeywordRole);
Space(policy.SpaceBeforeMethodDeclarationParentheses); Space(policy.SpaceBeforeMethodDeclarationParentheses);
WriteCommaSeparatedListInBrackets(indexerDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses); WriteCommaSeparatedListInBrackets(indexerDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses);
OpenBrace(policy.PropertyBraceStyle);
// output get/set in their original order if (indexerDeclaration.ExpressionBody.IsNull) {
foreach (AstNode node in indexerDeclaration.Children) { OpenBrace(policy.PropertyBraceStyle);
if (node.Role == IndexerDeclaration.GetterRole || node.Role == IndexerDeclaration.SetterRole) { // output get/set in their original order
node.AcceptVisitor(this); foreach (AstNode node in indexerDeclaration.Children) {
if (node.Role == IndexerDeclaration.GetterRole || node.Role == IndexerDeclaration.SetterRole) {
node.AcceptVisitor(this);
}
} }
CloseBrace(policy.PropertyBraceStyle);
NewLine();
} else {
Space();
WriteToken(Roles.Arrow);
Space();
indexerDeclaration.ExpressionBody.AcceptVisitor(this);
Semicolon();
} }
CloseBrace(policy.PropertyBraceStyle);
NewLine();
EndNode(indexerDeclaration); EndNode(indexerDeclaration);
} }

13
ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/IndexerDeclaration.cs

@ -35,7 +35,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public static readonly TokenRole ThisKeywordRole = new TokenRole ("this"); public static readonly TokenRole ThisKeywordRole = new TokenRole ("this");
public static readonly Role<Accessor> GetterRole = PropertyDeclaration.GetterRole; public static readonly Role<Accessor> GetterRole = PropertyDeclaration.GetterRole;
public static readonly Role<Accessor> SetterRole = PropertyDeclaration.SetterRole; public static readonly Role<Accessor> SetterRole = PropertyDeclaration.SetterRole;
public static readonly Role<Expression> ExpressionBodyRole = new Role<Expression>("ExpressionBody", Expression.Null);
public override SymbolKind SymbolKind { public override SymbolKind SymbolKind {
get { return SymbolKind.Indexer; } get { return SymbolKind.Indexer; }
} }
@ -93,7 +94,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public CSharpTokenNode RBraceToken { public CSharpTokenNode RBraceToken {
get { return GetChildByRole (Roles.RBrace); } get { return GetChildByRole (Roles.RBrace); }
} }
public Expression ExpressionBody {
get { return GetChildByRole(ExpressionBodyRole); }
set { SetChildByRole(ExpressionBodyRole, value); }
}
public override void AcceptVisitor (IAstVisitor visitor) public override void AcceptVisitor (IAstVisitor visitor)
{ {
visitor.VisitIndexerDeclaration (this); visitor.VisitIndexerDeclaration (this);
@ -116,7 +122,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
&& this.MatchAttributesAndModifiers(o, match) && this.ReturnType.DoMatch(o.ReturnType, match) && this.MatchAttributesAndModifiers(o, match) && this.ReturnType.DoMatch(o.ReturnType, match)
&& this.PrivateImplementationType.DoMatch(o.PrivateImplementationType, match) && this.PrivateImplementationType.DoMatch(o.PrivateImplementationType, match)
&& this.Parameters.DoMatch(o.Parameters, match) && this.Parameters.DoMatch(o.Parameters, match)
&& this.Getter.DoMatch(o.Getter, match) && this.Setter.DoMatch(o.Setter, match); && this.Getter.DoMatch(o.Getter, match) && this.Setter.DoMatch(o.Setter, match)
&& this.ExpressionBody.DoMatch(o.ExpressionBody, match);
} }
} }
} }

Loading…
Cancel
Save