Browse Source

Fix folding bug with string interpolation

pull/1087/head
Siegfried Pammer 7 years ago
parent
commit
72917b0bde
  1. 4
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  2. 7
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InterpolatedStringExpression.cs
  3. 5
      ICSharpCode.Decompiler/Output/TextTokenWriter.cs

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

@ -999,13 +999,13 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -999,13 +999,13 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
{
StartNode(interpolation);
writer.WriteToken(Roles.LBrace, "{");
writer.WriteToken(Interpolation.LBrace, "{");
interpolation.Expression.AcceptVisitor(this);
if (interpolation.Suffix != null) {
writer.WriteToken(Roles.Colon, ":");
writer.WritePrimitiveValue("", interpolation.Suffix);
}
writer.WriteToken(Roles.RBrace, "}");
writer.WriteToken(Interpolation.RBrace, "}");
EndNode(interpolation);
}

7
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/InterpolatedStringExpression.cs

@ -86,8 +86,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -86,8 +86,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary>
public class Interpolation : InterpolatedStringContent
{
public static readonly TokenRole LBrace = new TokenRole("{");
public static readonly TokenRole RBrace = new TokenRole("}");
public CSharpTokenNode LBraceToken {
get { return GetChildByRole(Roles.LBrace); }
get { return GetChildByRole(LBrace); }
}
public Expression Expression {
@ -98,7 +101,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -98,7 +101,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public string Suffix { get; }
public CSharpTokenNode RBraceToken {
get { return GetChildByRole(Roles.RBrace); }
get { return GetChildByRole(RBrace); }
}
public Interpolation()

5
ICSharpCode.Decompiler/Output/TextTokenWriter.cs

@ -214,6 +214,10 @@ namespace ICSharpCode.Decompiler @@ -214,6 +214,10 @@ namespace ICSharpCode.Decompiler
{
switch (token) {
case "{":
if (role != Roles.LBrace) {
output.Write("{");
break;
}
if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration)
braceLevelWithinType++;
if (nodeStack.OfType<BlockStatement>().Count() <= 1 || FoldBraces) {
@ -223,6 +227,7 @@ namespace ICSharpCode.Decompiler @@ -223,6 +227,7 @@ namespace ICSharpCode.Decompiler
break;
case "}":
output.Write('}');
if (role != Roles.RBrace) break;
if (nodeStack.OfType<BlockStatement>().Count() <= 1 || FoldBraces)
output.MarkFoldEnd();
if (braceLevelWithinType >= 0)

Loading…
Cancel
Save