@@ -55,6 +55,43 @@ public CSharpPrinter()
5555 }
5656 }
5757
58+ public override J ? VisitPointerType ( Cs . PointerType node , PrintOutputCapture < TState > p )
59+ {
60+ BeforeSyntax ( node , CsSpace . Location . POINTER_TYPE_PREFIX , p ) ;
61+ VisitRightPadded ( node . Padding . ElementType , CsRightPadded . Location . POINTER_TYPE_ELEMENT_TYPE , "*" , p ) ;
62+ AfterSyntax ( node , p ) ;
63+ return node ;
64+ }
65+
66+ public override Cs VisitTry ( Cs . Try tryable , PrintOutputCapture < TState > p )
67+ {
68+ BeforeSyntax ( tryable , Space . Location . TRY_PREFIX , p ) ;
69+ p . Append ( "try" ) ;
70+ Visit ( tryable . Body , p ) ;
71+ Visit ( tryable . Catches , p ) ;
72+ VisitLeftPadded ( "finally" , tryable . Padding . Finally , CsLeftPadded . Location . TRY_FINALLIE , p ) ;
73+ AfterSyntax ( tryable , p ) ;
74+ return tryable ;
75+ }
76+
77+
78+
79+ public override Cs VisitTryCatch ( Cs . Try . Catch @catch , PrintOutputCapture < TState > p )
80+ {
81+ BeforeSyntax ( @catch , Space . Location . CATCH_PREFIX , p ) ;
82+ p . Append ( "catch" ) ;
83+ if ( @catch . Parameter . Tree . TypeExpression != null )
84+ {
85+ Visit ( @catch . Parameter , p ) ;
86+ }
87+
88+ VisitLeftPadded ( "when" , @catch . Padding . FilterExpression , CsLeftPadded . Location . TRY_CATCH_FILTER_EXPRESSION , p ) ;
89+
90+ Visit ( @catch . Body , p ) ;
91+ AfterSyntax ( @catch , p ) ;
92+ return @catch ;
93+ }
94+
5895 public override Cs VisitArrayType ( Cs . ArrayType newArray , PrintOutputCapture < TState > p )
5996 {
6097 BeforeSyntax ( newArray , CsSpace . Location . ARRAY_TYPE_PREFIX , p ) ;
@@ -150,7 +187,6 @@ public override Cs VisitArrayType(Cs.ArrayType newArray, PrintOutputCapture<TSta
150187 VisitRightPadded ( node . Padding . LeftExpression , CsRightPadded . Location . JOIN_CLAUSE_LEFT_EXPRESSION , p ) ;
151188 p . Append ( "equals" ) ;
152189 Visit ( node . RightExpression , p ) ;
153- VisitLeftPadded ( "into" , node . Padding . Into , CsLeftPadded . Location . JOIN_CLAUSE_INTO , p ) ;
154190 Visit ( node . Into , p ) ;
155191 AfterSyntax ( node , p ) ;
156192 return node ;
@@ -282,15 +318,42 @@ protected void VisitRightPadded<T>(JRightPadded<T>? rightPadded, CsRightPadded.L
282318 return node ;
283319 }
284320
321+ public override J ? VisitCheckedExpression ( Cs . CheckedExpression node , PrintOutputCapture < TState > p )
322+ {
323+ BeforeSyntax ( node , CsSpace . Location . CHECKED_EXPRESSION_PREFIX , p ) ;
324+ Visit ( node . CheckedOrUncheckedKeyword , p ) ;
325+ Visit ( node . Expression , p ) ;
326+ AfterSyntax ( node , p ) ;
327+ return node ;
328+ }
285329 public override J ? VisitCheckedStatement ( Cs . CheckedStatement node , PrintOutputCapture < TState > p )
286330 {
287331 BeforeSyntax ( node , CsSpace . Location . CHECKED_STATEMENT_PREFIX , p ) ;
288- p . Append ( "checked" ) ;
332+ Visit ( node . Keyword , p ) ;
289333 Visit ( node . Block , p ) ;
290334 AfterSyntax ( node , p ) ;
291335 return node ;
292336 }
293337
338+ public override J ? VisitRefExpression ( Cs . RefExpression node , PrintOutputCapture < TState > p )
339+ {
340+ BeforeSyntax ( node , CsSpace . Location . REF_EXPRESSION_PREFIX , p ) ;
341+ p . Append ( "ref" ) ;
342+ Visit ( node . Expression , p ) ;
343+ AfterSyntax ( node , p ) ;
344+ return node ;
345+ }
346+
347+ public override J ? VisitRefType ( Cs . RefType node , PrintOutputCapture < TState > p )
348+ {
349+ BeforeSyntax ( node , CsSpace . Location . REF_TYPE_PREFIX , p ) ;
350+ p . Append ( "ref" ) ;
351+ Visit ( node . ReadonlyKeyword , p ) ;
352+ Visit ( node . TypeIdentifier , p ) ;
353+ AfterSyntax ( node , p ) ;
354+ return node ;
355+ }
356+
294357 public override J ? VisitRangeExpression ( Cs . RangeExpression node , PrintOutputCapture < TState > p )
295358 {
296359 BeforeSyntax ( node , CsSpace . Location . RANGE_EXPRESSION_PREFIX , p ) ;
@@ -649,6 +712,10 @@ protected void VisitRightPadded<T>(JRightPadded<T>? rightPadded, CsRightPadded.L
649712 Visit ( unary . Expression , p ) ;
650713 break ;
651714 case Cs . Unary . Types . PointerIndirection :
715+ p . Append ( "*" ) ;
716+ Visit ( unary . Expression , p ) ;
717+ break ;
718+ case Cs . Unary . Types . PointerType :
652719 Visit ( unary . Expression , p ) ;
653720 p . Append ( "*" ) ;
654721 break ;
@@ -666,6 +733,71 @@ protected void VisitRightPadded<T>(JRightPadded<T>? rightPadded, CsRightPadded.L
666733 return unary ;
667734 }
668735
736+ public override J ? VisitAccessorDeclaration ( Cs . AccessorDeclaration node , PrintOutputCapture < TState > p )
737+ {
738+ BeforeSyntax ( node , CsSpace . Location . ACCESSOR_DECLARATION_PREFIX , p ) ;
739+ Visit ( node . Attributes , p ) ;
740+ Visit ( node . Modifiers , p ) ;
741+ VisitLeftPaddedEnum ( node . Padding . Kind , CsLeftPadded . Location . ACCESSOR_DECLARATION_KIND , p ) ;
742+ Visit ( node . ExpressionBody , p ) ;
743+ Visit ( node . Body , p ) ;
744+ AfterSyntax ( node , p ) ;
745+ return node ;
746+ }
747+
748+ public override J ? VisitArrowExpressionClause ( Cs . ArrowExpressionClause node , PrintOutputCapture < TState > p )
749+ {
750+ BeforeSyntax ( node , CsSpace . Location . ARROW_EXPRESSION_CLAUSE_PREFIX , p ) ;
751+ p . Append ( "=>" ) ;
752+ VisitRightPadded ( node . Padding . Expression , CsRightPadded . Location . ARROW_EXPRESSION_CLAUSE_EXPRESSION , ";" , p ) ;
753+ AfterSyntax ( node , p ) ;
754+ return node ;
755+ }
756+
757+ public override J ? VisitStackAllocExpression ( Cs . StackAllocExpression node , PrintOutputCapture < TState > p )
758+ {
759+ BeforeSyntax ( node , Space . Location . COMPILATION_UNIT_PREFIX , p ) ;
760+ p . Append ( "stackalloc" ) ;
761+ var newArray = node . Expression ;
762+ VisitSpace ( newArray . Prefix , Space . Location . NEW_ARRAY_INITIALIZER , p ) ;
763+ Visit ( newArray . TypeExpression , p ) ;
764+ Visit ( newArray . Dimensions , p ) ;
765+ VisitContainer ( "{" , newArray . Padding . Initializer , CsContainer . Location . ANY , "," , "}" , p ) ;
766+ AfterSyntax ( node , p ) ;
767+ return node ;
768+ }
769+
770+
771+ public override Cs VisitPointerFieldAccess ( Cs . PointerFieldAccess node , PrintOutputCapture < TState > p )
772+ {
773+ BeforeSyntax ( node , CsSpace . Location . POINTER_FIELD_ACCESS_PREFIX , p ) ;
774+ Visit ( node . Target , p ) ;
775+ VisitLeftPadded ( "->" , node . Padding . Name , CsLeftPadded . Location . POINTER_FIELD_ACCESS_NAME , p ) ;
776+ AfterSyntax ( node , p ) ;
777+ return node ;
778+ }
779+
780+ public override J ? VisitGotoStatement ( Cs . GotoStatement node , PrintOutputCapture < TState > p )
781+ {
782+ BeforeSyntax ( node , CsSpace . Location . GOTO_STATEMENT_PREFIX , p ) ;
783+ p . Append ( "goto" ) ;
784+ Visit ( node . CaseOrDefaultKeyword , p ) ;
785+ Visit ( node . Target , p ) ;
786+ return node ;
787+ }
788+
789+ public override J ? VisitEventDeclaration ( Cs . EventDeclaration node , PrintOutputCapture < TState > p )
790+ {
791+ BeforeSyntax ( node , CsSpace . Location . EVENT_DECLARATION_PREFIX , p ) ;
792+ Visit ( node . AttributeLists , p ) ;
793+ Visit ( node . Modifiers , p ) ;
794+ VisitLeftPadded ( "event" , node . Padding . TypeExpression , CsLeftPadded . Location . EVENT_DECLARATION_TYPE_EXPRESSION , p ) ;
795+ VisitRightPadded ( node . Padding . InterfaceSpecifier , CsRightPadded . Location . EVENT_DECLARATION_INTERFACE_SPECIFIER , "." , p ) ;
796+ Visit ( node . Name , p ) ;
797+ VisitContainer ( "{" , node . Padding . Accessors , CsContainer . Location . EVENT_DECLARATION_ACCESSORS , "" , "}" , p ) ;
798+ return node ;
799+ }
800+
669801 public override Cs VisitCompilationUnit ( Cs . CompilationUnit compilationUnit , PrintOutputCapture < TState > p )
670802 {
671803 BeforeSyntax ( compilationUnit , Space . Location . COMPILATION_UNIT_PREFIX , p ) ;
@@ -716,7 +848,7 @@ public override Cs VisitCompilationUnit(Cs.CompilationUnit compilationUnit, Prin
716848 public override J ? VisitMethodDeclaration ( Cs . MethodDeclaration node , PrintOutputCapture < TState > p )
717849 {
718850 BeforeSyntax ( node , Space . Location . METHOD_DECLARATION_PREFIX , p ) ;
719- VisitSpace ( Space . EMPTY , Space . Location . ANNOTATIONS , p ) ;
851+ Visit ( node . Attributes , p ) ;
720852
721853 Visit ( node . Modifiers , p ) ;
722854
@@ -739,19 +871,15 @@ public override Cs VisitCompilationUnit(Cs.CompilationUnit compilationUnit, Prin
739871 }
740872
741873
742- public override J ? VisitAnnotatedStatement ( Cs . AnnotatedStatement annotatedStatement , PrintOutputCapture < TState > p )
874+ public override J ? VisitAnnotatedStatement ( Cs . AnnotatedStatement node , PrintOutputCapture < TState > p )
743875 {
744- BeforeSyntax ( annotatedStatement , CsSpace . Location . ANNOTATED_STATEMENT_PREFIX , p ) ;
745-
746- foreach ( var attributeList in annotatedStatement . AttributeLists )
747- {
748- Visit ( attributeList , p ) ;
749- }
876+ BeforeSyntax ( node , CsSpace . Location . ANNOTATED_STATEMENT_PREFIX , p ) ;
750877
751- Visit ( annotatedStatement . Statement , p ) ;
752- AfterSyntax ( annotatedStatement , p ) ;
878+ Visit ( node . AttributeLists , p ) ;
879+ Visit ( node . Statement , p ) ;
880+ AfterSyntax ( node , p ) ;
753881
754- return annotatedStatement ;
882+ return node ;
755883 }
756884
757885 public override J ? VisitAttributeList ( Cs . AttributeList attributeList , PrintOutputCapture < TState > p )
@@ -970,30 +1098,13 @@ public override Cs VisitFileScopeNamespaceDeclaration(Cs.FileScopeNamespaceDecla
9701098 {
9711099 BeforeSyntax ( propertyDeclaration , CsSpace . Location . PROPERTY_DECLARATION_PREFIX , p ) ;
9721100 Visit ( propertyDeclaration . AttributeLists , p ) ;
973-
974- foreach ( var m in propertyDeclaration . Modifiers )
975- {
976- _delegate . VisitModifier ( m , p ) ;
977- }
978-
1101+ Visit ( propertyDeclaration . Modifiers , p ) ;
9791102 Visit ( propertyDeclaration . TypeExpression , p ) ;
980-
981- if ( propertyDeclaration . Padding . InterfaceSpecifier != null )
982- {
983- VisitRightPadded ( propertyDeclaration . Padding . InterfaceSpecifier ,
984- CsRightPadded . Location . PROPERTY_DECLARATION_INTERFACE_SPECIFIER , p ) ;
985- p . Append ( '.' ) ;
986- }
987-
1103+ VisitRightPadded ( propertyDeclaration . Padding . InterfaceSpecifier , CsRightPadded . Location . PROPERTY_DECLARATION_INTERFACE_SPECIFIER , "." , p ) ;
9881104 Visit ( propertyDeclaration . Name , p ) ;
9891105 Visit ( propertyDeclaration . Accessors , p ) ;
990-
991- if ( propertyDeclaration . Initializer != null )
992- {
993- VisitLeftPadded ( "=" , propertyDeclaration . Padding . Initializer ,
994- CsLeftPadded . Location . PROPERTY_DECLARATION_INITIALIZER , p ) ;
995- }
996-
1106+ Visit ( propertyDeclaration . ExpressionBody , p ) ;
1107+ VisitLeftPadded ( "=" , propertyDeclaration . Padding . Initializer , CsLeftPadded . Location . PROPERTY_DECLARATION_INITIALIZER , p ) ;
9971108 AfterSyntax ( propertyDeclaration , p ) ;
9981109 return propertyDeclaration ;
9991110 }
@@ -1082,11 +1193,8 @@ public override Cs VisitFileScopeNamespaceDeclaration(Cs.FileScopeNamespaceDecla
10821193 public override J ? VisitDelegateDeclaration ( Cs . DelegateDeclaration node , PrintOutputCapture < TState > p )
10831194 {
10841195 BeforeSyntax ( node , CsSpace . Location . DELEGATE_DECLARATION_PREFIX , p ) ;
1085- foreach ( var modifier in node . Modifiers )
1086- {
1087- Visit ( modifier , p ) ;
1088- }
1089-
1196+ Visit ( node . Attributes , p ) ;
1197+ Visit ( node . Modifiers , p ) ;
10901198 VisitLeftPadded ( "delegate" , node . Padding . ReturnType , CsLeftPadded . Location . DELEGATE_DECLARATION_RETURN_TYPE , p ) ;
10911199 Visit ( node . Identifier , p ) ;
10921200 VisitContainer ( "<" , node . Padding . TypeParameters , CsContainer . Location . CONVERSION_OPERATOR_DECLARATION_PARAMETERS , "," , ">" , p ) ;
@@ -1159,14 +1267,10 @@ public override Cs VisitFileScopeNamespaceDeclaration(Cs.FileScopeNamespaceDecla
11591267
11601268 public override Cs VisitLambda ( Cs . Lambda lambda , PrintOutputCapture < TState > p )
11611269 {
1162- if ( lambda . Modifiers . Any ( ) ) // only put space in front if current node actually has anything to contribute
1163- {
1164- BeforeSyntax ( lambda , Space . Location . LAMBDA_PREFIX , p ) ;
1165- }
1270+ BeforeSyntax ( lambda , Space . Location . LAMBDA_PREFIX , p ) ;
11661271
11671272 var javaLambda = lambda . LambdaExpression ;
11681273
1169- VisitSpace ( lambda . Prefix , Space . Location . LAMBDA_PARAMETERS_PREFIX , p ) ;
11701274 VisitMarkers ( lambda . Markers , p ) ;
11711275 foreach ( var modifier in lambda . Modifiers )
11721276 {
@@ -1375,6 +1479,7 @@ public override J VisitNewArray(J.NewArray newArray, PrintOutputCapture<TState>
13751479
13761480
13771481
1482+
13781483 public override J ? VisitClassDeclarationKind ( J . ClassDeclaration . Kind kind , PrintOutputCapture < TState > p )
13791484 {
13801485 BeforeSyntax ( kind , Space . Location . CLASS_KIND , p ) ;
@@ -1443,11 +1548,21 @@ public override J VisitBlock(J.Block block, PrintOutputCapture<TState> p)
14431548 if ( block . Markers . FirstOrDefault ( m => m is SingleExpressionBlock ) != null )
14441549 {
14451550 p . Append ( "=>" ) ;
1446- VisitStatements ( block . Padding . Statements , JRightPadded . Location . BLOCK_STATEMENT , p ) ;
1551+ var statement = block . Padding . Statements . First ( ) ;
1552+ if ( statement . Element is Cs . ExpressionStatement expressionStatement )
1553+ {
1554+ // expression statements model their own semicolon
1555+ Visit ( expressionStatement , p ) ;
1556+ }
1557+ else
1558+ {
1559+ VisitRightPadded ( statement , JRightPadded . Location . BLOCK_STATEMENT , ";" , p ) ;
1560+ }
1561+ // VisitStatements(block.Padding.Statements, JRightPadded.Location.BLOCK_STATEMENT, p);
14471562
1448- VisitSpace ( block . End , Space . Location . BLOCK_END , p ) ;
1563+ // VisitSpace(block.End, Space.Location.BLOCK_END, p);
14491564 }
1450- else if ( ! block . Markers . OfType < OmitBraces > ( ) . Any ( ) || block . Statements . Any ( ) )
1565+ else if ( ! block . Markers . OfType < OmitBraces > ( ) . Any ( ) )
14511566 {
14521567 p . Append ( '{' ) ;
14531568 VisitStatements ( block . Padding . Statements , JRightPadded . Location . BLOCK_STATEMENT , p ) ;
@@ -1472,7 +1587,6 @@ public override J VisitBlock(J.Block block, PrintOutputCapture<TState> p)
14721587 return block ;
14731588 }
14741589
1475-
14761590 protected override void VisitStatements ( IList < JRightPadded < Statement > > statements , JRightPadded . Location location , PrintOutputCapture < TState > p )
14771591 {
14781592
@@ -1654,6 +1768,11 @@ public override M VisitMarker<M>(M marker, PrintOutputCapture<TState> p)
16541768 // override print
16551769 public override void PrintStatementTerminator ( Statement s , PrintOutputCapture < TState > p )
16561770 {
1771+ while ( s is Cs . AnnotatedStatement annotatedStatement )
1772+ s = annotatedStatement . Statement ;
1773+ // while (s is Cs.FixedStatement f && f.Block.Markers.OfType<OmitBraces>().Any() && f.Block.Statements.Count > 0)
1774+ // s = f.Block.Statements.First();
1775+
16571776 if ( s is
16581777 Cs . ExpressionStatement or
16591778 Cs . AwaitExpression { Expression : J . ForEachLoop { Body : J . Block } } )
@@ -1667,7 +1786,10 @@ Cs.Yield or
16671786 Cs . DelegateDeclaration or
16681787 Cs . UsingStatement { Statement : not J . Block and not Cs . UsingStatement and not Cs . ExpressionStatement } or
16691788 Cs . AwaitExpression { Expression : not J . ForEachLoop { Body : not J . Block } } or
1670- Cs . PropertyDeclaration { Initializer : not null }
1789+ Cs . PropertyDeclaration { Initializer : not null } or
1790+ Cs . EventDeclaration { Accessors : null } or
1791+ Cs . GotoStatement or
1792+ Cs . AccessorDeclaration { Body : null , ExpressionBody : null }
16711793 )
16721794 {
16731795 p . Append ( ';' ) ;
0 commit comments