From a3e92ff7ed90b7e09d2b0098afa56b03162d4f56 Mon Sep 17 00:00:00 2001 From: Andrew Stakhov Date: Wed, 18 Dec 2024 07:53:55 -0500 Subject: [PATCH] Add support for many new c# LST(#26) --- Rewrite/Directory.Build.props | 2 + Rewrite/Rewrite.Sources.sln | 2 +- Rewrite/src/Rewrite.CSharp/CSharpPrinter.cs | 385 ++- .../CSharpTypeSignatureBuilder.cs | 6 +- Rewrite/src/Rewrite.CSharp/CSharpVisitor.g.cs | 283 +- .../Parser/CSharpParserVisitor.cs | 882 +++--- .../Rewrite.CSharp/Tree/AliasQualifiedName.cs | 21 + .../Tree/AliasQualifiedName.g.cs | 136 + .../Tree/AllowsConstraintClause.g.cs | 2 +- .../Tree/AnnotatedStatement.g.cs | 2 +- Rewrite/src/Rewrite.CSharp/Tree/Argument.g.cs | 2 +- .../Tree/ArrayRankSpecifier.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/ArrayType.g.cs | 95 + .../Tree/AssignmentOperation.g.cs | 2 +- .../Rewrite.CSharp/Tree/AttributeList.g.cs | 2 +- .../Rewrite.CSharp/Tree/AwaitExpression.g.cs | 8 +- Rewrite/src/Rewrite.CSharp/Tree/Binary.g.cs | 2 +- .../Rewrite.CSharp/Tree/BinaryPattern.g.cs | 2 +- .../Tree/BlockScopeNamespaceDeclaration.g.cs | 2 +- .../Tree/CasePatternSwitchLabel.g.cs | 2 +- .../Rewrite.CSharp/Tree/CheckedStatement.g.cs | 2 +- .../Rewrite.CSharp/Tree/ClassDeclaration.g.cs | 134 +- .../Tree/ClassOrStructConstraint.g.cs | 2 +- .../Tree/CollectionExpression.g.cs | 2 +- .../Rewrite.CSharp/Tree/CompilationUnit.g.cs | 2 +- .../Rewrite.CSharp/Tree/ConstantPattern.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/Constructor.g.cs | 2 +- .../Tree/ConstructorConstraint.g.cs | 2 +- .../Tree/ConstructorInitializer.g.cs | 26 +- .../Tree/ConversionOperatorDeclaration.g.cs | 196 ++ .../Tree/DeclarationExpression.g.cs | 2 +- .../Tree/DefaultConstraint.g.cs | 2 +- .../Tree/DefaultExpression.g.cs | 2 +- .../Tree/DefaultSwitchLabel.g.cs | 2 +- .../Tree/DelegateDeclaration.g.cs | 197 ++ .../Tree/DestructorDeclaration.g.cs | 23 +- .../Rewrite.CSharp/Tree/DiscardPattern.g.cs | 2 +- .../Tree/DiscardVariableDesignation.g.cs | 2 +- .../Rewrite.CSharp/Tree/EnumDeclaration.g.cs | 181 ++ .../Tree/EnumMemberDeclaration.g.cs | 146 + .../Tree/ExpressionStatement.g.cs | 51 +- .../src/Rewrite.CSharp/Tree/ExternAlias.g.cs | 2 +- .../Tree/FileScopeNamespaceDeclaration.g.cs | 2 +- .../Rewrite.CSharp/Tree/FixedStatement.g.cs | 2 +- .../Tree/ForEachVariableLoop.g.cs | 4 +- .../src/Rewrite.CSharp/Tree/FromClause.g.cs | 148 + .../src/Rewrite.CSharp/Tree/GroupClause.g.cs | 134 + .../Tree/ImplicitElementAccess.g.cs | 2 +- .../Tree/IndexerDeclaration.g.cs | 176 ++ .../Tree/InitializerExpression.g.cs | 2 +- .../Tree/InterpolatedString.g.cs | 2 +- .../Rewrite.CSharp/Tree/Interpolation.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/IsPattern.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/JoinClause.g.cs | 189 ++ .../Rewrite.CSharp/Tree/JoinIntoClause.g.cs | 100 + Rewrite/src/Rewrite.CSharp/Tree/Keyword.g.cs | 2 +- Rewrite/src/Rewrite.CSharp/Tree/Lambda.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/LetClause.g.cs | 147 + .../src/Rewrite.CSharp/Tree/ListPattern.g.cs | 2 +- .../Rewrite.CSharp/Tree/LockStatement.g.cs | 2 +- .../Tree/MethodDeclaration.g.cs | 98 +- Rewrite/src/Rewrite.CSharp/Tree/NewClass.g.cs | 2 +- .../Tree/NullSafeExpression.g.cs | 2 +- .../Rewrite.CSharp/Tree/OrderByClause.g.cs | 137 + Rewrite/src/Rewrite.CSharp/Tree/Ordering.g.cs | 137 + .../Tree/ParenthesizedPattern.g.cs | 2 +- .../ParenthesizedVariableDesignation.g.cs | 2 +- .../Tree/PositionalPatternClause.g.cs | 2 +- .../Tree/PropertyDeclaration.g.cs | 2 +- .../Tree/PropertyPatternClause.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/QueryBody.g.cs | 115 + .../src/Rewrite.CSharp/Tree/QueryClause.g.cs | 30 + .../Tree/QueryContinuation.g.cs | 106 + .../Rewrite.CSharp/Tree/QueryExpression.g.cs | 110 + .../Rewrite.CSharp/Tree/RangeExpression.g.cs | 2 +- .../Rewrite.CSharp/Tree/RecursivePattern.g.cs | 2 +- .../Tree/RefStructConstraint.g.cs | 2 +- .../Tree/RelationalPattern.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/SelectClause.g.cs | 90 + .../Tree/SelectOrGroupClause.g.cs | 30 + .../Tree/SingleVariableDesignation.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/SlicePattern.g.cs | 2 +- .../Tree/StatementExpression.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/Subpattern.g.cs | 8 +- .../Rewrite.CSharp/Tree/SwitchExpression.g.cs | 2 +- .../Tree/SwitchExpressionArm.g.cs | 2 +- .../Rewrite.CSharp/Tree/SwitchSection.g.cs | 2 +- .../Rewrite.CSharp/Tree/SwitchStatement.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/TupleElement.g.cs | 2 +- .../Rewrite.CSharp/Tree/TupleExpression.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/TupleType.g.cs | 2 +- .../Rewrite.CSharp/Tree/TypeConstraint.g.cs | 4 +- .../Rewrite.CSharp/Tree/TypeParameter.g.cs | 152 + .../Tree/TypeParameterConstraintClause.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/TypePattern.g.cs | 2 +- Rewrite/src/Rewrite.CSharp/Tree/Unary.g.cs | 5 +- .../src/Rewrite.CSharp/Tree/UnaryPattern.g.cs | 2 +- .../Rewrite.CSharp/Tree/UnsafeStatement.g.cs | 2 +- .../Rewrite.CSharp/Tree/UsingDirective.g.cs | 2 +- .../Rewrite.CSharp/Tree/UsingStatement.g.cs | 16 +- .../src/Rewrite.CSharp/Tree/VarPattern.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/WhereClause.g.cs | 101 + Rewrite/src/Rewrite.CSharp/Tree/Yield.g.cs | 2 +- .../src/Rewrite.CSharp/Tree/_Extensions.cs | 31 + Rewrite/src/Rewrite.Core/ParseError.cs | 13 +- Rewrite/src/Rewrite.Core/ParseErrorResult.cs | 2 + .../src/Rewrite.Java/Tree/AnnotatedType.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Annotation.g.cs | 2 +- .../src/Rewrite.Java/Tree/ArrayAccess.g.cs | 2 +- .../src/Rewrite.Java/Tree/ArrayDimension.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/ArrayType.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Assert.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Assignment.g.cs | 2 +- .../Tree/AssignmentOperation.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Binary.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Block.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Break.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Case.g.cs | 2 +- .../Rewrite.Java/Tree/ClassDeclaration.g.cs | 4 +- .../Rewrite.Java/Tree/CompilationUnit.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Continue.g.cs | 2 +- .../Rewrite.Java/Tree/ControlParentheses.g.cs | 2 +- .../src/Rewrite.Java/Tree/DoWhileLoop.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Empty.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/EnumValue.g.cs | 2 +- .../src/Rewrite.Java/Tree/EnumValueSet.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Expression.cs | 4 + .../src/Rewrite.Java/Tree/FieldAccess.g.cs | 2 +- .../src/Rewrite.Java/Tree/ForEachLoop.g.cs | 4 +- Rewrite/src/Rewrite.Java/Tree/ForLoop.g.cs | 4 +- Rewrite/src/Rewrite.Java/Tree/Identifier.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/If.g.cs | 4 +- Rewrite/src/Rewrite.Java/Tree/Import.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/InstanceOf.g.cs | 2 +- .../Rewrite.Java/Tree/IntersectionType.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/J.cs | 16 + Rewrite/src/Rewrite.Java/Tree/Label.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Lambda.g.cs | 4 +- Rewrite/src/Rewrite.Java/Tree/Literal.g.cs | 2 +- .../Rewrite.Java/Tree/MemberReference.g.cs | 2 +- .../Rewrite.Java/Tree/MethodDeclaration.g.cs | 2 +- .../Rewrite.Java/Tree/MethodInvocation.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Modifier.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/MultiCatch.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/NewArray.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/NewClass.g.cs | 2 +- .../src/Rewrite.Java/Tree/NullableType.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Package.g.cs | 2 +- .../Rewrite.Java/Tree/ParameterizedType.g.cs | 2 +- .../src/Rewrite.Java/Tree/Parentheses.g.cs | 2 +- .../Tree/ParenthesizedTypeTree.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Primitive.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Return.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Space.cs | 17 + Rewrite/src/Rewrite.Java/Tree/Switch.g.cs | 2 +- .../Rewrite.Java/Tree/SwitchExpression.g.cs | 2 +- .../src/Rewrite.Java/Tree/Synchronized.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Ternary.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Throw.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Try.g.cs | 6 +- Rewrite/src/Rewrite.Java/Tree/TypeCast.g.cs | 2 +- .../src/Rewrite.Java/Tree/TypeParameter.g.cs | 2 +- .../src/Rewrite.Java/Tree/TypeParameters.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/TypedTree.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Unary.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Unknown.g.cs | 4 +- .../Tree/VariableDeclarations.g.cs | 4 +- Rewrite/src/Rewrite.Java/Tree/WhileLoop.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Wildcard.g.cs | 2 +- Rewrite/src/Rewrite.Java/Tree/Yield.g.cs | 2 +- .../CSharp/CSharpReceiver.g.cs | 728 ++++- .../CSharp/CSharpSender.g.cs | 247 +- .../Java/JavaReceiver.g.cs | 146 +- .../RemotingFixture.cs | 3 + Rewrite/src/Rewrite.Test/RewriteTest.cs | 19 +- .../Rewrite.Test/StringAssertionExtensions.cs | 4 +- .../tests/Rewrite.CSharp.Tests/FindClass.cs | 6 +- .../tests/Rewrite.CSharp.Tests/PlayTests.cs | 16 +- .../Solutions/SolutionTests.cs | 77 +- .../Rewrite.CSharp.Tests/Tree/AliasTests.cs | 50 + .../Tree/ArrayAccessTests.cs | 13 +- .../Tree/ArrayTypeTests.cs | 3 +- .../Tree/AttributeTests.cs | 13 + .../Tree/ClassDeclarationTests.cs | 29 + .../Tree/ConversionOperatorTests.cs | 176 ++ .../Tree/DefaultExpressionTests.cs | 2 +- .../Tree/DelegateDeclarationTests.cs | 120 + .../Tree/DestructorTests.cs | 100 + .../Tree/DirectiveTests.cs | 35 + .../Rewrite.CSharp.Tests/Tree/DoWhileTests.cs | 35 + .../Tree/EnumDeclarationTests.cs | 37 + .../Tree/ForEachLoopTests.cs | 14 + .../Rewrite.CSharp.Tests/Tree/ForLoopTests.cs | 1 + .../Rewrite.CSharp.Tests/Tree/IndexerTests.cs | 129 + .../Tree/InterfaceDeclarationTests.cs | 29 +- .../Tree/IsExpressionPatternTests.cs | 12 + .../Rewrite.CSharp.Tests/Tree/LinqTests.cs | 124 + .../Tree/MethodDeclarationTests.cs | 74 +- .../Tree/MethodInvocationTests.cs | 12 + .../Tree/NullSafeExpressionTests.cs | 13 + .../Tree/PropertyDeclarationTests.cs | 26 +- .../Rewrite.CSharp.Tests/Tree/TupleTests.cs | 16 + .../Rewrite.CSharp.Tests/Tree/UnaryTests.cs | 36 + .../Rewrite.CSharp.Tests/Tree/UsingTests.cs | 146 +- .../csharp/remote/CSharpReceiver.java | 512 +++- .../csharp/remote/CSharpSender.java | 247 +- .../openrewrite/csharp/CSharpIsoVisitor.java | 100 + .../org/openrewrite/csharp/CSharpPrinter.java | 462 ++- .../org/openrewrite/csharp/CSharpVisitor.java | 257 +- .../java/org/openrewrite/csharp/tree/Cs.java | 2589 ++++++++++++++++- .../openrewrite/csharp/tree/CsContainer.java | 12 +- .../openrewrite/csharp/tree/CsLeftPadded.java | 14 +- .../csharp/tree/CsRightPadded.java | 24 +- .../org/openrewrite/csharp/tree/CsSpace.java | 2 +- 214 files changed, 10783 insertions(+), 1087 deletions(-) create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/AliasQualifiedName.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/AliasQualifiedName.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/ArrayType.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/ConversionOperatorDeclaration.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/DelegateDeclaration.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/EnumDeclaration.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/EnumMemberDeclaration.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/FromClause.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/GroupClause.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/IndexerDeclaration.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/JoinClause.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/JoinIntoClause.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/LetClause.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/OrderByClause.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/Ordering.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/QueryBody.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/QueryClause.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/QueryContinuation.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/QueryExpression.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/SelectClause.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/SelectOrGroupClause.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/TypeParameter.g.cs create mode 100644 Rewrite/src/Rewrite.CSharp/Tree/WhereClause.g.cs create mode 100644 Rewrite/src/Rewrite.Java/Tree/J.cs create mode 100644 Rewrite/tests/Rewrite.CSharp.Tests/Tree/AliasTests.cs create mode 100644 Rewrite/tests/Rewrite.CSharp.Tests/Tree/ConversionOperatorTests.cs create mode 100644 Rewrite/tests/Rewrite.CSharp.Tests/Tree/DelegateDeclarationTests.cs create mode 100644 Rewrite/tests/Rewrite.CSharp.Tests/Tree/DestructorTests.cs create mode 100644 Rewrite/tests/Rewrite.CSharp.Tests/Tree/DirectiveTests.cs create mode 100644 Rewrite/tests/Rewrite.CSharp.Tests/Tree/DoWhileTests.cs create mode 100644 Rewrite/tests/Rewrite.CSharp.Tests/Tree/IndexerTests.cs create mode 100644 Rewrite/tests/Rewrite.CSharp.Tests/Tree/LinqTests.cs diff --git a/Rewrite/Directory.Build.props b/Rewrite/Directory.Build.props index 4855891..b757c5b 100644 --- a/Rewrite/Directory.Build.props +++ b/Rewrite/Directory.Build.props @@ -15,6 +15,7 @@ True False True + true @@ -30,5 +31,6 @@ $(DefineConstants);REMOTE_PRINTER $(DefineConstants);DEBUG_VISITOR $(DefineConstants);SANITIZE_STACK_TRACE + $(DefineConstants);EMBEDDED_SERVER diff --git a/Rewrite/Rewrite.Sources.sln b/Rewrite/Rewrite.Sources.sln index 29f5c45..8d3dc91 100644 --- a/Rewrite/Rewrite.Sources.sln +++ b/Rewrite/Rewrite.Sources.sln @@ -47,7 +47,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Test.CSharp", "src\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Test.Engine.Remote", "src\Rewrite.Test.Engine.Remote\Rewrite.Test.Engine.Remote.csproj", "{C04C7CA4-69C3-444F-A654-6C722A0FC3BE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Server", "..\..\..\moderneinc\rewrite-remote\Rewrite.Remote\src\Rewrite.Server\Rewrite.Server.csproj", "{E0721BA1-2772-4486-BDF3-FC9301723BB9}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Remote.Server", "..\..\..\moderneinc\rewrite-remote\Rewrite.Remote\src\Rewrite.Remote.Server\Rewrite.Remote.Server.csproj", "{E0721BA1-2772-4486-BDF3-FC9301723BB9}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Analyzers", "src\Rewrite.Analyzers\Rewrite.Analyzers.csproj", "{9818146E-C516-4D3C-80CE-A84741E7772B}" EndProject diff --git a/Rewrite/src/Rewrite.CSharp/CSharpPrinter.cs b/Rewrite/src/Rewrite.CSharp/CSharpPrinter.cs index 3f59db0..ce58ffa 100644 --- a/Rewrite/src/Rewrite.CSharp/CSharpPrinter.cs +++ b/Rewrite/src/Rewrite.CSharp/CSharpPrinter.cs @@ -55,6 +55,134 @@ public CSharpPrinter() } } + public override Cs VisitArrayType(Cs.ArrayType newArray, PrintOutputCapture p) + { + BeforeSyntax(newArray, CsSpace.Location.ARRAY_TYPE_PREFIX, p); + Visit(newArray.TypeExpression, p); + Visit(newArray.Dimensions, p); + AfterSyntax(newArray, p); + return newArray; + } + + public override J? VisitAliasQualifiedName(Cs.AliasQualifiedName node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.ALIAS_QUALIFIED_NAME_PREFIX, p); + VisitRightPadded(node.Padding.Alias, CsRightPadded.Location.ALIAS_QUALIFIED_NAME_ALIAS, p); + p.Append("::"); + Visit(node.Name, p); + AfterSyntax(node, p); + return node; + } + + public override J? VisitTypeParameter(Cs.TypeParameter node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.TYPE_PARAMETER_PREFIX, p); + Visit(node.AttributeLists, p); + VisitLeftPaddedEnum(node.Padding.Variance, CsLeftPadded.Location.TYPE_PARAMETER_VARIANCE, p); + Visit(node.Name, p); + AfterSyntax(node, p); + return node; + } + + public override J? VisitQueryExpression(Cs.QueryExpression node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.QUERY_EXPRESSION_PREFIX, p); + Visit(node.FromClause, p); + Visit(node.Body, p); + AfterSyntax(node, p); + return node; + } + + public override J? VisitQueryContinuation(Cs.QueryContinuation node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.QUERY_CONTINUATION_PREFIX, p); + p.Append("into"); + Visit(node.Identifier, p); + Visit(node.Body, p); + AfterSyntax(node, p); + return node; + } + + public override J? VisitFromClause(Cs.FromClause node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.FROM_CLAUSE_PREFIX, p); + p.Append("from"); + Visit(node.TypeIdentifier, p); + VisitRightPadded(node.Padding.Identifier, CsRightPadded.Location.FROM_CLAUSE_IDENTIFIER, p); + p.Append("in"); + Visit(node.Expression, p); + AfterSyntax(node, p); + return node; + } + + public override J? VisitQueryBody(Cs.QueryBody node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.QUERY_BODY_PREFIX, p); + foreach (var clause in node.Clauses) + { + Visit(clause, p); + } + Visit(node.SelectOrGroup, p); + Visit(node.Continuation, p); + AfterSyntax(node, p); + return node; + } + + public override J? VisitLetClause(Cs.LetClause node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.LET_CLAUSE_PREFIX, p); + p.Append("let"); + VisitRightPadded(node.Padding.Identifier, CsRightPadded.Location.LET_CLAUSE_IDENTIFIER, p); + p.Append("="); + Visit(node.Expression, p); + AfterSyntax(node, p); + return node; + } + + public override J? VisitJoinClause(Cs.JoinClause node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.JOIN_CLAUSE_PREFIX, p); + p.Append("join"); + VisitRightPadded(node.Padding.Identifier, CsRightPadded.Location.JOIN_CLAUSE_IDENTIFIER, p); + p.Append("in"); + VisitRightPadded(node.Padding.InExpression, CsRightPadded.Location.JOIN_CLAUSE_IN_EXPRESSION, p); + p.Append("on"); + VisitRightPadded(node.Padding.LeftExpression, CsRightPadded.Location.JOIN_CLAUSE_LEFT_EXPRESSION, p); + p.Append("equals"); + Visit(node.RightExpression, p); + VisitLeftPadded("into", node.Padding.Into, CsLeftPadded.Location.JOIN_CLAUSE_INTO, p); + Visit(node.Into, p); + AfterSyntax(node, p); + return node; + } + + public override J? VisitWhereClause(Cs.WhereClause node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.WHERE_CLAUSE_PREFIX, p); + p.Append("where"); + Visit(node.Condition, p); + AfterSyntax(node, p); + return node; + } + + public override J? VisitJoinIntoClause(Cs.JoinIntoClause node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.JOIN_INTO_CLAUSE_PREFIX, p); + p.Append("into"); + Visit(node.Identifier, p); + AfterSyntax(node, p); + return node; + } + + public override J? VisitOrderByClause(Cs.OrderByClause node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.JOIN_INTO_CLAUSE_PREFIX, p); + p.Append("orderby"); + VisitRightPadded(node.Padding.Orderings, CsRightPadded.Location.ORDER_BY_CLAUSE_ORDERINGS, ",", p); + AfterSyntax(node, p); + return node; + } + public override J VisitForEachVariableLoop(Cs.ForEachVariableLoop forEachLoop, PrintOutputCapture p) { BeforeSyntax(forEachLoop, Space.Location.FOR_EACH_LOOP_PREFIX, p); @@ -70,6 +198,35 @@ public override J VisitForEachVariableLoop(Cs.ForEachVariableLoop forEachLoop, P return forEachLoop; } + public override Cs VisitGroupClause(Cs.GroupClause node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.GROUP_CLAUSE_PREFIX, p); + p.Append("group"); + VisitRightPadded(node.Padding.GroupExpression, CsRightPadded.Location.GROUP_CLAUSE_GROUP_EXPRESSION, "by", p); + Visit(node.Key, p); + AfterSyntax(node, p); + return node; + } + + public override J? VisitSelectClause(Cs.SelectClause node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.SELECT_CLAUSE_PREFIX, p); + p.Append("select"); + Visit(node.Expression, p); + AfterSyntax(node, p); + return node; + } + + public override J? VisitOrdering(Cs.Ordering node, PrintOutputCapture p) + { + var direction = node.Direction.ToString()?.ToLower() ?? ""; + BeforeSyntax(node, CsSpace.Location.ORDERING_PREFIX, p); + VisitRightPadded(node.Padding.Expression, CsRightPadded.Location.ORDERING_EXPRESSION, p); + p.Append(direction); + AfterSyntax(node, p); + return node; + } + protected void VisitRightPadded(JRightPadded? rightPadded, CsRightPadded.Location location, string? suffix, PrintOutputCapture p) where T : J { if (rightPadded != null) @@ -469,24 +626,36 @@ protected void VisitRightPadded(JRightPadded? rightPadded, CsRightPadded.L public override J? VisitUsingStatement(Cs.UsingStatement usingStatement, PrintOutputCapture p) { BeforeSyntax(usingStatement, CsSpace.Location.NAMED_ARGUMENT_PREFIX, p); - p.Append("using"); if (usingStatement.AwaitKeyword != null) { Visit(usingStatement.AwaitKeyword, p); } - VisitContainer("(", usingStatement.Padding.Expression, CsContainer.Location.USING_STATEMENT_EXPRESSION, "", ")", p); + VisitLeftPadded("using", usingStatement.Padding.Expression, CsLeftPadded.Location.USING_STATEMENT_EXPRESSION, p); Visit(usingStatement.Statement, p); AfterSyntax(usingStatement, p); + return usingStatement; } + public override J? VisitUnary(Cs.Unary unary, PrintOutputCapture p) { BeforeSyntax(unary, Space.Location.UNARY_PREFIX, p); switch (unary.Operator) { - default: + case Cs.Unary.Types.FromEnd: + p.Append("^"); + Visit(unary.Expression, p); + break; + case Cs.Unary.Types.PointerIndirection: + Visit(unary.Expression, p); + p.Append("*"); + break; + case Cs.Unary.Types.AddressOf: + p.Append("&"); + Visit(unary.Expression, p); + break; case Cs.Unary.Types.SuppressNullableWarning: Visit(unary.Expression, p); p.Append("!"); @@ -525,20 +694,48 @@ public override Cs VisitCompilationUnit(Cs.CompilationUnit compilationUnit, Prin return compilationUnit; } - public override J? VisitClassDeclaration(Cs.ClassDeclaration classDeclaration, PrintOutputCapture p) + public override J? VisitClassDeclaration(Cs.ClassDeclaration node, PrintOutputCapture p) { - _delegate.Visit(classDeclaration.ClassDeclarationCore, p); - return classDeclaration; + BeforeSyntax(node, Space.Location.CLASS_DECLARATION_PREFIX, p); + Visit(node.AttributeList, p); + Visit(node.Modifiers, p); + + Visit(node.Kind, p); + Visit(node.Name, p); + VisitContainer("<", node.Padding.TypeParameters, CsContainer.Location.CLASS_DECLARATION_TYPE_PARAMETERS, ",", ">", p); + VisitContainer("(", node.Padding.PrimaryConstructor, CsContainer.Location.CLASS_DECLARATION_PRIMARY_CONSTRUCTOR, ",", ")", p); + VisitLeftPadded(":", node.Padding.Extendings, CsLeftPadded.Location.CLASS_DECLARATION_EXTENDINGS, p); + VisitContainer(node.Padding.Extendings == null ? ":" : ",", node.Padding.Implementings, CsContainer.Location.CLASS_DECLARATION_IMPLEMENTINGS, ",", "", p); + VisitContainer("", node.Padding.TypeParameterConstraintClauses, CsContainer.Location.CLASS_DECLARATION_TYPE_PARAMETERS, "", "", p); + + Visit(node.Body, p); + AfterSyntax(node, p); + return node; } - public override J? VisitMethodDeclaration(Cs.MethodDeclaration methodDeclaration, PrintOutputCapture p) + public override J? VisitMethodDeclaration(Cs.MethodDeclaration node, PrintOutputCapture p) { - _delegate.Visit(methodDeclaration.MethodDeclarationCore, p); - if (methodDeclaration.MethodDeclarationCore.Body == null) + BeforeSyntax(node, Space.Location.METHOD_DECLARATION_PREFIX, p); + VisitSpace(Space.EMPTY, Space.Location.ANNOTATIONS, p); + + Visit(node.Modifiers, p); + + Visit(node.ReturnTypeExpression, p); + VisitRightPadded(node.Padding.ExplicitInterfaceSpecifier, CsRightPadded.Location.METHOD_DECLARATION_EXPLICIT_INTERFACE_SPECIFIER, ".", p); + Visit(node.Name, p); + + + VisitContainer("<", node.Padding.TypeParameters, CsContainer.Location.METHOD_DECLARATION_TYPE_PARAMETERS, ",", ">", p); + + if (node.Markers.FirstOrDefault(m => m is CompactConstructor) == null) { - p.Append(";"); + VisitContainer("(", node.Padding.Parameters, CsContainer.Location.METHOD_DECLARATION_PARAMETERS, ",", ")", p); } - return methodDeclaration; + + VisitContainer(node.Padding.TypeParameterConstraintClauses, CsContainer.Location.METHOD_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES, p); + Visit(node.Body, p); + AfterSyntax(node, p); + return node; } @@ -577,8 +774,7 @@ public override Cs VisitCompilationUnit(Cs.CompilationUnit compilationUnit, Prin public override J? VisitArrayRankSpecifier(Cs.ArrayRankSpecifier arrayRankSpecifier, PrintOutputCapture p) { BeforeSyntax(arrayRankSpecifier, CsSpace.Location.ARRAY_RANK_SPECIFIER_PREFIX, p); - VisitContainer("", arrayRankSpecifier.Padding.Sizes, CsContainer.Location.ARRAY_RANK_SPECIFIER_SIZES, ",", "", - p); + VisitContainer("", arrayRankSpecifier.Padding.Sizes, CsContainer.Location.ARRAY_RANK_SPECIFIER_SIZES, ",", "", p); AfterSyntax(arrayRankSpecifier, p); return arrayRankSpecifier; } @@ -666,10 +862,27 @@ public override Cs VisitBlockScopeNamespaceDeclaration(Cs.BlockScopeNamespaceDec return collectionExpression; } + public override J? VisitEnumDeclaration(Cs.EnumDeclaration node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.ENUM_DECLARATION_PREFIX, p); + Visit(node.AttributeLists, p); + Visit(node.Modifiers, p); + VisitLeftPadded("enum", node.Padding.Name, CsLeftPadded.Location.ENUM_DECLARATION_NAME, p); + if (node.BaseType != null) + { + VisitLeftPadded(":", node.Padding.BaseType, CsLeftPadded.Location.ENUM_DECLARATION_BASE_TYPE, p); + } + + VisitContainer("{", node.Padding.Members, CsContainer.Location.ENUM_DECLARATION_MEMBERS, ",", "}", p); + AfterSyntax(node, p); + return node; + } + public override J? VisitExpressionStatement(Cs.ExpressionStatement expressionStatement, PrintOutputCapture p) { BeforeSyntax(expressionStatement, CsSpace.Location.AWAIT_EXPRESSION_PREFIX, p); - Visit(expressionStatement.Expression, p); + VisitRightPadded(expressionStatement.Padding.Expression, CsRightPadded.Location.EXPRESSION_STATEMENT_EXPRESSION, p); + p.Append(";"); AfterSyntax(expressionStatement, p); return expressionStatement; } @@ -819,6 +1032,93 @@ public override Cs VisitFileScopeNamespaceDeclaration(Cs.FileScopeNamespaceDecla return usingDirective; } + public override J? VisitConversionOperatorDeclaration(Cs.ConversionOperatorDeclaration node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.CONVERSION_OPERATOR_DECLARATION_PREFIX, p); + foreach (var modifier in node.Modifiers) + { + Visit(modifier, p); + } + + VisitLeftPadded(node.Padding.Kind, CsLeftPadded.Location.CONVERSION_OPERATOR_DECLARATION_KIND, p); + p.Append(node.Kind.ToString().ToLower()); + VisitLeftPadded("operator", node.Padding.ReturnType, CsLeftPadded.Location.CONVERSION_OPERATOR_DECLARATION_RETURN_TYPE, p); + VisitContainer("(", node.Padding.Parameters, CsContainer.Location.CONVERSION_OPERATOR_DECLARATION_PARAMETERS, ",", ")", p); + Visit(node.ExpressionBody, p); + Visit(node.Body, p); + + AfterSyntax(node, p); + return node; + } + + public override J? VisitEnumMemberDeclaration(Cs.EnumMemberDeclaration node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.ENUM_MEMBER_DECLARATION_PREFIX, p); + Visit(node.AttributeLists, p); + Visit(node.Name, p); + VisitLeftPadded("=", node.Padding.Initializer, CsLeftPadded.Location.ENUM_MEMBER_DECLARATION_INITIALIZER, p); + + AfterSyntax(node, p); + return node; + } + + public override J? VisitIndexerDeclaration(Cs.IndexerDeclaration node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.INDEXER_DECLARATION_PREFIX, p); + foreach (var modifier in node.Modifiers) + { + Visit(modifier, p); + } + + Visit(node.TypeExpression, p); + Visit(node.Indexer, p); + VisitContainer("[", node.Padding.Parameters, CsContainer.Location.INDEXER_DECLARATION_PARAMETERS, ",", "]", p); + VisitLeftPadded("", node.Padding.ExpressionBody, CsLeftPadded.Location.INDEXER_DECLARATION_EXPRESSION_BODY, p); //todo: probably should be => as inner block is just wrong representation + Visit(node.Accessors, p); + AfterSyntax(node, p); + return node; + } + + public override J? VisitDelegateDeclaration(Cs.DelegateDeclaration node, PrintOutputCapture p) + { + BeforeSyntax(node, CsSpace.Location.DELEGATE_DECLARATION_PREFIX, p); + foreach (var modifier in node.Modifiers) + { + Visit(modifier, p); + } + + VisitLeftPadded("delegate", node.Padding.ReturnType, CsLeftPadded.Location.DELEGATE_DECLARATION_RETURN_TYPE, p); + Visit(node.Identifier, p); + VisitContainer("<", node.Padding.TypeParameters, CsContainer.Location.CONVERSION_OPERATOR_DECLARATION_PARAMETERS, ",", ">", p); + VisitContainer("(", node.Padding.Parameters, CsContainer.Location.CONVERSION_OPERATOR_DECLARATION_PARAMETERS, ",", ")", p); + VisitContainer(node.Padding.TypeParameterConstraintClauses, CsContainer.Location.DELEGATE_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES, p); + + AfterSyntax(node, p); + return node; + } + + public override J? VisitDestructorDeclaration(Cs.DestructorDeclaration node, PrintOutputCapture p) + { + var method = node.MethodCore; + BeforeSyntax(method, CsSpace.Location.DESTRUCTOR_DECLARATION_PREFIX, p); + VisitSpace(Space.EMPTY, Space.Location.ANNOTATIONS, p); + Visit(method.LeadingAnnotations, p); + foreach (var modifier in method.Modifiers) + { + _delegate.Visit(modifier, p); + } + + Visit(method.Annotations.Name.Annotations, p); + p.Append("~"); + Visit(method.Name, p); + + VisitContainer("(", method.Padding.Parameters, CsContainer.Location.METHOD_DECLARATION_PARAMETERS, ",", ")", p); + + Visit(method.Body, p); + AfterSyntax(node, p); + return node; + } + public override J? VisitConstructor(Cs.Constructor constructor, PrintOutputCapture p) { var method = constructor.ConstructorCore; @@ -827,7 +1127,7 @@ public override Cs VisitFileScopeNamespaceDeclaration(Cs.FileScopeNamespaceDecla Visit(method.LeadingAnnotations, p); foreach (var modifier in method.Modifiers) { - _delegate.VisitModifier(modifier, p); + _delegate.Visit(modifier, p); } Visit(method.Annotations.Name.Annotations, p); @@ -888,8 +1188,14 @@ public override Space VisitSpace(Space space, Space.Location? loc, PrintOutputCa return _delegate.VisitSpace(space, loc, p); } - protected void VisitLeftPadded(string prefix, JLeftPadded? leftPadded, CsLeftPadded.Location location, - PrintOutputCapture p) where T : J + protected void VisitLeftPaddedEnum(JLeftPadded? leftPadded, CsLeftPadded.Location location, PrintOutputCapture p) where T : Enum + { + if (leftPadded == null) + return; + VisitLeftPadded(leftPadded, location, p); + p.Append(leftPadded.Element.ToString().ToLower()); + } + protected void VisitLeftPadded(string prefix, JLeftPadded? leftPadded, CsLeftPadded.Location location, PrintOutputCapture p) where T : J { if (leftPadded != null) { @@ -1041,15 +1347,15 @@ private class CSharpJavaPrinter(CSharpPrinter _parent) : JavaPrinter", p); - VisitContainer("(", classDecl.Padding.PrimaryConstructor, JContainer.Location.RECORD_STATE_VECTOR, ",", ")", - p); + VisitContainer("(", classDecl.Padding.PrimaryConstructor, JContainer.Location.RECORD_STATE_VECTOR, ",", ")", p); VisitLeftPadded(":", classDecl.Padding.Extends, JLeftPadded.Location.EXTENDS, p); VisitContainer(classDecl.Padding.Extends == null ? ":" : ",", classDecl.Padding.Implements, JContainer.Location.IMPLEMENTS, ",", null, p); foreach (var typeParameterClause in csClassDeclaration?.TypeParameterConstraintClauses ?? []) @@ -1139,10 +1444,6 @@ public override J VisitBlock(J.Block block, PrintOutputCapture p) { p.Append("=>"); VisitStatements(block.Padding.Statements, JRightPadded.Location.BLOCK_STATEMENT, p); - if (block.Statements.FirstOrDefault() is not Cs.ExpressionStatement) // expression statements print their own semicolon - { - p.Append(";"); - } VisitSpace(block.End, Space.Location.BLOCK_END, p); } @@ -1353,17 +1654,25 @@ public override M VisitMarker(M marker, PrintOutputCapture p) // override print public override void PrintStatementTerminator(Statement s, PrintOutputCapture p) { - var parent = Cursor.Parent; - if (s is Cs.ExpressionStatement or Cs.AssignmentOperation or Cs.Yield) + if (s is + Cs.ExpressionStatement or + Cs.AwaitExpression { Expression: J.ForEachLoop { Body: J.Block } }) { - p.Append(';'); + return; } - else - if (s is Cs.PropertyDeclaration propertyDeclaration && propertyDeclaration.Initializer != null) + + if (s is + Cs.AssignmentOperation or + Cs.Yield or + Cs.DelegateDeclaration or + Cs.UsingStatement { Statement: not J.Block and not Cs.UsingStatement and not Cs.ExpressionStatement } or + Cs.AwaitExpression { Expression: not J.ForEachLoop { Body: not J.Block}} or + Cs.PropertyDeclaration { Initializer: not null } + ) { p.Append(';'); } - else + else if(Cursor.Parent?.Value is not Cs.ExpressionStatement) { base.PrintStatementTerminator(s, p); } diff --git a/Rewrite/src/Rewrite.CSharp/CSharpTypeSignatureBuilder.cs b/Rewrite/src/Rewrite.CSharp/CSharpTypeSignatureBuilder.cs index 77c1b78..d35eedd 100644 --- a/Rewrite/src/Rewrite.CSharp/CSharpTypeSignatureBuilder.cs +++ b/Rewrite/src/Rewrite.CSharp/CSharpTypeSignatureBuilder.cs @@ -10,6 +10,8 @@ public string Signature(ISymbol type) { if (type is ITypeSymbol) return type.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat); + if(type is IPropertySymbol propertySymbol) + return propertySymbol.Type.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat); throw new NotImplementedException(); } @@ -56,7 +58,7 @@ public string ParameterSignature(IParameterSymbol parameterSymbol) { containingSymbol = containingSymbol.ContainingSymbol; } - + string owner; if (containingSymbol is IMethodSymbol ms) { @@ -66,4 +68,4 @@ public string ParameterSignature(IParameterSymbol parameterSymbol) owner = Signature(containingSymbol); return owner + '{' + parameterSymbol.Name + ',' + Signature(parameterSymbol.Type) + '}'; } -} \ No newline at end of file +} diff --git a/Rewrite/src/Rewrite.CSharp/CSharpVisitor.g.cs b/Rewrite/src/Rewrite.CSharp/CSharpVisitor.g.cs index 756dbb1..7e56a92 100644 --- a/Rewrite/src/Rewrite.CSharp/CSharpVisitor.g.cs +++ b/Rewrite/src/Rewrite.CSharp/CSharpVisitor.g.cs @@ -140,6 +140,12 @@ public override bool IsAcceptable(SourceFile sourceFile, P p) public virtual J? VisitAwaitExpression(Cs.AwaitExpression awaitExpression, P p) { awaitExpression = awaitExpression.WithPrefix(VisitSpace(awaitExpression.Prefix, CsSpace.Location.AWAIT_EXPRESSION_PREFIX, p)!); + var tempStatement = (Statement) VisitStatement(awaitExpression, p); + if (tempStatement is not Cs.AwaitExpression) + { + return tempStatement; + } + awaitExpression = (Cs.AwaitExpression) tempStatement; var tempExpression = (Expression) VisitExpression(awaitExpression, p); if (tempExpression is not Cs.AwaitExpression) { @@ -147,7 +153,7 @@ public override bool IsAcceptable(SourceFile sourceFile, P p) } awaitExpression = (Cs.AwaitExpression) tempExpression; awaitExpression = awaitExpression.WithMarkers(VisitMarkers(awaitExpression.Markers, p)); - awaitExpression = awaitExpression.WithExpression(VisitAndCast(awaitExpression.Expression, p)!); + awaitExpression = awaitExpression.WithExpression(VisitAndCast(awaitExpression.Expression, p)!); return awaitExpression; } @@ -209,7 +215,7 @@ public override bool IsAcceptable(SourceFile sourceFile, P p) } expressionStatement = (Cs.ExpressionStatement) tempStatement; expressionStatement = expressionStatement.WithMarkers(VisitMarkers(expressionStatement.Markers, p)); - expressionStatement = expressionStatement.WithExpression(VisitAndCast(expressionStatement.Expression, p)!); + expressionStatement = expressionStatement.Padding.WithExpression(VisitRightPadded(expressionStatement.Padding.Expression, CsRightPadded.Location.EXPRESSION_STATEMENT_EXPRESSION, p)!); return expressionStatement; } @@ -378,8 +384,16 @@ public override bool IsAcceptable(SourceFile sourceFile, P p) } classDeclaration = (Cs.ClassDeclaration) tempStatement; classDeclaration = classDeclaration.WithMarkers(VisitMarkers(classDeclaration.Markers, p)); - classDeclaration = classDeclaration.WithClassDeclarationCore(VisitAndCast(classDeclaration.ClassDeclarationCore, p)!); - classDeclaration = classDeclaration.Padding.WithTypeParameterConstraintClauses(VisitContainer(classDeclaration.Padding.TypeParameterConstraintClauses, CsContainer.Location.CLASS_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES, p)!); + classDeclaration = classDeclaration.WithAttributeList(classDeclaration.AttributeList.Map(el => (Cs.AttributeList?)Visit(el, p))); + classDeclaration = classDeclaration.WithModifiers(classDeclaration.Modifiers.Map(el => (J.Modifier?)Visit(el, p))); + classDeclaration = classDeclaration.Padding.WithKind(VisitAndCast(classDeclaration.Padding.Kind, p)!); + classDeclaration = classDeclaration.WithName(VisitAndCast(classDeclaration.Name, p)!); + classDeclaration = classDeclaration.Padding.WithTypeParameters(classDeclaration.Padding.TypeParameters == null ? null : VisitContainer(classDeclaration.Padding.TypeParameters, CsContainer.Location.CLASS_DECLARATION_TYPE_PARAMETERS, p)); + classDeclaration = classDeclaration.Padding.WithPrimaryConstructor(classDeclaration.Padding.PrimaryConstructor == null ? null : VisitContainer(classDeclaration.Padding.PrimaryConstructor, CsContainer.Location.CLASS_DECLARATION_PRIMARY_CONSTRUCTOR, p)); + classDeclaration = classDeclaration.Padding.WithExtendings(classDeclaration.Padding.Extendings == null ? null : VisitLeftPadded(classDeclaration.Padding.Extendings, CsLeftPadded.Location.CLASS_DECLARATION_EXTENDINGS, p)); + classDeclaration = classDeclaration.Padding.WithImplementings(classDeclaration.Padding.Implementings == null ? null : VisitContainer(classDeclaration.Padding.Implementings, CsContainer.Location.CLASS_DECLARATION_IMPLEMENTINGS, p)); + classDeclaration = classDeclaration.WithBody(VisitAndCast(classDeclaration.Body, p)); + classDeclaration = classDeclaration.Padding.WithTypeParameterConstraintClauses(classDeclaration.Padding.TypeParameterConstraintClauses == null ? null : VisitContainer(classDeclaration.Padding.TypeParameterConstraintClauses, CsContainer.Location.CLASS_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES, p)); return classDeclaration; } @@ -393,7 +407,14 @@ public override bool IsAcceptable(SourceFile sourceFile, P p) } methodDeclaration = (Cs.MethodDeclaration) tempStatement; methodDeclaration = methodDeclaration.WithMarkers(VisitMarkers(methodDeclaration.Markers, p)); - methodDeclaration = methodDeclaration.WithMethodDeclarationCore(VisitAndCast(methodDeclaration.MethodDeclarationCore, p)!); + methodDeclaration = methodDeclaration.WithAttributes(methodDeclaration.Attributes.Map(el => (Cs.AttributeList?)Visit(el, p))); + methodDeclaration = methodDeclaration.WithModifiers(methodDeclaration.Modifiers.Map(el => (J.Modifier?)Visit(el, p))); + methodDeclaration = methodDeclaration.Padding.WithTypeParameters(methodDeclaration.Padding.TypeParameters == null ? null : VisitContainer(methodDeclaration.Padding.TypeParameters, CsContainer.Location.METHOD_DECLARATION_TYPE_PARAMETERS, p)); + methodDeclaration = methodDeclaration.WithReturnTypeExpression(VisitAndCast(methodDeclaration.ReturnTypeExpression, p)!); + methodDeclaration = methodDeclaration.Padding.WithExplicitInterfaceSpecifier(methodDeclaration.Padding.ExplicitInterfaceSpecifier == null ? null : VisitRightPadded(methodDeclaration.Padding.ExplicitInterfaceSpecifier, CsRightPadded.Location.METHOD_DECLARATION_EXPLICIT_INTERFACE_SPECIFIER, p)); + methodDeclaration = methodDeclaration.WithName(VisitAndCast(methodDeclaration.Name, p)!); + methodDeclaration = methodDeclaration.Padding.WithParameters(VisitContainer(methodDeclaration.Padding.Parameters, CsContainer.Location.METHOD_DECLARATION_PARAMETERS, p)!); + methodDeclaration = methodDeclaration.WithBody(VisitAndCast(methodDeclaration.Body, p)); methodDeclaration = methodDeclaration.Padding.WithTypeParameterConstraintClauses(VisitContainer(methodDeclaration.Padding.TypeParameterConstraintClauses, CsContainer.Location.METHOD_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES, p)!); return methodDeclaration; } @@ -409,7 +430,7 @@ public override bool IsAcceptable(SourceFile sourceFile, P p) usingStatement = (Cs.UsingStatement) tempStatement; usingStatement = usingStatement.WithMarkers(VisitMarkers(usingStatement.Markers, p)); usingStatement = usingStatement.WithAwaitKeyword(VisitAndCast(usingStatement.AwaitKeyword, p)); - usingStatement = usingStatement.Padding.WithExpression(VisitContainer(usingStatement.Padding.Expression, CsContainer.Location.USING_STATEMENT_EXPRESSION, p)!); + usingStatement = usingStatement.Padding.WithExpression(VisitLeftPadded(usingStatement.Padding.Expression, CsLeftPadded.Location.USING_STATEMENT_EXPRESSION, p)!); usingStatement = usingStatement.WithStatement(VisitAndCast(usingStatement.Statement, p)!); return usingStatement; } @@ -563,8 +584,7 @@ public override bool IsAcceptable(SourceFile sourceFile, P p) } destructorDeclaration = (Cs.DestructorDeclaration) tempStatement; destructorDeclaration = destructorDeclaration.WithMarkers(VisitMarkers(destructorDeclaration.Markers, p)); - destructorDeclaration = destructorDeclaration.WithInitializer(VisitAndCast(destructorDeclaration.Initializer, p)); - destructorDeclaration = destructorDeclaration.WithConstructorCore(VisitAndCast(destructorDeclaration.ConstructorCore, p)!); + destructorDeclaration = destructorDeclaration.WithMethodCore(VisitAndCast(destructorDeclaration.MethodCore, p)!); return destructorDeclaration; } @@ -895,7 +915,7 @@ public override bool IsAcceptable(SourceFile sourceFile, P p) { subpattern = subpattern.WithPrefix(VisitSpace(subpattern.Prefix, CsSpace.Location.SUBPATTERN_PREFIX, p)!); subpattern = subpattern.WithMarkers(VisitMarkers(subpattern.Markers, p)); - subpattern = subpattern.WithName(VisitAndCast(subpattern.Name, p)); + subpattern = subpattern.WithName(VisitAndCast(subpattern.Name, p)); subpattern = subpattern.Padding.WithPattern(VisitLeftPadded(subpattern.Padding.Pattern, CsLeftPadded.Location.SUBPATTERN_PATTERN, p)!); return subpattern; } @@ -1058,6 +1078,251 @@ public override bool IsAcceptable(SourceFile sourceFile, P p) return rangeExpression; } + public virtual J? VisitQueryExpression(Cs.QueryExpression queryExpression, P p) + { + queryExpression = queryExpression.WithPrefix(VisitSpace(queryExpression.Prefix, CsSpace.Location.QUERY_EXPRESSION_PREFIX, p)!); + var tempExpression = (Expression) VisitExpression(queryExpression, p); + if (tempExpression is not Cs.QueryExpression) + { + return tempExpression; + } + queryExpression = (Cs.QueryExpression) tempExpression; + queryExpression = queryExpression.WithMarkers(VisitMarkers(queryExpression.Markers, p)); + queryExpression = queryExpression.WithFromClause(VisitAndCast(queryExpression.FromClause, p)!); + queryExpression = queryExpression.WithBody(VisitAndCast(queryExpression.Body, p)!); + return queryExpression; + } + + public virtual J? VisitQueryBody(Cs.QueryBody queryBody, P p) + { + queryBody = queryBody.WithPrefix(VisitSpace(queryBody.Prefix, CsSpace.Location.QUERY_BODY_PREFIX, p)!); + queryBody = queryBody.WithMarkers(VisitMarkers(queryBody.Markers, p)); + queryBody = queryBody.WithClauses(queryBody.Clauses.Map(el => (Cs.QueryClause?)Visit(el, p))); + queryBody = queryBody.WithSelectOrGroup(VisitAndCast(queryBody.SelectOrGroup, p)); + queryBody = queryBody.WithContinuation(VisitAndCast(queryBody.Continuation, p)); + return queryBody; + } + + public virtual J? VisitFromClause(Cs.FromClause fromClause, P p) + { + fromClause = fromClause.WithPrefix(VisitSpace(fromClause.Prefix, CsSpace.Location.FROM_CLAUSE_PREFIX, p)!); + var tempExpression = (Expression) VisitExpression(fromClause, p); + if (tempExpression is not Cs.FromClause) + { + return tempExpression; + } + fromClause = (Cs.FromClause) tempExpression; + fromClause = fromClause.WithMarkers(VisitMarkers(fromClause.Markers, p)); + fromClause = fromClause.WithTypeIdentifier(VisitAndCast(fromClause.TypeIdentifier, p)); + fromClause = fromClause.Padding.WithIdentifier(VisitRightPadded(fromClause.Padding.Identifier, CsRightPadded.Location.FROM_CLAUSE_IDENTIFIER, p)!); + fromClause = fromClause.WithExpression(VisitAndCast(fromClause.Expression, p)!); + return fromClause; + } + + public virtual J? VisitLetClause(Cs.LetClause letClause, P p) + { + letClause = letClause.WithPrefix(VisitSpace(letClause.Prefix, CsSpace.Location.LET_CLAUSE_PREFIX, p)!); + letClause = letClause.WithMarkers(VisitMarkers(letClause.Markers, p)); + letClause = letClause.Padding.WithIdentifier(VisitRightPadded(letClause.Padding.Identifier, CsRightPadded.Location.LET_CLAUSE_IDENTIFIER, p)!); + letClause = letClause.WithExpression(VisitAndCast(letClause.Expression, p)!); + return letClause; + } + + public virtual J? VisitJoinClause(Cs.JoinClause joinClause, P p) + { + joinClause = joinClause.WithPrefix(VisitSpace(joinClause.Prefix, CsSpace.Location.JOIN_CLAUSE_PREFIX, p)!); + joinClause = joinClause.WithMarkers(VisitMarkers(joinClause.Markers, p)); + joinClause = joinClause.Padding.WithIdentifier(VisitRightPadded(joinClause.Padding.Identifier, CsRightPadded.Location.JOIN_CLAUSE_IDENTIFIER, p)!); + joinClause = joinClause.Padding.WithInExpression(VisitRightPadded(joinClause.Padding.InExpression, CsRightPadded.Location.JOIN_CLAUSE_IN_EXPRESSION, p)!); + joinClause = joinClause.Padding.WithLeftExpression(VisitRightPadded(joinClause.Padding.LeftExpression, CsRightPadded.Location.JOIN_CLAUSE_LEFT_EXPRESSION, p)!); + joinClause = joinClause.WithRightExpression(VisitAndCast(joinClause.RightExpression, p)!); + joinClause = joinClause.Padding.WithInto(joinClause.Padding.Into == null ? null : VisitLeftPadded(joinClause.Padding.Into, CsLeftPadded.Location.JOIN_CLAUSE_INTO, p)); + return joinClause; + } + + public virtual J? VisitJoinIntoClause(Cs.JoinIntoClause joinIntoClause, P p) + { + joinIntoClause = joinIntoClause.WithPrefix(VisitSpace(joinIntoClause.Prefix, CsSpace.Location.JOIN_INTO_CLAUSE_PREFIX, p)!); + joinIntoClause = joinIntoClause.WithMarkers(VisitMarkers(joinIntoClause.Markers, p)); + joinIntoClause = joinIntoClause.WithIdentifier(VisitAndCast(joinIntoClause.Identifier, p)!); + return joinIntoClause; + } + + public virtual J? VisitWhereClause(Cs.WhereClause whereClause, P p) + { + whereClause = whereClause.WithPrefix(VisitSpace(whereClause.Prefix, CsSpace.Location.WHERE_CLAUSE_PREFIX, p)!); + whereClause = whereClause.WithMarkers(VisitMarkers(whereClause.Markers, p)); + whereClause = whereClause.WithCondition(VisitAndCast(whereClause.Condition, p)!); + return whereClause; + } + + public virtual J? VisitOrderByClause(Cs.OrderByClause orderByClause, P p) + { + orderByClause = orderByClause.WithPrefix(VisitSpace(orderByClause.Prefix, CsSpace.Location.ORDER_BY_CLAUSE_PREFIX, p)!); + orderByClause = orderByClause.WithMarkers(VisitMarkers(orderByClause.Markers, p)); + orderByClause = orderByClause.Padding.WithOrderings(orderByClause.Padding.Orderings.Map(el => VisitRightPadded(el, CsRightPadded.Location.ORDER_BY_CLAUSE_ORDERINGS, p))); + return orderByClause; + } + + public virtual J? VisitQueryContinuation(Cs.QueryContinuation queryContinuation, P p) + { + queryContinuation = queryContinuation.WithPrefix(VisitSpace(queryContinuation.Prefix, CsSpace.Location.QUERY_CONTINUATION_PREFIX, p)!); + queryContinuation = queryContinuation.WithMarkers(VisitMarkers(queryContinuation.Markers, p)); + queryContinuation = queryContinuation.WithIdentifier(VisitAndCast(queryContinuation.Identifier, p)!); + queryContinuation = queryContinuation.WithBody(VisitAndCast(queryContinuation.Body, p)!); + return queryContinuation; + } + + public virtual J? VisitOrdering(Cs.Ordering ordering, P p) + { + ordering = ordering.WithPrefix(VisitSpace(ordering.Prefix, CsSpace.Location.ORDERING_PREFIX, p)!); + ordering = ordering.WithMarkers(VisitMarkers(ordering.Markers, p)); + ordering = ordering.Padding.WithExpression(VisitRightPadded(ordering.Padding.Expression, CsRightPadded.Location.ORDERING_EXPRESSION, p)!); + return ordering; + } + + public virtual J? VisitSelectClause(Cs.SelectClause selectClause, P p) + { + selectClause = selectClause.WithPrefix(VisitSpace(selectClause.Prefix, CsSpace.Location.SELECT_CLAUSE_PREFIX, p)!); + selectClause = selectClause.WithMarkers(VisitMarkers(selectClause.Markers, p)); + selectClause = selectClause.WithExpression(VisitAndCast(selectClause.Expression, p)!); + return selectClause; + } + + public virtual J? VisitGroupClause(Cs.GroupClause groupClause, P p) + { + groupClause = groupClause.WithPrefix(VisitSpace(groupClause.Prefix, CsSpace.Location.GROUP_CLAUSE_PREFIX, p)!); + groupClause = groupClause.WithMarkers(VisitMarkers(groupClause.Markers, p)); + groupClause = groupClause.Padding.WithGroupExpression(VisitRightPadded(groupClause.Padding.GroupExpression, CsRightPadded.Location.GROUP_CLAUSE_GROUP_EXPRESSION, p)!); + groupClause = groupClause.WithKey(VisitAndCast(groupClause.Key, p)!); + return groupClause; + } + + public virtual J? VisitIndexerDeclaration(Cs.IndexerDeclaration indexerDeclaration, P p) + { + indexerDeclaration = indexerDeclaration.WithPrefix(VisitSpace(indexerDeclaration.Prefix, CsSpace.Location.INDEXER_DECLARATION_PREFIX, p)!); + var tempStatement = (Statement) VisitStatement(indexerDeclaration, p); + if (tempStatement is not Cs.IndexerDeclaration) + { + return tempStatement; + } + indexerDeclaration = (Cs.IndexerDeclaration) tempStatement; + indexerDeclaration = indexerDeclaration.WithMarkers(VisitMarkers(indexerDeclaration.Markers, p)); + indexerDeclaration = indexerDeclaration.WithModifiers(indexerDeclaration.Modifiers.Map(el => (J.Modifier?)Visit(el, p))); + indexerDeclaration = indexerDeclaration.WithTypeExpression(VisitAndCast(indexerDeclaration.TypeExpression, p)!); + indexerDeclaration = indexerDeclaration.WithIndexer(VisitAndCast(indexerDeclaration.Indexer, p)!); + indexerDeclaration = indexerDeclaration.Padding.WithParameters(VisitContainer(indexerDeclaration.Padding.Parameters, CsContainer.Location.INDEXER_DECLARATION_PARAMETERS, p)!); + indexerDeclaration = indexerDeclaration.Padding.WithExpressionBody(indexerDeclaration.Padding.ExpressionBody == null ? null : VisitLeftPadded(indexerDeclaration.Padding.ExpressionBody, CsLeftPadded.Location.INDEXER_DECLARATION_EXPRESSION_BODY, p)); + indexerDeclaration = indexerDeclaration.WithAccessors(VisitAndCast(indexerDeclaration.Accessors, p)); + return indexerDeclaration; + } + + public virtual J? VisitDelegateDeclaration(Cs.DelegateDeclaration delegateDeclaration, P p) + { + delegateDeclaration = delegateDeclaration.WithPrefix(VisitSpace(delegateDeclaration.Prefix, CsSpace.Location.DELEGATE_DECLARATION_PREFIX, p)!); + var tempStatement = (Statement) VisitStatement(delegateDeclaration, p); + if (tempStatement is not Cs.DelegateDeclaration) + { + return tempStatement; + } + delegateDeclaration = (Cs.DelegateDeclaration) tempStatement; + delegateDeclaration = delegateDeclaration.WithMarkers(VisitMarkers(delegateDeclaration.Markers, p)); + delegateDeclaration = delegateDeclaration.WithModifiers(delegateDeclaration.Modifiers.Map(el => (J.Modifier?)Visit(el, p))); + delegateDeclaration = delegateDeclaration.Padding.WithReturnType(VisitLeftPadded(delegateDeclaration.Padding.ReturnType, CsLeftPadded.Location.DELEGATE_DECLARATION_RETURN_TYPE, p)!); + delegateDeclaration = delegateDeclaration.WithIdentifier(VisitAndCast(delegateDeclaration.Identifier, p)!); + delegateDeclaration = delegateDeclaration.Padding.WithTypeParameters(delegateDeclaration.Padding.TypeParameters == null ? null : VisitContainer(delegateDeclaration.Padding.TypeParameters, CsContainer.Location.DELEGATE_DECLARATION_TYPE_PARAMETERS, p)); + delegateDeclaration = delegateDeclaration.Padding.WithParameters(VisitContainer(delegateDeclaration.Padding.Parameters, CsContainer.Location.DELEGATE_DECLARATION_PARAMETERS, p)!); + delegateDeclaration = delegateDeclaration.Padding.WithTypeParameterConstraintClauses(delegateDeclaration.Padding.TypeParameterConstraintClauses == null ? null : VisitContainer(delegateDeclaration.Padding.TypeParameterConstraintClauses, CsContainer.Location.DELEGATE_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES, p)); + return delegateDeclaration; + } + + public virtual J? VisitConversionOperatorDeclaration(Cs.ConversionOperatorDeclaration conversionOperatorDeclaration, P p) + { + conversionOperatorDeclaration = conversionOperatorDeclaration.WithPrefix(VisitSpace(conversionOperatorDeclaration.Prefix, CsSpace.Location.CONVERSION_OPERATOR_DECLARATION_PREFIX, p)!); + var tempStatement = (Statement) VisitStatement(conversionOperatorDeclaration, p); + if (tempStatement is not Cs.ConversionOperatorDeclaration) + { + return tempStatement; + } + conversionOperatorDeclaration = (Cs.ConversionOperatorDeclaration) tempStatement; + conversionOperatorDeclaration = conversionOperatorDeclaration.WithMarkers(VisitMarkers(conversionOperatorDeclaration.Markers, p)); + conversionOperatorDeclaration = conversionOperatorDeclaration.WithModifiers(conversionOperatorDeclaration.Modifiers.Map(el => (J.Modifier?)Visit(el, p))); + conversionOperatorDeclaration = conversionOperatorDeclaration.Padding.WithKind(VisitLeftPadded(conversionOperatorDeclaration.Padding.Kind, CsLeftPadded.Location.CONVERSION_OPERATOR_DECLARATION_KIND, p)!); + conversionOperatorDeclaration = conversionOperatorDeclaration.Padding.WithReturnType(VisitLeftPadded(conversionOperatorDeclaration.Padding.ReturnType, CsLeftPadded.Location.CONVERSION_OPERATOR_DECLARATION_RETURN_TYPE, p)!); + conversionOperatorDeclaration = conversionOperatorDeclaration.Padding.WithParameters(VisitContainer(conversionOperatorDeclaration.Padding.Parameters, CsContainer.Location.CONVERSION_OPERATOR_DECLARATION_PARAMETERS, p)!); + conversionOperatorDeclaration = conversionOperatorDeclaration.Padding.WithExpressionBody(conversionOperatorDeclaration.Padding.ExpressionBody == null ? null : VisitLeftPadded(conversionOperatorDeclaration.Padding.ExpressionBody, CsLeftPadded.Location.CONVERSION_OPERATOR_DECLARATION_EXPRESSION_BODY, p)); + conversionOperatorDeclaration = conversionOperatorDeclaration.WithBody(VisitAndCast(conversionOperatorDeclaration.Body, p)); + return conversionOperatorDeclaration; + } + + public virtual J? VisitTypeParameter(Cs.TypeParameter typeParameter, P p) + { + typeParameter = typeParameter.WithPrefix(VisitSpace(typeParameter.Prefix, CsSpace.Location.TYPE_PARAMETER_PREFIX, p)!); + typeParameter = typeParameter.WithMarkers(VisitMarkers(typeParameter.Markers, p)); + typeParameter = typeParameter.WithAttributeLists(typeParameter.AttributeLists.Map(el => (Cs.AttributeList?)Visit(el, p))); + typeParameter = typeParameter.Padding.WithVariance(typeParameter.Padding.Variance == null ? null : VisitLeftPadded(typeParameter.Padding.Variance, CsLeftPadded.Location.TYPE_PARAMETER_VARIANCE, p)); + typeParameter = typeParameter.WithName(VisitAndCast(typeParameter.Name, p)!); + return typeParameter; + } + + public virtual J? VisitEnumDeclaration(Cs.EnumDeclaration enumDeclaration, P p) + { + enumDeclaration = enumDeclaration.WithPrefix(VisitSpace(enumDeclaration.Prefix, CsSpace.Location.ENUM_DECLARATION_PREFIX, p)!); + var tempStatement = (Statement) VisitStatement(enumDeclaration, p); + if (tempStatement is not Cs.EnumDeclaration) + { + return tempStatement; + } + enumDeclaration = (Cs.EnumDeclaration) tempStatement; + enumDeclaration = enumDeclaration.WithMarkers(VisitMarkers(enumDeclaration.Markers, p)); + enumDeclaration = enumDeclaration.WithAttributeLists(enumDeclaration.AttributeLists?.Map(el => (Cs.AttributeList?)Visit(el, p))); + enumDeclaration = enumDeclaration.WithModifiers(enumDeclaration.Modifiers.Map(el => (J.Modifier?)Visit(el, p))); + enumDeclaration = enumDeclaration.Padding.WithName(VisitLeftPadded(enumDeclaration.Padding.Name, CsLeftPadded.Location.ENUM_DECLARATION_NAME, p)!); + enumDeclaration = enumDeclaration.Padding.WithBaseType(enumDeclaration.Padding.BaseType == null ? null : VisitLeftPadded(enumDeclaration.Padding.BaseType, CsLeftPadded.Location.ENUM_DECLARATION_BASE_TYPE, p)); + enumDeclaration = enumDeclaration.Padding.WithMembers(enumDeclaration.Padding.Members == null ? null : VisitContainer(enumDeclaration.Padding.Members, CsContainer.Location.ENUM_DECLARATION_MEMBERS, p)); + return enumDeclaration; + } + + public virtual J? VisitEnumMemberDeclaration(Cs.EnumMemberDeclaration enumMemberDeclaration, P p) + { + enumMemberDeclaration = enumMemberDeclaration.WithPrefix(VisitSpace(enumMemberDeclaration.Prefix, CsSpace.Location.ENUM_MEMBER_DECLARATION_PREFIX, p)!); + enumMemberDeclaration = enumMemberDeclaration.WithMarkers(VisitMarkers(enumMemberDeclaration.Markers, p)); + enumMemberDeclaration = enumMemberDeclaration.WithAttributeLists(enumMemberDeclaration.AttributeLists.Map(el => (Cs.AttributeList?)Visit(el, p))); + enumMemberDeclaration = enumMemberDeclaration.WithName(VisitAndCast(enumMemberDeclaration.Name, p)!); + enumMemberDeclaration = enumMemberDeclaration.Padding.WithInitializer(enumMemberDeclaration.Padding.Initializer == null ? null : VisitLeftPadded(enumMemberDeclaration.Padding.Initializer, CsLeftPadded.Location.ENUM_MEMBER_DECLARATION_INITIALIZER, p)); + return enumMemberDeclaration; + } + + public virtual J? VisitAliasQualifiedName(Cs.AliasQualifiedName aliasQualifiedName, P p) + { + aliasQualifiedName = aliasQualifiedName.WithPrefix(VisitSpace(aliasQualifiedName.Prefix, CsSpace.Location.ALIAS_QUALIFIED_NAME_PREFIX, p)!); + var tempExpression = (Expression) VisitExpression(aliasQualifiedName, p); + if (tempExpression is not Cs.AliasQualifiedName) + { + return tempExpression; + } + aliasQualifiedName = (Cs.AliasQualifiedName) tempExpression; + aliasQualifiedName = aliasQualifiedName.WithMarkers(VisitMarkers(aliasQualifiedName.Markers, p)); + aliasQualifiedName = aliasQualifiedName.Padding.WithAlias(VisitRightPadded(aliasQualifiedName.Padding.Alias, CsRightPadded.Location.ALIAS_QUALIFIED_NAME_ALIAS, p)!); + aliasQualifiedName = aliasQualifiedName.WithName(VisitAndCast(aliasQualifiedName.Name, p)!); + return aliasQualifiedName; + } + + public virtual J? VisitArrayType(Cs.ArrayType arrayType, P p) + { + arrayType = arrayType.WithPrefix(VisitSpace(arrayType.Prefix, CsSpace.Location.ARRAY_TYPE_PREFIX, p)!); + var tempExpression = (Expression) VisitExpression(arrayType, p); + if (tempExpression is not Cs.ArrayType) + { + return tempExpression; + } + arrayType = (Cs.ArrayType) tempExpression; + arrayType = arrayType.WithMarkers(VisitMarkers(arrayType.Markers, p)); + arrayType = arrayType.WithTypeExpression(VisitAndCast(arrayType.TypeExpression, p)); + arrayType = arrayType.WithDimensions(arrayType.Dimensions.Map(el => (J.ArrayDimension?)Visit(el, p))); + return arrayType; + } + protected virtual JContainer? VisitContainer(JContainer? container, CsContainer.Location loc, P p) where J2 : J { if (container == null) { diff --git a/Rewrite/src/Rewrite.CSharp/Parser/CSharpParserVisitor.cs b/Rewrite/src/Rewrite.CSharp/Parser/CSharpParserVisitor.cs index dded33e..33bb30d 100644 --- a/Rewrite/src/Rewrite.CSharp/Parser/CSharpParserVisitor.cs +++ b/Rewrite/src/Rewrite.CSharp/Parser/CSharpParserVisitor.cs @@ -1,6 +1,10 @@ using System.Collections; +using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Security.Cryptography; +using System.Text; +using System.Xml.Serialization; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -130,67 +134,19 @@ public override Cs VisitFileScopedNamespaceDeclaration(FileScopedNamespaceDeclar return VisitTypeDeclaration(node, type: J.ClassDeclaration.Kind.Types.Value); } + public override J? VisitEnumDeclaration(EnumDeclarationSyntax node) { - var attributeLists = MapAttributes(m: node.AttributeLists); - var javaType = MapType( node); - var hasBaseClass = node.BaseList is { Types.Count: > 0 }; - - var isEmptyBody = node.OpenBraceToken.IsKind(SyntaxKind.None); - - var classDeclaration = new J.ClassDeclaration( + var classDeclaration = new Cs.EnumDeclaration( id: Core.Tree.RandomId(), prefix: Format(Leading(node)), markers: Markers.EMPTY, - leadingAnnotations: [], + attributeLists: MapAttributes(node.AttributeLists), modifiers: MapModifiers(stl: node.Modifiers), - declarationKind: new J.ClassDeclaration.Kind( - id: Core.Tree.RandomId(), - prefix: Format(Leading(node.EnumKeyword)), - markers: Markers.EMPTY, - annotations: [], - kindType: J.ClassDeclaration.Kind.Types.Enum - ), - name: new J.Identifier( - id: Core.Tree.RandomId(), - prefix: Format(Leading(node.Identifier)), - markers: Markers.EMPTY, - annotations: [], - simpleName: node.Identifier.Text, - type: javaType, - fieldType: null - ), - typeParameters: null, - primaryConstructor: null, - extends: hasBaseClass - ? new JLeftPadded(before: Format(Leading(node.BaseList!)), - element: (Visit(node.BaseList!.Types[index: 0]) as TypeTree)!, markers: Markers.EMPTY) - : null, - implements: null, - permits: null, - body: new J.Block( - id: Core.Tree.RandomId(), - prefix: Format(Leading(isEmptyBody ? node.SemicolonToken : node.OpenBraceToken)), - markers: isEmptyBody ? Markers.Create(markers: new OmitBraces()) : Markers.EMPTY, - @static: JRightPadded.Create(element: false), - statements: [JRightPadded.Create(element: MapEnumMembers(members: node.Members))], - end: Format(Leading(node.CloseBraceToken)) - ), - type: javaType as JavaType.FullyQualified + name: JLeftPadded.Create(MapIdentifier(node.Identifier), Format(Leading(node.EnumKeyword))), + baseType: ToLeftPadded(node.BaseList?.Types[0]), + members: ToJContainer(node.Members, node.OpenBraceToken) ); - - if(attributeLists != null) - { - return new Cs.AnnotatedStatement( - id: Core.Tree.RandomId(), - prefix: Format(Leading(node)), - markers: Markers.EMPTY, - attributeLists: attributeLists, - statement: classDeclaration); - } - - - return classDeclaration; } @@ -237,42 +193,31 @@ private Statement VisitTypeDeclaration(TypeDeclarationSyntax node, J.ClassDeclar var isEmptyBody = node.OpenBraceToken.IsKind(SyntaxKind.None); - var classDeclaration = new J.ClassDeclaration( + var classDeclaration = new Cs.ClassDeclaration( id: Core.Tree.RandomId(), prefix: Format(Leading(node)), markers: Markers.EMPTY, - leadingAnnotations: [], + attributeList: attributeLists, modifiers: MapModifiers(stl: node.Modifiers), - declarationKind: new J.ClassDeclaration.Kind( + kind: new J.ClassDeclaration.Kind( id: Core.Tree.RandomId(), prefix: Format(Leading(node.Keyword)), markers: Markers.EMPTY, annotations: [], kindType: type ), - name: new J.Identifier( - id: Core.Tree.RandomId(), - prefix: Format(Leading(node.Identifier)), - markers: Markers.EMPTY, - annotations: [], - simpleName: node.Identifier.Text, - type: javaType, - fieldType: null - ), - typeParameters: MapTypeParameters(tpls: node.TypeParameterList), + name: MapIdentifier(node.Identifier), + typeParameters: node.TypeParameterList != null ? ToJContainer(node.TypeParameterList.Parameters, node.TypeParameterList.LessThanToken) : null, primaryConstructor: MapParameters(pls: node.ParameterList), - extends: hasBaseClass - ? new JLeftPadded(before: Format(Leading(node.BaseList!)), - element: (Visit(node.BaseList!.Types[index: 0]) as TypeTree)!, markers: Markers.EMPTY) + extendings: hasBaseClass + ? new JLeftPadded(before: Format(Leading(node.BaseList!)), element: (Visit(node.BaseList!.Types[index: 0]) as TypeTree)!, markers: Markers.EMPTY) : null, - implements: hasBaseInterfaces + implementings: hasBaseInterfaces ? new JContainer(before: hasBaseClass ? Space.EMPTY : Format(Leading(node.BaseList!)), elements: node.BaseList!.Types.Skip(count: hasBaseClass ? 1 : 0) - .Select(selector: bts => - new JRightPadded(element: (Visit(bts) as TypeTree)!, after: Format(Trailing(bts)), markers: Markers.EMPTY)) + .Select(selector: bts => new JRightPadded(element: (Visit(bts) as TypeTree)!, after: Format(Trailing(bts)), markers: Markers.EMPTY)) .ToList(), markers: Markers.EMPTY) : null, - permits: null, body: new J.Block( id: Core.Tree.RandomId(), prefix: Format(Leading(isEmptyBody ? node.SemicolonToken : node.OpenBraceToken)), @@ -281,30 +226,13 @@ private Statement VisitTypeDeclaration(TypeDeclarationSyntax node, J.ClassDeclar statements: node.Members.Select(selector: MapMemberDeclaration).ToList(), end: Format(Leading(node.CloseBraceToken)) ), - type: javaType as JavaType.FullyQualified + type: javaType as JavaType.FullyQualified, + typeParameterConstraintClauses: MapTypeParameterConstraintClauses(node.ConstraintClauses) ); - var constraints = MapTypeParameterConstraintClauses(list: node.ConstraintClauses); - Statement returnValue = new Cs.ClassDeclaration( - id: Core.Tree.RandomId(), - prefix: Format(Leading(node)), - markers: Markers.EMPTY, - classDeclarationCore: classDeclaration, - typeParameterConstraintClauses: constraints); - - if(attributeLists != null) - { - returnValue = new Cs.AnnotatedStatement( - id: Core.Tree.RandomId(), - prefix: Format(Leading(node)), - markers: Markers.EMPTY, - attributeLists: attributeLists, - statement: classDeclaration); - } - - return returnValue; + return classDeclaration; } /// @@ -400,7 +328,7 @@ public override Statement VisitParameter(ParameterSyntax p) ) ] ); - return attributeLists != null + return attributeLists.Count > 0 ? new Cs.AnnotatedStatement( id: Core.Tree.RandomId(), prefix: Format(Leading(p)), @@ -437,24 +365,15 @@ public override Statement VisitParameter(ParameterSyntax p) ); } - public override J.TypeParameter VisitTypeParameter(TypeParameterSyntax p) + public override Cs.TypeParameter VisitTypeParameter(TypeParameterSyntax node) { - return new J.TypeParameter( + return new Cs.TypeParameter( id: Core.Tree.RandomId(), - prefix: Format(Leading(p)), + prefix: Format(Leading(node)), markers: Markers.EMPTY, - annotations: [], - modifiers: [], - name: new J.Identifier( - id: Core.Tree.RandomId(), - prefix: Format(Leading(p.Identifier)), - markers: Markers.EMPTY, - annotations: [], - simpleName: p.Identifier.Text, - type: MapType( p), - fieldType: null - ), - bounds: null + attributeLists: MapAttributes(node.AttributeLists)!, + variance: ToLeftPadded(node.VarianceKeyword), + name: MapIdentifier(node.Identifier) ); } @@ -492,88 +411,94 @@ public override J VisitIdentifierName(IdentifierNameSyntax node) { var prefix = Format(Leading(node)); var select = Convert(node.Expression); - if (select is J.FieldAccess fa) + switch (select) { - var operatorToken = node.Expression switch + case J.FieldAccess fa: { - MemberAccessExpressionSyntax mae => mae.OperatorToken, - MemberBindingExpressionSyntax mbe => mbe.OperatorToken, - _ => throw new InvalidOperationException(message: $"Unexpected node of type {node.Expression.GetType()} encountered.") - }; - - return new J.MethodInvocation( - id: Core.Tree.RandomId(), - prefix: prefix, - markers: fa.Markers, - select: new JRightPadded(element: fa.Target, after: fa.Padding.Name.Before, markers: Markers.EMPTY), - typeParameters: null, - name: fa.Name, - arguments: MapArgumentList(argumentList: node.ArgumentList), - methodType: MapType( node) as JavaType.Method - ); - } - else if (select is J.Identifier id) - { - return new J.MethodInvocation( - id: Core.Tree.RandomId(), - prefix: prefix, - markers: Markers.EMPTY, - select: null, - typeParameters: null, - name: id, - arguments: MapArgumentList(argumentList: node.ArgumentList), - methodType: MapType( node) as JavaType.Method - ); - } - else if (select is J.ParameterizedType pt) - { - // return mi - // .WithPrefix(prefix) - // .Padding.WithArguments(MapArgumentList(node.ArgumentList)) - // .WithMethodType(MapType(node) as JavaType.Method); - - return new J.MethodInvocation( - id: Core.Tree.RandomId(), - prefix: prefix, - markers: Markers.EMPTY, - select: pt.Clazz is J.FieldAccess lfa - ? new JRightPadded(element: lfa.Target, after: Format(Leading(node.ArgumentList)), markers: Markers.EMPTY) - : null, - typeParameters: pt.TypeParameters != null - ? new JContainer( - before: Space.EMPTY, - elements: pt.TypeParameters.Select(selector: JRightPadded.Create).ToList(), - markers: Markers.EMPTY - ) - : null, // TODO: type parameters - name: pt.Clazz is J.Identifier i - ? i - : (pt.Clazz as J.FieldAccess)?.Name ?? - MapIdentifier(identifier: node.Expression.GetFirstToken(), type: MapType( node.Expression)), - arguments: MapArgumentList(argumentList: node.ArgumentList), - methodType: MapType( node) as JavaType.Method - ); - } - else if (select is J.MethodInvocation or J.ArrayAccess) // chained method invocation (method returns a delegate). ex. Something()() - { + return new J.MethodInvocation( + id: Core.Tree.RandomId(), + prefix: prefix, + markers: fa.Markers, + select: new JRightPadded(element: fa.Target, after: fa.Padding.Name.Before, markers: Markers.EMPTY), + typeParameters: null, + name: fa.Name, + arguments: MapArgumentList(argumentList: node.ArgumentList), + methodType: MapType( node) as JavaType.Method + ); + } + case J.Identifier id: + return new J.MethodInvocation( + id: Core.Tree.RandomId(), + prefix: prefix, + markers: Markers.EMPTY, + select: null, + typeParameters: null, + name: id, + arguments: MapArgumentList(argumentList: node.ArgumentList), + methodType: MapType( node) as JavaType.Method + ); + case J.ParameterizedType pt: + // return mi + // .WithPrefix(prefix) + // .Padding.WithArguments(MapArgumentList(node.ArgumentList)) + // .WithMethodType(MapType(node) as JavaType.Method); - return new J.MethodInvocation( - id: Core.Tree.RandomId(), - prefix: prefix, - markers: Markers.EMPTY, - select: JRightPadded.Create(element: select), - typeParameters: null, - name: new J.Identifier( + return new J.MethodInvocation( id: Core.Tree.RandomId(), - prefix: Space.EMPTY, + prefix: prefix, + markers: pt.Markers, + select: pt.Clazz is J.FieldAccess lfa + ? new JRightPadded(element: lfa.Target, after: lfa.Padding.Name.Before, markers: Markers.EMPTY) + : null, + typeParameters: pt.TypeParameters != null + ? new JContainer( + before: Space.EMPTY, + elements: pt.TypeParameters.Select(selector: JRightPadded.Create).ToList(), + markers: Markers.EMPTY + ) + : null, // TODO: type parameters + name: pt.Clazz is J.Identifier i + ? i + : (pt.Clazz as J.FieldAccess)?.Name ?? + MapIdentifier(identifier: node.Expression.GetFirstToken(), type: MapType( node.Expression)), + arguments: MapArgumentList(argumentList: node.ArgumentList), + methodType: MapType( node) as JavaType.Method + ); + // chained method invocation (method returns a delegate). ex. Something()() + case J.MethodInvocation or J.ArrayAccess: + return new J.MethodInvocation( + id: Core.Tree.RandomId(), + prefix: prefix, markers: Markers.EMPTY, - annotations: new List(), - simpleName: "", - type: null, - fieldType: null), - arguments: MapArgumentList(argumentList: node.ArgumentList), - methodType: MapType( node) as JavaType.Method - ); + select: JRightPadded.Create(element: select), + typeParameters: null, + name: new J.Identifier( + id: Core.Tree.RandomId(), + prefix: Space.EMPTY, + markers: Markers.EMPTY, + annotations: new List(), + simpleName: "", + type: null, + fieldType: null), + arguments: MapArgumentList(argumentList: node.ArgumentList), + methodType: MapType( node) as JavaType.Method + ); + case Cs.AliasQualifiedName alias: + return new Cs.AliasQualifiedName( + id: Core.Tree.RandomId(), + prefix: prefix, + markers: Markers.EMPTY, + alias: alias.Padding.Alias, + name: new J.MethodInvocation( + id: Core.Tree.RandomId(), + prefix: Space.EMPTY, + markers: Markers.EMPTY, + select: null, + typeParameters: null, + name: (J.Identifier)alias.Name, + arguments: MapArgumentList(argumentList: node.ArgumentList), + methodType: MapType(node) as JavaType.Method + )); } for (var index = 0; index < node.ArgumentList.Arguments.Count; index++) @@ -616,11 +541,22 @@ private JRightPadded MapArgument(ArgumentSyntax argument) before: Format(Leading(node.ArgumentList.OpenParenToken)), elements: node.ArgumentList.Arguments.Count > 0 ? node.ArgumentList.Arguments.Select(selector: a => - new JRightPadded( - element: Convert(a.Expression)!, + { + var expression = a.NameEquals == null ? Convert(a.Expression)! : new J.Assignment( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + variable: Convert(a.NameEquals.Name)!, + expression: ToLeftPadded(a.Expression)!, + type: MapType(a.Expression) + ); + + return new JRightPadded( + element: expression, after: Format(Trailing(a)), markers: Markers.EMPTY - )).ToList() + ); + }).ToList() : [ new JRightPadded( @@ -666,11 +602,6 @@ private JRightPadded MapArgument(ArgumentSyntax argument) public override J? VisitMethodDeclaration(MethodDeclarationSyntax node) { - // DeclarationExpressionSyntax f; - // SingleVariableDesignationSyntax s; - // ArgumentSyntax s; - // J.VariableDeclarations; - J.Block body; if (node.Body != null) { @@ -691,49 +622,30 @@ private JRightPadded MapArgument(ArgumentSyntax argument) end: Format(Trailing(node.SemicolonToken))); } var attributeLists = MapAttributes(m: node.AttributeLists); - var methodDeclaration = new J.MethodDeclaration( + Statement returnValue = new Cs.MethodDeclaration( id: Core.Tree.RandomId(), prefix: Format(Leading(node)), markers: Markers.EMPTY, - leadingAnnotations: [], modifiers: MapModifiers(stl: node.Modifiers), - typeParameters: Visit(node.TypeParameterList) as J.TypeParameters, - returnTypeExpression: Convert(node.ReturnType), - name: new J.MethodDeclaration.IdentifierWithAnnotations( - identifier: new J.Identifier( - id: Core.Tree.RandomId(), - prefix: Format(Leading(node.Identifier)), - markers: Markers.EMPTY, - annotations: (Enumerable.Empty() as IList)!, - simpleName: node.Identifier.Text, - type: null, - fieldType: null - ), - annotations: [] - ), + typeParameters: MapTypeParameters(node.TypeParameterList), + returnTypeExpression: Convert(node.ReturnType)!, + explicitInterfaceSpecifier: ToRightPadded(node.ExplicitInterfaceSpecifier), + name: MapIdentifier(node.Identifier, null), parameters: MapParameters(pls: node.ParameterList)!, - throws: null, body: body, - defaultValue: null, - methodType: MapType( node) as JavaType.Method + methodType: MapType( node) as JavaType.Method, + attributes: MapAttributes(node.AttributeLists), + typeParameterConstraintClauses: MapTypeParameterConstraintClauses(node.ConstraintClauses) ); - var constraints = MapTypeParameterConstraintClauses(list: node.ConstraintClauses); - Statement returnValue = new Cs.MethodDeclaration( - id: Core.Tree.RandomId(), - prefix: Format(Leading(node)), - markers: Markers.EMPTY, - methodDeclarationCore: methodDeclaration, - typeParameterConstraintClauses: constraints); - - if(attributeLists != null) + if(attributeLists.Count > 0) { returnValue = new Cs.AnnotatedStatement( id: Core.Tree.RandomId(), prefix: Format(Leading(node)), markers: Markers.EMPTY, attributeLists: attributeLists, - statement: methodDeclaration); + statement: returnValue); } @@ -741,6 +653,11 @@ private JRightPadded MapArgument(ArgumentSyntax argument) return returnValue; } + private JContainer? MapTypeParameters(TypeParameterListSyntax? parameters) + { + return parameters != null ? ToJContainer(parameters.Parameters, parameters.GreaterThanToken) : null; + } + public override J? VisitUsingDirective(UsingDirectiveSyntax node) { var global = node.GlobalKeyword.IsKind(SyntaxKind.GlobalKeyword); @@ -851,7 +768,17 @@ public override J.Block VisitBlock(BlockSyntax node) public override J? VisitOrdering(OrderingSyntax node) { - return base.VisitOrdering(node); + Cs.Ordering.DirectionKind? direction = null; + if (Enum.TryParse(node.AscendingOrDescendingKeyword.ToString(), true, out Cs.Ordering.DirectionKind outVal)) + { + direction = outVal; + } + return new Cs.Ordering( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + expression: ToRightPadded(node.Expression)!, + direction: direction); } public override J? VisitSubpattern(SubpatternSyntax node) @@ -861,7 +788,7 @@ public override J.Block VisitBlock(BlockSyntax node) id: Core.Tree.RandomId(), prefix: Format(Leading(node)), markers: Markers.EMPTY, - name: node.ExpressionColon != null ? MapIdentifier(node.ExpressionColon.Expression.GetFirstToken(), MapType(node.ExpressionColon)) : null, + name: Convert(node.ExpressionColon?.Expression), pattern: JLeftPadded.Create(Convert(node.Pattern)!, Format(Leading(node.Pattern))) ); } @@ -920,7 +847,15 @@ private JRightPadded MapAccessor(AccessorDeclarationSyntax accessorDe public override J? VisitArrayType(ArrayTypeSyntax node) { - return MapArrayType(node, rank: 0); + return new Cs.ArrayType( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + typeExpression: Convert(node.ElementType), + dimensions: node.RankSpecifiers.Select(selector: r => Convert(r)!).ToList(), + type: MapType( node) + ); + // return MapArrayType(node, rank: 0); } private J.ArrayType MapArrayType(ArrayTypeSyntax node, int rank) @@ -1311,6 +1246,11 @@ private static J.Binary.Types MapBinaryExpressionOperator(SyntaxToken operatorTo ); } + private J.Identifier MapIdentifier(SyntaxToken identifier) + { + var type = identifier.Parent != null ? MapType(identifier.Parent) : null; + return MapIdentifier(identifier, type); + } private J.Identifier MapIdentifier(SyntaxToken identifier, JavaType? type) { var variable = type as JavaType.Variable; @@ -1332,7 +1272,13 @@ private J.Identifier MapIdentifier(SyntaxToken identifier, JavaType? type) public override J? VisitAliasQualifiedName(AliasQualifiedNameSyntax node) { - return base.VisitAliasQualifiedName(node); + return new Cs.AliasQualifiedName( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + alias: ToRightPadded(node.Alias)!, + name: Convert(node.Name)! + ); } public override J? VisitPredefinedType(PredefinedTypeSyntax node) @@ -1443,7 +1389,7 @@ public override Cs VisitTupleElement(TupleElementSyntax node) id: Core.Tree.RandomId(), prefix: Format(Leading(node)), markers: Markers.EMPTY, - type: MapTypeTree(node.Type), + type: Convert(node.Type)!, name: MapIdentifier(identifier: node.Identifier, type: type)); } @@ -1485,12 +1431,30 @@ public override Cs VisitTupleElement(TupleElementSyntax node) public override J? VisitPrefixUnaryExpression(PrefixUnaryExpressionSyntax node) { - if (node.OperatorToken.IsKind(SyntaxKind.CaretToken) || node.OperatorToken.IsKind(SyntaxKind.AsteriskToken) ) - // TODO implement C# 8.0 "index from the end" operator `^` - return base.VisitPrefixUnaryExpression(node); try { + Cs.Unary.Types? operatorType = node.OperatorToken.Kind() switch + { + SyntaxKind.CaretToken => Cs.Unary.Types.FromEnd, + SyntaxKind.AsteriskToken => Cs.Unary.Types.PointerIndirection, + SyntaxKind.AmpersandToken => Cs.Unary.Types.AddressOf, + _ => null, + }; + if (operatorType != null) + { + return new Cs.Unary( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + @operator: new JLeftPadded( + before: Format(Leading(node.OperatorToken)), + element: operatorType.Value, + markers: Markers.EMPTY), + expression: Convert(node.Operand)!, + type: MapType( node) + ); + } return new J.Unary( id: Core.Tree.RandomId(), prefix: Format(Leading(node)), @@ -1666,8 +1630,11 @@ private Enum MapPostfixUnaryOperator(SyntaxToken operatorToken) .WithMarkers(markers: bindingNode.Markers.MarkerList.Where(predicate: x => x is not MemberBinding).ToList()); if (bindingNode is J.MethodInvocation methodNode) { + var innerPrefix = methodNode.Prefix; + var outerExpression = currentExpression; var newMethod = methodNode - .WithSelect(newSelect: currentExpression) + .WithPrefix(Space.EMPTY) + .Padding.WithSelect(JRightPadded.Create(outerExpression,innerPrefix)) .WithMarkers(newMarkers: newMarkers); lstNode = methodNode.Equals(other: lstNode) ? newMethod : lstNode.ReplaceNode(oldNode: methodNode, newNode: newMethod); } @@ -1716,16 +1683,24 @@ private Enum MapPostfixUnaryOperator(SyntaxToken operatorToken) /// public override J? VisitMemberBindingExpression(MemberBindingExpressionSyntax node) { - var name = Convert(node.Name)!; - return new J.FieldAccess( - id: Core.Tree.RandomId(), - // Format(Leading(node.OperatorToken)), - prefix: Space.EMPTY, - markers: Markers.Create(markers: new MemberBinding()), - target: new J.Empty(id: Core.Tree.RandomId(), prefix: Space.EMPTY, markers: Markers.EMPTY), - name: name.AsLeftPadded(before: Format(Leading(node.OperatorToken))), - type: MapType( node) - ); + var name = Convert(node.Name)!; + + if (name is J.ParameterizedType generic) + { + return generic.WithMarkers(Markers.Create(markers: new MemberBinding())); + } + else + { + return new J.FieldAccess( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.Create(markers: new MemberBinding()), + target: new J.Empty(id: Core.Tree.RandomId(), prefix: Space.EMPTY, markers: Markers.EMPTY), + name: ((J.Identifier)name).AsLeftPadded(before: Format(Leading(node.OperatorToken))), + type: MapType( node) + ); + } + } public override J? VisitElementBindingExpression(ElementBindingExpressionSyntax node) @@ -2078,11 +2053,6 @@ private J.ArrayAccess MapArrayAccess(ElementAccessExpressionSyntax node, int ind return initializer; } - private IList> ToStatementList(SeparatedSyntaxList expressions) - { - return expressions.Count == 0 ? [] : expressions.SkipLast(count: 1).Select(selector: MapExpressionStatement).Append(element: MapExpressionStatement(es: expressions.Last(), isLastElement: true)).ToList(); - } - public override J? VisitImplicitObjectCreationExpression(ImplicitObjectCreationExpressionSyntax node) { var jNewClass = new J.NewClass( @@ -2395,68 +2365,113 @@ private JRightPadded MapAnonymousObjectMember(AnonymousObjectMemberDe public override J? VisitQueryExpression(QueryExpressionSyntax node) { - // This was added in C# 3.0 - return base.VisitQueryExpression(node); + return new Cs.QueryExpression( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + fromClause: Convert(node.FromClause)!, + body: Convert(node.Body)!); } public override J? VisitQueryBody(QueryBodySyntax node) { - // This was added in C# 3.0 - return base.VisitQueryBody(node); + return new Cs.QueryBody( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + clauses: node.Clauses.Select(x => Convert(x)!).ToList(), + selectOrGroup: Convert(node.SelectOrGroup)!, + continuation: Convert(node.Continuation)!); } public override J? VisitFromClause(FromClauseSyntax node) { - // This was added in C# 3.0 - return base.VisitFromClause(node); + return new Cs.FromClause( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + typeIdentifier: node.Type != null ? MapTypeTree(node.Type) : null, + identifier: JRightPadded.Create(MapIdentifier(node.Identifier, MapType(node.Expression)), Format(Trailing(node.Identifier))), + expression: Convert(node.Expression)!); } public override J? VisitLetClause(LetClauseSyntax node) { - // This was added in C# 3.0 - return base.VisitLetClause(node); + return new Cs.LetClause( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + identifier: JRightPadded.Create(MapIdentifier(node.Identifier, MapType(node.Expression)), Format(Trailing(node.Identifier))), + expression: Convert(node.Expression)!); } public override J? VisitJoinClause(JoinClauseSyntax node) { - // This was added in C# 3.0 - return base.VisitJoinClause(node); + return new Cs.JoinClause( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + identifier: JRightPadded.Create(MapIdentifier(node.Identifier, MapType(node.InExpression)), Format(Trailing(node.Identifier))), + inExpression: ToRightPadded(node.InExpression)!, + leftExpression: ToRightPadded(node.LeftExpression)!, + rightExpression: Convert(node.RightExpression)!, + into: ToLeftPadded(node.Into)); } public override J? VisitJoinIntoClause(JoinIntoClauseSyntax node) { - // This was added in C# 3.0 - return base.VisitJoinIntoClause(node); + return new Cs.JoinIntoClause( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + identifier: MapIdentifier(node.Identifier, MapType(node))); } public override J? VisitWhereClause(WhereClauseSyntax node) { - // This was added in C# 3.0 - return base.VisitWhereClause(node); + return new Cs.WhereClause( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + condition: Convert(node.Condition)!); } public override J? VisitOrderByClause(OrderByClauseSyntax node) { - // This was added in C# 3.0 - return base.VisitOrderByClause(node); + return new Cs.OrderByClause( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + orderings: ToRightPadded(node.Orderings)!); } public override J? VisitSelectClause(SelectClauseSyntax node) { - // This was added in C# 3.0 - return base.VisitSelectClause(node); + return new Cs.SelectClause( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + expression: Convert(node.Expression)!); } public override J? VisitGroupClause(GroupClauseSyntax node) { - // This was added in C# 3.0 - return base.VisitGroupClause(node); + return new Cs.GroupClause( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + groupExpression: ToRightPadded(node.GroupExpression)!, + key: Convert(node.ByExpression)!); } public override J? VisitQueryContinuation(QueryContinuationSyntax node) { - // This was added in C# 3.0 - return base.VisitQueryContinuation(node); + return new Cs.QueryContinuation( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + identifier: MapIdentifier(node.Identifier, MapType(node.Body)), + body: Convert(node.Body)!); } public override J? VisitOmittedArraySizeExpression(OmittedArraySizeExpressionSyntax node) @@ -2805,28 +2820,64 @@ private Cs.Keyword MapKeyword(SyntaxToken keyword) public override J? VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node) { - var usingModifier = node.UsingKeyword.IsKind(SyntaxKind.UsingKeyword) - ? new J.Modifier( + Statement result; + var type = MapType(node); + if (node.UsingKeyword.IsPresent()) + { + result = + new Cs.UsingStatement( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + awaitKeyword: VisitKeyword(node.AwaitKeyword), + expression: ToLeftPadded(node.Declaration)!, + statement: new J.Empty( + id: Core.Tree.RandomId(), + prefix: Space.EMPTY, + markers: Markers.EMPTY)); + } + else + { + + + + // var usingModifier = node.UsingKeyword.IsKind(SyntaxKind.UsingKeyword) + // ? new J.Modifier( + // id: Core.Tree.RandomId(), + // prefix: Format(Leading(node.UsingKeyword)), + // markers: Markers.EMPTY, + // keyword: "using", + // modifierType: J.Modifier.Types.LanguageExtension, + // annotations: [] + // ) + // : null; + + var typeExpression = Convert(node.Declaration.Type)!; + + result = new J.VariableDeclarations( id: Core.Tree.RandomId(), - prefix: Format(Leading(node.UsingKeyword)), + prefix: Format(Leading(node)), markers: Markers.EMPTY, - keyword: "using", - modifierType: J.Modifier.Types.LanguageExtension, - annotations: [] - ) - : null; + leadingAnnotations: [], + modifiers: MapModifiers(stl: node.Modifiers), //usingModifier != null ? [usingModifier, .. MapModifiers(stl: node.Modifiers)] : MapModifiers(stl: node.Modifiers), + typeExpression: typeExpression, + varargs: null!, + dimensionsBeforeName: [], + variables: node.Declaration.Variables.Select(selector: MapVariable).ToList() + ); + if (node.AwaitKeyword.IsPresent()) + { + result = new Cs.AwaitExpression( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + expression: result, + type: type); - return new J.VariableDeclarations( - id: Core.Tree.RandomId(), - prefix: Format(Leading(node)), - markers: Markers.EMPTY, - leadingAnnotations: [], - modifiers: usingModifier != null ? [usingModifier, .. MapModifiers(stl: node.Modifiers)] : MapModifiers(stl: node.Modifiers), - typeExpression: Visit(node.Declaration.Type) as TypeTree, - varargs: null!, - dimensionsBeforeName: [], - variables: node.Declaration.Variables.Select(selector: MapVariable).ToList() - ); + } + } + + return result; } private JRightPadded MapVariable(VariableDeclaratorSyntax variableDeclarator) @@ -2922,15 +2973,11 @@ private IList> MapArrayDimensions(BracketedArgumentListSyntax public override J? VisitExpressionStatement(ExpressionStatementSyntax node) { - var j = Convert(node.Expression); - // if (j is Statement) - // return j; - return new Cs.ExpressionStatement( id: Core.Tree.RandomId(), prefix: Format(Leading(node)), markers: Markers.EMPTY, - expression: (j as Expression)! + expression: ToRightPadded(node.Expression)! ); } @@ -3035,7 +3082,21 @@ private IList> MapArrayDimensions(BracketedArgumentListSyntax public override J? VisitDoStatement(DoStatementSyntax node) { - return base.VisitDoStatement(node); + var condition = JLeftPadded.Create( + new J.ControlParentheses( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node.OpenParenToken)), + markers: Markers.EMPTY, + tree: ToRightPadded(node.Condition)!), + Format(Leading(node.WhileKeyword))); + var body = ToRightPadded(node.Statement)!; + return new J.DoWhileLoop( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + body: body, + whileCondition: condition); + } public override J? VisitForStatement(ForStatementSyntax node) @@ -3072,7 +3133,7 @@ private IList> MapArrayDimensions(BracketedArgumentListSyntax JRightPadded.Create(element: new J.Empty(id: Core.Tree.RandomId(), prefix: Format(Leading(node.CloseParenToken)), markers: Markers.EMPTY)) ] - : node.Incrementors.Select(selector: MapExpressionStatement).ToList() + : node.Incrementors.Select(MapExpressionStatement).ToList() ), body: MapStatement(statementSyntax: node.Statement) ); @@ -3081,9 +3142,9 @@ private IList> MapArrayDimensions(BracketedArgumentListSyntax public override J? VisitForEachStatement(ForEachStatementSyntax node) { var javaType = (MapType( node) as JavaType.Variable)!; - return new J.ForEachLoop( + var loop = new J.ForEachLoop( id: Core.Tree.RandomId(), - prefix: Format(Leading(node)), + prefix: Format(Leading(node.ForEachKeyword)), markers: Markers.EMPTY, loopControl: new J.ForEachLoop.Control( id: Core.Tree.RandomId(), @@ -3131,6 +3192,17 @@ private IList> MapArrayDimensions(BracketedArgumentListSyntax ), body: MapStatement(statementSyntax: node.Statement) ); + + if (node.AwaitKeyword.IsKeyword()) + { + return new Cs.AwaitExpression( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + loop, + loop.LoopControl.Iterable.Type); + } + return loop; } public override J? VisitForEachVariableStatement(ForEachVariableStatementSyntax node) @@ -3154,17 +3226,16 @@ private IList> MapArrayDimensions(BracketedArgumentListSyntax public override J? VisitUsingStatement(UsingStatementSyntax node) { var statement = Convert(node.Statement) ?? throw new InvalidOperationException(message: "Statement is empty after conversion"); - JRightPadded expression = JRightPadded.Create(element: Convert((SyntaxNode?)node.Expression ?? node.Declaration)!, after: Format(Leading(node.CloseParenToken))); + var expressionNode = (SyntaxNode?)node.Expression ?? node.Declaration!; + var expression = node.OpenParenToken.IsPresent() ? ToControlParentheses(expressionNode, node.OpenParenToken) : Convert(expressionNode)!; + var usingStatement = new Cs.UsingStatement( id: Core.Tree.RandomId(), prefix: Format(Leading(node)), markers: Markers.EMPTY, awaitKeyword: VisitKeyword(node.AwaitKeyword), - expression: JContainer.Create(elements: new List> - { - expression - }, space: Format(Leading(node.OpenParenToken))), + expression: JLeftPadded.Create(expression, Format(Leading(node.UsingKeyword))), statement: statement); return usingStatement; } @@ -3259,38 +3330,21 @@ private JRightPadded MapExpression(ExpressionSyntax es) ); } - private JRightPadded MapExpressionStatement(ExpressionSyntax es) - { - return MapExpressionStatement(es: es, isLastElement: false); - } - - private JRightPadded MapExpressionStatement(ExpressionSyntax es, bool isLastElement) + private JRightPadded MapExpressionStatement(ExpressionSyntax es) => MapExpressionStatement(es, false); + private JRightPadded MapExpressionStatement(ExpressionSyntax es, bool forceWrap) { - var j = Convert(es); - var trailingComma = isLastElement && es.GetLastToken().GetNextToken().IsKind(SyntaxKind.CommaToken); - if (j is Statement s) - return new JRightPadded( - element: s, - after: Format(Trailing(es)), - markers: trailingComma - ? Markers.EMPTY.Add(marker: new TrailingComma(Id: Core.Tree.RandomId(), - Suffix: Format(Trailing(es.GetLastToken().GetNextToken())))) - : Markers.EMPTY - ); + var lst = Convert(es)!; + if (lst is Cs.ExpressionStatement || (lst is Statement && !forceWrap)) + { + return JRightPadded.Create((Statement)lst, Format(Trailing(es))); + } - return new JRightPadded( - element: new Cs.ExpressionStatement( + return JRightPadded.Create(new Cs.ExpressionStatement( id: Core.Tree.RandomId(), prefix: Format(Leading(es)), markers: Markers.EMPTY, - expression: (j as Expression)! - ), - after: Format(Trailing(es)), - markers: trailingComma - ? Markers.EMPTY.Add(marker: new TrailingComma(Id: Core.Tree.RandomId(), - Suffix: Format(Trailing(es.GetLastToken().GetNextToken())))) - : Markers.EMPTY - ); + expression: JRightPadded.Create((Expression)lst, Format(Trailing(es))) + )); } public override J? VisitElseClause(ElseClauseSyntax node) @@ -3476,13 +3530,27 @@ private JRightPadded MapExpressionStatement(ExpressionSyntax es, bool public override J? VisitDelegateDeclaration(DelegateDeclarationSyntax node) { - // This was added in C# 1.0 - return base.VisitDelegateDeclaration(node); + return new Cs.DelegateDeclaration( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + modifiers: MapModifiers(node.Modifiers), + returnType: ToLeftPadded(node.ReturnType)!, + identifier: MapIdentifier(node.Identifier), + typeParameters: MapTypeParameters(node.TypeParameterList), + parameters: MapParameters(node.ParameterList)!, + typeParameterConstraintClauses: MapTypeParameterConstraintClauses(node.ConstraintClauses)); } public override J? VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node) { - return base.VisitEnumMemberDeclaration(node); + return new Cs.EnumMemberDeclaration( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + attributeLists: MapAttributes(node.AttributeLists), + name: MapIdentifier(node.Identifier), + initializer: ToLeftPadded(node.EqualsValue?.Value)); } public override J? VisitConstructorConstraint(ConstructorConstraintSyntax node) @@ -3547,7 +3615,7 @@ private JRightPadded MapExpressionStatement(ExpressionSyntax es, bool dimensionsBeforeName: [], variables: node.Declaration.Variables.Select(selector: MapVariable).ToList() ); - return attributeLists != null + return attributeLists.Count > 0 ? new Cs.AnnotatedStatement( id: Core.Tree.RandomId(), prefix: Format(Leading(node)), @@ -3565,7 +3633,7 @@ private JRightPadded MapExpressionStatement(ExpressionSyntax es, bool public override J? VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node) { - return base.VisitExplicitInterfaceSpecifier(node); + return Convert(node.Name); } public override J? VisitOperatorDeclaration(OperatorDeclarationSyntax node) @@ -3575,7 +3643,29 @@ private JRightPadded MapExpressionStatement(ExpressionSyntax es, bool public override J? VisitConversionOperatorDeclaration(ConversionOperatorDeclarationSyntax node) { - return base.VisitConversionOperatorDeclaration(node); + var attributeLists = MapAttributes(m: node.AttributeLists); + Statement returnValue = new Cs.ConversionOperatorDeclaration( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + modifiers: MapModifiers(node.Modifiers), + kind: ToLeftPadded(node.ImplicitOrExplicitKeyword)!, + returnType: ToLeftPadded(node.Type)!, + parameters: MapParameters(node.ParameterList)!, + expressionBody: ToLeftPadded(node.ExpressionBody), + body: Convert(node.Body)); + + if(attributeLists.Count > 0) + { + returnValue = new Cs.AnnotatedStatement( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + attributeLists: attributeLists, + statement: returnValue); + } + + return returnValue; } public override J? VisitConstructorDeclaration(ConstructorDeclarationSyntax node) @@ -3611,7 +3701,7 @@ private JRightPadded MapExpressionStatement(ExpressionSyntax es, bool initializer: Convert(node.Initializer), constructorCore: methodDeclaration); - return attributeLists != null + return attributeLists.Count > 0 ? new Cs.AnnotatedStatement( id: Core.Tree.RandomId(), prefix: Format(Leading(node)), @@ -3634,16 +3724,50 @@ private JRightPadded MapExpressionStatement(ExpressionSyntax es, bool markers: Markers.EMPTY, kind: node.ThisOrBaseKeyword.IsKind(SyntaxKind.BaseKeyword) ? Cs.Keyword.KeywordKind.Base : Cs.Keyword.KeywordKind.This ), - arguments: ToJContainer(syntaxList: node.ArgumentList.Arguments, openingToken: node.ArgumentList.OpenParenToken) + arguments: ToJContainer(syntaxList: node.ArgumentList.Arguments, openingToken: node.ArgumentList.OpenParenToken) ); } - ~CSharpParserVisitor() => Console.WriteLine(""); - public override J? VisitDestructorDeclaration(DestructorDeclarationSyntax node) { - return base.VisitDestructorDeclaration(node); + + + var attributeLists = MapAttributes(m: node.AttributeLists); + var methodDeclaration = new J.MethodDeclaration( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node.TildeToken)), + markers: Markers.EMPTY, + leadingAnnotations: [], + modifiers: MapModifiers(stl: node.Modifiers), + typeParameters: null, // constructors have no type parameters + returnTypeExpression: null, // constructors have no return type + name: new J.MethodDeclaration.IdentifierWithAnnotations( + identifier: MapIdentifier(identifier: node.Identifier, type: null), + annotations: [] // attributes always appear as leading + ), + parameters: MapParameters(pls: node.ParameterList)!, + throws: null, // C# has no checked exceptions + body: Convert(node.Body as SyntaxNode ?? node.ExpressionBody), + defaultValue: null, // not applicable to constructors + methodType: MapType( node) as JavaType.Method + ); + + var destructor = new Cs.DestructorDeclaration( + id: Core.Tree.RandomId(), + prefix: Space.EMPTY, + markers: Markers.EMPTY, + methodCore: methodDeclaration); + + return attributeLists.Count > 0 + ? new Cs.AnnotatedStatement( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + attributeLists: attributeLists, + statement: destructor + ) + : destructor; } public override J? VisitPropertyDeclaration(PropertyDeclarationSyntax node) @@ -3687,7 +3811,7 @@ private JRightPadded MapExpressionStatement(ExpressionSyntax es, bool @static: JRightPadded.Create(element: false), statements: [ - MapExpressionStatement(es: node.Expression) + MapExpressionStatement(node.Expression, forceWrap: true) ], end: Space.EMPTY ); @@ -3701,8 +3825,40 @@ private JRightPadded MapExpressionStatement(ExpressionSyntax es, bool public override J? VisitIndexerDeclaration(IndexerDeclarationSyntax node) { - // This was added in C# 1.0 - return base.VisitIndexerDeclaration(node); + // return base.VisitIndexerDeclaration(node); + var attributeLists = MapAttributes(m: node.AttributeLists); + // Expression indexer = node.ExplicitInterfaceSpecifier + Statement returnValue = new Cs.IndexerDeclaration( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + modifiers: MapModifiers(stl: node.Modifiers), + typeExpression: MapTypeTree(node.Type), + indexer: new J.Identifier( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node.ThisKeyword)), + markers: Markers.EMPTY, + annotations: [], + simpleName: "this", + type: null, + fieldType: null), + parameters: ToJContainer(node.ParameterList.Parameters, node.ParameterList.OpenBracketToken), + expressionBody: ToLeftPadded(node.ExpressionBody), + accessors: Convert(node.AccessorList) + ); + + if(attributeLists != null) + { + returnValue = new Cs.AnnotatedStatement( + id: Core.Tree.RandomId(), + prefix: Format(Leading(node)), + markers: Markers.EMPTY, + attributeLists: attributeLists, + statement: returnValue); + } + + return returnValue; + } public override J? VisitParameterList(ParameterListSyntax node) @@ -3969,7 +4125,7 @@ private JRightPadded MapExpressionStatement(ExpressionSyntax es, bool private JRightPadded MapMemberDeclaration(MemberDeclarationSyntax m) { - var memberDeclaration = (Visit(m) as Statement)!; + var memberDeclaration = (Statement)Visit(m)!; var trailingSemicolon = m.GetLastToken().IsKind(SyntaxKind.SemicolonToken); if (trailingSemicolon && m is BaseTypeDeclarationSyntax { CloseBraceToken.Text: "}" } or NamespaceDeclarationSyntax { CloseBraceToken.Text: "}" }) @@ -4010,20 +4166,20 @@ private JRightPadded MapParameter(ParameterSyntax tps) where T : J var parameter = ((T?)Visit(tps))!; return new JRightPadded( element: parameter, - after: Format(Trailing(tps.Identifier)), + after: Format(Trailing(tps)), markers: Markers.EMPTY ); } - private JContainer? MapTypeParameters(TypeParameterListSyntax? tpls) - { - return tpls == null || tpls.Parameters.Count == 0 - ? null - : JContainer.Build(before: Format(Leading(tpls)), - elements: tpls.Parameters.Select(selector: MapTypeParameter).ToList(), - markers: Markers.EMPTY - ); - } + // private JContainer? MapTypeParameters(TypeParameterListSyntax? tpls) + // { + // return tpls == null || tpls.Parameters.Count == 0 + // ? null + // : JContainer.Build(before: Format(Leading(tpls)), + // elements: tpls.Parameters.Select(selector: MapTypeParameter).ToList(), + // markers: Markers.EMPTY + // ); + // } private JRightPadded MapTypeParameter(TypeParameterSyntax tps) { @@ -4064,9 +4220,9 @@ private JRightPadded MapParameter(ParameterSyntax tps) where T : J #if DEBUG_VISITOR [DebuggerStepThrough] #endif - private List? MapAttributes(SyntaxList m) + private List MapAttributes(SyntaxList m) { - return m.Count == 0 ? null : m.Select(selector: x => Convert(x)!).ToList(); + return m.Select(selector: x => Convert(x)!).ToList(); } #if DEBUG_VISITOR [DebuggerStepThrough] @@ -4181,12 +4337,18 @@ internal SyntaxTriviaList Trailing(SyntaxToken token) #if DEBUG_VISITOR [DebuggerStepThrough] #endif - internal static Space Format(SyntaxTriviaList trivia) + internal static Space Format(SyntaxTriviaList triviaList) { - // FIXME optimize - return Space.Format(trivia.ToString()); + return Space.Format(triviaList.ToFullString()); } + private JLeftPadded? ToLeftPadded(SyntaxToken node) where TTo : struct, Enum + { + if (node.IsKind(SyntaxKind.None)) + return null; + var value = Enum.Parse(node.ToString(), ignoreCase: true); + return JLeftPadded.Create(value, Format(Leading(node))); + } private JLeftPadded? ToLeftPadded(SyntaxNode? node) where TTo : class, J { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/AliasQualifiedName.cs b/Rewrite/src/Rewrite.CSharp/Tree/AliasQualifiedName.cs new file mode 100644 index 0000000..2121a0b --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/AliasQualifiedName.cs @@ -0,0 +1,21 @@ +using System.Diagnostics.CodeAnalysis; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + partial class AliasQualifiedName + { + public bool Equals(Core.Marker.Marker? other) + { + return other is AliasQualifiedName otherAlias && otherAlias.Alias.Equals(this.Alias) && otherAlias.Name.Equals(this.Name); + } + } +} diff --git a/Rewrite/src/Rewrite.CSharp/Tree/AliasQualifiedName.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/AliasQualifiedName.g.cs new file mode 100644 index 0000000..342ce57 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/AliasQualifiedName.g.cs @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + /// + /// Represents a C# alias qualified name, which uses an extern alias to qualify a name. + ///
+ /// For example: + /// + /// // Using LibA to qualify TypeName + /// LibA::TypeName + /// // Using LibB to qualify namespace + /// LibB::System.Collections + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class AliasQualifiedName( + Guid id, + Space prefix, + Markers markers, + JRightPadded alias, + Expression name + ) : Cs, TypeTree, Expression, Rewrite.Core.Marker.Marker, Expression, TypedTree, J, TypeTree, MutableTree + { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitAliasQualifiedName(this, p); + } + + public Guid Id => id; + + public AliasQualifiedName WithId(Guid newId) + { + return newId == id ? this : new AliasQualifiedName(newId, prefix, markers, _alias, name); + } + public Space Prefix => prefix; + + public AliasQualifiedName WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new AliasQualifiedName(id, newPrefix, markers, _alias, name); + } + public Markers Markers => markers; + + public AliasQualifiedName WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new AliasQualifiedName(id, prefix, newMarkers, _alias, name); + } + private readonly JRightPadded _alias = alias; + public J.Identifier Alias => _alias.Element; + + public AliasQualifiedName WithAlias(J.Identifier newAlias) + { + return Padding.WithAlias(_alias.WithElement(newAlias)); + } + public Expression Name => name; + + public AliasQualifiedName WithName(Expression newName) + { + return ReferenceEquals(newName, name) ? this : new AliasQualifiedName(id, prefix, markers, _alias, newName); + } + public sealed record PaddingHelper(Cs.AliasQualifiedName T) + { + public JRightPadded Alias => T._alias; + + public Cs.AliasQualifiedName WithAlias(JRightPadded newAlias) + { + return T._alias == newAlias ? T : new Cs.AliasQualifiedName(T.Id, T.Prefix, T.Markers, newAlias, T.Name); + } + + } + + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is AliasQualifiedName && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/AllowsConstraintClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/AllowsConstraintClause.g.cs index 387e935..1e9f6ed 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/AllowsConstraintClause.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/AllowsConstraintClause.g.cs @@ -36,7 +36,7 @@ public partial class AllowsConstraintClause( Space prefix, Markers markers, JContainer expressions - ) : Cs, Cs.TypeParameterConstraint, MutableTree + ) : Cs, Cs.TypeParameterConstraint, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/AnnotatedStatement.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/AnnotatedStatement.g.cs index 11ea1c6..8ee3f0c 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/AnnotatedStatement.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/AnnotatedStatement.g.cs @@ -33,7 +33,7 @@ public partial class AnnotatedStatement( Markers markers, IList attributeLists, Statement statement - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/Argument.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/Argument.g.cs index 3c238ff..3388794 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/Argument.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/Argument.g.cs @@ -34,7 +34,7 @@ public partial class Argument( JRightPadded? nameColumn, Keyword? refKindKeyword, Expression expression - ) : Cs, Expression, Expression, MutableTree + ) : Cs, Expression, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ArrayRankSpecifier.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ArrayRankSpecifier.g.cs index 524c589..32ff93a 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/ArrayRankSpecifier.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/ArrayRankSpecifier.g.cs @@ -32,7 +32,7 @@ public partial class ArrayRankSpecifier( Space prefix, Markers markers, JContainer sizes - ) : Cs, Expression, Expression, MutableTree + ) : Cs, Expression, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ArrayType.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ArrayType.g.cs new file mode 100644 index 0000000..d519a26 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/ArrayType.g.cs @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class ArrayType( + Guid id, + Space prefix, + Markers markers, + TypeTree? typeExpression, + IList dimensions, + JavaType? type + ) : Cs, Expression, TypeTree, Expression, TypedTree, J, TypeTree, MutableTree + { + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitArrayType(this, p); + } + + public Guid Id => id; + + public ArrayType WithId(Guid newId) + { + return newId == id ? this : new ArrayType(newId, prefix, markers, typeExpression, dimensions, type); + } + public Space Prefix => prefix; + + public ArrayType WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new ArrayType(id, newPrefix, markers, typeExpression, dimensions, type); + } + public Markers Markers => markers; + + public ArrayType WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new ArrayType(id, prefix, newMarkers, typeExpression, dimensions, type); + } + public TypeTree? TypeExpression => typeExpression; + + public ArrayType WithTypeExpression(TypeTree? newTypeExpression) + { + return ReferenceEquals(newTypeExpression, typeExpression) ? this : new ArrayType(id, prefix, markers, newTypeExpression, dimensions, type); + } + public IList Dimensions => dimensions; + + public ArrayType WithDimensions(IList newDimensions) + { + return newDimensions == dimensions ? this : new ArrayType(id, prefix, markers, typeExpression, newDimensions, type); + } + public JavaType? Type => type; + + public ArrayType WithType(JavaType? newType) + { + return newType == type ? this : new ArrayType(id, prefix, markers, typeExpression, dimensions, newType); + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is ArrayType && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/AssignmentOperation.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/AssignmentOperation.g.cs index 3634ab5..9797bfa 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/AssignmentOperation.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/AssignmentOperation.g.cs @@ -35,7 +35,7 @@ public partial class AssignmentOperation( JLeftPadded @operator, Expression assignment, JavaType? type - ) : Cs, Statement, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : Cs, Statement, Expression, TypedTree, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/AttributeList.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/AttributeList.g.cs index 8219fb7..2d6bfed 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/AttributeList.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/AttributeList.g.cs @@ -33,7 +33,7 @@ public partial class AttributeList( Markers markers, JRightPadded? target, IList> attributes - ) : Cs, MutableTree + ) : Cs, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/AwaitExpression.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/AwaitExpression.g.cs index 27323d3..b806dbc 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/AwaitExpression.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/AwaitExpression.g.cs @@ -31,9 +31,9 @@ public partial class AwaitExpression( Guid id, Space prefix, Markers markers, - Expression expression, + J expression, JavaType? type - ) : Cs, Expression, Expression, MutableTree + ) : Cs, Expression, Statement, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { @@ -58,9 +58,9 @@ public AwaitExpression WithMarkers(Markers newMarkers) { return ReferenceEquals(newMarkers, markers) ? this : new AwaitExpression(id, prefix, newMarkers, expression, type); } - public Expression Expression => expression; + public J Expression => expression; - public AwaitExpression WithExpression(Expression newExpression) + public AwaitExpression WithExpression(J newExpression) { return ReferenceEquals(newExpression, expression) ? this : new AwaitExpression(id, prefix, markers, newExpression, type); } diff --git a/Rewrite/src/Rewrite.CSharp/Tree/Binary.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/Binary.g.cs index 9315167..b10f346 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/Binary.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/Binary.g.cs @@ -35,7 +35,7 @@ public partial class Binary( JLeftPadded @operator, Expression right, JavaType? type - ) : Cs, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : Cs, Expression, TypedTree, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/BinaryPattern.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/BinaryPattern.g.cs index ba1fa47..2e81faa 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/BinaryPattern.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/BinaryPattern.g.cs @@ -58,7 +58,7 @@ public partial class BinaryPattern( Pattern left, JLeftPadded @operator, Pattern right - ) : Cs.Pattern, Expression, MutableTree + ) : Cs.Pattern, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/BlockScopeNamespaceDeclaration.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/BlockScopeNamespaceDeclaration.g.cs index efc19ec..d9d7204 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/BlockScopeNamespaceDeclaration.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/BlockScopeNamespaceDeclaration.g.cs @@ -36,7 +36,7 @@ public partial class BlockScopeNamespaceDeclaration( IList> usings, IList> members, Space end - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/CasePatternSwitchLabel.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/CasePatternSwitchLabel.g.cs index d2ae232..85bfd38 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/CasePatternSwitchLabel.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/CasePatternSwitchLabel.g.cs @@ -49,7 +49,7 @@ public partial class CasePatternSwitchLabel( Pattern pattern, JLeftPadded? whenClause, Space colonToken - ) : Cs, Cs.SwitchLabel, Expression, MutableTree + ) : Cs, Cs.SwitchLabel, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/CheckedStatement.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/CheckedStatement.g.cs index 7d84127..2328dd5 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/CheckedStatement.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/CheckedStatement.g.cs @@ -55,7 +55,7 @@ public partial class CheckedStatement( Space prefix, Markers markers, J.Block block - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ClassDeclaration.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ClassDeclaration.g.cs index 36ff0ff..1820244 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/ClassDeclaration.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/ClassDeclaration.g.cs @@ -31,9 +31,18 @@ public partial class ClassDeclaration( Guid id, Space prefix, Markers markers, - J.ClassDeclaration classDeclarationCore, - JContainer typeParameterConstraintClauses - ) : Cs, Statement, MutableTree + IList attributeList, + IList modifiers, + J.ClassDeclaration.Kind kind, + J.Identifier name, + JContainer? typeParameters, + JContainer? primaryConstructor, + JLeftPadded? extendings, + JContainer? implementings, + J.Block? body, + JContainer? typeParameterConstraintClauses, + JavaType.FullyQualified? type + ) : Cs, Statement, TypedTree, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; @@ -69,40 +78,133 @@ public PaddingHelper Padding public ClassDeclaration WithId(Guid newId) { - return newId == id ? this : new ClassDeclaration(newId, prefix, markers, classDeclarationCore, _typeParameterConstraintClauses); + return newId == id ? this : new ClassDeclaration(newId, prefix, markers, attributeList, modifiers, _kind, name, _typeParameters, _primaryConstructor, _extendings, _implementings, body, _typeParameterConstraintClauses, type); } public Space Prefix => prefix; public ClassDeclaration WithPrefix(Space newPrefix) { - return newPrefix == prefix ? this : new ClassDeclaration(id, newPrefix, markers, classDeclarationCore, _typeParameterConstraintClauses); + return newPrefix == prefix ? this : new ClassDeclaration(id, newPrefix, markers, attributeList, modifiers, _kind, name, _typeParameters, _primaryConstructor, _extendings, _implementings, body, _typeParameterConstraintClauses, type); } public Markers Markers => markers; public ClassDeclaration WithMarkers(Markers newMarkers) { - return ReferenceEquals(newMarkers, markers) ? this : new ClassDeclaration(id, prefix, newMarkers, classDeclarationCore, _typeParameterConstraintClauses); + return ReferenceEquals(newMarkers, markers) ? this : new ClassDeclaration(id, prefix, newMarkers, attributeList, modifiers, _kind, name, _typeParameters, _primaryConstructor, _extendings, _implementings, body, _typeParameterConstraintClauses, type); } - public J.ClassDeclaration ClassDeclarationCore => classDeclarationCore; + public IList AttributeList => attributeList; - public ClassDeclaration WithClassDeclarationCore(J.ClassDeclaration newClassDeclarationCore) + public ClassDeclaration WithAttributeList(IList newAttributeList) { - return ReferenceEquals(newClassDeclarationCore, classDeclarationCore) ? this : new ClassDeclaration(id, prefix, markers, newClassDeclarationCore, _typeParameterConstraintClauses); + return newAttributeList == attributeList ? this : new ClassDeclaration(id, prefix, markers, newAttributeList, modifiers, _kind, name, _typeParameters, _primaryConstructor, _extendings, _implementings, body, _typeParameterConstraintClauses, type); } - private readonly JContainer _typeParameterConstraintClauses = typeParameterConstraintClauses; - public IList TypeParameterConstraintClauses => _typeParameterConstraintClauses.GetElements(); + public IList Modifiers => modifiers; - public ClassDeclaration WithTypeParameterConstraintClauses(IList newTypeParameterConstraintClauses) + public ClassDeclaration WithModifiers(IList newModifiers) { - return Padding.WithTypeParameterConstraintClauses(JContainer.WithElements(_typeParameterConstraintClauses, newTypeParameterConstraintClauses)); + return newModifiers == modifiers ? this : new ClassDeclaration(id, prefix, markers, attributeList, newModifiers, _kind, name, _typeParameters, _primaryConstructor, _extendings, _implementings, body, _typeParameterConstraintClauses, type); + } + private readonly J.ClassDeclaration.Kind _kind = kind; + + public ClassDeclaration WithKind(J.ClassDeclaration.Kind newKind) + { + return ReferenceEquals(newKind, _kind) ? this : new ClassDeclaration(id, prefix, markers, attributeList, modifiers, _kind, name, _typeParameters, _primaryConstructor, _extendings, _implementings, body, _typeParameterConstraintClauses, type); + } + public J.Identifier Name => name; + + public ClassDeclaration WithName(J.Identifier newName) + { + return ReferenceEquals(newName, name) ? this : new ClassDeclaration(id, prefix, markers, attributeList, modifiers, _kind, newName, _typeParameters, _primaryConstructor, _extendings, _implementings, body, _typeParameterConstraintClauses, type); + } + private readonly JContainer? _typeParameters = typeParameters; + public IList? TypeParameters => _typeParameters?.GetElements(); + + public ClassDeclaration WithTypeParameters(IList? newTypeParameters) + { + return Padding.WithTypeParameters(JContainer.WithElementsNullable(_typeParameters, newTypeParameters)); + } + private readonly JContainer? _primaryConstructor = primaryConstructor; + public IList? PrimaryConstructor => _primaryConstructor?.GetElements(); + + public ClassDeclaration WithPrimaryConstructor(IList? newPrimaryConstructor) + { + return Padding.WithPrimaryConstructor(JContainer.WithElementsNullable(_primaryConstructor, newPrimaryConstructor)); + } + private readonly JLeftPadded? _extendings = extendings; + public TypeTree? Extendings => _extendings?.Element; + + public ClassDeclaration WithExtendings(TypeTree? newExtendings) + { + return Padding.WithExtendings(JLeftPadded.WithElement(_extendings, newExtendings)); + } + private readonly JContainer? _implementings = implementings; + public IList? Implementings => _implementings?.GetElements(); + + public ClassDeclaration WithImplementings(IList? newImplementings) + { + return Padding.WithImplementings(JContainer.WithElementsNullable(_implementings, newImplementings)); + } + public J.Block? Body => body; + + public ClassDeclaration WithBody(J.Block? newBody) + { + return ReferenceEquals(newBody, body) ? this : new ClassDeclaration(id, prefix, markers, attributeList, modifiers, _kind, name, _typeParameters, _primaryConstructor, _extendings, _implementings, newBody, _typeParameterConstraintClauses, type); + } + private readonly JContainer? _typeParameterConstraintClauses = typeParameterConstraintClauses; + public IList? TypeParameterConstraintClauses => _typeParameterConstraintClauses?.GetElements(); + + public ClassDeclaration WithTypeParameterConstraintClauses(IList? newTypeParameterConstraintClauses) + { + return Padding.WithTypeParameterConstraintClauses(JContainer.WithElementsNullable(_typeParameterConstraintClauses, newTypeParameterConstraintClauses)); + } + public JavaType.FullyQualified? Type => type; + + public ClassDeclaration WithType(JavaType.FullyQualified? newType) + { + return newType == type ? this : new ClassDeclaration(id, prefix, markers, attributeList, modifiers, _kind, name, _typeParameters, _primaryConstructor, _extendings, _implementings, body, _typeParameterConstraintClauses, newType); } public sealed record PaddingHelper(Cs.ClassDeclaration T) { - public JContainer TypeParameterConstraintClauses => T._typeParameterConstraintClauses; + public J.ClassDeclaration.Kind Kind => T._kind; + + public Cs.ClassDeclaration WithKind(J.ClassDeclaration.Kind newKind) + { + return T._kind == newKind ? T : new Cs.ClassDeclaration(T.Id, T.Prefix, T.Markers, T.AttributeList, T.Modifiers, newKind, T.Name, T._typeParameters, T._primaryConstructor, T._extendings, T._implementings, T.Body, T._typeParameterConstraintClauses, T.Type); + } + + public JContainer? TypeParameters => T._typeParameters; + + public Cs.ClassDeclaration WithTypeParameters(JContainer? newTypeParameters) + { + return T._typeParameters == newTypeParameters ? T : new Cs.ClassDeclaration(T.Id, T.Prefix, T.Markers, T.AttributeList, T.Modifiers, T._kind, T.Name, newTypeParameters, T._primaryConstructor, T._extendings, T._implementings, T.Body, T._typeParameterConstraintClauses, T.Type); + } + + public JContainer? PrimaryConstructor => T._primaryConstructor; + + public Cs.ClassDeclaration WithPrimaryConstructor(JContainer? newPrimaryConstructor) + { + return T._primaryConstructor == newPrimaryConstructor ? T : new Cs.ClassDeclaration(T.Id, T.Prefix, T.Markers, T.AttributeList, T.Modifiers, T._kind, T.Name, T._typeParameters, newPrimaryConstructor, T._extendings, T._implementings, T.Body, T._typeParameterConstraintClauses, T.Type); + } + + public JLeftPadded? Extendings => T._extendings; + + public Cs.ClassDeclaration WithExtendings(JLeftPadded? newExtendings) + { + return T._extendings == newExtendings ? T : new Cs.ClassDeclaration(T.Id, T.Prefix, T.Markers, T.AttributeList, T.Modifiers, T._kind, T.Name, T._typeParameters, T._primaryConstructor, newExtendings, T._implementings, T.Body, T._typeParameterConstraintClauses, T.Type); + } + + public JContainer? Implementings => T._implementings; + + public Cs.ClassDeclaration WithImplementings(JContainer? newImplementings) + { + return T._implementings == newImplementings ? T : new Cs.ClassDeclaration(T.Id, T.Prefix, T.Markers, T.AttributeList, T.Modifiers, T._kind, T.Name, T._typeParameters, T._primaryConstructor, T._extendings, newImplementings, T.Body, T._typeParameterConstraintClauses, T.Type); + } + + public JContainer? TypeParameterConstraintClauses => T._typeParameterConstraintClauses; - public Cs.ClassDeclaration WithTypeParameterConstraintClauses(JContainer newTypeParameterConstraintClauses) + public Cs.ClassDeclaration WithTypeParameterConstraintClauses(JContainer? newTypeParameterConstraintClauses) { - return T._typeParameterConstraintClauses == newTypeParameterConstraintClauses ? T : new Cs.ClassDeclaration(T.Id, T.Prefix, T.Markers, T.ClassDeclarationCore, newTypeParameterConstraintClauses); + return T._typeParameterConstraintClauses == newTypeParameterConstraintClauses ? T : new Cs.ClassDeclaration(T.Id, T.Prefix, T.Markers, T.AttributeList, T.Modifiers, T._kind, T.Name, T._typeParameters, T._primaryConstructor, T._extendings, T._implementings, T.Body, newTypeParameterConstraintClauses, T.Type); } } diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ClassOrStructConstraint.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ClassOrStructConstraint.g.cs index 5816b20..a2ede7e 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/ClassOrStructConstraint.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/ClassOrStructConstraint.g.cs @@ -36,7 +36,7 @@ public partial class ClassOrStructConstraint( Space prefix, Markers markers, ClassOrStructConstraint.TypeKind kind - ) : Cs, Cs.TypeParameterConstraint, MutableTree + ) : Cs, Cs.TypeParameterConstraint, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/CollectionExpression.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/CollectionExpression.g.cs index d52c717..b5000c7 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/CollectionExpression.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/CollectionExpression.g.cs @@ -33,7 +33,7 @@ public partial class CollectionExpression( Markers markers, IList> elements, JavaType type - ) : Cs, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : Cs, Expression, TypedTree, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/CompilationUnit.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/CompilationUnit.g.cs index 0d3a49b..51bce84 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/CompilationUnit.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/CompilationUnit.g.cs @@ -41,7 +41,7 @@ public partial class CompilationUnit( IList attributeLists, IList> members, Space eof - ) : Cs, JavaSourceFile, MutableTree + ) : Cs, JavaSourceFile, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ConstantPattern.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ConstantPattern.g.cs index e56bbef..9c56e11 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/ConstantPattern.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/ConstantPattern.g.cs @@ -59,7 +59,7 @@ public partial class ConstantPattern( Space prefix, Markers markers, Expression value - ) : Cs.Pattern, Expression, MutableTree + ) : Cs.Pattern, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/Constructor.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/Constructor.g.cs index b431742..1236b87 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/Constructor.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/Constructor.g.cs @@ -49,7 +49,7 @@ public partial class Constructor( Markers markers, ConstructorInitializer? initializer, J.MethodDeclaration constructorCore - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ConstructorConstraint.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ConstructorConstraint.g.cs index c6c85fe..2700b0e 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/ConstructorConstraint.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/ConstructorConstraint.g.cs @@ -39,7 +39,7 @@ public partial class ConstructorConstraint( Guid id, Space prefix, Markers markers - ) : Cs, Cs.TypeParameterConstraint, MutableTree + ) : Cs, Cs.TypeParameterConstraint, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ConstructorInitializer.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ConstructorInitializer.g.cs index 32f960b..90c7bb6 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/ConstructorInitializer.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/ConstructorInitializer.g.cs @@ -28,12 +28,12 @@ public partial interface Cs : J /// Represents a constructor initializer which is a call to another constructor, either in the same class (this) /// or in the base class (base). /// Examples: - /// + /// /// class Person { - /// // Constructor with 'this' initializer - /// public Person(string name) : this(name, 0) { } - /// // Constructor with 'base' initializer - /// public Person(string name, int age) : base(name) { } + /// // Constructor with 'this' initializer + /// public Person(string name) : this(name, 0) { } + /// // Constructor with 'base' initializer + /// public Person(string name, int age) : base(name) { } /// } /// /// @@ -45,8 +45,8 @@ public partial class ConstructorInitializer( Space prefix, Markers markers, Keyword keyword, - JContainer arguments - ) : Cs, MutableTree + JContainer arguments + ) : Cs, J, MutableTree { [NonSerialized] private WeakReference? _padding; @@ -102,18 +102,18 @@ public ConstructorInitializer WithKeyword(Cs.Keyword newKeyword) { return ReferenceEquals(newKeyword, keyword) ? this : new ConstructorInitializer(id, prefix, markers, newKeyword, _arguments); } - private readonly JContainer _arguments = arguments; - public IList Arguments => _arguments.GetElements(); + private readonly JContainer _arguments = arguments; + public IList Arguments => _arguments.GetElements(); - public ConstructorInitializer WithArguments(IList newArguments) + public ConstructorInitializer WithArguments(IList newArguments) { - return Padding.WithArguments(JContainer.WithElements(_arguments, newArguments)); + return Padding.WithArguments(JContainer.WithElements(_arguments, newArguments)); } public sealed record PaddingHelper(Cs.ConstructorInitializer T) { - public JContainer Arguments => T._arguments; + public JContainer Arguments => T._arguments; - public Cs.ConstructorInitializer WithArguments(JContainer newArguments) + public Cs.ConstructorInitializer WithArguments(JContainer newArguments) { return T._arguments == newArguments ? T : new Cs.ConstructorInitializer(T.Id, T.Prefix, T.Markers, T.Keyword, newArguments); } diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ConversionOperatorDeclaration.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ConversionOperatorDeclaration.g.cs new file mode 100644 index 0000000..aad5069 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/ConversionOperatorDeclaration.g.cs @@ -0,0 +1,196 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a C# operator conversion declaration that defines custom type conversion behavior. + /// + /// // Implicit conversion + /// public static implicit operator string(MyType t) => t.ToString(); + /// // Explicit conversion + /// public static explicit operator int(MyType t) { return t.Value; } + /// // With expression body + /// public static explicit operator double(MyType t) => t.Value; + /// // With block body + /// public static implicit operator bool(MyType t) { + /// return t.Value != 0; + /// } + /// + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class ConversionOperatorDeclaration( + Guid id, + Space prefix, + Markers markers, + IList modifiers, + JLeftPadded kind, + JLeftPadded returnType, + JContainer parameters, + JLeftPadded? expressionBody, + J.Block? body + ) : Cs, Statement, J, MutableTree + { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitConversionOperatorDeclaration(this, p); + } + + public Guid Id => id; + + public ConversionOperatorDeclaration WithId(Guid newId) + { + return newId == id ? this : new ConversionOperatorDeclaration(newId, prefix, markers, modifiers, _kind, _returnType, _parameters, _expressionBody, body); + } + public Space Prefix => prefix; + + public ConversionOperatorDeclaration WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new ConversionOperatorDeclaration(id, newPrefix, markers, modifiers, _kind, _returnType, _parameters, _expressionBody, body); + } + public Markers Markers => markers; + + public ConversionOperatorDeclaration WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new ConversionOperatorDeclaration(id, prefix, newMarkers, modifiers, _kind, _returnType, _parameters, _expressionBody, body); + } + public IList Modifiers => modifiers; + + public ConversionOperatorDeclaration WithModifiers(IList newModifiers) + { + return newModifiers == modifiers ? this : new ConversionOperatorDeclaration(id, prefix, markers, newModifiers, _kind, _returnType, _parameters, _expressionBody, body); + } + private readonly JLeftPadded _kind = kind; + public ExplicitImplicit Kind => _kind.Element; + + public ConversionOperatorDeclaration WithKind(ExplicitImplicit newKind) + { + return Padding.WithKind(_kind.WithElement(newKind)); + } + private readonly JLeftPadded _returnType = returnType; + public TypeTree ReturnType => _returnType.Element; + + public ConversionOperatorDeclaration WithReturnType(TypeTree newReturnType) + { + return Padding.WithReturnType(_returnType.WithElement(newReturnType)); + } + private readonly JContainer _parameters = parameters; + public IList Parameters => _parameters.GetElements(); + + public ConversionOperatorDeclaration WithParameters(IList newParameters) + { + return Padding.WithParameters(JContainer.WithElements(_parameters, newParameters)); + } + private readonly JLeftPadded? _expressionBody = expressionBody; + public Expression? ExpressionBody => _expressionBody?.Element; + + public ConversionOperatorDeclaration WithExpressionBody(Expression? newExpressionBody) + { + return Padding.WithExpressionBody(JLeftPadded.WithElement(_expressionBody, newExpressionBody)); + } + public J.Block? Body => body; + + public ConversionOperatorDeclaration WithBody(J.Block? newBody) + { + return ReferenceEquals(newBody, body) ? this : new ConversionOperatorDeclaration(id, prefix, markers, modifiers, _kind, _returnType, _parameters, _expressionBody, newBody); + } + public enum ExplicitImplicit + { + Implicit, + Explicit, + } + public sealed record PaddingHelper(Cs.ConversionOperatorDeclaration T) + { + public JLeftPadded Kind => T._kind; + + public Cs.ConversionOperatorDeclaration WithKind(JLeftPadded newKind) + { + return T._kind == newKind ? T : new Cs.ConversionOperatorDeclaration(T.Id, T.Prefix, T.Markers, T.Modifiers, newKind, T._returnType, T._parameters, T._expressionBody, T.Body); + } + + public JLeftPadded ReturnType => T._returnType; + + public Cs.ConversionOperatorDeclaration WithReturnType(JLeftPadded newReturnType) + { + return T._returnType == newReturnType ? T : new Cs.ConversionOperatorDeclaration(T.Id, T.Prefix, T.Markers, T.Modifiers, T._kind, newReturnType, T._parameters, T._expressionBody, T.Body); + } + + public JContainer Parameters => T._parameters; + + public Cs.ConversionOperatorDeclaration WithParameters(JContainer newParameters) + { + return T._parameters == newParameters ? T : new Cs.ConversionOperatorDeclaration(T.Id, T.Prefix, T.Markers, T.Modifiers, T._kind, T._returnType, newParameters, T._expressionBody, T.Body); + } + + public JLeftPadded? ExpressionBody => T._expressionBody; + + public Cs.ConversionOperatorDeclaration WithExpressionBody(JLeftPadded? newExpressionBody) + { + return T._expressionBody == newExpressionBody ? T : new Cs.ConversionOperatorDeclaration(T.Id, T.Prefix, T.Markers, T.Modifiers, T._kind, T._returnType, T._parameters, newExpressionBody, T.Body); + } + + } + + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is ConversionOperatorDeclaration && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/DeclarationExpression.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/DeclarationExpression.g.cs index e47a3c1..3480a81 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/DeclarationExpression.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/DeclarationExpression.g.cs @@ -57,7 +57,7 @@ public partial class DeclarationExpression( Markers markers, TypeTree? typeExpression, VariableDesignation variables - ) : Cs, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : Cs, Expression, TypedTree, Expression, TypedTree, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/DefaultConstraint.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/DefaultConstraint.g.cs index d20f5f5..d045a63 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/DefaultConstraint.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/DefaultConstraint.g.cs @@ -39,7 +39,7 @@ public partial class DefaultConstraint( Guid id, Space prefix, Markers markers - ) : Cs, Cs.TypeParameterConstraint, MutableTree + ) : Cs, Cs.TypeParameterConstraint, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/DefaultExpression.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/DefaultExpression.g.cs index 4b379b5..fb8f39f 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/DefaultExpression.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/DefaultExpression.g.cs @@ -44,7 +44,7 @@ public partial class DefaultExpression( Space prefix, Markers markers, JContainer? typeOperator - ) : Cs, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : Cs, Expression, TypedTree, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/DefaultSwitchLabel.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/DefaultSwitchLabel.g.cs index 8e10802..a40cbfc 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/DefaultSwitchLabel.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/DefaultSwitchLabel.g.cs @@ -51,7 +51,7 @@ public partial class DefaultSwitchLabel( Space prefix, Markers markers, Space colonToken - ) : Cs, Cs.SwitchLabel, Expression, Expression, MutableTree + ) : Cs, Cs.SwitchLabel, Expression, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/DelegateDeclaration.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/DelegateDeclaration.g.cs new file mode 100644 index 0000000..e27bf27 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/DelegateDeclaration.g.cs @@ -0,0 +1,197 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a C# delegate declaration which defines a type that can reference methods. + /// Delegates act as type-safe function pointers and provide the foundation for events in C#. + ///
+ /// For example: + /// + /// // Simple non-generic delegate with single parameter + /// public delegate void Logger(string message); + /// // Generic delegate + /// public delegate T Factory() where T : class, new(); + /// // Delegate with multiple parameters and constraint + /// public delegate TResult Convert(T input) + /// where T : struct + /// where TResult : class; + /// // Static delegate (C# 11+) + /// public static delegate int StaticHandler(string msg); + /// // Protected access + /// protected delegate bool Validator(T item); + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class DelegateDeclaration( + Guid id, + Space prefix, + Markers markers, + IList modifiers, + JLeftPadded returnType, + J.Identifier identifier, + JContainer? typeParameters, + JContainer parameters, + JContainer? typeParameterConstraintClauses + ) : Cs, Statement, J, MutableTree + { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitDelegateDeclaration(this, p); + } + + public Guid Id => id; + + public DelegateDeclaration WithId(Guid newId) + { + return newId == id ? this : new DelegateDeclaration(newId, prefix, markers, modifiers, _returnType, identifier, _typeParameters, _parameters, _typeParameterConstraintClauses); + } + public Space Prefix => prefix; + + public DelegateDeclaration WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new DelegateDeclaration(id, newPrefix, markers, modifiers, _returnType, identifier, _typeParameters, _parameters, _typeParameterConstraintClauses); + } + public Markers Markers => markers; + + public DelegateDeclaration WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new DelegateDeclaration(id, prefix, newMarkers, modifiers, _returnType, identifier, _typeParameters, _parameters, _typeParameterConstraintClauses); + } + public IList Modifiers => modifiers; + + public DelegateDeclaration WithModifiers(IList newModifiers) + { + return newModifiers == modifiers ? this : new DelegateDeclaration(id, prefix, markers, newModifiers, _returnType, identifier, _typeParameters, _parameters, _typeParameterConstraintClauses); + } + private readonly JLeftPadded _returnType = returnType; + public TypeTree ReturnType => _returnType.Element; + + public DelegateDeclaration WithReturnType(TypeTree newReturnType) + { + return Padding.WithReturnType(_returnType.WithElement(newReturnType)); + } + public J.Identifier Identifier => identifier; + + public DelegateDeclaration WithIdentifier(J.Identifier newIdentifier) + { + return ReferenceEquals(newIdentifier, identifier) ? this : new DelegateDeclaration(id, prefix, markers, modifiers, _returnType, newIdentifier, _typeParameters, _parameters, _typeParameterConstraintClauses); + } + private readonly JContainer? _typeParameters = typeParameters; + public IList? TypeParameters => _typeParameters?.GetElements(); + + public DelegateDeclaration WithTypeParameters(IList? newTypeParameters) + { + return Padding.WithTypeParameters(JContainer.WithElementsNullable(_typeParameters, newTypeParameters)); + } + private readonly JContainer _parameters = parameters; + public IList Parameters => _parameters.GetElements(); + + public DelegateDeclaration WithParameters(IList newParameters) + { + return Padding.WithParameters(JContainer.WithElements(_parameters, newParameters)); + } + private readonly JContainer? _typeParameterConstraintClauses = typeParameterConstraintClauses; + public IList? TypeParameterConstraintClauses => _typeParameterConstraintClauses?.GetElements(); + + public DelegateDeclaration WithTypeParameterConstraintClauses(IList? newTypeParameterConstraintClauses) + { + return Padding.WithTypeParameterConstraintClauses(JContainer.WithElementsNullable(_typeParameterConstraintClauses, newTypeParameterConstraintClauses)); + } + public sealed record PaddingHelper(Cs.DelegateDeclaration T) + { + public JLeftPadded ReturnType => T._returnType; + + public Cs.DelegateDeclaration WithReturnType(JLeftPadded newReturnType) + { + return T._returnType == newReturnType ? T : new Cs.DelegateDeclaration(T.Id, T.Prefix, T.Markers, T.Modifiers, newReturnType, T.Identifier, T._typeParameters, T._parameters, T._typeParameterConstraintClauses); + } + + public JContainer? TypeParameters => T._typeParameters; + + public Cs.DelegateDeclaration WithTypeParameters(JContainer? newTypeParameters) + { + return T._typeParameters == newTypeParameters ? T : new Cs.DelegateDeclaration(T.Id, T.Prefix, T.Markers, T.Modifiers, T._returnType, T.Identifier, newTypeParameters, T._parameters, T._typeParameterConstraintClauses); + } + + public JContainer Parameters => T._parameters; + + public Cs.DelegateDeclaration WithParameters(JContainer newParameters) + { + return T._parameters == newParameters ? T : new Cs.DelegateDeclaration(T.Id, T.Prefix, T.Markers, T.Modifiers, T._returnType, T.Identifier, T._typeParameters, newParameters, T._typeParameterConstraintClauses); + } + + public JContainer? TypeParameterConstraintClauses => T._typeParameterConstraintClauses; + + public Cs.DelegateDeclaration WithTypeParameterConstraintClauses(JContainer? newTypeParameterConstraintClauses) + { + return T._typeParameterConstraintClauses == newTypeParameterConstraintClauses ? T : new Cs.DelegateDeclaration(T.Id, T.Prefix, T.Markers, T.Modifiers, T._returnType, T.Identifier, T._typeParameters, T._parameters, newTypeParameterConstraintClauses); + } + + } + + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is DelegateDeclaration && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/DestructorDeclaration.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/DestructorDeclaration.g.cs index ad308c9..4338172 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/DestructorDeclaration.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/DestructorDeclaration.g.cs @@ -68,9 +68,8 @@ public partial class DestructorDeclaration( Guid id, Space prefix, Markers markers, - ConstructorInitializer? initializer, - J.MethodDeclaration constructorCore - ) : Cs, Statement, MutableTree + J.MethodDeclaration methodCore + ) : Cs, Statement, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { @@ -81,31 +80,25 @@ J.MethodDeclaration constructorCore public DestructorDeclaration WithId(Guid newId) { - return newId == id ? this : new DestructorDeclaration(newId, prefix, markers, initializer, constructorCore); + return newId == id ? this : new DestructorDeclaration(newId, prefix, markers, methodCore); } public Space Prefix => prefix; public DestructorDeclaration WithPrefix(Space newPrefix) { - return newPrefix == prefix ? this : new DestructorDeclaration(id, newPrefix, markers, initializer, constructorCore); + return newPrefix == prefix ? this : new DestructorDeclaration(id, newPrefix, markers, methodCore); } public Markers Markers => markers; public DestructorDeclaration WithMarkers(Markers newMarkers) { - return ReferenceEquals(newMarkers, markers) ? this : new DestructorDeclaration(id, prefix, newMarkers, initializer, constructorCore); + return ReferenceEquals(newMarkers, markers) ? this : new DestructorDeclaration(id, prefix, newMarkers, methodCore); } - public Cs.ConstructorInitializer? Initializer => initializer; + public J.MethodDeclaration MethodCore => methodCore; - public DestructorDeclaration WithInitializer(Cs.ConstructorInitializer? newInitializer) + public DestructorDeclaration WithMethodCore(J.MethodDeclaration newMethodCore) { - return ReferenceEquals(newInitializer, initializer) ? this : new DestructorDeclaration(id, prefix, markers, newInitializer, constructorCore); - } - public J.MethodDeclaration ConstructorCore => constructorCore; - - public DestructorDeclaration WithConstructorCore(J.MethodDeclaration newConstructorCore) - { - return ReferenceEquals(newConstructorCore, constructorCore) ? this : new DestructorDeclaration(id, prefix, markers, initializer, newConstructorCore); + return ReferenceEquals(newMethodCore, methodCore) ? this : new DestructorDeclaration(id, prefix, markers, newMethodCore); } #if DEBUG_VISITOR [DebuggerStepThrough] diff --git a/Rewrite/src/Rewrite.CSharp/Tree/DiscardPattern.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/DiscardPattern.g.cs index c871798..7328df1 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/DiscardPattern.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/DiscardPattern.g.cs @@ -51,7 +51,7 @@ public partial class DiscardPattern( Space prefix, Markers markers, JavaType type - ) : Cs.Pattern, Expression, MutableTree + ) : Cs.Pattern, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/DiscardVariableDesignation.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/DiscardVariableDesignation.g.cs index 81c5669..1aa4f56 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/DiscardVariableDesignation.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/DiscardVariableDesignation.g.cs @@ -41,7 +41,7 @@ public partial class DiscardVariableDesignation( Space prefix, Markers markers, J.Identifier discard - ) : Cs.VariableDesignation, Cs, Expression, MutableTree + ) : Cs.VariableDesignation, Cs, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/EnumDeclaration.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/EnumDeclaration.g.cs new file mode 100644 index 0000000..49f1027 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/EnumDeclaration.g.cs @@ -0,0 +1,181 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a C# enum declaration, including optional modifiers, attributes, and enum members. + ///
+ /// For example: + /// + /// // Simple enum + /// public enum Colors { Red, Green, Blue } + /// // Enum with base type + /// enum Flags : byte { None, All } + /// // Enum with attributes and explicit values + /// [Flags] + /// internal enum Permissions { + /// None = 0, + /// Read = 1, + /// Write = 2, + /// ReadWrite = Read | Write + /// } + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class EnumDeclaration( + Guid id, + Space prefix, + Markers markers, + IList? attributeLists, + IList modifiers, + JLeftPadded name, + JLeftPadded? baseType, + JContainer? members + ) : Cs, Statement, J, MutableTree + { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitEnumDeclaration(this, p); + } + + public Guid Id => id; + + public EnumDeclaration WithId(Guid newId) + { + return newId == id ? this : new EnumDeclaration(newId, prefix, markers, attributeLists, modifiers, _name, _baseType, _members); + } + public Space Prefix => prefix; + + public EnumDeclaration WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new EnumDeclaration(id, newPrefix, markers, attributeLists, modifiers, _name, _baseType, _members); + } + public Markers Markers => markers; + + public EnumDeclaration WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new EnumDeclaration(id, prefix, newMarkers, attributeLists, modifiers, _name, _baseType, _members); + } + public IList? AttributeLists => attributeLists; + + public EnumDeclaration WithAttributeLists(IList? newAttributeLists) + { + return newAttributeLists == attributeLists ? this : new EnumDeclaration(id, prefix, markers, newAttributeLists, modifiers, _name, _baseType, _members); + } + public IList Modifiers => modifiers; + + public EnumDeclaration WithModifiers(IList newModifiers) + { + return newModifiers == modifiers ? this : new EnumDeclaration(id, prefix, markers, attributeLists, newModifiers, _name, _baseType, _members); + } + private readonly JLeftPadded _name = name; + public J.Identifier Name => _name.Element; + + public EnumDeclaration WithName(J.Identifier newName) + { + return Padding.WithName(_name.WithElement(newName)); + } + private readonly JLeftPadded? _baseType = baseType; + public TypeTree? BaseType => _baseType?.Element; + + public EnumDeclaration WithBaseType(TypeTree? newBaseType) + { + return Padding.WithBaseType(JLeftPadded.WithElement(_baseType, newBaseType)); + } + private readonly JContainer? _members = members; + public IList? Members => _members?.GetElements(); + + public EnumDeclaration WithMembers(IList? newMembers) + { + return Padding.WithMembers(JContainer.WithElementsNullable(_members, newMembers)); + } + public sealed record PaddingHelper(Cs.EnumDeclaration T) + { + public JLeftPadded Name => T._name; + + public Cs.EnumDeclaration WithName(JLeftPadded newName) + { + return T._name == newName ? T : new Cs.EnumDeclaration(T.Id, T.Prefix, T.Markers, T.AttributeLists, T.Modifiers, newName, T._baseType, T._members); + } + + public JLeftPadded? BaseType => T._baseType; + + public Cs.EnumDeclaration WithBaseType(JLeftPadded? newBaseType) + { + return T._baseType == newBaseType ? T : new Cs.EnumDeclaration(T.Id, T.Prefix, T.Markers, T.AttributeLists, T.Modifiers, T._name, newBaseType, T._members); + } + + public JContainer? Members => T._members; + + public Cs.EnumDeclaration WithMembers(JContainer? newMembers) + { + return T._members == newMembers ? T : new Cs.EnumDeclaration(T.Id, T.Prefix, T.Markers, T.AttributeLists, T.Modifiers, T._name, T._baseType, newMembers); + } + + } + + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is EnumDeclaration && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/EnumMemberDeclaration.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/EnumMemberDeclaration.g.cs new file mode 100644 index 0000000..5010414 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/EnumMemberDeclaration.g.cs @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a C# enum member declaration, including optional attributes and initializer. + ///
+ /// For example: + /// + /// // Simple enum member + /// Red, + /// // Member with initializer + /// Green = 2, + /// // Member with attributes and expression initializer + /// [Obsolete] + /// Blue = Red | Green, + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class EnumMemberDeclaration( + Guid id, + Space prefix, + Markers markers, + IList attributeLists, + J.Identifier name, + JLeftPadded? initializer + ) : Cs, J, MutableTree + { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitEnumMemberDeclaration(this, p); + } + + public Guid Id => id; + + public EnumMemberDeclaration WithId(Guid newId) + { + return newId == id ? this : new EnumMemberDeclaration(newId, prefix, markers, attributeLists, name, _initializer); + } + public Space Prefix => prefix; + + public EnumMemberDeclaration WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new EnumMemberDeclaration(id, newPrefix, markers, attributeLists, name, _initializer); + } + public Markers Markers => markers; + + public EnumMemberDeclaration WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new EnumMemberDeclaration(id, prefix, newMarkers, attributeLists, name, _initializer); + } + public IList AttributeLists => attributeLists; + + public EnumMemberDeclaration WithAttributeLists(IList newAttributeLists) + { + return newAttributeLists == attributeLists ? this : new EnumMemberDeclaration(id, prefix, markers, newAttributeLists, name, _initializer); + } + public J.Identifier Name => name; + + public EnumMemberDeclaration WithName(J.Identifier newName) + { + return ReferenceEquals(newName, name) ? this : new EnumMemberDeclaration(id, prefix, markers, attributeLists, newName, _initializer); + } + private readonly JLeftPadded? _initializer = initializer; + public Expression? Initializer => _initializer?.Element; + + public EnumMemberDeclaration WithInitializer(Expression? newInitializer) + { + return Padding.WithInitializer(JLeftPadded.WithElement(_initializer, newInitializer)); + } + public sealed record PaddingHelper(Cs.EnumMemberDeclaration T) + { + public JLeftPadded? Initializer => T._initializer; + + public Cs.EnumMemberDeclaration WithInitializer(JLeftPadded? newInitializer) + { + return T._initializer == newInitializer ? T : new Cs.EnumMemberDeclaration(T.Id, T.Prefix, T.Markers, T.AttributeLists, T.Name, newInitializer); + } + + } + + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is EnumMemberDeclaration && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ExpressionStatement.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ExpressionStatement.g.cs index cb9526c..e79c551 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/ExpressionStatement.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/ExpressionStatement.g.cs @@ -31,9 +31,34 @@ public partial class ExpressionStatement( Guid id, Space prefix, Markers markers, - Expression expression - ) : Cs, Statement, MutableTree + JRightPadded expression + ) : Cs, Statement, J, MutableTree { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + public J? AcceptCSharp

(CSharpVisitor

v, P p) { return v.VisitExpressionStatement(this, p); @@ -43,26 +68,38 @@ Expression expression public ExpressionStatement WithId(Guid newId) { - return newId == id ? this : new ExpressionStatement(newId, prefix, markers, expression); + return newId == id ? this : new ExpressionStatement(newId, prefix, markers, _expression); } public Space Prefix => prefix; public ExpressionStatement WithPrefix(Space newPrefix) { - return newPrefix == prefix ? this : new ExpressionStatement(id, newPrefix, markers, expression); + return newPrefix == prefix ? this : new ExpressionStatement(id, newPrefix, markers, _expression); } public Markers Markers => markers; public ExpressionStatement WithMarkers(Markers newMarkers) { - return ReferenceEquals(newMarkers, markers) ? this : new ExpressionStatement(id, prefix, newMarkers, expression); + return ReferenceEquals(newMarkers, markers) ? this : new ExpressionStatement(id, prefix, newMarkers, _expression); } - public Expression Expression => expression; + private readonly JRightPadded _expression = expression; + public Expression Expression => _expression.Element; public ExpressionStatement WithExpression(Expression newExpression) { - return ReferenceEquals(newExpression, expression) ? this : new ExpressionStatement(id, prefix, markers, newExpression); + return Padding.WithExpression(_expression.WithElement(newExpression)); } + public sealed record PaddingHelper(Cs.ExpressionStatement T) + { + public JRightPadded Expression => T._expression; + + public Cs.ExpressionStatement WithExpression(JRightPadded newExpression) + { + return T._expression == newExpression ? T : new Cs.ExpressionStatement(T.Id, T.Prefix, T.Markers, newExpression); + } + + } + #if DEBUG_VISITOR [DebuggerStepThrough] #endif diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ExternAlias.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ExternAlias.g.cs index f7a0c18..2091535 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/ExternAlias.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/ExternAlias.g.cs @@ -32,7 +32,7 @@ public partial class ExternAlias( Space prefix, Markers markers, JLeftPadded identifier - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/FileScopeNamespaceDeclaration.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/FileScopeNamespaceDeclaration.g.cs index 7c4e68b..91c86db 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/FileScopeNamespaceDeclaration.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/FileScopeNamespaceDeclaration.g.cs @@ -35,7 +35,7 @@ public partial class FileScopeNamespaceDeclaration( IList> externs, IList> usings, IList> members - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/FixedStatement.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/FixedStatement.g.cs index 90cc20b..7ec396c 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/FixedStatement.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/FixedStatement.g.cs @@ -58,7 +58,7 @@ public partial class FixedStatement( Markers markers, J.ControlParentheses declarations, J.Block block - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ForEachVariableLoop.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ForEachVariableLoop.g.cs index 41de401..0e5e65f 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/ForEachVariableLoop.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/ForEachVariableLoop.g.cs @@ -33,7 +33,7 @@ public partial class ForEachVariableLoop( Markers markers, ForEachVariableLoop.Control controlElement, JRightPadded body - ) : Cs, Loop, MutableTree + ) : Cs, Loop, J, MutableTree { [NonSerialized] private WeakReference? _padding; @@ -105,7 +105,7 @@ public partial class Control( Markers markers, JRightPadded variable, JRightPadded iterable - ) : Cs, MutableTree + ) : Cs, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/FromClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/FromClause.g.cs new file mode 100644 index 0000000..22d0fa2 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/FromClause.g.cs @@ -0,0 +1,148 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a LINQ from clause that introduces a range variable and its source collection. + /// This is typically the initial clause of a LINQ query. + ///
+ /// For example: + /// + /// // Simple from clause + /// from user in users + /// // With type + /// from Customer c in customers + /// // With pattern match + /// from (x, y) in points + /// // With type and pattern + /// from (int x, int y) in coordinates + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class FromClause( + Guid id, + Space prefix, + Markers markers, + TypeTree? typeIdentifier, + JRightPadded identifier, + Expression expression + ) : Cs, Cs.QueryClause, Expression, Expression, J, MutableTree + { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitFromClause(this, p); + } + + public Guid Id => id; + + public FromClause WithId(Guid newId) + { + return newId == id ? this : new FromClause(newId, prefix, markers, typeIdentifier, _identifier, expression); + } + public Space Prefix => prefix; + + public FromClause WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new FromClause(id, newPrefix, markers, typeIdentifier, _identifier, expression); + } + public Markers Markers => markers; + + public FromClause WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new FromClause(id, prefix, newMarkers, typeIdentifier, _identifier, expression); + } + public TypeTree? TypeIdentifier => typeIdentifier; + + public FromClause WithTypeIdentifier(TypeTree? newTypeIdentifier) + { + return ReferenceEquals(newTypeIdentifier, typeIdentifier) ? this : new FromClause(id, prefix, markers, newTypeIdentifier, _identifier, expression); + } + private readonly JRightPadded _identifier = identifier; + public J.Identifier Identifier => _identifier.Element; + + public FromClause WithIdentifier(J.Identifier newIdentifier) + { + return Padding.WithIdentifier(_identifier.WithElement(newIdentifier)); + } + public Expression Expression => expression; + + public FromClause WithExpression(Expression newExpression) + { + return ReferenceEquals(newExpression, expression) ? this : new FromClause(id, prefix, markers, typeIdentifier, _identifier, newExpression); + } + public sealed record PaddingHelper(Cs.FromClause T) + { + public JRightPadded Identifier => T._identifier; + + public Cs.FromClause WithIdentifier(JRightPadded newIdentifier) + { + return T._identifier == newIdentifier ? T : new Cs.FromClause(T.Id, T.Prefix, T.Markers, T.TypeIdentifier, newIdentifier, T.Expression); + } + + } + + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is FromClause && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/GroupClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/GroupClause.g.cs new file mode 100644 index 0000000..158ba21 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/GroupClause.g.cs @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a group clause in a LINQ query. + /// + /// // Simple group by + /// group item by key + /// // Group by with complex key + /// group customer by new { customer.State, customer.City } + /// + /// + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class GroupClause( + Guid id, + Space prefix, + Markers markers, + JRightPadded groupExpression, + Expression key + ) : Cs, Cs.SelectOrGroupClause, J, MutableTree + { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitGroupClause(this, p); + } + + public Guid Id => id; + + public GroupClause WithId(Guid newId) + { + return newId == id ? this : new GroupClause(newId, prefix, markers, _groupExpression, key); + } + public Space Prefix => prefix; + + public GroupClause WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new GroupClause(id, newPrefix, markers, _groupExpression, key); + } + public Markers Markers => markers; + + public GroupClause WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new GroupClause(id, prefix, newMarkers, _groupExpression, key); + } + private readonly JRightPadded _groupExpression = groupExpression; + public Expression GroupExpression => _groupExpression.Element; + + public GroupClause WithGroupExpression(Expression newGroupExpression) + { + return Padding.WithGroupExpression(_groupExpression.WithElement(newGroupExpression)); + } + public Expression Key => key; + + public GroupClause WithKey(Expression newKey) + { + return ReferenceEquals(newKey, key) ? this : new GroupClause(id, prefix, markers, _groupExpression, newKey); + } + public sealed record PaddingHelper(Cs.GroupClause T) + { + public JRightPadded GroupExpression => T._groupExpression; + + public Cs.GroupClause WithGroupExpression(JRightPadded newGroupExpression) + { + return T._groupExpression == newGroupExpression ? T : new Cs.GroupClause(T.Id, T.Prefix, T.Markers, newGroupExpression, T.Key); + } + + } + + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is GroupClause && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ImplicitElementAccess.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ImplicitElementAccess.g.cs index e9ac518..47c1607 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/ImplicitElementAccess.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/ImplicitElementAccess.g.cs @@ -52,7 +52,7 @@ public partial class ImplicitElementAccess( Space prefix, Markers markers, JContainer argumentList - ) : Cs, Expression, Expression, MutableTree + ) : Cs, Expression, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/IndexerDeclaration.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/IndexerDeclaration.g.cs new file mode 100644 index 0000000..7cf970e --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/IndexerDeclaration.g.cs @@ -0,0 +1,176 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a C# indexer declaration which allows objects to be indexed like arrays. + /// + /// // Simple indexer + /// public int this[int index] { get { } set { } } + /// // Indexer with multiple parameters + /// public string this[int x, int y] { get; set; } + /// // Readonly indexer + /// public MyType this[string key] { get; } + /// // Interface indexer + /// string this[int index] { get; set; } + /// // Protected indexer with expression body + /// protected internal int this[int i] => array[i]; + /// + /// + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class IndexerDeclaration( + Guid id, + Space prefix, + Markers markers, + IList modifiers, + TypeTree typeExpression, + Expression indexer, + JContainer parameters, + JLeftPadded? expressionBody, + J.Block? accessors + ) : Cs, Statement, TypedTree, TypedTree, J, MutableTree + { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitIndexerDeclaration(this, p); + } + + public Guid Id => id; + + public IndexerDeclaration WithId(Guid newId) + { + return newId == id ? this : new IndexerDeclaration(newId, prefix, markers, modifiers, typeExpression, indexer, _parameters, _expressionBody, accessors); + } + public Space Prefix => prefix; + + public IndexerDeclaration WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new IndexerDeclaration(id, newPrefix, markers, modifiers, typeExpression, indexer, _parameters, _expressionBody, accessors); + } + public Markers Markers => markers; + + public IndexerDeclaration WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new IndexerDeclaration(id, prefix, newMarkers, modifiers, typeExpression, indexer, _parameters, _expressionBody, accessors); + } + public IList Modifiers => modifiers; + + public IndexerDeclaration WithModifiers(IList newModifiers) + { + return newModifiers == modifiers ? this : new IndexerDeclaration(id, prefix, markers, newModifiers, typeExpression, indexer, _parameters, _expressionBody, accessors); + } + public TypeTree TypeExpression => typeExpression; + + public IndexerDeclaration WithTypeExpression(TypeTree newTypeExpression) + { + return ReferenceEquals(newTypeExpression, typeExpression) ? this : new IndexerDeclaration(id, prefix, markers, modifiers, newTypeExpression, indexer, _parameters, _expressionBody, accessors); + } + public Expression Indexer => indexer; + + public IndexerDeclaration WithIndexer(Expression newIndexer) + { + return ReferenceEquals(newIndexer, indexer) ? this : new IndexerDeclaration(id, prefix, markers, modifiers, typeExpression, newIndexer, _parameters, _expressionBody, accessors); + } + private readonly JContainer _parameters = parameters; + public IList Parameters => _parameters.GetElements(); + + public IndexerDeclaration WithParameters(IList newParameters) + { + return Padding.WithParameters(JContainer.WithElements(_parameters, newParameters)); + } + private readonly JLeftPadded? _expressionBody = expressionBody; + public Expression? ExpressionBody => _expressionBody?.Element; + + public IndexerDeclaration WithExpressionBody(Expression? newExpressionBody) + { + return Padding.WithExpressionBody(JLeftPadded.WithElement(_expressionBody, newExpressionBody)); + } + public J.Block? Accessors => accessors; + + public IndexerDeclaration WithAccessors(J.Block? newAccessors) + { + return ReferenceEquals(newAccessors, accessors) ? this : new IndexerDeclaration(id, prefix, markers, modifiers, typeExpression, indexer, _parameters, _expressionBody, newAccessors); + } + public sealed record PaddingHelper(Cs.IndexerDeclaration T) + { + public JContainer Parameters => T._parameters; + + public Cs.IndexerDeclaration WithParameters(JContainer newParameters) + { + return T._parameters == newParameters ? T : new Cs.IndexerDeclaration(T.Id, T.Prefix, T.Markers, T.Modifiers, T.TypeExpression, T.Indexer, newParameters, T._expressionBody, T.Accessors); + } + + public JLeftPadded? ExpressionBody => T._expressionBody; + + public Cs.IndexerDeclaration WithExpressionBody(JLeftPadded? newExpressionBody) + { + return T._expressionBody == newExpressionBody ? T : new Cs.IndexerDeclaration(T.Id, T.Prefix, T.Markers, T.Modifiers, T.TypeExpression, T.Indexer, T._parameters, newExpressionBody, T.Accessors); + } + + } + + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is IndexerDeclaration && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/InitializerExpression.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/InitializerExpression.g.cs index e8c1734..72f230c 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/InitializerExpression.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/InitializerExpression.g.cs @@ -46,7 +46,7 @@ public partial class InitializerExpression( Space prefix, Markers markers, JContainer expressions - ) : Cs, Expression, Expression, MutableTree + ) : Cs, Expression, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/InterpolatedString.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/InterpolatedString.g.cs index 89d236b..93251a7 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/InterpolatedString.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/InterpolatedString.g.cs @@ -34,7 +34,7 @@ public partial class InterpolatedString( string start, IList> parts, string end - ) : Cs, Expression, Expression, MutableTree + ) : Cs, Expression, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/Interpolation.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/Interpolation.g.cs index 70ebb70..73c91c0 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/Interpolation.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/Interpolation.g.cs @@ -34,7 +34,7 @@ public partial class Interpolation( JRightPadded expression, JRightPadded? alignment, JRightPadded? format - ) : Cs, Expression, Expression, MutableTree + ) : Cs, Expression, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/IsPattern.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/IsPattern.g.cs index 2764dd0..75002e7 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/IsPattern.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/IsPattern.g.cs @@ -55,7 +55,7 @@ public partial class IsPattern( Markers markers, Expression expression, JLeftPadded pattern - ) : Cs, Expression, Expression, MutableTree + ) : Cs, Expression, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/JoinClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/JoinClause.g.cs new file mode 100644 index 0000000..9ea5e2d --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/JoinClause.g.cs @@ -0,0 +1,189 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a C# join clause in a LINQ query expression. + ///
+ /// For example: + /// + /// // Simple join + /// join customer in customers on order.CustomerId equals customer.Id + /// // Join with into (group join) + /// join category in categories + /// on product.CategoryId equals category.Id + /// into productCategories + /// // Multiple joins + /// from order in orders + /// join customer in customers + /// on order.CustomerId equals customer.Id + /// join employee in employees + /// on order.EmployeeId equals employee.Id + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class JoinClause( + Guid id, + Space prefix, + Markers markers, + JRightPadded identifier, + JRightPadded inExpression, + JRightPadded leftExpression, + Expression rightExpression, + JLeftPadded? into + ) : Cs, Cs.QueryClause, J, MutableTree + { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitJoinClause(this, p); + } + + public Guid Id => id; + + public JoinClause WithId(Guid newId) + { + return newId == id ? this : new JoinClause(newId, prefix, markers, _identifier, _inExpression, _leftExpression, rightExpression, _into); + } + public Space Prefix => prefix; + + public JoinClause WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new JoinClause(id, newPrefix, markers, _identifier, _inExpression, _leftExpression, rightExpression, _into); + } + public Markers Markers => markers; + + public JoinClause WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new JoinClause(id, prefix, newMarkers, _identifier, _inExpression, _leftExpression, rightExpression, _into); + } + private readonly JRightPadded _identifier = identifier; + public J.Identifier Identifier => _identifier.Element; + + public JoinClause WithIdentifier(J.Identifier newIdentifier) + { + return Padding.WithIdentifier(_identifier.WithElement(newIdentifier)); + } + private readonly JRightPadded _inExpression = inExpression; + public Expression InExpression => _inExpression.Element; + + public JoinClause WithInExpression(Expression newInExpression) + { + return Padding.WithInExpression(_inExpression.WithElement(newInExpression)); + } + private readonly JRightPadded _leftExpression = leftExpression; + public Expression LeftExpression => _leftExpression.Element; + + public JoinClause WithLeftExpression(Expression newLeftExpression) + { + return Padding.WithLeftExpression(_leftExpression.WithElement(newLeftExpression)); + } + public Expression RightExpression => rightExpression; + + public JoinClause WithRightExpression(Expression newRightExpression) + { + return ReferenceEquals(newRightExpression, rightExpression) ? this : new JoinClause(id, prefix, markers, _identifier, _inExpression, _leftExpression, newRightExpression, _into); + } + private readonly JLeftPadded? _into = into; + public Cs.JoinIntoClause? Into => _into?.Element; + + public JoinClause WithInto(Cs.JoinIntoClause? newInto) + { + return Padding.WithInto(JLeftPadded.WithElement(_into, newInto)); + } + public sealed record PaddingHelper(Cs.JoinClause T) + { + public JRightPadded Identifier => T._identifier; + + public Cs.JoinClause WithIdentifier(JRightPadded newIdentifier) + { + return T._identifier == newIdentifier ? T : new Cs.JoinClause(T.Id, T.Prefix, T.Markers, newIdentifier, T._inExpression, T._leftExpression, T.RightExpression, T._into); + } + + public JRightPadded InExpression => T._inExpression; + + public Cs.JoinClause WithInExpression(JRightPadded newInExpression) + { + return T._inExpression == newInExpression ? T : new Cs.JoinClause(T.Id, T.Prefix, T.Markers, T._identifier, newInExpression, T._leftExpression, T.RightExpression, T._into); + } + + public JRightPadded LeftExpression => T._leftExpression; + + public Cs.JoinClause WithLeftExpression(JRightPadded newLeftExpression) + { + return T._leftExpression == newLeftExpression ? T : new Cs.JoinClause(T.Id, T.Prefix, T.Markers, T._identifier, T._inExpression, newLeftExpression, T.RightExpression, T._into); + } + + public JLeftPadded? Into => T._into; + + public Cs.JoinClause WithInto(JLeftPadded? newInto) + { + return T._into == newInto ? T : new Cs.JoinClause(T.Id, T.Prefix, T.Markers, T._identifier, T._inExpression, T._leftExpression, T.RightExpression, newInto); + } + + } + + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is JoinClause && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/JoinIntoClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/JoinIntoClause.g.cs new file mode 100644 index 0000000..92b5194 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/JoinIntoClause.g.cs @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents the 'into' portion of a group join clause in C# LINQ syntax. + /// Used to specify the identifier that will hold the grouped results. + ///
+ /// For example: + /// + /// // Group join using into clause + /// join category in categories + /// on product.CategoryId equals category.Id + /// into productCategories + /// // Multiple group joins + /// join orders in db.Orders + /// on customer.Id equals orders.CustomerId + /// into customerOrders + /// join returns in db.Returns + /// on customer.Id equals returns.CustomerId + /// into customerReturns + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class JoinIntoClause( + Guid id, + Space prefix, + Markers markers, + J.Identifier identifier + ) : Cs, Cs.QueryClause, J, MutableTree + { + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitJoinIntoClause(this, p); + } + + public Guid Id => id; + + public JoinIntoClause WithId(Guid newId) + { + return newId == id ? this : new JoinIntoClause(newId, prefix, markers, identifier); + } + public Space Prefix => prefix; + + public JoinIntoClause WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new JoinIntoClause(id, newPrefix, markers, identifier); + } + public Markers Markers => markers; + + public JoinIntoClause WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new JoinIntoClause(id, prefix, newMarkers, identifier); + } + public J.Identifier Identifier => identifier; + + public JoinIntoClause WithIdentifier(J.Identifier newIdentifier) + { + return ReferenceEquals(newIdentifier, identifier) ? this : new JoinIntoClause(id, prefix, markers, newIdentifier); + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is JoinIntoClause && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/Keyword.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/Keyword.g.cs index c2c3bf9..0751496 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/Keyword.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/Keyword.g.cs @@ -32,7 +32,7 @@ public partial class Keyword( Space prefix, Markers markers, Keyword.KeywordKind kind - ) : Cs, MutableTree + ) : Cs, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/Lambda.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/Lambda.g.cs index 2a11078..651c403 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/Lambda.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/Lambda.g.cs @@ -33,7 +33,7 @@ public partial class Lambda( Markers markers, J.Lambda lambdaExpression, IList modifiers - ) : Cs, Statement, Expression, Expression, MutableTree + ) : Cs, Statement, Expression, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/LetClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/LetClause.g.cs new file mode 100644 index 0000000..20aa5a5 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/LetClause.g.cs @@ -0,0 +1,147 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a let clause in a C# LINQ query expression that introduces + /// a new range variable based on a computation. + ///
+ /// For example: + /// + /// // Simple let clause + /// from n in numbers + /// let square = n * n + /// select square + /// // Multiple let clauses + /// from s in strings + /// let length = s.Length + /// let upperCase = s.ToUpper() + /// select new { s, length, upperCase } + /// // Let with complex expressions + /// from p in people + /// let fullName = p.FirstName + " " + p.LastName + /// let age = DateTime.Now.Year - p.BirthYear + /// select new { fullName, age } + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class LetClause( + Guid id, + Space prefix, + Markers markers, + JRightPadded identifier, + Expression expression + ) : Cs, Cs.QueryClause, J, MutableTree + { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitLetClause(this, p); + } + + public Guid Id => id; + + public LetClause WithId(Guid newId) + { + return newId == id ? this : new LetClause(newId, prefix, markers, _identifier, expression); + } + public Space Prefix => prefix; + + public LetClause WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new LetClause(id, newPrefix, markers, _identifier, expression); + } + public Markers Markers => markers; + + public LetClause WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new LetClause(id, prefix, newMarkers, _identifier, expression); + } + private readonly JRightPadded _identifier = identifier; + public J.Identifier Identifier => _identifier.Element; + + public LetClause WithIdentifier(J.Identifier newIdentifier) + { + return Padding.WithIdentifier(_identifier.WithElement(newIdentifier)); + } + public Expression Expression => expression; + + public LetClause WithExpression(Expression newExpression) + { + return ReferenceEquals(newExpression, expression) ? this : new LetClause(id, prefix, markers, _identifier, newExpression); + } + public sealed record PaddingHelper(Cs.LetClause T) + { + public JRightPadded Identifier => T._identifier; + + public Cs.LetClause WithIdentifier(JRightPadded newIdentifier) + { + return T._identifier == newIdentifier ? T : new Cs.LetClause(T.Id, T.Prefix, T.Markers, newIdentifier, T.Expression); + } + + } + + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is LetClause && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ListPattern.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ListPattern.g.cs index af80441..a468f18 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/ListPattern.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/ListPattern.g.cs @@ -61,7 +61,7 @@ public partial class ListPattern( Markers markers, JContainer patterns, VariableDesignation? designation - ) : Cs.Pattern, Expression, MutableTree + ) : Cs.Pattern, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/LockStatement.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/LockStatement.g.cs index a4b7a57..420f803 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/LockStatement.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/LockStatement.g.cs @@ -52,7 +52,7 @@ public partial class LockStatement( Markers markers, J.ControlParentheses expression, JRightPadded statement - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/MethodDeclaration.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/MethodDeclaration.g.cs index 8540140..a5d0092 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/MethodDeclaration.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/MethodDeclaration.g.cs @@ -31,9 +31,17 @@ public partial class MethodDeclaration( Guid id, Space prefix, Markers markers, - J.MethodDeclaration methodDeclarationCore, + IList attributes, + IList modifiers, + JContainer? typeParameters, + TypeTree returnTypeExpression, + JRightPadded? explicitInterfaceSpecifier, + J.Identifier name, + JContainer parameters, + J.Block? body, + JavaType.Method? methodType, JContainer typeParameterConstraintClauses - ) : Cs, Statement, MutableTree + ) : Cs, Statement, TypedTree, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; @@ -69,25 +77,76 @@ public PaddingHelper Padding public MethodDeclaration WithId(Guid newId) { - return newId == id ? this : new MethodDeclaration(newId, prefix, markers, methodDeclarationCore, _typeParameterConstraintClauses); + return newId == id ? this : new MethodDeclaration(newId, prefix, markers, attributes, modifiers, _typeParameters, returnTypeExpression, _explicitInterfaceSpecifier, name, _parameters, body, methodType, _typeParameterConstraintClauses); } public Space Prefix => prefix; public MethodDeclaration WithPrefix(Space newPrefix) { - return newPrefix == prefix ? this : new MethodDeclaration(id, newPrefix, markers, methodDeclarationCore, _typeParameterConstraintClauses); + return newPrefix == prefix ? this : new MethodDeclaration(id, newPrefix, markers, attributes, modifiers, _typeParameters, returnTypeExpression, _explicitInterfaceSpecifier, name, _parameters, body, methodType, _typeParameterConstraintClauses); } public Markers Markers => markers; public MethodDeclaration WithMarkers(Markers newMarkers) { - return ReferenceEquals(newMarkers, markers) ? this : new MethodDeclaration(id, prefix, newMarkers, methodDeclarationCore, _typeParameterConstraintClauses); + return ReferenceEquals(newMarkers, markers) ? this : new MethodDeclaration(id, prefix, newMarkers, attributes, modifiers, _typeParameters, returnTypeExpression, _explicitInterfaceSpecifier, name, _parameters, body, methodType, _typeParameterConstraintClauses); } - public J.MethodDeclaration MethodDeclarationCore => methodDeclarationCore; + public IList Attributes => attributes; - public MethodDeclaration WithMethodDeclarationCore(J.MethodDeclaration newMethodDeclarationCore) + public MethodDeclaration WithAttributes(IList newAttributes) { - return ReferenceEquals(newMethodDeclarationCore, methodDeclarationCore) ? this : new MethodDeclaration(id, prefix, markers, newMethodDeclarationCore, _typeParameterConstraintClauses); + return newAttributes == attributes ? this : new MethodDeclaration(id, prefix, markers, newAttributes, modifiers, _typeParameters, returnTypeExpression, _explicitInterfaceSpecifier, name, _parameters, body, methodType, _typeParameterConstraintClauses); + } + public IList Modifiers => modifiers; + + public MethodDeclaration WithModifiers(IList newModifiers) + { + return newModifiers == modifiers ? this : new MethodDeclaration(id, prefix, markers, attributes, newModifiers, _typeParameters, returnTypeExpression, _explicitInterfaceSpecifier, name, _parameters, body, methodType, _typeParameterConstraintClauses); + } + private readonly JContainer? _typeParameters = typeParameters; + public IList? TypeParameters => _typeParameters?.GetElements(); + + public MethodDeclaration WithTypeParameters(IList? newTypeParameters) + { + return Padding.WithTypeParameters(JContainer.WithElementsNullable(_typeParameters, newTypeParameters)); + } + public TypeTree ReturnTypeExpression => returnTypeExpression; + + public MethodDeclaration WithReturnTypeExpression(TypeTree newReturnTypeExpression) + { + return ReferenceEquals(newReturnTypeExpression, returnTypeExpression) ? this : new MethodDeclaration(id, prefix, markers, attributes, modifiers, _typeParameters, newReturnTypeExpression, _explicitInterfaceSpecifier, name, _parameters, body, methodType, _typeParameterConstraintClauses); + } + private readonly JRightPadded? _explicitInterfaceSpecifier = explicitInterfaceSpecifier; + public TypeTree? ExplicitInterfaceSpecifier => _explicitInterfaceSpecifier?.Element; + + public MethodDeclaration WithExplicitInterfaceSpecifier(TypeTree? newExplicitInterfaceSpecifier) + { + return Padding.WithExplicitInterfaceSpecifier(JRightPadded.WithElement(_explicitInterfaceSpecifier, newExplicitInterfaceSpecifier)); + } + public J.Identifier Name => name; + + public MethodDeclaration WithName(J.Identifier newName) + { + return ReferenceEquals(newName, name) ? this : new MethodDeclaration(id, prefix, markers, attributes, modifiers, _typeParameters, returnTypeExpression, _explicitInterfaceSpecifier, newName, _parameters, body, methodType, _typeParameterConstraintClauses); + } + private readonly JContainer _parameters = parameters; + public IList Parameters => _parameters.GetElements(); + + public MethodDeclaration WithParameters(IList newParameters) + { + return Padding.WithParameters(JContainer.WithElements(_parameters, newParameters)); + } + public J.Block? Body => body; + + public MethodDeclaration WithBody(J.Block? newBody) + { + return ReferenceEquals(newBody, body) ? this : new MethodDeclaration(id, prefix, markers, attributes, modifiers, _typeParameters, returnTypeExpression, _explicitInterfaceSpecifier, name, _parameters, newBody, methodType, _typeParameterConstraintClauses); + } + public JavaType.Method? MethodType => methodType; + + public MethodDeclaration WithMethodType(JavaType.Method? newMethodType) + { + return newMethodType == methodType ? this : new MethodDeclaration(id, prefix, markers, attributes, modifiers, _typeParameters, returnTypeExpression, _explicitInterfaceSpecifier, name, _parameters, body, newMethodType, _typeParameterConstraintClauses); } private readonly JContainer _typeParameterConstraintClauses = typeParameterConstraintClauses; public IList TypeParameterConstraintClauses => _typeParameterConstraintClauses.GetElements(); @@ -98,11 +157,32 @@ public MethodDeclaration WithTypeParameterConstraintClauses(IList? TypeParameters => T._typeParameters; + + public Cs.MethodDeclaration WithTypeParameters(JContainer? newTypeParameters) + { + return T._typeParameters == newTypeParameters ? T : new Cs.MethodDeclaration(T.Id, T.Prefix, T.Markers, T.Attributes, T.Modifiers, newTypeParameters, T.ReturnTypeExpression, T._explicitInterfaceSpecifier, T.Name, T._parameters, T.Body, T.MethodType, T._typeParameterConstraintClauses); + } + + public JRightPadded? ExplicitInterfaceSpecifier => T._explicitInterfaceSpecifier; + + public Cs.MethodDeclaration WithExplicitInterfaceSpecifier(JRightPadded? newExplicitInterfaceSpecifier) + { + return T._explicitInterfaceSpecifier == newExplicitInterfaceSpecifier ? T : new Cs.MethodDeclaration(T.Id, T.Prefix, T.Markers, T.Attributes, T.Modifiers, T._typeParameters, T.ReturnTypeExpression, newExplicitInterfaceSpecifier, T.Name, T._parameters, T.Body, T.MethodType, T._typeParameterConstraintClauses); + } + + public JContainer Parameters => T._parameters; + + public Cs.MethodDeclaration WithParameters(JContainer newParameters) + { + return T._parameters == newParameters ? T : new Cs.MethodDeclaration(T.Id, T.Prefix, T.Markers, T.Attributes, T.Modifiers, T._typeParameters, T.ReturnTypeExpression, T._explicitInterfaceSpecifier, T.Name, newParameters, T.Body, T.MethodType, T._typeParameterConstraintClauses); + } + public JContainer TypeParameterConstraintClauses => T._typeParameterConstraintClauses; public Cs.MethodDeclaration WithTypeParameterConstraintClauses(JContainer newTypeParameterConstraintClauses) { - return T._typeParameterConstraintClauses == newTypeParameterConstraintClauses ? T : new Cs.MethodDeclaration(T.Id, T.Prefix, T.Markers, T.MethodDeclarationCore, newTypeParameterConstraintClauses); + return T._typeParameterConstraintClauses == newTypeParameterConstraintClauses ? T : new Cs.MethodDeclaration(T.Id, T.Prefix, T.Markers, T.Attributes, T.Modifiers, T._typeParameters, T.ReturnTypeExpression, T._explicitInterfaceSpecifier, T.Name, T._parameters, T.Body, T.MethodType, newTypeParameterConstraintClauses); } } diff --git a/Rewrite/src/Rewrite.CSharp/Tree/NewClass.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/NewClass.g.cs index d3fb49b..697c608 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/NewClass.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/NewClass.g.cs @@ -51,7 +51,7 @@ public partial class NewClass( Markers markers, J.NewClass newClassCore, InitializerExpression? initializer - ) : Cs, Statement, Expression, Expression, MutableTree + ) : Cs, Statement, Expression, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/NullSafeExpression.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/NullSafeExpression.g.cs index 08d9e5d..dbed12f 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/NullSafeExpression.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/NullSafeExpression.g.cs @@ -32,7 +32,7 @@ public partial class NullSafeExpression( Space prefix, Markers markers, JRightPadded expression - ) : Cs, Expression, Expression, MutableTree + ) : Cs, Expression, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/OrderByClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/OrderByClause.g.cs new file mode 100644 index 0000000..2406124 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/OrderByClause.g.cs @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a C# LINQ orderby clause that specifies the ordering of results in a query. + ///
+ /// For example: + /// + /// // Simple orderby with single key + /// from p in people + /// orderby p.LastName + /// select p + /// // Multiple orderings + /// from p in people + /// orderby p.LastName ascending, p.FirstName descending + /// select p + /// // Orderby with complex key expressions + /// from o in orders + /// orderby o.Customer.Name, o.Total * 1.08 + /// select o + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class OrderByClause( + Guid id, + Space prefix, + Markers markers, + IList> orderings + ) : Cs, Cs.QueryClause, J, MutableTree + { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitOrderByClause(this, p); + } + + public Guid Id => id; + + public OrderByClause WithId(Guid newId) + { + return newId == id ? this : new OrderByClause(newId, prefix, markers, _orderings); + } + public Space Prefix => prefix; + + public OrderByClause WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new OrderByClause(id, newPrefix, markers, _orderings); + } + public Markers Markers => markers; + + public OrderByClause WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new OrderByClause(id, prefix, newMarkers, _orderings); + } + private readonly IList> _orderings = orderings; + public IList Orderings => _orderings.Elements(); + + public OrderByClause WithOrderings(IList newOrderings) + { + return Padding.WithOrderings(_orderings.WithElements(newOrderings)); + } + public sealed record PaddingHelper(Cs.OrderByClause T) + { + public IList> Orderings => T._orderings; + + public Cs.OrderByClause WithOrderings(IList> newOrderings) + { + return T._orderings == newOrderings ? T : new Cs.OrderByClause(T.Id, T.Prefix, T.Markers, newOrderings); + } + + } + + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is OrderByClause && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/Ordering.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/Ordering.g.cs new file mode 100644 index 0000000..63b542f --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/Ordering.g.cs @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a single ordering clause within C# orderby expression. + /// + /// orderby name ascending + /// orderby age descending, name ascending + /// + /// + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class Ordering( + Guid id, + Space prefix, + Markers markers, + JRightPadded expression, + Ordering.DirectionKind? direction + ) : Cs, J, MutableTree + { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitOrdering(this, p); + } + + public Guid Id => id; + + public Ordering WithId(Guid newId) + { + return newId == id ? this : new Ordering(newId, prefix, markers, _expression, direction); + } + public Space Prefix => prefix; + + public Ordering WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new Ordering(id, newPrefix, markers, _expression, direction); + } + public Markers Markers => markers; + + public Ordering WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new Ordering(id, prefix, newMarkers, _expression, direction); + } + private readonly JRightPadded _expression = expression; + public Expression Expression => _expression.Element; + + public Ordering WithExpression(Expression newExpression) + { + return Padding.WithExpression(_expression.WithElement(newExpression)); + } + public DirectionKind? Direction => direction; + + public Ordering WithDirection(DirectionKind? newDirection) + { + return newDirection == direction ? this : new Ordering(id, prefix, markers, _expression, newDirection); + } + public enum DirectionKind + { + Ascending, + Descending, + } + public sealed record PaddingHelper(Cs.Ordering T) + { + public JRightPadded Expression => T._expression; + + public Cs.Ordering WithExpression(JRightPadded newExpression) + { + return T._expression == newExpression ? T : new Cs.Ordering(T.Id, T.Prefix, T.Markers, newExpression, T.Direction); + } + + } + + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is Ordering && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ParenthesizedPattern.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ParenthesizedPattern.g.cs index 7bf84e2..bc7ab83 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/ParenthesizedPattern.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/ParenthesizedPattern.g.cs @@ -51,7 +51,7 @@ public partial class ParenthesizedPattern( Space prefix, Markers markers, JContainer pattern - ) : Cs.Pattern, Expression, MutableTree + ) : Cs.Pattern, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/ParenthesizedVariableDesignation.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/ParenthesizedVariableDesignation.g.cs index 85330dd..bf98bf5 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/ParenthesizedVariableDesignation.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/ParenthesizedVariableDesignation.g.cs @@ -46,7 +46,7 @@ public partial class ParenthesizedVariableDesignation( Markers markers, JContainer variables, JavaType? type - ) : Cs.VariableDesignation, Cs, Expression, MutableTree + ) : Cs.VariableDesignation, Cs, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/PositionalPatternClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/PositionalPatternClause.g.cs index 57e5d46..3d24498 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/PositionalPatternClause.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/PositionalPatternClause.g.cs @@ -51,7 +51,7 @@ public partial class PositionalPatternClause( Space prefix, Markers markers, JContainer subpatterns - ) : Cs, MutableTree + ) : Cs, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/PropertyDeclaration.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/PropertyDeclaration.g.cs index 2328f0d..09d18b6 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/PropertyDeclaration.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/PropertyDeclaration.g.cs @@ -38,7 +38,7 @@ public partial class PropertyDeclaration( J.Identifier name, J.Block accessors, JLeftPadded? initializer - ) : Cs, Statement, TypedTree, TypedTree, MutableTree + ) : Cs, Statement, TypedTree, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/PropertyPatternClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/PropertyPatternClause.g.cs index e4db3c4..3499831 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/PropertyPatternClause.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/PropertyPatternClause.g.cs @@ -53,7 +53,7 @@ public partial class PropertyPatternClause( Space prefix, Markers markers, JContainer subpatterns - ) : Cs, MutableTree + ) : Cs, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/QueryBody.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/QueryBody.g.cs new file mode 100644 index 0000000..77c2662 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/QueryBody.g.cs @@ -0,0 +1,115 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents the body of a LINQ query expression, consisting of the query clauses and a final select or group clause. + ///
+ /// For example: + /// + /// // Body of query includes everything after initial 'from': + /// from c in customers + /// where c.Age > 18 // Clauses part + /// orderby c.LastName // Clauses part + /// select c.Name // SelectOrGroup part + /// into oldCustomers // Continuation part + /// where oldCustomers... + /// // Another example with join: + /// from o in orders + /// join c in customers // Clauses part + /// on o.CustomerId equals c.Id + /// where o.Total > 1000 // Clauses part + /// select new { o, c } // SelectOrGroup part + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class QueryBody( + Guid id, + Space prefix, + Markers markers, + IList clauses, + SelectOrGroupClause? selectOrGroup, + QueryContinuation? continuation + ) : Cs, J, MutableTree + { + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitQueryBody(this, p); + } + + public Guid Id => id; + + public QueryBody WithId(Guid newId) + { + return newId == id ? this : new QueryBody(newId, prefix, markers, clauses, selectOrGroup, continuation); + } + public Space Prefix => prefix; + + public QueryBody WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new QueryBody(id, newPrefix, markers, clauses, selectOrGroup, continuation); + } + public Markers Markers => markers; + + public QueryBody WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new QueryBody(id, prefix, newMarkers, clauses, selectOrGroup, continuation); + } + public IList Clauses => clauses; + + public QueryBody WithClauses(IList newClauses) + { + return newClauses == clauses ? this : new QueryBody(id, prefix, markers, newClauses, selectOrGroup, continuation); + } + public Cs.SelectOrGroupClause? SelectOrGroup => selectOrGroup; + + public QueryBody WithSelectOrGroup(Cs.SelectOrGroupClause? newSelectOrGroup) + { + return ReferenceEquals(newSelectOrGroup, selectOrGroup) ? this : new QueryBody(id, prefix, markers, clauses, newSelectOrGroup, continuation); + } + public Cs.QueryContinuation? Continuation => continuation; + + public QueryBody WithContinuation(Cs.QueryContinuation? newContinuation) + { + return ReferenceEquals(newContinuation, continuation) ? this : new QueryBody(id, prefix, markers, clauses, selectOrGroup, newContinuation); + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is QueryBody && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/QueryClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/QueryClause.g.cs new file mode 100644 index 0000000..9f30f93 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/QueryClause.g.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + public partial interface QueryClause : Cs + { + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/QueryContinuation.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/QueryContinuation.g.cs new file mode 100644 index 0000000..58bbb80 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/QueryContinuation.g.cs @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a LINQ query continuation using the 'into' keyword, which allows query results to be + /// further processed in subsequent query clauses. + ///
+ /// For example: + /// + /// // Query continuation with grouping + /// from c in customers + /// group c by c.Country into g + /// select new { Country = g.Key, Count = g.Count() } + /// // Multiple continuations + /// from n in numbers + /// group n by n % 2 into g + /// select new { Modulo = g.Key, Items = g } into r + /// where r.Items.Count() > 2 + /// select r + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class QueryContinuation( + Guid id, + Space prefix, + Markers markers, + J.Identifier identifier, + QueryBody body + ) : Cs, J, MutableTree + { + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitQueryContinuation(this, p); + } + + public Guid Id => id; + + public QueryContinuation WithId(Guid newId) + { + return newId == id ? this : new QueryContinuation(newId, prefix, markers, identifier, body); + } + public Space Prefix => prefix; + + public QueryContinuation WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new QueryContinuation(id, newPrefix, markers, identifier, body); + } + public Markers Markers => markers; + + public QueryContinuation WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new QueryContinuation(id, prefix, newMarkers, identifier, body); + } + public J.Identifier Identifier => identifier; + + public QueryContinuation WithIdentifier(J.Identifier newIdentifier) + { + return ReferenceEquals(newIdentifier, identifier) ? this : new QueryContinuation(id, prefix, markers, newIdentifier, body); + } + public Cs.QueryBody Body => body; + + public QueryContinuation WithBody(Cs.QueryBody newBody) + { + return ReferenceEquals(newBody, body) ? this : new QueryContinuation(id, prefix, markers, identifier, newBody); + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is QueryContinuation && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/QueryExpression.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/QueryExpression.g.cs new file mode 100644 index 0000000..4760517 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/QueryExpression.g.cs @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a C# LINQ query expression that provides SQL-like syntax for working with collections. + ///
+ /// For example: + /// + /// // Simple query + /// from user in users + /// where user.Age > 18 + /// select user.Name + /// // Query with multiple clauses + /// from c in customers + /// join o in orders on c.Id equals o.CustomerId + /// where o.Total > 1000 + /// orderby o.Date + /// select new { c.Name, o.Total } + /// // Query with multiple from clauses + /// from c in customers + /// from o in c.Orders + /// where o.Total > 1000 + /// select new { c.Name, o.Total } + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class QueryExpression( + Guid id, + Space prefix, + Markers markers, + FromClause fromClause, + QueryBody body + ) : Cs, Expression, Expression, J, MutableTree + { + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitQueryExpression(this, p); + } + + public Guid Id => id; + + public QueryExpression WithId(Guid newId) + { + return newId == id ? this : new QueryExpression(newId, prefix, markers, fromClause, body); + } + public Space Prefix => prefix; + + public QueryExpression WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new QueryExpression(id, newPrefix, markers, fromClause, body); + } + public Markers Markers => markers; + + public QueryExpression WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new QueryExpression(id, prefix, newMarkers, fromClause, body); + } + public Cs.FromClause FromClause => fromClause; + + public QueryExpression WithFromClause(Cs.FromClause newFromClause) + { + return ReferenceEquals(newFromClause, fromClause) ? this : new QueryExpression(id, prefix, markers, newFromClause, body); + } + public Cs.QueryBody Body => body; + + public QueryExpression WithBody(Cs.QueryBody newBody) + { + return ReferenceEquals(newBody, body) ? this : new QueryExpression(id, prefix, markers, fromClause, newBody); + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is QueryExpression && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/RangeExpression.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/RangeExpression.g.cs index b7ace4d..b5cb8dd 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/RangeExpression.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/RangeExpression.g.cs @@ -57,7 +57,7 @@ public partial class RangeExpression( Markers markers, JRightPadded? start, Expression? end - ) : Cs, Expression, Expression, MutableTree + ) : Cs, Expression, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/RecursivePattern.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/RecursivePattern.g.cs index be82f8c..a9b7802 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/RecursivePattern.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/RecursivePattern.g.cs @@ -58,7 +58,7 @@ public partial class RecursivePattern( PositionalPatternClause? positionalPattern, PropertyPatternClause? propertyPattern, VariableDesignation? designation - ) : Cs.Pattern, Expression, MutableTree + ) : Cs.Pattern, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/RefStructConstraint.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/RefStructConstraint.g.cs index 6cdbcee..4729bec 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/RefStructConstraint.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/RefStructConstraint.g.cs @@ -35,7 +35,7 @@ public partial class RefStructConstraint( Guid id, Space prefix, Markers markers - ) : Cs, Cs.AllowsConstraint, MutableTree + ) : Cs, Cs.AllowsConstraint, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/RelationalPattern.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/RelationalPattern.g.cs index b720216..1660514 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/RelationalPattern.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/RelationalPattern.g.cs @@ -53,7 +53,7 @@ public partial class RelationalPattern( Markers markers, JLeftPadded @operator, Expression value - ) : Cs.Pattern, Expression, MutableTree + ) : Cs.Pattern, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/SelectClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/SelectClause.g.cs new file mode 100644 index 0000000..adc6766 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/SelectClause.g.cs @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a select clause in a LINQ expression in C#. + /// + /// // Simple select + /// select item + /// // Select with projection + /// select new { Name = p.Name, Age = p.Age } + /// + /// + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class SelectClause( + Guid id, + Space prefix, + Markers markers, + Expression expression + ) : Cs, Cs.SelectOrGroupClause, J, MutableTree + { + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitSelectClause(this, p); + } + + public Guid Id => id; + + public SelectClause WithId(Guid newId) + { + return newId == id ? this : new SelectClause(newId, prefix, markers, expression); + } + public Space Prefix => prefix; + + public SelectClause WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new SelectClause(id, newPrefix, markers, expression); + } + public Markers Markers => markers; + + public SelectClause WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new SelectClause(id, prefix, newMarkers, expression); + } + public Expression Expression => expression; + + public SelectClause WithExpression(Expression newExpression) + { + return ReferenceEquals(newExpression, expression) ? this : new SelectClause(id, prefix, markers, newExpression); + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is SelectClause && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/SelectOrGroupClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/SelectOrGroupClause.g.cs new file mode 100644 index 0000000..b233578 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/SelectOrGroupClause.g.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + public partial interface SelectOrGroupClause : Cs + { + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/SingleVariableDesignation.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/SingleVariableDesignation.g.cs index 1a47e12..9804a3b 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/SingleVariableDesignation.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/SingleVariableDesignation.g.cs @@ -44,7 +44,7 @@ public partial class SingleVariableDesignation( Space prefix, Markers markers, J.Identifier name - ) : Cs.VariableDesignation, Cs, Expression, MutableTree + ) : Cs.VariableDesignation, Cs, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/SlicePattern.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/SlicePattern.g.cs index 078a651..b5674b0 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/SlicePattern.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/SlicePattern.g.cs @@ -52,7 +52,7 @@ public partial class SlicePattern( Guid id, Space prefix, Markers markers - ) : Cs.Pattern, Expression, MutableTree + ) : Cs.Pattern, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/StatementExpression.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/StatementExpression.g.cs index 04ca17c..9a29b1f 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/StatementExpression.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/StatementExpression.g.cs @@ -32,7 +32,7 @@ public partial class StatementExpression( Space prefix, Markers markers, Statement statement - ) : Cs, Expression, Expression, MutableTree + ) : Cs, Expression, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/Subpattern.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/Subpattern.g.cs index 62d0fa5..937b89c 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/Subpattern.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/Subpattern.g.cs @@ -59,9 +59,9 @@ public partial class Subpattern( Guid id, Space prefix, Markers markers, - J.Identifier? name, + Expression? name, JLeftPadded pattern - ) : Cs, MutableTree + ) : Cs, J, MutableTree { [NonSerialized] private WeakReference? _padding; @@ -111,9 +111,9 @@ public Subpattern WithMarkers(Markers newMarkers) { return ReferenceEquals(newMarkers, markers) ? this : new Subpattern(id, prefix, newMarkers, name, _pattern); } - public J.Identifier? Name => name; + public Expression? Name => name; - public Subpattern WithName(J.Identifier? newName) + public Subpattern WithName(Expression? newName) { return ReferenceEquals(newName, name) ? this : new Subpattern(id, prefix, markers, newName, _pattern); } diff --git a/Rewrite/src/Rewrite.CSharp/Tree/SwitchExpression.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/SwitchExpression.g.cs index 5a94115..ac8f665 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/SwitchExpression.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/SwitchExpression.g.cs @@ -50,7 +50,7 @@ public partial class SwitchExpression( Markers markers, JRightPadded expression, JContainer arms - ) : Cs, Expression, Expression, MutableTree + ) : Cs, Expression, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/SwitchExpressionArm.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/SwitchExpressionArm.g.cs index 0ac5d04..343afb7 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/SwitchExpressionArm.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/SwitchExpressionArm.g.cs @@ -50,7 +50,7 @@ public partial class SwitchExpressionArm( Pattern pattern, JLeftPadded? whenExpression, JLeftPadded expression - ) : Cs, MutableTree + ) : Cs, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/SwitchSection.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/SwitchSection.g.cs index 4491e99..4c40637 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/SwitchSection.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/SwitchSection.g.cs @@ -55,7 +55,7 @@ public partial class SwitchSection( Markers markers, IList labels, IList> statements - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/SwitchStatement.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/SwitchStatement.g.cs index ef77f99..a5a438d 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/SwitchStatement.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/SwitchStatement.g.cs @@ -57,7 +57,7 @@ public partial class SwitchStatement( Markers markers, JContainer expression, JContainer sections - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/TupleElement.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/TupleElement.g.cs index 9d955df..a9bfb27 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/TupleElement.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/TupleElement.g.cs @@ -37,7 +37,7 @@ public partial class TupleElement( Markers markers, TypeTree type, J.Identifier? name - ) : Cs, MutableTree + ) : Cs, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/TupleExpression.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/TupleExpression.g.cs index 1016446..0c1da74 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/TupleExpression.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/TupleExpression.g.cs @@ -47,7 +47,7 @@ public partial class TupleExpression( Space prefix, Markers markers, JContainer arguments - ) : Cs, Expression, Expression, MutableTree + ) : Cs, Expression, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/TupleType.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/TupleType.g.cs index c0d12d6..84623dc 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/TupleType.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/TupleType.g.cs @@ -51,7 +51,7 @@ public partial class TupleType( Markers markers, JContainer elements, JavaType? type - ) : Cs, TypeTree, Expression, Expression, TypedTree, TypeTree, MutableTree + ) : Cs, TypeTree, Expression, Expression, TypedTree, J, TypeTree, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/TypeConstraint.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/TypeConstraint.g.cs index 760605d..6955ff6 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/TypeConstraint.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/TypeConstraint.g.cs @@ -27,7 +27,7 @@ public partial interface Cs : J ///

/// Represents a type constraint in a type parameter's constraint clause. /// Example: where T : SomeClass - /// where T : IInterface + /// where T : IInterface /// #if DEBUG_VISITOR [DebuggerStepThrough] @@ -37,7 +37,7 @@ public partial class TypeConstraint( Space prefix, Markers markers, TypeTree typeExpression - ) : Cs, Cs.TypeParameterConstraint, TypedTree, TypedTree, MutableTree + ) : Cs, Cs.TypeParameterConstraint, TypedTree, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/TypeParameter.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/TypeParameter.g.cs new file mode 100644 index 0000000..aa0e362 --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/TypeParameter.g.cs @@ -0,0 +1,152 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + /// + /// Represents a C# type parameter in generic type declarations, including optional variance and constraints. + ///
+ /// For example: + /// + /// // Simple type parameter + /// class Container<T> + /// // Type parameter with variance + /// interface IEnumerable<out T> + /// // Type parameter with attributes + /// class Handler<[Category("A")] T> + /// // Type parameter with variance and attributes + /// interface IComparer<[NotNull] in T> + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class TypeParameter( + Guid id, + Space prefix, + Markers markers, + IList attributeLists, + JLeftPadded? variance, + J.Identifier name + ) : Cs, J, MutableTree + { + [NonSerialized] private WeakReference? _padding; + + public PaddingHelper Padding + { + get + { + PaddingHelper? p; + if (_padding == null) + { + p = new PaddingHelper(this); + _padding = new WeakReference(p); + } + else + { + _padding.TryGetTarget(out p); + if (p == null || p.T != this) + { + p = new PaddingHelper(this); + _padding.SetTarget(p); + } + } + return p; + } + } + + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitTypeParameter(this, p); + } + + public Guid Id => id; + + public TypeParameter WithId(Guid newId) + { + return newId == id ? this : new TypeParameter(newId, prefix, markers, attributeLists, _variance, name); + } + public Space Prefix => prefix; + + public TypeParameter WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new TypeParameter(id, newPrefix, markers, attributeLists, _variance, name); + } + public Markers Markers => markers; + + public TypeParameter WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new TypeParameter(id, prefix, newMarkers, attributeLists, _variance, name); + } + public IList AttributeLists => attributeLists; + + public TypeParameter WithAttributeLists(IList newAttributeLists) + { + return newAttributeLists == attributeLists ? this : new TypeParameter(id, prefix, markers, newAttributeLists, _variance, name); + } + private readonly JLeftPadded? _variance = variance; + public VarianceKind? Variance => _variance?.Element; + + public TypeParameter WithVariance(VarianceKind? newVariance) + { + return Padding.WithVariance(newVariance == null ? null : JLeftPadded.WithElement(_variance, newVariance.Value)); + } + public J.Identifier Name => name; + + public TypeParameter WithName(J.Identifier newName) + { + return ReferenceEquals(newName, name) ? this : new TypeParameter(id, prefix, markers, attributeLists, _variance, newName); + } + public enum VarianceKind + { + In, + Out, + } + public sealed record PaddingHelper(Cs.TypeParameter T) + { + public JLeftPadded? Variance => T._variance; + + public Cs.TypeParameter WithVariance(JLeftPadded? newVariance) + { + return T._variance == newVariance ? T : new Cs.TypeParameter(T.Id, T.Prefix, T.Markers, T.AttributeLists, newVariance, T.Name); + } + + } + + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is TypeParameter && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/TypeParameterConstraintClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/TypeParameterConstraintClause.g.cs index 54de80a..3fca48c 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/TypeParameterConstraintClause.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/TypeParameterConstraintClause.g.cs @@ -33,7 +33,7 @@ public partial class TypeParameterConstraintClause( Markers markers, JRightPadded typeParameter, JContainer typeParameterConstraints - ) : Cs, MutableTree + ) : Cs, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/TypePattern.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/TypePattern.g.cs index 51a42dd..422aba3 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/TypePattern.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/TypePattern.g.cs @@ -56,7 +56,7 @@ public partial class TypePattern( Markers markers, TypeTree typeIdentifier, VariableDesignation? designation - ) : Cs.Pattern, Expression, MutableTree + ) : Cs.Pattern, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/Unary.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/Unary.g.cs index aa5117b..d5e30e1 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/Unary.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/Unary.g.cs @@ -34,7 +34,7 @@ public partial class Unary( JLeftPadded @operator, Expression expression, JavaType? type - ) : Cs, Statement, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : Cs, Statement, Expression, TypedTree, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; @@ -106,6 +106,9 @@ public Unary WithType(JavaType? newType) public enum Types { SuppressNullableWarning, + PointerIndirection, + AddressOf, + FromEnd, } public sealed record PaddingHelper(Cs.Unary T) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/UnaryPattern.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/UnaryPattern.g.cs index 3a94308..cd754a2 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/UnaryPattern.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/UnaryPattern.g.cs @@ -51,7 +51,7 @@ public partial class UnaryPattern( Markers markers, Keyword @operator, Pattern pattern - ) : Cs, Cs.Pattern, Expression, Expression, MutableTree + ) : Cs, Cs.Pattern, Expression, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/UnsafeStatement.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/UnsafeStatement.g.cs index 05a04b1..bf1d2b5 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/UnsafeStatement.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/UnsafeStatement.g.cs @@ -62,7 +62,7 @@ public partial class UnsafeStatement( Space prefix, Markers markers, J.Block block - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/UsingDirective.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/UsingDirective.g.cs index 3dade0c..03b48bf 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/UsingDirective.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/UsingDirective.g.cs @@ -36,7 +36,7 @@ public partial class UsingDirective( JLeftPadded @unsafe, JRightPadded? alias, TypeTree namespaceOrType - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.CSharp/Tree/UsingStatement.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/UsingStatement.g.cs index 1ff82a1..8ee4b5e 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/UsingStatement.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/UsingStatement.g.cs @@ -32,9 +32,9 @@ public partial class UsingStatement( Space prefix, Markers markers, Keyword? awaitKeyword, - JContainer expression, + JLeftPadded expression, Statement statement - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; @@ -90,12 +90,12 @@ public UsingStatement WithAwaitKeyword(Cs.Keyword? newAwaitKeyword) { return ReferenceEquals(newAwaitKeyword, awaitKeyword) ? this : new UsingStatement(id, prefix, markers, newAwaitKeyword, _expression, statement); } - private readonly JContainer _expression = expression; - public IList Expression => _expression.GetElements(); + private readonly JLeftPadded _expression = expression; + public Expression Expression => _expression.Element; - public UsingStatement WithExpression(IList newExpression) + public UsingStatement WithExpression(Expression newExpression) { - return Padding.WithExpression(JContainer.WithElements(_expression, newExpression)); + return Padding.WithExpression(_expression.WithElement(newExpression)); } public Statement Statement => statement; @@ -105,9 +105,9 @@ public UsingStatement WithStatement(Statement newStatement) } public sealed record PaddingHelper(Cs.UsingStatement T) { - public JContainer Expression => T._expression; + public JLeftPadded Expression => T._expression; - public Cs.UsingStatement WithExpression(JContainer newExpression) + public Cs.UsingStatement WithExpression(JLeftPadded newExpression) { return T._expression == newExpression ? T : new Cs.UsingStatement(T.Id, T.Prefix, T.Markers, T.AwaitKeyword, newExpression, T.Statement); } diff --git a/Rewrite/src/Rewrite.CSharp/Tree/VarPattern.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/VarPattern.g.cs index 9b92909..273861d 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/VarPattern.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/VarPattern.g.cs @@ -39,7 +39,7 @@ public partial class VarPattern( Space prefix, Markers markers, VariableDesignation designation - ) : Cs, Cs.Pattern, Expression, MutableTree + ) : Cs, Cs.Pattern, Expression, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/WhereClause.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/WhereClause.g.cs new file mode 100644 index 0000000..f1132ab --- /dev/null +++ b/Rewrite/src/Rewrite.CSharp/Tree/WhereClause.g.cs @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +#pragma warning disable CS0108 // 'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using Rewrite.Core; +using Rewrite.Core.Marker; +using FileAttributes = Rewrite.Core.FileAttributes; +using Rewrite.RewriteJava.Tree; + +namespace Rewrite.RewriteCSharp.Tree; + +[SuppressMessage("ReSharper", "InconsistentNaming")] +[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")] +[SuppressMessage("ReSharper", "InvertIf")] +[SuppressMessage("ReSharper", "RedundantExtendsListEntry")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +[SuppressMessage("ReSharper", "RedundantNameQualifier")] +public partial interface Cs : J +{ + ///

+ /// Represents a C# LINQ where clause that filters elements in a query based on a condition. + ///
+ /// For example: + /// + /// // Simple where clause + /// from p in people + /// where p.Age >= 18 + /// select p + /// // Multiple where clauses + /// from p in people + /// where p.Age >= 18 + /// where p.Name.StartsWith("J") + /// select p + /// // Where with complex condition + /// from o in orders + /// where o.Total > 1000 && o.Status == "Pending" + /// select o + /// + ///
+ #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public partial class WhereClause( + Guid id, + Space prefix, + Markers markers, + Expression condition + ) : Cs, Cs.QueryClause, J, MutableTree + { + public J? AcceptCSharp

(CSharpVisitor

v, P p) + { + return v.VisitWhereClause(this, p); + } + + public Guid Id => id; + + public WhereClause WithId(Guid newId) + { + return newId == id ? this : new WhereClause(newId, prefix, markers, condition); + } + public Space Prefix => prefix; + + public WhereClause WithPrefix(Space newPrefix) + { + return newPrefix == prefix ? this : new WhereClause(id, newPrefix, markers, condition); + } + public Markers Markers => markers; + + public WhereClause WithMarkers(Markers newMarkers) + { + return ReferenceEquals(newMarkers, markers) ? this : new WhereClause(id, prefix, newMarkers, condition); + } + public Expression Condition => condition; + + public WhereClause WithCondition(Expression newCondition) + { + return ReferenceEquals(newCondition, condition) ? this : new WhereClause(id, prefix, markers, newCondition); + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public bool Equals(Rewrite.Core.Tree? other) + { + return other is WhereClause && other.Id == Id; + } + #if DEBUG_VISITOR + [DebuggerStepThrough] + #endif + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Rewrite/src/Rewrite.CSharp/Tree/Yield.g.cs b/Rewrite/src/Rewrite.CSharp/Tree/Yield.g.cs index 9b793a1..589fd8b 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/Yield.g.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/Yield.g.cs @@ -42,7 +42,7 @@ public partial class Yield( Markers markers, Keyword returnOrBreakKeyword, Expression? expression - ) : Cs, Statement, MutableTree + ) : Cs, Statement, J, MutableTree { public J? AcceptCSharp

(CSharpVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.CSharp/Tree/_Extensions.cs b/Rewrite/src/Rewrite.CSharp/Tree/_Extensions.cs index a0412ae..7324303 100644 --- a/Rewrite/src/Rewrite.CSharp/Tree/_Extensions.cs +++ b/Rewrite/src/Rewrite.CSharp/Tree/_Extensions.cs @@ -5,6 +5,37 @@ namespace Rewrite.RewriteCSharp.Tree; public partial interface Cs { + public partial class AliasQualifiedName : Expression + { + JavaType? TypedTree.Type => this.Name.Type; + public AliasQualifiedName WithType(JavaType? type) => WithName(Name.WithType(type)); + } + public partial class ClassDeclaration : Expression + { + public J.ClassDeclaration.Kind Kind => _kind; + JavaType? TypedTree.Type => type; + public ClassDeclaration WithType(JavaType? type) => WithType((JavaType.FullyQualified?)type); + } + public partial class MethodDeclaration : Expression + { + public JavaType? Type => this.MethodType; + public MethodDeclaration WithType(JavaType? type) => WithMethodType(type as JavaType.Method); + } + public partial class IndexerDeclaration : Expression + { + public JavaType? Type => this.TypeExpression.Type; + public IndexerDeclaration WithType(JavaType? type) => WithTypeExpression(TypeExpression.WithType(type)); + } + public partial class QueryExpression : Expression + { + public JavaType? Type => this.FromClause.Type; + public QueryExpression WithType(JavaType? type) => WithFromClause(FromClause.WithType(type)); + } + public partial class FromClause : Expression + { + public JavaType? Type => this.Expression.Type; + public FromClause WithType(JavaType? type) => WithExpression(Expression.WithType(type)); + } public partial class RangeExpression : Expression { public JavaType? Type => Start?.Type ?? End?.Type; diff --git a/Rewrite/src/Rewrite.Core/ParseError.cs b/Rewrite/src/Rewrite.Core/ParseError.cs index 38031ee..70f6401 100644 --- a/Rewrite/src/Rewrite.Core/ParseError.cs +++ b/Rewrite/src/Rewrite.Core/ParseError.cs @@ -118,7 +118,7 @@ public bool IsAcceptable(ITreeVisitor v, P p) where R : class, Tree { return v.IsAdaptableTo(typeof(ParseErrorVisitor

)); } - + R? Tree.Accept(ITreeVisitor v, P p) where R : class { return (R?)Accept(v.Adapt>(), p); @@ -155,4 +155,13 @@ public static ParseError Build(Parser parser, null ); } -} \ No newline at end of file + + public override string ToString() + { + StringBuilder sb = new(); + sb.AppendLine($"Parse error in {SourcePath}"); + var parseError = Markers.OfType().FirstOrDefault(); + sb.AppendLine(parseError?.ToString()); + return sb.ToString(); + } +} diff --git a/Rewrite/src/Rewrite.Core/ParseErrorResult.cs b/Rewrite/src/Rewrite.Core/ParseErrorResult.cs index 392bd9c..a9f7c39 100644 --- a/Rewrite/src/Rewrite.Core/ParseErrorResult.cs +++ b/Rewrite/src/Rewrite.Core/ParseErrorResult.cs @@ -86,4 +86,6 @@ public override int GetHashCode() { return Id.GetHashCode(); } + + public override string ToString() => Message; } diff --git a/Rewrite/src/Rewrite.Java/Tree/AnnotatedType.g.cs b/Rewrite/src/Rewrite.Java/Tree/AnnotatedType.g.cs index 0e82bdf..81143b9 100644 --- a/Rewrite/src/Rewrite.Java/Tree/AnnotatedType.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/AnnotatedType.g.cs @@ -32,7 +32,7 @@ public partial class AnnotatedType( Markers markers, IList annotations, TypeTree typeExpression - ) : J, Expression, TypeTree, Expression, TypedTree, TypeTree, MutableTree + ) : J, Expression, TypeTree, Expression, TypedTree, J, TypeTree, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/Annotation.g.cs b/Rewrite/src/Rewrite.Java/Tree/Annotation.g.cs index 91643e6..272207a 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Annotation.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Annotation.g.cs @@ -32,7 +32,7 @@ public partial class Annotation( Markers markers, NameTree annotationType, JContainer? arguments - ) : J, Expression, Expression, MutableTree + ) : J, Expression, Expression, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/ArrayAccess.g.cs b/Rewrite/src/Rewrite.Java/Tree/ArrayAccess.g.cs index 3ed383f..4eaeb72 100644 --- a/Rewrite/src/Rewrite.Java/Tree/ArrayAccess.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/ArrayAccess.g.cs @@ -33,7 +33,7 @@ public partial class ArrayAccess( Expression indexed, ArrayDimension dimension, JavaType? type - ) : J, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : J, Expression, TypedTree, Expression, TypedTree, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/ArrayDimension.g.cs b/Rewrite/src/Rewrite.Java/Tree/ArrayDimension.g.cs index 6377609..5f851cd 100644 --- a/Rewrite/src/Rewrite.Java/Tree/ArrayDimension.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/ArrayDimension.g.cs @@ -31,7 +31,7 @@ public partial class ArrayDimension( Space prefix, Markers markers, JRightPadded index - ) : J, MutableTree + ) : J, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/ArrayType.g.cs b/Rewrite/src/Rewrite.Java/Tree/ArrayType.g.cs index 1abc93e..2c9c71c 100644 --- a/Rewrite/src/Rewrite.Java/Tree/ArrayType.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/ArrayType.g.cs @@ -34,7 +34,7 @@ public partial class ArrayType( IList? annotations, JLeftPadded? dimension, JavaType type - ) : J, TypeTree, Expression, Expression, TypedTree, TypeTree, MutableTree + ) : J, TypeTree, Expression, Expression, TypedTree, J, TypeTree, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/Assert.g.cs b/Rewrite/src/Rewrite.Java/Tree/Assert.g.cs index 767283f..2b0efa8 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Assert.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Assert.g.cs @@ -32,7 +32,7 @@ public partial class Assert( Markers markers, Expression condition, JLeftPadded? detail - ) : J, Statement, MutableTree + ) : J, Statement, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/Assignment.g.cs b/Rewrite/src/Rewrite.Java/Tree/Assignment.g.cs index 231b100..80d1585 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Assignment.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Assignment.g.cs @@ -33,7 +33,7 @@ public partial class Assignment( Expression variable, JLeftPadded expression, JavaType? type - ) : J, Statement, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : J, Statement, Expression, TypedTree, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/AssignmentOperation.g.cs b/Rewrite/src/Rewrite.Java/Tree/AssignmentOperation.g.cs index 3496cf5..e5e39d7 100644 --- a/Rewrite/src/Rewrite.Java/Tree/AssignmentOperation.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/AssignmentOperation.g.cs @@ -34,7 +34,7 @@ public partial class AssignmentOperation( JLeftPadded @operator, Expression assignment, JavaType? type - ) : J, Statement, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : J, Statement, Expression, TypedTree, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Binary.g.cs b/Rewrite/src/Rewrite.Java/Tree/Binary.g.cs index 5a9710a..6ec4351 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Binary.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Binary.g.cs @@ -34,7 +34,7 @@ public partial class Binary( JLeftPadded @operator, Expression right, JavaType? type - ) : J, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : J, Expression, TypedTree, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Block.g.cs b/Rewrite/src/Rewrite.Java/Tree/Block.g.cs index 0289f52..db570b8 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Block.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Block.g.cs @@ -38,7 +38,7 @@ public partial class Block( JRightPadded @static, IList> statements, Space end - ) : J, Statement, MutableTree + ) : J, Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Break.g.cs b/Rewrite/src/Rewrite.Java/Tree/Break.g.cs index bcc242d..94c3ff3 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Break.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Break.g.cs @@ -31,7 +31,7 @@ public partial class Break( Space prefix, Markers markers, Identifier? label - ) : J, Statement, MutableTree + ) : J, Statement, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/Case.g.cs b/Rewrite/src/Rewrite.Java/Tree/Case.g.cs index 0813c51..e503deb 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Case.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Case.g.cs @@ -34,7 +34,7 @@ public partial class Case( JContainer expressions, JContainer statements, JRightPadded? body - ) : J, Statement, MutableTree + ) : J, Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/ClassDeclaration.g.cs b/Rewrite/src/Rewrite.Java/Tree/ClassDeclaration.g.cs index db5304d..8ce1133 100644 --- a/Rewrite/src/Rewrite.Java/Tree/ClassDeclaration.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/ClassDeclaration.g.cs @@ -41,7 +41,7 @@ public partial class ClassDeclaration( JContainer? permits, Block body, JavaType.FullyQualified? type - ) : J, Statement, TypedTree, TypedTree, MutableTree + ) : J, Statement, TypedTree, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; @@ -171,7 +171,7 @@ public partial class Kind( Markers markers, IList annotations, Kind.Types kindType - ) : J, MutableTree + ) : J, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/CompilationUnit.g.cs b/Rewrite/src/Rewrite.Java/Tree/CompilationUnit.g.cs index 2d31430..2412ffe 100644 --- a/Rewrite/src/Rewrite.Java/Tree/CompilationUnit.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/CompilationUnit.g.cs @@ -39,7 +39,7 @@ public partial class CompilationUnit( IList> imports, IList classes, Space eof - ) : J, JavaSourceFile, MutableSourceFile, MutableTree + ) : J, JavaSourceFile, MutableSourceFile, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Continue.g.cs b/Rewrite/src/Rewrite.Java/Tree/Continue.g.cs index 1247329..24426c3 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Continue.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Continue.g.cs @@ -31,7 +31,7 @@ public partial class Continue( Space prefix, Markers markers, Identifier? label - ) : J, Statement, MutableTree + ) : J, Statement, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/ControlParentheses.g.cs b/Rewrite/src/Rewrite.Java/Tree/ControlParentheses.g.cs index 3551193..716b193 100644 --- a/Rewrite/src/Rewrite.Java/Tree/ControlParentheses.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/ControlParentheses.g.cs @@ -31,7 +31,7 @@ public partial class ControlParentheses( Space prefix, Markers markers, JRightPadded tree - ) : J, Expression, Expression>, MutableTree> where J2 : J + ) : J, Expression, Expression>, J>, MutableTree> where J2 : J { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/DoWhileLoop.g.cs b/Rewrite/src/Rewrite.Java/Tree/DoWhileLoop.g.cs index 7260469..09d20be 100644 --- a/Rewrite/src/Rewrite.Java/Tree/DoWhileLoop.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/DoWhileLoop.g.cs @@ -32,7 +32,7 @@ public partial class DoWhileLoop( Markers markers, JRightPadded body, JLeftPadded> whileCondition - ) : J, Loop, MutableTree + ) : J, Loop, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Empty.g.cs b/Rewrite/src/Rewrite.Java/Tree/Empty.g.cs index c0a51dc..72f168e 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Empty.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Empty.g.cs @@ -30,7 +30,7 @@ public partial class Empty( Guid id, Space prefix, Markers markers - ) : J, Statement, Expression, TypeTree, Expression, TypedTree, TypeTree, MutableTree + ) : J, Statement, Expression, TypeTree, Expression, TypedTree, J, TypeTree, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/EnumValue.g.cs b/Rewrite/src/Rewrite.Java/Tree/EnumValue.g.cs index 13bfaf5..4941eac 100644 --- a/Rewrite/src/Rewrite.Java/Tree/EnumValue.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/EnumValue.g.cs @@ -33,7 +33,7 @@ public partial class EnumValue( IList annotations, Identifier name, NewClass? initializer - ) : J, MutableTree + ) : J, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/EnumValueSet.g.cs b/Rewrite/src/Rewrite.Java/Tree/EnumValueSet.g.cs index 50e6d00..c47ac76 100644 --- a/Rewrite/src/Rewrite.Java/Tree/EnumValueSet.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/EnumValueSet.g.cs @@ -32,7 +32,7 @@ public partial class EnumValueSet( Markers markers, IList> enums, bool terminatedWithSemicolon - ) : J, Statement, MutableTree + ) : J, Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Expression.cs b/Rewrite/src/Rewrite.Java/Tree/Expression.cs index dc62a8b..2699e1a 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Expression.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Expression.cs @@ -7,6 +7,8 @@ namespace Rewrite.RewriteJava.Tree; public interface Expression : Expression, TypedTree where T : Expression { + J J.WithPrefix(Space space) => ((J)this).WithPrefix(space); + Expression Expression.WithPrefix(Space space) => ((J)this).WithPrefix(space); TypedTree TypedTree.WithType(JavaType? type) => ((TypedTree)this).WithType(type); Expression Expression.WithType(JavaType? type) => ((TypedTree)this).WithType(type); } @@ -17,6 +19,8 @@ public interface Expression : TypedTree public new Expression WithType(JavaType? type); TypedTree TypedTree.WithType(JavaType? type) => WithType(type); + public new Expression WithPrefix(Space padding); + J J.WithPrefix(Space padding) => WithPrefix(padding); IList SideEffects => (Enumerable.Empty() as IList)!; diff --git a/Rewrite/src/Rewrite.Java/Tree/FieldAccess.g.cs b/Rewrite/src/Rewrite.Java/Tree/FieldAccess.g.cs index 58a797d..0d7f8e3 100644 --- a/Rewrite/src/Rewrite.Java/Tree/FieldAccess.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/FieldAccess.g.cs @@ -33,7 +33,7 @@ public partial class FieldAccess( Expression target, JLeftPadded name, JavaType? type - ) : J, TypeTree, Expression, Statement, Expression, TypedTree, TypeTree, MutableTree + ) : J, TypeTree, Expression, Statement, Expression, TypedTree, J, TypeTree, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/ForEachLoop.g.cs b/Rewrite/src/Rewrite.Java/Tree/ForEachLoop.g.cs index c812d91..8cf0105 100644 --- a/Rewrite/src/Rewrite.Java/Tree/ForEachLoop.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/ForEachLoop.g.cs @@ -32,7 +32,7 @@ public partial class ForEachLoop( Markers markers, ForEachLoop.Control loopControl, JRightPadded body - ) : J, Loop, MutableTree + ) : J, Loop, J, MutableTree { [NonSerialized] private WeakReference? _padding; @@ -104,7 +104,7 @@ public partial class Control( Markers markers, JRightPadded variable, JRightPadded iterable - ) : J, MutableTree + ) : J, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/ForLoop.g.cs b/Rewrite/src/Rewrite.Java/Tree/ForLoop.g.cs index b07f9c3..417ce61 100644 --- a/Rewrite/src/Rewrite.Java/Tree/ForLoop.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/ForLoop.g.cs @@ -32,7 +32,7 @@ public partial class ForLoop( Markers markers, ForLoop.Control loopControl, JRightPadded body - ) : J, Loop, MutableTree + ) : J, Loop, J, MutableTree { [NonSerialized] private WeakReference? _padding; @@ -105,7 +105,7 @@ public partial class Control( IList> init, JRightPadded condition, IList> update - ) : J, MutableTree + ) : J, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Identifier.g.cs b/Rewrite/src/Rewrite.Java/Tree/Identifier.g.cs index bd732a0..4bfa951 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Identifier.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Identifier.g.cs @@ -34,7 +34,7 @@ public sealed partial class Identifier( string simpleName, JavaType? type, JavaType.Variable? fieldType - ) : J, TypeTree, Expression, Expression, TypedTree, TypeTree, MutableTree + ) : J, TypeTree, Expression, Expression, TypedTree, J, TypeTree, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/If.g.cs b/Rewrite/src/Rewrite.Java/Tree/If.g.cs index 232d20f..007fe48 100644 --- a/Rewrite/src/Rewrite.Java/Tree/If.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/If.g.cs @@ -33,7 +33,7 @@ public partial class If( J.ControlParentheses ifCondition, JRightPadded thenPart, If.Else? elsePart - ) : J, Statement, MutableTree + ) : J, Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; @@ -110,7 +110,7 @@ public partial class Else( Space prefix, Markers markers, JRightPadded body - ) : J, MutableTree + ) : J, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Import.g.cs b/Rewrite/src/Rewrite.Java/Tree/Import.g.cs index ff344ea..c92bb44 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Import.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Import.g.cs @@ -33,7 +33,7 @@ public partial class Import( JLeftPadded @static, FieldAccess qualid, JLeftPadded? alias - ) : Statement, MutableTree + ) : Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/InstanceOf.g.cs b/Rewrite/src/Rewrite.Java/Tree/InstanceOf.g.cs index bc9693d..92d8ce4 100644 --- a/Rewrite/src/Rewrite.Java/Tree/InstanceOf.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/InstanceOf.g.cs @@ -34,7 +34,7 @@ public partial class InstanceOf( J clazz, J? pattern, JavaType? type - ) : J, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : J, Expression, TypedTree, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/IntersectionType.g.cs b/Rewrite/src/Rewrite.Java/Tree/IntersectionType.g.cs index 6eff46a..f3fb91d 100644 --- a/Rewrite/src/Rewrite.Java/Tree/IntersectionType.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/IntersectionType.g.cs @@ -31,7 +31,7 @@ public partial class IntersectionType( Space prefix, Markers markers, JContainer bounds - ) : J, TypeTree, Expression, Expression, TypedTree, TypeTree, MutableTree + ) : J, TypeTree, Expression, Expression, TypedTree, J, TypeTree, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/J.cs b/Rewrite/src/Rewrite.Java/Tree/J.cs new file mode 100644 index 0000000..3273472 --- /dev/null +++ b/Rewrite/src/Rewrite.Java/Tree/J.cs @@ -0,0 +1,16 @@ +using Rewrite.Core.Marker; + +namespace Rewrite.RewriteJava.Tree; + +public partial interface J : J where T : J +{ + public new T WithPrefix(Space prefix); + J J.WithPrefix(Space prefix) => WithPrefix(prefix); + public new T WithMarkers(Markers markers); + J J.WithMarkers(Markers markers) => WithMarkers(markers); +} +public partial interface J +{ + public J WithPrefix(Space prefix); + public J WithMarkers(Markers markers); +} diff --git a/Rewrite/src/Rewrite.Java/Tree/Label.g.cs b/Rewrite/src/Rewrite.Java/Tree/Label.g.cs index d96ae86..2b0d5d2 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Label.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Label.g.cs @@ -32,7 +32,7 @@ public partial class Label( Markers markers, JRightPadded name, Statement statement - ) : J, Statement, MutableTree

(JavaVisitor

v, P p) { @@ -92,7 +92,7 @@ public partial class Parameters( Markers markers, bool parenthesized, IList> elements - ) : J, MutableTree + ) : J, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Literal.g.cs b/Rewrite/src/Rewrite.Java/Tree/Literal.g.cs index 427b808..e620063 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Literal.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Literal.g.cs @@ -34,7 +34,7 @@ public partial class Literal( string? valueSource, IList? unicodeEscapes, JavaType.Primitive type - ) : J, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : J, Expression, TypedTree, Expression, TypedTree, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/MemberReference.g.cs b/Rewrite/src/Rewrite.Java/Tree/MemberReference.g.cs index 214397c..69f13b1 100644 --- a/Rewrite/src/Rewrite.Java/Tree/MemberReference.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/MemberReference.g.cs @@ -36,7 +36,7 @@ public partial class MemberReference( JavaType? type, JavaType.Method? methodType, JavaType.Variable? variableType - ) : J, TypedTree, MethodCall, Expression, TypedTree, MutableTree + ) : J, TypedTree, MethodCall, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/MethodDeclaration.g.cs b/Rewrite/src/Rewrite.Java/Tree/MethodDeclaration.g.cs index fba1f80..7f717df 100644 --- a/Rewrite/src/Rewrite.Java/Tree/MethodDeclaration.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/MethodDeclaration.g.cs @@ -40,7 +40,7 @@ public partial class MethodDeclaration( Block? body, JLeftPadded? defaultValue, JavaType.Method? methodType - ) : J, Statement, TypedTree, TypedTree, MutableTree + ) : J, Statement, TypedTree, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/MethodInvocation.g.cs b/Rewrite/src/Rewrite.Java/Tree/MethodInvocation.g.cs index a9e6add..1caf6bd 100644 --- a/Rewrite/src/Rewrite.Java/Tree/MethodInvocation.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/MethodInvocation.g.cs @@ -35,7 +35,7 @@ public partial class MethodInvocation( Identifier name, JContainer arguments, JavaType.Method? methodType - ) : J, Statement, TypedTree, MethodCall, Expression, TypedTree, MutableTree + ) : J, Statement, TypedTree, MethodCall, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Modifier.g.cs b/Rewrite/src/Rewrite.Java/Tree/Modifier.g.cs index a02f05f..590848c 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Modifier.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Modifier.g.cs @@ -33,7 +33,7 @@ public partial class Modifier( string? keyword, Modifier.Types modifierType, IList annotations - ) : J, MutableTree + ) : J, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/MultiCatch.g.cs b/Rewrite/src/Rewrite.Java/Tree/MultiCatch.g.cs index 4604921..626c4ab 100644 --- a/Rewrite/src/Rewrite.Java/Tree/MultiCatch.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/MultiCatch.g.cs @@ -31,7 +31,7 @@ public partial class MultiCatch( Space prefix, Markers markers, IList> alternatives - ) : J, TypeTree, TypedTree, TypeTree, MutableTree + ) : J, TypeTree, TypedTree, J, TypeTree, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/NewArray.g.cs b/Rewrite/src/Rewrite.Java/Tree/NewArray.g.cs index cba4fae..c21e4b3 100644 --- a/Rewrite/src/Rewrite.Java/Tree/NewArray.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/NewArray.g.cs @@ -34,7 +34,7 @@ public partial class NewArray( IList dimensions, JContainer? initializer, JavaType? type - ) : J, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : J, Expression, TypedTree, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/NewClass.g.cs b/Rewrite/src/Rewrite.Java/Tree/NewClass.g.cs index 131465e..18f4416 100644 --- a/Rewrite/src/Rewrite.Java/Tree/NewClass.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/NewClass.g.cs @@ -36,7 +36,7 @@ public partial class NewClass( JContainer arguments, Block? body, JavaType.Method? constructorType - ) : J, Statement, TypedTree, MethodCall, Expression, TypedTree, MutableTree + ) : J, Statement, TypedTree, MethodCall, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/NullableType.g.cs b/Rewrite/src/Rewrite.Java/Tree/NullableType.g.cs index f8ed5d4..3983ec9 100644 --- a/Rewrite/src/Rewrite.Java/Tree/NullableType.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/NullableType.g.cs @@ -32,7 +32,7 @@ public partial class NullableType( Markers markers, IList annotations, JRightPadded typeTree - ) : J, TypeTree, Expression, Expression, TypedTree, TypeTree, MutableTree + ) : J, TypeTree, Expression, Expression, TypedTree, J, TypeTree, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Package.g.cs b/Rewrite/src/Rewrite.Java/Tree/Package.g.cs index 667a715..559592c 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Package.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Package.g.cs @@ -32,7 +32,7 @@ public partial class Package( Markers markers, Expression expression, IList annotations - ) : Statement, J, MutableTree + ) : Statement, J, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/ParameterizedType.g.cs b/Rewrite/src/Rewrite.Java/Tree/ParameterizedType.g.cs index 8b9c379..ad10151 100644 --- a/Rewrite/src/Rewrite.Java/Tree/ParameterizedType.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/ParameterizedType.g.cs @@ -33,7 +33,7 @@ public partial class ParameterizedType( NameTree clazz, JContainer? typeParameters, JavaType? type - ) : J, TypeTree, Expression, Expression, TypedTree, TypeTree, MutableTree + ) : J, TypeTree, Expression, Expression, TypedTree, J, TypeTree, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Parentheses.g.cs b/Rewrite/src/Rewrite.Java/Tree/Parentheses.g.cs index 1307de2..4609233 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Parentheses.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Parentheses.g.cs @@ -31,7 +31,7 @@ public partial class Parentheses( Space prefix, Markers markers, JRightPadded tree - ) : J, Expression, Expression>, MutableTree> where J2 : J + ) : J, Expression, Expression>, J>, MutableTree> where J2 : J { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/ParenthesizedTypeTree.g.cs b/Rewrite/src/Rewrite.Java/Tree/ParenthesizedTypeTree.g.cs index 65e2fb9..abd2d8c 100644 --- a/Rewrite/src/Rewrite.Java/Tree/ParenthesizedTypeTree.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/ParenthesizedTypeTree.g.cs @@ -36,7 +36,7 @@ public sealed partial class ParenthesizedTypeTree( Markers markers, IList annotations, J.Parentheses parenthesizedType - ) : J, TypeTree, Expression, Expression, TypedTree, TypeTree, MutableTree + ) : J, TypeTree, Expression, Expression, TypedTree, J, TypeTree, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/Primitive.g.cs b/Rewrite/src/Rewrite.Java/Tree/Primitive.g.cs index cb10630..9846296 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Primitive.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Primitive.g.cs @@ -31,7 +31,7 @@ public partial class Primitive( Space prefix, Markers markers, JavaType.Primitive type - ) : J, TypeTree, Expression, Expression, TypedTree, TypeTree, MutableTree + ) : J, TypeTree, Expression, Expression, TypedTree, J, TypeTree, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/Return.g.cs b/Rewrite/src/Rewrite.Java/Tree/Return.g.cs index c0fede2..ddf7c5d 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Return.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Return.g.cs @@ -31,7 +31,7 @@ public partial class Return( Space prefix, Markers markers, Expression? expression - ) : J, Statement, MutableTree + ) : J, Statement, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/Space.cs b/Rewrite/src/Rewrite.Java/Tree/Space.cs index 05ae781..b4b5827 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Space.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Space.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Text; +using Rewrite.Core; using Rewrite.Core.Marker; namespace Rewrite.RewriteJava.Tree; @@ -174,6 +175,22 @@ public static Space Format(string formatting, int beginIndex, int toIndex) return Build(whitespace, comments); } + public override string? ToString() + { + StringBuilder p = new(); + p.Append(Whitespace); + + for (int i = 0; i < comments.Count; ++i) + { + var comment = comments[i]; + var text = ((TextComment)comment).Text; + p.Append(comment.Multiline ? $"/*{text}*/" : $"//{text}"); + p.Append(comment.Suffix); + } + + return p.ToString(); + } + public enum Location { ANY, diff --git a/Rewrite/src/Rewrite.Java/Tree/Switch.g.cs b/Rewrite/src/Rewrite.Java/Tree/Switch.g.cs index e0a8863..7b964e4 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Switch.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Switch.g.cs @@ -32,7 +32,7 @@ public partial class Switch( Markers markers, J.ControlParentheses selector, Block cases - ) : J, Statement, MutableTree + ) : J, Statement, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/SwitchExpression.g.cs b/Rewrite/src/Rewrite.Java/Tree/SwitchExpression.g.cs index cf99aab..d5fe241 100644 --- a/Rewrite/src/Rewrite.Java/Tree/SwitchExpression.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/SwitchExpression.g.cs @@ -32,7 +32,7 @@ public partial class SwitchExpression( Markers markers, J.ControlParentheses selector, Block cases - ) : J, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : J, Expression, TypedTree, Expression, TypedTree, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/Synchronized.g.cs b/Rewrite/src/Rewrite.Java/Tree/Synchronized.g.cs index 73e90ab..c9958ed 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Synchronized.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Synchronized.g.cs @@ -32,7 +32,7 @@ public partial class Synchronized( Markers markers, J.ControlParentheses @lock, Block body - ) : J, Statement, MutableTree + ) : J, Statement, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/Ternary.g.cs b/Rewrite/src/Rewrite.Java/Tree/Ternary.g.cs index 2b80247..361c617 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Ternary.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Ternary.g.cs @@ -34,7 +34,7 @@ public partial class Ternary( JLeftPadded truePart, JLeftPadded falsePart, JavaType? type - ) : J, Expression, Statement, TypedTree, Expression, TypedTree, MutableTree + ) : J, Expression, Statement, TypedTree, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Throw.g.cs b/Rewrite/src/Rewrite.Java/Tree/Throw.g.cs index 0ba6e0c..4ef2098 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Throw.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Throw.g.cs @@ -31,7 +31,7 @@ public partial class Throw( Space prefix, Markers markers, Expression exception - ) : J, Statement, MutableTree + ) : J, Statement, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/Try.g.cs b/Rewrite/src/Rewrite.Java/Tree/Try.g.cs index dd4bfc3..1c3c135 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Try.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Try.g.cs @@ -34,7 +34,7 @@ public partial class Try( Block body, IList catches, JLeftPadded? @finally - ) : J, Statement, MutableTree + ) : J, Statement, J, MutableTree { [NonSerialized] private WeakReference? _padding; @@ -119,7 +119,7 @@ public partial class Resource( Markers markers, TypedTree variableDeclarations, bool terminatedWithSemicolon - ) : J, MutableTree + ) : J, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { @@ -180,7 +180,7 @@ public partial class Catch( Markers markers, J.ControlParentheses parameter, J.Block body - ) : J, MutableTree + ) : J, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/TypeCast.g.cs b/Rewrite/src/Rewrite.Java/Tree/TypeCast.g.cs index 3ed6621..e4a1ccc 100644 --- a/Rewrite/src/Rewrite.Java/Tree/TypeCast.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/TypeCast.g.cs @@ -32,7 +32,7 @@ public partial class TypeCast( Markers markers, J.ControlParentheses clazz, Expression expression - ) : J, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : J, Expression, TypedTree, Expression, TypedTree, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/TypeParameter.g.cs b/Rewrite/src/Rewrite.Java/Tree/TypeParameter.g.cs index 0cfa1b2..ece8f80 100644 --- a/Rewrite/src/Rewrite.Java/Tree/TypeParameter.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/TypeParameter.g.cs @@ -34,7 +34,7 @@ public partial class TypeParameter( IList modifiers, Expression name, JContainer? bounds - ) : J, MutableTree + ) : J, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/TypeParameters.g.cs b/Rewrite/src/Rewrite.Java/Tree/TypeParameters.g.cs index 01ad79d..d739be7 100644 --- a/Rewrite/src/Rewrite.Java/Tree/TypeParameters.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/TypeParameters.g.cs @@ -32,7 +32,7 @@ public partial class TypeParameters( Markers markers, IList annotations, IList> parameters - ) : J, MutableTree + ) : J, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/TypedTree.cs b/Rewrite/src/Rewrite.Java/Tree/TypedTree.cs index 8911068..299c5dd 100644 --- a/Rewrite/src/Rewrite.Java/Tree/TypedTree.cs +++ b/Rewrite/src/Rewrite.Java/Tree/TypedTree.cs @@ -6,7 +6,7 @@ namespace Rewrite.RewriteJava.Tree; -public interface TypedTree : TypedTree where T : TypedTree +public interface TypedTree : J, TypedTree where T : TypedTree { public new T WithType(JavaType? type); TypedTree TypedTree.WithType(JavaType? type) => WithType(type); diff --git a/Rewrite/src/Rewrite.Java/Tree/Unary.g.cs b/Rewrite/src/Rewrite.Java/Tree/Unary.g.cs index a9026ac..91019e6 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Unary.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Unary.g.cs @@ -33,7 +33,7 @@ public partial class Unary( JLeftPadded @operator, Expression expression, JavaType? type - ) : J, Statement, Expression, TypedTree, Expression, TypedTree, MutableTree + ) : J, Statement, Expression, TypedTree, Expression, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Unknown.g.cs b/Rewrite/src/Rewrite.Java/Tree/Unknown.g.cs index a6f2f2c..31f51dc 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Unknown.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Unknown.g.cs @@ -34,7 +34,7 @@ public partial class Unknown( Space prefix, Markers markers, Unknown.Source unknownSource - ) : J, Statement, Expression, TypeTree, Expression, TypedTree, TypeTree, MutableTree + ) : J, Statement, Expression, TypeTree, Expression, TypedTree, J, TypeTree, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { @@ -77,7 +77,7 @@ public partial class Source( Space prefix, Markers markers, string text - ) : J, MutableTree + ) : J, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Java/Tree/VariableDeclarations.g.cs b/Rewrite/src/Rewrite.Java/Tree/VariableDeclarations.g.cs index ddac987..6c0c294 100644 --- a/Rewrite/src/Rewrite.Java/Tree/VariableDeclarations.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/VariableDeclarations.g.cs @@ -36,7 +36,7 @@ public partial class VariableDeclarations( Space? varargs, IList> dimensionsBeforeName, IList> variables - ) : J, Statement, TypedTree, TypedTree, MutableTree + ) : J, Statement, TypedTree, TypedTree, J, MutableTree { [NonSerialized] private WeakReference? _padding; @@ -134,7 +134,7 @@ public partial class NamedVariable( IList> dimensionsAfterName, JLeftPadded? initializer, JavaType.Variable? variableType - ) : J, NameTree, TypedTree, TypeTree, MutableTree + ) : J, NameTree, TypedTree, J, TypeTree, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/WhileLoop.g.cs b/Rewrite/src/Rewrite.Java/Tree/WhileLoop.g.cs index 43a1ee1..2d7360e 100644 --- a/Rewrite/src/Rewrite.Java/Tree/WhileLoop.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/WhileLoop.g.cs @@ -32,7 +32,7 @@ public partial class WhileLoop( Markers markers, J.ControlParentheses condition, JRightPadded body - ) : J, Loop, MutableTree + ) : J, Loop, J, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Wildcard.g.cs b/Rewrite/src/Rewrite.Java/Tree/Wildcard.g.cs index c9dbe2b..82c184a 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Wildcard.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Wildcard.g.cs @@ -32,7 +32,7 @@ public partial class Wildcard( Markers markers, JLeftPadded? wildcardBound, NameTree? boundedType - ) : J, Expression, TypeTree, Expression, TypedTree, TypeTree, MutableTree + ) : J, Expression, TypeTree, Expression, TypedTree, J, TypeTree, MutableTree { [NonSerialized] private WeakReference? _padding; diff --git a/Rewrite/src/Rewrite.Java/Tree/Yield.g.cs b/Rewrite/src/Rewrite.Java/Tree/Yield.g.cs index 36044c8..42f741e 100644 --- a/Rewrite/src/Rewrite.Java/Tree/Yield.g.cs +++ b/Rewrite/src/Rewrite.Java/Tree/Yield.g.cs @@ -32,7 +32,7 @@ public sealed partial class Yield( Markers markers, bool @implicit, Expression value - ) : J, Statement, MutableTree + ) : J, Statement, J, MutableTree { public J? AcceptJava

(JavaVisitor

v, P p) { diff --git a/Rewrite/src/Rewrite.Remote.Codec/CSharp/CSharpReceiver.g.cs b/Rewrite/src/Rewrite.Remote.Codec/CSharp/CSharpReceiver.g.cs index 8cda74b..5b03d3b 100644 --- a/Rewrite/src/Rewrite.Remote.Codec/CSharp/CSharpReceiver.g.cs +++ b/Rewrite/src/Rewrite.Remote.Codec/CSharp/CSharpReceiver.g.cs @@ -187,7 +187,7 @@ public override J VisitExpressionStatement(Cs.ExpressionStatement expressionStat expressionStatement = expressionStatement.WithId(ctx.ReceiveValue(expressionStatement.Id)!); expressionStatement = expressionStatement.WithPrefix(ctx.ReceiveNode(expressionStatement.Prefix, ReceiveSpace)!); expressionStatement = expressionStatement.WithMarkers(ctx.ReceiveNode(expressionStatement.Markers, ctx.ReceiveMarkers)!); - expressionStatement = expressionStatement.WithExpression(ctx.ReceiveNode(expressionStatement.Expression, ctx.ReceiveTree)!); + expressionStatement = expressionStatement.Padding.WithExpression(ctx.ReceiveNode(expressionStatement.Padding.Expression, ReceiveRightPadded)!); return expressionStatement; } @@ -304,8 +304,17 @@ public override J VisitClassDeclaration(Cs.ClassDeclaration classDeclaration, Re classDeclaration = classDeclaration.WithId(ctx.ReceiveValue(classDeclaration.Id)!); classDeclaration = classDeclaration.WithPrefix(ctx.ReceiveNode(classDeclaration.Prefix, ReceiveSpace)!); classDeclaration = classDeclaration.WithMarkers(ctx.ReceiveNode(classDeclaration.Markers, ctx.ReceiveMarkers)!); - classDeclaration = classDeclaration.WithClassDeclarationCore(ctx.ReceiveNode(classDeclaration.ClassDeclarationCore, ctx.ReceiveTree)!); - classDeclaration = classDeclaration.Padding.WithTypeParameterConstraintClauses(ctx.ReceiveNode(classDeclaration.Padding.TypeParameterConstraintClauses, ReceiveContainer)!); + classDeclaration = classDeclaration.WithAttributeList(ctx.ReceiveNodes(classDeclaration.AttributeList, ctx.ReceiveTree)!); + classDeclaration = classDeclaration.WithModifiers(ctx.ReceiveNodes(classDeclaration.Modifiers, ctx.ReceiveTree)!); + classDeclaration = classDeclaration.Padding.WithKind(ctx.ReceiveNode(classDeclaration.Padding.Kind, ctx.ReceiveTree)!); + classDeclaration = classDeclaration.WithName(ctx.ReceiveNode(classDeclaration.Name, ctx.ReceiveTree)!); + classDeclaration = classDeclaration.Padding.WithTypeParameters(ctx.ReceiveNode(classDeclaration.Padding.TypeParameters, ReceiveContainer)); + classDeclaration = classDeclaration.Padding.WithPrimaryConstructor(ctx.ReceiveNode(classDeclaration.Padding.PrimaryConstructor, ReceiveContainer)); + classDeclaration = classDeclaration.Padding.WithExtendings(ctx.ReceiveNode(classDeclaration.Padding.Extendings, ReceiveLeftPadded)); + classDeclaration = classDeclaration.Padding.WithImplementings(ctx.ReceiveNode(classDeclaration.Padding.Implementings, ReceiveContainer)); + classDeclaration = classDeclaration.WithBody(ctx.ReceiveNode(classDeclaration.Body, ctx.ReceiveTree)); + classDeclaration = classDeclaration.Padding.WithTypeParameterConstraintClauses(ctx.ReceiveNode(classDeclaration.Padding.TypeParameterConstraintClauses, ReceiveContainer)); + classDeclaration = classDeclaration.WithType(ctx.ReceiveValue(classDeclaration.Type)); return classDeclaration; } @@ -314,7 +323,15 @@ public override J VisitMethodDeclaration(Cs.MethodDeclaration methodDeclaration, methodDeclaration = methodDeclaration.WithId(ctx.ReceiveValue(methodDeclaration.Id)!); methodDeclaration = methodDeclaration.WithPrefix(ctx.ReceiveNode(methodDeclaration.Prefix, ReceiveSpace)!); methodDeclaration = methodDeclaration.WithMarkers(ctx.ReceiveNode(methodDeclaration.Markers, ctx.ReceiveMarkers)!); - methodDeclaration = methodDeclaration.WithMethodDeclarationCore(ctx.ReceiveNode(methodDeclaration.MethodDeclarationCore, ctx.ReceiveTree)!); + methodDeclaration = methodDeclaration.WithAttributes(ctx.ReceiveNodes(methodDeclaration.Attributes, ctx.ReceiveTree)!); + methodDeclaration = methodDeclaration.WithModifiers(ctx.ReceiveNodes(methodDeclaration.Modifiers, ctx.ReceiveTree)!); + methodDeclaration = methodDeclaration.Padding.WithTypeParameters(ctx.ReceiveNode(methodDeclaration.Padding.TypeParameters, ReceiveContainer)); + methodDeclaration = methodDeclaration.WithReturnTypeExpression(ctx.ReceiveNode(methodDeclaration.ReturnTypeExpression, ctx.ReceiveTree)!); + methodDeclaration = methodDeclaration.Padding.WithExplicitInterfaceSpecifier(ctx.ReceiveNode(methodDeclaration.Padding.ExplicitInterfaceSpecifier, ReceiveRightPadded)); + methodDeclaration = methodDeclaration.WithName(ctx.ReceiveNode(methodDeclaration.Name, ctx.ReceiveTree)!); + methodDeclaration = methodDeclaration.Padding.WithParameters(ctx.ReceiveNode(methodDeclaration.Padding.Parameters, ReceiveContainer)!); + methodDeclaration = methodDeclaration.WithBody(ctx.ReceiveNode(methodDeclaration.Body, ctx.ReceiveTree)); + methodDeclaration = methodDeclaration.WithMethodType(ctx.ReceiveValue(methodDeclaration.MethodType)); methodDeclaration = methodDeclaration.Padding.WithTypeParameterConstraintClauses(ctx.ReceiveNode(methodDeclaration.Padding.TypeParameterConstraintClauses, ReceiveContainer)!); return methodDeclaration; } @@ -325,7 +342,7 @@ public override J VisitUsingStatement(Cs.UsingStatement usingStatement, Receiver usingStatement = usingStatement.WithPrefix(ctx.ReceiveNode(usingStatement.Prefix, ReceiveSpace)!); usingStatement = usingStatement.WithMarkers(ctx.ReceiveNode(usingStatement.Markers, ctx.ReceiveMarkers)!); usingStatement = usingStatement.WithAwaitKeyword(ctx.ReceiveNode(usingStatement.AwaitKeyword, ctx.ReceiveTree)); - usingStatement = usingStatement.Padding.WithExpression(ctx.ReceiveNode(usingStatement.Padding.Expression, ReceiveContainer)!); + usingStatement = usingStatement.Padding.WithExpression(ctx.ReceiveNode(usingStatement.Padding.Expression, ReceiveLeftPadded)!); usingStatement = usingStatement.WithStatement(ctx.ReceiveNode(usingStatement.Statement, ctx.ReceiveTree)!); return usingStatement; } @@ -453,8 +470,7 @@ public override J VisitDestructorDeclaration(Cs.DestructorDeclaration destructor destructorDeclaration = destructorDeclaration.WithId(ctx.ReceiveValue(destructorDeclaration.Id)!); destructorDeclaration = destructorDeclaration.WithPrefix(ctx.ReceiveNode(destructorDeclaration.Prefix, ReceiveSpace)!); destructorDeclaration = destructorDeclaration.WithMarkers(ctx.ReceiveNode(destructorDeclaration.Markers, ctx.ReceiveMarkers)!); - destructorDeclaration = destructorDeclaration.WithInitializer(ctx.ReceiveNode(destructorDeclaration.Initializer, ctx.ReceiveTree)); - destructorDeclaration = destructorDeclaration.WithConstructorCore(ctx.ReceiveNode(destructorDeclaration.ConstructorCore, ctx.ReceiveTree)!); + destructorDeclaration = destructorDeclaration.WithMethodCore(ctx.ReceiveNode(destructorDeclaration.MethodCore, ctx.ReceiveTree)!); return destructorDeclaration; } @@ -800,6 +816,225 @@ public override J VisitRangeExpression(Cs.RangeExpression rangeExpression, Recei return rangeExpression; } + public override J VisitQueryExpression(Cs.QueryExpression queryExpression, ReceiverContext ctx) + { + queryExpression = queryExpression.WithId(ctx.ReceiveValue(queryExpression.Id)!); + queryExpression = queryExpression.WithPrefix(ctx.ReceiveNode(queryExpression.Prefix, ReceiveSpace)!); + queryExpression = queryExpression.WithMarkers(ctx.ReceiveNode(queryExpression.Markers, ctx.ReceiveMarkers)!); + queryExpression = queryExpression.WithFromClause(ctx.ReceiveNode(queryExpression.FromClause, ctx.ReceiveTree)!); + queryExpression = queryExpression.WithBody(ctx.ReceiveNode(queryExpression.Body, ctx.ReceiveTree)!); + return queryExpression; + } + + public override J VisitQueryBody(Cs.QueryBody queryBody, ReceiverContext ctx) + { + queryBody = queryBody.WithId(ctx.ReceiveValue(queryBody.Id)!); + queryBody = queryBody.WithPrefix(ctx.ReceiveNode(queryBody.Prefix, ReceiveSpace)!); + queryBody = queryBody.WithMarkers(ctx.ReceiveNode(queryBody.Markers, ctx.ReceiveMarkers)!); + queryBody = queryBody.WithClauses(ctx.ReceiveNodes(queryBody.Clauses, ctx.ReceiveTree)!); + queryBody = queryBody.WithSelectOrGroup(ctx.ReceiveNode(queryBody.SelectOrGroup, ctx.ReceiveTree)); + queryBody = queryBody.WithContinuation(ctx.ReceiveNode(queryBody.Continuation, ctx.ReceiveTree)); + return queryBody; + } + + public override J VisitFromClause(Cs.FromClause fromClause, ReceiverContext ctx) + { + fromClause = fromClause.WithId(ctx.ReceiveValue(fromClause.Id)!); + fromClause = fromClause.WithPrefix(ctx.ReceiveNode(fromClause.Prefix, ReceiveSpace)!); + fromClause = fromClause.WithMarkers(ctx.ReceiveNode(fromClause.Markers, ctx.ReceiveMarkers)!); + fromClause = fromClause.WithTypeIdentifier(ctx.ReceiveNode(fromClause.TypeIdentifier, ctx.ReceiveTree)); + fromClause = fromClause.Padding.WithIdentifier(ctx.ReceiveNode(fromClause.Padding.Identifier, ReceiveRightPadded)!); + fromClause = fromClause.WithExpression(ctx.ReceiveNode(fromClause.Expression, ctx.ReceiveTree)!); + return fromClause; + } + + public override J VisitLetClause(Cs.LetClause letClause, ReceiverContext ctx) + { + letClause = letClause.WithId(ctx.ReceiveValue(letClause.Id)!); + letClause = letClause.WithPrefix(ctx.ReceiveNode(letClause.Prefix, ReceiveSpace)!); + letClause = letClause.WithMarkers(ctx.ReceiveNode(letClause.Markers, ctx.ReceiveMarkers)!); + letClause = letClause.Padding.WithIdentifier(ctx.ReceiveNode(letClause.Padding.Identifier, ReceiveRightPadded)!); + letClause = letClause.WithExpression(ctx.ReceiveNode(letClause.Expression, ctx.ReceiveTree)!); + return letClause; + } + + public override J VisitJoinClause(Cs.JoinClause joinClause, ReceiverContext ctx) + { + joinClause = joinClause.WithId(ctx.ReceiveValue(joinClause.Id)!); + joinClause = joinClause.WithPrefix(ctx.ReceiveNode(joinClause.Prefix, ReceiveSpace)!); + joinClause = joinClause.WithMarkers(ctx.ReceiveNode(joinClause.Markers, ctx.ReceiveMarkers)!); + joinClause = joinClause.Padding.WithIdentifier(ctx.ReceiveNode(joinClause.Padding.Identifier, ReceiveRightPadded)!); + joinClause = joinClause.Padding.WithInExpression(ctx.ReceiveNode(joinClause.Padding.InExpression, ReceiveRightPadded)!); + joinClause = joinClause.Padding.WithLeftExpression(ctx.ReceiveNode(joinClause.Padding.LeftExpression, ReceiveRightPadded)!); + joinClause = joinClause.WithRightExpression(ctx.ReceiveNode(joinClause.RightExpression, ctx.ReceiveTree)!); + joinClause = joinClause.Padding.WithInto(ctx.ReceiveNode(joinClause.Padding.Into, ReceiveLeftPadded)); + return joinClause; + } + + public override J VisitJoinIntoClause(Cs.JoinIntoClause joinIntoClause, ReceiverContext ctx) + { + joinIntoClause = joinIntoClause.WithId(ctx.ReceiveValue(joinIntoClause.Id)!); + joinIntoClause = joinIntoClause.WithPrefix(ctx.ReceiveNode(joinIntoClause.Prefix, ReceiveSpace)!); + joinIntoClause = joinIntoClause.WithMarkers(ctx.ReceiveNode(joinIntoClause.Markers, ctx.ReceiveMarkers)!); + joinIntoClause = joinIntoClause.WithIdentifier(ctx.ReceiveNode(joinIntoClause.Identifier, ctx.ReceiveTree)!); + return joinIntoClause; + } + + public override J VisitWhereClause(Cs.WhereClause whereClause, ReceiverContext ctx) + { + whereClause = whereClause.WithId(ctx.ReceiveValue(whereClause.Id)!); + whereClause = whereClause.WithPrefix(ctx.ReceiveNode(whereClause.Prefix, ReceiveSpace)!); + whereClause = whereClause.WithMarkers(ctx.ReceiveNode(whereClause.Markers, ctx.ReceiveMarkers)!); + whereClause = whereClause.WithCondition(ctx.ReceiveNode(whereClause.Condition, ctx.ReceiveTree)!); + return whereClause; + } + + public override J VisitOrderByClause(Cs.OrderByClause orderByClause, ReceiverContext ctx) + { + orderByClause = orderByClause.WithId(ctx.ReceiveValue(orderByClause.Id)!); + orderByClause = orderByClause.WithPrefix(ctx.ReceiveNode(orderByClause.Prefix, ReceiveSpace)!); + orderByClause = orderByClause.WithMarkers(ctx.ReceiveNode(orderByClause.Markers, ctx.ReceiveMarkers)!); + orderByClause = orderByClause.Padding.WithOrderings(ctx.ReceiveNodes(orderByClause.Padding.Orderings, ReceiveRightPadded)!); + return orderByClause; + } + + public override J VisitQueryContinuation(Cs.QueryContinuation queryContinuation, ReceiverContext ctx) + { + queryContinuation = queryContinuation.WithId(ctx.ReceiveValue(queryContinuation.Id)!); + queryContinuation = queryContinuation.WithPrefix(ctx.ReceiveNode(queryContinuation.Prefix, ReceiveSpace)!); + queryContinuation = queryContinuation.WithMarkers(ctx.ReceiveNode(queryContinuation.Markers, ctx.ReceiveMarkers)!); + queryContinuation = queryContinuation.WithIdentifier(ctx.ReceiveNode(queryContinuation.Identifier, ctx.ReceiveTree)!); + queryContinuation = queryContinuation.WithBody(ctx.ReceiveNode(queryContinuation.Body, ctx.ReceiveTree)!); + return queryContinuation; + } + + public override J VisitOrdering(Cs.Ordering ordering, ReceiverContext ctx) + { + ordering = ordering.WithId(ctx.ReceiveValue(ordering.Id)!); + ordering = ordering.WithPrefix(ctx.ReceiveNode(ordering.Prefix, ReceiveSpace)!); + ordering = ordering.WithMarkers(ctx.ReceiveNode(ordering.Markers, ctx.ReceiveMarkers)!); + ordering = ordering.Padding.WithExpression(ctx.ReceiveNode(ordering.Padding.Expression, ReceiveRightPadded)!); + ordering = ordering.WithDirection(ctx.ReceiveValue(ordering.Direction)); + return ordering; + } + + public override J VisitSelectClause(Cs.SelectClause selectClause, ReceiverContext ctx) + { + selectClause = selectClause.WithId(ctx.ReceiveValue(selectClause.Id)!); + selectClause = selectClause.WithPrefix(ctx.ReceiveNode(selectClause.Prefix, ReceiveSpace)!); + selectClause = selectClause.WithMarkers(ctx.ReceiveNode(selectClause.Markers, ctx.ReceiveMarkers)!); + selectClause = selectClause.WithExpression(ctx.ReceiveNode(selectClause.Expression, ctx.ReceiveTree)!); + return selectClause; + } + + public override J VisitGroupClause(Cs.GroupClause groupClause, ReceiverContext ctx) + { + groupClause = groupClause.WithId(ctx.ReceiveValue(groupClause.Id)!); + groupClause = groupClause.WithPrefix(ctx.ReceiveNode(groupClause.Prefix, ReceiveSpace)!); + groupClause = groupClause.WithMarkers(ctx.ReceiveNode(groupClause.Markers, ctx.ReceiveMarkers)!); + groupClause = groupClause.Padding.WithGroupExpression(ctx.ReceiveNode(groupClause.Padding.GroupExpression, ReceiveRightPadded)!); + groupClause = groupClause.WithKey(ctx.ReceiveNode(groupClause.Key, ctx.ReceiveTree)!); + return groupClause; + } + + public override J VisitIndexerDeclaration(Cs.IndexerDeclaration indexerDeclaration, ReceiverContext ctx) + { + indexerDeclaration = indexerDeclaration.WithId(ctx.ReceiveValue(indexerDeclaration.Id)!); + indexerDeclaration = indexerDeclaration.WithPrefix(ctx.ReceiveNode(indexerDeclaration.Prefix, ReceiveSpace)!); + indexerDeclaration = indexerDeclaration.WithMarkers(ctx.ReceiveNode(indexerDeclaration.Markers, ctx.ReceiveMarkers)!); + indexerDeclaration = indexerDeclaration.WithModifiers(ctx.ReceiveNodes(indexerDeclaration.Modifiers, ctx.ReceiveTree)!); + indexerDeclaration = indexerDeclaration.WithTypeExpression(ctx.ReceiveNode(indexerDeclaration.TypeExpression, ctx.ReceiveTree)!); + indexerDeclaration = indexerDeclaration.WithIndexer(ctx.ReceiveNode(indexerDeclaration.Indexer, ctx.ReceiveTree)!); + indexerDeclaration = indexerDeclaration.Padding.WithParameters(ctx.ReceiveNode(indexerDeclaration.Padding.Parameters, ReceiveContainer)!); + indexerDeclaration = indexerDeclaration.Padding.WithExpressionBody(ctx.ReceiveNode(indexerDeclaration.Padding.ExpressionBody, ReceiveLeftPadded)); + indexerDeclaration = indexerDeclaration.WithAccessors(ctx.ReceiveNode(indexerDeclaration.Accessors, ctx.ReceiveTree)); + return indexerDeclaration; + } + + public override J VisitDelegateDeclaration(Cs.DelegateDeclaration delegateDeclaration, ReceiverContext ctx) + { + delegateDeclaration = delegateDeclaration.WithId(ctx.ReceiveValue(delegateDeclaration.Id)!); + delegateDeclaration = delegateDeclaration.WithPrefix(ctx.ReceiveNode(delegateDeclaration.Prefix, ReceiveSpace)!); + delegateDeclaration = delegateDeclaration.WithMarkers(ctx.ReceiveNode(delegateDeclaration.Markers, ctx.ReceiveMarkers)!); + delegateDeclaration = delegateDeclaration.WithModifiers(ctx.ReceiveNodes(delegateDeclaration.Modifiers, ctx.ReceiveTree)!); + delegateDeclaration = delegateDeclaration.Padding.WithReturnType(ctx.ReceiveNode(delegateDeclaration.Padding.ReturnType, ReceiveLeftPadded)!); + delegateDeclaration = delegateDeclaration.WithIdentifier(ctx.ReceiveNode(delegateDeclaration.Identifier, ctx.ReceiveTree)!); + delegateDeclaration = delegateDeclaration.Padding.WithTypeParameters(ctx.ReceiveNode(delegateDeclaration.Padding.TypeParameters, ReceiveContainer)); + delegateDeclaration = delegateDeclaration.Padding.WithParameters(ctx.ReceiveNode(delegateDeclaration.Padding.Parameters, ReceiveContainer)!); + delegateDeclaration = delegateDeclaration.Padding.WithTypeParameterConstraintClauses(ctx.ReceiveNode(delegateDeclaration.Padding.TypeParameterConstraintClauses, ReceiveContainer)); + return delegateDeclaration; + } + + public override J VisitConversionOperatorDeclaration(Cs.ConversionOperatorDeclaration conversionOperatorDeclaration, ReceiverContext ctx) + { + conversionOperatorDeclaration = conversionOperatorDeclaration.WithId(ctx.ReceiveValue(conversionOperatorDeclaration.Id)!); + conversionOperatorDeclaration = conversionOperatorDeclaration.WithPrefix(ctx.ReceiveNode(conversionOperatorDeclaration.Prefix, ReceiveSpace)!); + conversionOperatorDeclaration = conversionOperatorDeclaration.WithMarkers(ctx.ReceiveNode(conversionOperatorDeclaration.Markers, ctx.ReceiveMarkers)!); + conversionOperatorDeclaration = conversionOperatorDeclaration.WithModifiers(ctx.ReceiveNodes(conversionOperatorDeclaration.Modifiers, ctx.ReceiveTree)!); + conversionOperatorDeclaration = conversionOperatorDeclaration.Padding.WithKind(ctx.ReceiveNode(conversionOperatorDeclaration.Padding.Kind, ReceiveLeftPadded)!); + conversionOperatorDeclaration = conversionOperatorDeclaration.Padding.WithReturnType(ctx.ReceiveNode(conversionOperatorDeclaration.Padding.ReturnType, ReceiveLeftPadded)!); + conversionOperatorDeclaration = conversionOperatorDeclaration.Padding.WithParameters(ctx.ReceiveNode(conversionOperatorDeclaration.Padding.Parameters, ReceiveContainer)!); + conversionOperatorDeclaration = conversionOperatorDeclaration.Padding.WithExpressionBody(ctx.ReceiveNode(conversionOperatorDeclaration.Padding.ExpressionBody, ReceiveLeftPadded)); + conversionOperatorDeclaration = conversionOperatorDeclaration.WithBody(ctx.ReceiveNode(conversionOperatorDeclaration.Body, ctx.ReceiveTree)); + return conversionOperatorDeclaration; + } + + public override J VisitTypeParameter(Cs.TypeParameter typeParameter, ReceiverContext ctx) + { + typeParameter = typeParameter.WithId(ctx.ReceiveValue(typeParameter.Id)!); + typeParameter = typeParameter.WithPrefix(ctx.ReceiveNode(typeParameter.Prefix, ReceiveSpace)!); + typeParameter = typeParameter.WithMarkers(ctx.ReceiveNode(typeParameter.Markers, ctx.ReceiveMarkers)!); + typeParameter = typeParameter.WithAttributeLists(ctx.ReceiveNodes(typeParameter.AttributeLists, ctx.ReceiveTree)!); + typeParameter = typeParameter.Padding.WithVariance(ctx.ReceiveNode(typeParameter.Padding.Variance, ReceiveLeftPadded)); + typeParameter = typeParameter.WithName(ctx.ReceiveNode(typeParameter.Name, ctx.ReceiveTree)!); + return typeParameter; + } + + public override J VisitEnumDeclaration(Cs.EnumDeclaration enumDeclaration, ReceiverContext ctx) + { + enumDeclaration = enumDeclaration.WithId(ctx.ReceiveValue(enumDeclaration.Id)!); + enumDeclaration = enumDeclaration.WithPrefix(ctx.ReceiveNode(enumDeclaration.Prefix, ReceiveSpace)!); + enumDeclaration = enumDeclaration.WithMarkers(ctx.ReceiveNode(enumDeclaration.Markers, ctx.ReceiveMarkers)!); + enumDeclaration = enumDeclaration.WithAttributeLists(ctx.ReceiveNodes(enumDeclaration.AttributeLists, ctx.ReceiveTree)); + enumDeclaration = enumDeclaration.WithModifiers(ctx.ReceiveNodes(enumDeclaration.Modifiers, ctx.ReceiveTree)!); + enumDeclaration = enumDeclaration.Padding.WithName(ctx.ReceiveNode(enumDeclaration.Padding.Name, ReceiveLeftPadded)!); + enumDeclaration = enumDeclaration.Padding.WithBaseType(ctx.ReceiveNode(enumDeclaration.Padding.BaseType, ReceiveLeftPadded)); + enumDeclaration = enumDeclaration.Padding.WithMembers(ctx.ReceiveNode(enumDeclaration.Padding.Members, ReceiveContainer)); + return enumDeclaration; + } + + public override J VisitEnumMemberDeclaration(Cs.EnumMemberDeclaration enumMemberDeclaration, ReceiverContext ctx) + { + enumMemberDeclaration = enumMemberDeclaration.WithId(ctx.ReceiveValue(enumMemberDeclaration.Id)!); + enumMemberDeclaration = enumMemberDeclaration.WithPrefix(ctx.ReceiveNode(enumMemberDeclaration.Prefix, ReceiveSpace)!); + enumMemberDeclaration = enumMemberDeclaration.WithMarkers(ctx.ReceiveNode(enumMemberDeclaration.Markers, ctx.ReceiveMarkers)!); + enumMemberDeclaration = enumMemberDeclaration.WithAttributeLists(ctx.ReceiveNodes(enumMemberDeclaration.AttributeLists, ctx.ReceiveTree)!); + enumMemberDeclaration = enumMemberDeclaration.WithName(ctx.ReceiveNode(enumMemberDeclaration.Name, ctx.ReceiveTree)!); + enumMemberDeclaration = enumMemberDeclaration.Padding.WithInitializer(ctx.ReceiveNode(enumMemberDeclaration.Padding.Initializer, ReceiveLeftPadded)); + return enumMemberDeclaration; + } + + public override J VisitAliasQualifiedName(Cs.AliasQualifiedName aliasQualifiedName, ReceiverContext ctx) + { + aliasQualifiedName = aliasQualifiedName.WithId(ctx.ReceiveValue(aliasQualifiedName.Id)!); + aliasQualifiedName = aliasQualifiedName.WithPrefix(ctx.ReceiveNode(aliasQualifiedName.Prefix, ReceiveSpace)!); + aliasQualifiedName = aliasQualifiedName.WithMarkers(ctx.ReceiveNode(aliasQualifiedName.Markers, ctx.ReceiveMarkers)!); + aliasQualifiedName = aliasQualifiedName.Padding.WithAlias(ctx.ReceiveNode(aliasQualifiedName.Padding.Alias, ReceiveRightPadded)!); + aliasQualifiedName = aliasQualifiedName.WithName(ctx.ReceiveNode(aliasQualifiedName.Name, ctx.ReceiveTree)!); + return aliasQualifiedName; + } + + public override J VisitArrayType(Cs.ArrayType arrayType, ReceiverContext ctx) + { + arrayType = arrayType.WithId(ctx.ReceiveValue(arrayType.Id)!); + arrayType = arrayType.WithPrefix(ctx.ReceiveNode(arrayType.Prefix, ReceiveSpace)!); + arrayType = arrayType.WithMarkers(ctx.ReceiveNode(arrayType.Markers, ctx.ReceiveMarkers)!); + arrayType = arrayType.WithTypeExpression(ctx.ReceiveNode(arrayType.TypeExpression, ctx.ReceiveTree)); + arrayType = arrayType.WithDimensions(ctx.ReceiveNodes(arrayType.Dimensions, ctx.ReceiveTree)!); + arrayType = arrayType.WithType(ctx.ReceiveValue(arrayType.Type)); + return arrayType; + } + public override J VisitAnnotatedType(J.AnnotatedType annotatedType, ReceiverContext ctx) { annotatedType = annotatedType.WithId(ctx.ReceiveValue(annotatedType.Id)!); @@ -1538,10 +1773,10 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveValue(default(string))!, - ctx.ReceiveValue(default(FileAttributes)), - ctx.ReceiveValue(default(string)), - ctx.ReceiveValue(default(bool)), - ctx.ReceiveValue(default(Checksum)), + ctx.ReceiveValue(default(FileAttributes?))!, + ctx.ReceiveValue(default(string?))!, + ctx.ReceiveValue(default(bool))!, + ctx.ReceiveValue(default(Checksum?))!, ctx.ReceiveNodes(default(IList>), ReceiveRightPadded)!, ctx.ReceiveNodes(default(IList>), ReceiveRightPadded)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, @@ -1578,8 +1813,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded), - ctx.ReceiveNode(default(Cs.Keyword), ctx.ReceiveTree), + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)!, + ctx.ReceiveNode(default(Cs.Keyword?), ctx.ReceiveTree)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)! ); } @@ -1614,7 +1849,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -1624,7 +1859,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded), + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)!, ctx.ReceiveNodes(default(IList>), ReceiveRightPadded)! ); } @@ -1635,8 +1870,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveNode(default(J), ctx.ReceiveTree)!, + ctx.ReceiveValue(default(JavaType?))! ); } @@ -1649,7 +1884,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -1684,7 +1919,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)! + ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)! ); } @@ -1730,8 +1965,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded), - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded) + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)!, + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)! ); } @@ -1764,7 +1999,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded), + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)!, ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree)! ); } @@ -1778,10 +2013,10 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded), + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)!, ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, ctx.ReceiveNode(default(J.Block), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded) + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)! ); } @@ -1812,8 +2047,17 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(J.ClassDeclaration), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer)! + ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, + ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(J.ClassDeclaration.Kind), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveNode(default(J.Block?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveValue(default(JavaType.FullyQualified?))! ); } @@ -1823,7 +2067,15 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(J.MethodDeclaration), ctx.ReceiveTree)!, + ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, + ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)!, + ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, + ctx.ReceiveNode(default(J.Block?), ctx.ReceiveTree)!, + ctx.ReceiveValue(default(JavaType.Method?))!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)! ); } @@ -1834,8 +2086,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(Cs.Keyword), ctx.ReceiveTree), - ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, + ctx.ReceiveNode(default(Cs.Keyword?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(Statement), ctx.ReceiveTree)! ); } @@ -1914,7 +2166,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree), + ctx.ReceiveNode(default(TypeTree?), ctx.ReceiveTree)!, ctx.ReceiveNode(default(Cs.VariableDesignation), ctx.ReceiveTree)! ); } @@ -1936,7 +2188,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -1966,7 +2218,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(Cs.ConstructorInitializer), ctx.ReceiveTree), + ctx.ReceiveNode(default(Cs.ConstructorInitializer?), ctx.ReceiveTree)!, ctx.ReceiveNode(default(J.MethodDeclaration), ctx.ReceiveTree)! ); } @@ -1977,7 +2229,6 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(Cs.ConstructorInitializer), ctx.ReceiveTree), ctx.ReceiveNode(default(J.MethodDeclaration), ctx.ReceiveTree)! ); } @@ -1990,7 +2241,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -2001,7 +2252,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(Cs.Keyword), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer)! + ctx.ReceiveNode(default(JContainer), ReceiveContainer)! ); } @@ -2012,7 +2263,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -2023,7 +2274,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree) + ctx.ReceiveNode(default(J.Identifier?), ctx.ReceiveTree)! ); } @@ -2034,7 +2285,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(J.NewClass), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(Cs.InitializerExpression), ctx.ReceiveTree) + ctx.ReceiveNode(default(Cs.InitializerExpression?), ctx.ReceiveTree)! ); } @@ -2065,7 +2316,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(Cs.Keyword), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(Expression), ctx.ReceiveTree) + ctx.ReceiveNode(default(Expression?), ctx.ReceiveTree)! ); } @@ -2075,7 +2326,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer) + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)! ); } @@ -2108,7 +2359,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(Cs.VariableDesignation), ctx.ReceiveTree) + ctx.ReceiveNode(default(Cs.VariableDesignation?), ctx.ReceiveTree)! ); } @@ -2151,7 +2402,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, - ctx.ReceiveNode(default(Cs.VariableDesignation), ctx.ReceiveTree) + ctx.ReceiveNode(default(Cs.VariableDesignation?), ctx.ReceiveTree)! ); } @@ -2171,10 +2422,10 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree), - ctx.ReceiveNode(default(Cs.PositionalPatternClause), ctx.ReceiveTree), - ctx.ReceiveNode(default(Cs.PropertyPatternClause), ctx.ReceiveTree), - ctx.ReceiveNode(default(Cs.VariableDesignation), ctx.ReceiveTree) + ctx.ReceiveNode(default(TypeTree?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(Cs.PositionalPatternClause?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(Cs.PropertyPatternClause?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(Cs.VariableDesignation?), ctx.ReceiveTree)! ); } @@ -2234,7 +2485,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree), + ctx.ReceiveNode(default(Expression?), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)! ); } @@ -2257,7 +2508,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(Cs.Pattern), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded), + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)! ); } @@ -2290,7 +2541,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(Cs.Pattern), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded), + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, ctx.ReceiveNode(default(Space), ReceiveSpace)! ); } @@ -2354,8 +2605,247 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded), - ctx.ReceiveNode(default(Expression), ctx.ReceiveTree) + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)!, + ctx.ReceiveNode(default(Expression?), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.QueryExpression" or "org.openrewrite.csharp.tree.Cs$QueryExpression") + { + return new Cs.QueryExpression( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNode(default(Cs.FromClause), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(Cs.QueryBody), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.QueryBody" or "org.openrewrite.csharp.tree.Cs$QueryBody") + { + return new Cs.QueryBody( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(Cs.SelectOrGroupClause?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(Cs.QueryContinuation?), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.FromClause" or "org.openrewrite.csharp.tree.Cs$FromClause") + { + return new Cs.FromClause( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNode(default(TypeTree?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, + ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.LetClause" or "org.openrewrite.csharp.tree.Cs$LetClause") + { + return new Cs.LetClause( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, + ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.JoinClause" or "org.openrewrite.csharp.tree.Cs$JoinClause") + { + return new Cs.JoinClause( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, + ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, + ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, + ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.JoinIntoClause" or "org.openrewrite.csharp.tree.Cs$JoinIntoClause") + { + return new Cs.JoinIntoClause( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.WhereClause" or "org.openrewrite.csharp.tree.Cs$WhereClause") + { + return new Cs.WhereClause( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.OrderByClause" or "org.openrewrite.csharp.tree.Cs$OrderByClause") + { + return new Cs.OrderByClause( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNodes(default(IList>), ReceiveRightPadded)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.QueryContinuation" or "org.openrewrite.csharp.tree.Cs$QueryContinuation") + { + return new Cs.QueryContinuation( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(Cs.QueryBody), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.Ordering" or "org.openrewrite.csharp.tree.Cs$Ordering") + { + return new Cs.Ordering( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, + ctx.ReceiveValue(default(Cs.Ordering.DirectionKind?))! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.SelectClause" or "org.openrewrite.csharp.tree.Cs$SelectClause") + { + return new Cs.SelectClause( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.GroupClause" or "org.openrewrite.csharp.tree.Cs$GroupClause") + { + return new Cs.GroupClause( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, + ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.IndexerDeclaration" or "org.openrewrite.csharp.tree.Cs$IndexerDeclaration") + { + return new Cs.IndexerDeclaration( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, + ctx.ReceiveNode(default(J.Block?), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.DelegateDeclaration" or "org.openrewrite.csharp.tree.Cs$DelegateDeclaration") + { + return new Cs.DelegateDeclaration( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, + ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.ConversionOperatorDeclaration" or "org.openrewrite.csharp.tree.Cs$ConversionOperatorDeclaration") + { + return new Cs.ConversionOperatorDeclaration( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, + ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, + ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, + ctx.ReceiveNode(default(J.Block?), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.TypeParameter" or "org.openrewrite.csharp.tree.Cs$TypeParameter") + { + return new Cs.TypeParameter( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, + ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.EnumDeclaration" or "org.openrewrite.csharp.tree.Cs$EnumDeclaration") + { + return new Cs.EnumDeclaration( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNodes(default(IList?), ctx.ReceiveTree)!, + ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.EnumMemberDeclaration" or "org.openrewrite.csharp.tree.Cs$EnumMemberDeclaration") + { + return new Cs.EnumMemberDeclaration( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.AliasQualifiedName" or "org.openrewrite.csharp.tree.Cs$AliasQualifiedName") + { + return new Cs.AliasQualifiedName( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, + ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)! + ); + } + + if (type is "Rewrite.RewriteCSharp.Tree.Cs.ArrayType" or "org.openrewrite.csharp.tree.Cs$ArrayType") + { + return new Cs.ArrayType( + ctx.ReceiveValue(default(Guid))!, + ctx.ReceiveNode(default(Space), ReceiveSpace)!, + ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, + ctx.ReceiveNode(default(TypeTree?), ctx.ReceiveTree)!, + ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, + ctx.ReceiveValue(default(JavaType?))! ); } @@ -2377,7 +2867,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(NameTree), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer) + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)! ); } @@ -2389,7 +2879,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(J.ArrayDimension), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -2400,8 +2890,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree)!, - ctx.ReceiveNodes(default(IList), ctx.ReceiveTree), - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded), + ctx.ReceiveNodes(default(IList?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, ctx.ReceiveValue(default(JavaType))! ); } @@ -2413,7 +2903,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded) + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)! ); } @@ -2425,7 +2915,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -2438,7 +2928,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -2451,7 +2941,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -2473,7 +2963,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree) + ctx.ReceiveNode(default(J.Identifier?), ctx.ReceiveTree)! ); } @@ -2486,7 +2976,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(J.Case.Types))!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded) + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)! ); } @@ -2500,13 +2990,13 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNode(default(J.ClassDeclaration.Kind), ctx.ReceiveTree)!, ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer), - ctx.ReceiveNode(default(JContainer), ReceiveContainer), - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded), - ctx.ReceiveNode(default(JContainer), ReceiveContainer), - ctx.ReceiveNode(default(JContainer), ReceiveContainer), + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, ctx.ReceiveNode(default(J.Block), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType.FullyQualified)) + ctx.ReceiveValue(default(JavaType.FullyQualified?))! ); } @@ -2527,7 +3017,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree) + ctx.ReceiveNode(default(J.Identifier?), ctx.ReceiveTree)! ); } @@ -2559,7 +3049,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(J.NewClass), ctx.ReceiveTree) + ctx.ReceiveNode(default(J.NewClass?), ctx.ReceiveTree)! ); } @@ -2570,7 +3060,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNodes(default(IList>), ReceiveRightPadded)!, - ctx.ReceiveValue(default(bool)) + ctx.ReceiveValue(default(bool))! ); } @@ -2582,7 +3072,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -2650,8 +3140,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveValue(default(string))!, - ctx.ReceiveValue(default(JavaType)), - ctx.ReceiveValue(default(JavaType.Variable)) + ctx.ReceiveValue(default(JavaType?))!, + ctx.ReceiveValue(default(JavaType.Variable?))! ); } @@ -2663,7 +3153,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(J.ControlParentheses), ReceiveControlParentheses)!, ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, - ctx.ReceiveNode(default(J.If.Else), ctx.ReceiveTree) + ctx.ReceiveNode(default(J.If.Else?), ctx.ReceiveTree)! ); } @@ -2685,7 +3175,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(J.FieldAccess), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded) + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)! ); } @@ -2697,8 +3187,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, ctx.ReceiveNode(default(J), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(J), ctx.ReceiveTree), - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveNode(default(J?), ctx.ReceiveTree)!, + ctx.ReceiveValue(default(JavaType?))! ); } @@ -2732,7 +3222,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(J.Lambda.Parameters), ctx.ReceiveTree)!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(J), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -2742,7 +3232,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveValue(default(bool)), + ctx.ReceiveValue(default(bool))!, ctx.ReceiveNodes(default(IList>), ReceiveRightPadded)! ); } @@ -2753,9 +3243,9 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveValue(default(object)), - ctx.ReceiveValue(default(string)), - ctx.ReceiveValues(default(IList)), + ctx.ReceiveValue(default(object?))!, + ctx.ReceiveValue(default(string?))!, + ctx.ReceiveValues(default(IList?))!, ctx.ReceiveValue(default(JavaType.Primitive))! ); } @@ -2767,11 +3257,11 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer), + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, - ctx.ReceiveValue(default(JavaType)), - ctx.ReceiveValue(default(JavaType.Method)), - ctx.ReceiveValue(default(JavaType.Variable)) + ctx.ReceiveValue(default(JavaType?))!, + ctx.ReceiveValue(default(JavaType.Method?))!, + ctx.ReceiveValue(default(JavaType.Variable?))! ); } @@ -2783,14 +3273,14 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(J.TypeParameters), ctx.ReceiveTree), - ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree), + ctx.ReceiveNode(default(J.TypeParameters?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(TypeTree?), ctx.ReceiveTree)!, ctx.ReceiveNode(default(J.MethodDeclaration.IdentifierWithAnnotations), ReceiveMethodIdentifierWithAnnotations)!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer), - ctx.ReceiveNode(default(J.Block), ctx.ReceiveTree), - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded), - ctx.ReceiveValue(default(JavaType.Method)) + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveNode(default(J.Block?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, + ctx.ReceiveValue(default(JavaType.Method?))! ); } @@ -2800,11 +3290,11 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded), - ctx.ReceiveNode(default(JContainer), ReceiveContainer), + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, - ctx.ReceiveValue(default(JavaType.Method)) + ctx.ReceiveValue(default(JavaType.Method?))! ); } @@ -2814,7 +3304,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveValue(default(string)), + ctx.ReceiveValue(default(string?))!, ctx.ReceiveValue(default(J.Modifier.Types))!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)! ); @@ -2836,10 +3326,10 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree), + ctx.ReceiveNode(default(TypeTree?), ctx.ReceiveTree)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer), - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveValue(default(JavaType?))! ); } @@ -2859,12 +3349,12 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded), + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, - ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree), + ctx.ReceiveNode(default(TypeTree?), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, - ctx.ReceiveNode(default(J.Block), ctx.ReceiveTree), - ctx.ReceiveValue(default(JavaType.Method)) + ctx.ReceiveNode(default(J.Block?), ctx.ReceiveTree)!, + ctx.ReceiveValue(default(JavaType.Method?))! ); } @@ -2897,8 +3387,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(NameTree), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer), - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveValue(default(JavaType?))! ); } @@ -2938,7 +3428,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(Expression), ctx.ReceiveTree) + ctx.ReceiveNode(default(Expression?), ctx.ReceiveTree)! ); } @@ -2984,7 +3474,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -3004,10 +3494,10 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer), + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, ctx.ReceiveNode(default(J.Block), ctx.ReceiveTree)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded) + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)! ); } @@ -3018,7 +3508,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(TypedTree), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(bool)) + ctx.ReceiveValue(default(bool))! ); } @@ -3053,7 +3543,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer) + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)! ); } @@ -3076,7 +3566,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -3088,8 +3578,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree), - ctx.ReceiveNode(default(Space), ReceiveSpace), + ctx.ReceiveNode(default(TypeTree?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(Space?), ReceiveSpace)!, ctx.ReceiveNodes(default(IList>), ReceiveLeftPadded)!, ctx.ReceiveNodes(default(IList>), ReceiveRightPadded)! ); @@ -3103,8 +3593,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, ctx.ReceiveNodes(default(IList>), ReceiveLeftPadded)!, - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded), - ctx.ReceiveValue(default(JavaType.Variable)) + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, + ctx.ReceiveValue(default(JavaType.Variable?))! ); } @@ -3125,8 +3615,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded), - ctx.ReceiveNode(default(NameTree), ctx.ReceiveTree) + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, + ctx.ReceiveNode(default(NameTree?), ctx.ReceiveTree)! ); } @@ -3136,7 +3626,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveValue(default(bool)), + ctx.ReceiveValue(default(bool))!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)! ); } diff --git a/Rewrite/src/Rewrite.Remote.Codec/CSharp/CSharpSender.g.cs b/Rewrite/src/Rewrite.Remote.Codec/CSharp/CSharpSender.g.cs index 16d908b..d01bc07 100644 --- a/Rewrite/src/Rewrite.Remote.Codec/CSharp/CSharpSender.g.cs +++ b/Rewrite/src/Rewrite.Remote.Codec/CSharp/CSharpSender.g.cs @@ -178,7 +178,7 @@ public override J VisitExpressionStatement(Cs.ExpressionStatement expressionStat ctx.SendValue(expressionStatement, v => v.Id); ctx.SendNode(expressionStatement, v => v.Prefix, SendSpace); ctx.SendNode(expressionStatement, v => v.Markers, ctx.SendMarkers); - ctx.SendNode(expressionStatement, v => v.Expression, ctx.SendTree); + ctx.SendNode(expressionStatement, v => v.Padding.Expression, SendRightPadded); return expressionStatement; } @@ -295,8 +295,17 @@ public override J VisitClassDeclaration(Cs.ClassDeclaration classDeclaration, Se ctx.SendValue(classDeclaration, v => v.Id); ctx.SendNode(classDeclaration, v => v.Prefix, SendSpace); ctx.SendNode(classDeclaration, v => v.Markers, ctx.SendMarkers); - ctx.SendNode(classDeclaration, v => v.ClassDeclarationCore, ctx.SendTree); + ctx.SendNodes(classDeclaration, v => v.AttributeList, ctx.SendTree, t => t.Id); + ctx.SendNodes(classDeclaration, v => v.Modifiers, ctx.SendTree, t => t.Id); + ctx.SendNode(classDeclaration, v => v.Padding.Kind, ctx.SendTree); + ctx.SendNode(classDeclaration, v => v.Name, ctx.SendTree); + ctx.SendNode(classDeclaration, v => v.Padding.TypeParameters, SendContainer); + ctx.SendNode(classDeclaration, v => v.Padding.PrimaryConstructor, SendContainer); + ctx.SendNode(classDeclaration, v => v.Padding.Extendings, SendLeftPadded); + ctx.SendNode(classDeclaration, v => v.Padding.Implementings, SendContainer); + ctx.SendNode(classDeclaration, v => v.Body, ctx.SendTree); ctx.SendNode(classDeclaration, v => v.Padding.TypeParameterConstraintClauses, SendContainer); + ctx.SendTypedValue(classDeclaration, v => v.Type); return classDeclaration; } @@ -305,7 +314,15 @@ public override J VisitMethodDeclaration(Cs.MethodDeclaration methodDeclaration, ctx.SendValue(methodDeclaration, v => v.Id); ctx.SendNode(methodDeclaration, v => v.Prefix, SendSpace); ctx.SendNode(methodDeclaration, v => v.Markers, ctx.SendMarkers); - ctx.SendNode(methodDeclaration, v => v.MethodDeclarationCore, ctx.SendTree); + ctx.SendNodes(methodDeclaration, v => v.Attributes, ctx.SendTree, t => t.Id); + ctx.SendNodes(methodDeclaration, v => v.Modifiers, ctx.SendTree, t => t.Id); + ctx.SendNode(methodDeclaration, v => v.Padding.TypeParameters, SendContainer); + ctx.SendNode(methodDeclaration, v => v.ReturnTypeExpression, ctx.SendTree); + ctx.SendNode(methodDeclaration, v => v.Padding.ExplicitInterfaceSpecifier, SendRightPadded); + ctx.SendNode(methodDeclaration, v => v.Name, ctx.SendTree); + ctx.SendNode(methodDeclaration, v => v.Padding.Parameters, SendContainer); + ctx.SendNode(methodDeclaration, v => v.Body, ctx.SendTree); + ctx.SendTypedValue(methodDeclaration, v => v.MethodType); ctx.SendNode(methodDeclaration, v => v.Padding.TypeParameterConstraintClauses, SendContainer); return methodDeclaration; } @@ -316,7 +333,7 @@ public override J VisitUsingStatement(Cs.UsingStatement usingStatement, SenderCo ctx.SendNode(usingStatement, v => v.Prefix, SendSpace); ctx.SendNode(usingStatement, v => v.Markers, ctx.SendMarkers); ctx.SendNode(usingStatement, v => v.AwaitKeyword, ctx.SendTree); - ctx.SendNode(usingStatement, v => v.Padding.Expression, SendContainer); + ctx.SendNode(usingStatement, v => v.Padding.Expression, SendLeftPadded); ctx.SendNode(usingStatement, v => v.Statement, ctx.SendTree); return usingStatement; } @@ -444,8 +461,7 @@ public override J VisitDestructorDeclaration(Cs.DestructorDeclaration destructor ctx.SendValue(destructorDeclaration, v => v.Id); ctx.SendNode(destructorDeclaration, v => v.Prefix, SendSpace); ctx.SendNode(destructorDeclaration, v => v.Markers, ctx.SendMarkers); - ctx.SendNode(destructorDeclaration, v => v.Initializer, ctx.SendTree); - ctx.SendNode(destructorDeclaration, v => v.ConstructorCore, ctx.SendTree); + ctx.SendNode(destructorDeclaration, v => v.MethodCore, ctx.SendTree); return destructorDeclaration; } @@ -791,6 +807,225 @@ public override J VisitRangeExpression(Cs.RangeExpression rangeExpression, Sende return rangeExpression; } + public override J VisitQueryExpression(Cs.QueryExpression queryExpression, SenderContext ctx) + { + ctx.SendValue(queryExpression, v => v.Id); + ctx.SendNode(queryExpression, v => v.Prefix, SendSpace); + ctx.SendNode(queryExpression, v => v.Markers, ctx.SendMarkers); + ctx.SendNode(queryExpression, v => v.FromClause, ctx.SendTree); + ctx.SendNode(queryExpression, v => v.Body, ctx.SendTree); + return queryExpression; + } + + public override J VisitQueryBody(Cs.QueryBody queryBody, SenderContext ctx) + { + ctx.SendValue(queryBody, v => v.Id); + ctx.SendNode(queryBody, v => v.Prefix, SendSpace); + ctx.SendNode(queryBody, v => v.Markers, ctx.SendMarkers); + ctx.SendNodes(queryBody, v => v.Clauses, ctx.SendTree, t => t.Id); + ctx.SendNode(queryBody, v => v.SelectOrGroup, ctx.SendTree); + ctx.SendNode(queryBody, v => v.Continuation, ctx.SendTree); + return queryBody; + } + + public override J VisitFromClause(Cs.FromClause fromClause, SenderContext ctx) + { + ctx.SendValue(fromClause, v => v.Id); + ctx.SendNode(fromClause, v => v.Prefix, SendSpace); + ctx.SendNode(fromClause, v => v.Markers, ctx.SendMarkers); + ctx.SendNode(fromClause, v => v.TypeIdentifier, ctx.SendTree); + ctx.SendNode(fromClause, v => v.Padding.Identifier, SendRightPadded); + ctx.SendNode(fromClause, v => v.Expression, ctx.SendTree); + return fromClause; + } + + public override J VisitLetClause(Cs.LetClause letClause, SenderContext ctx) + { + ctx.SendValue(letClause, v => v.Id); + ctx.SendNode(letClause, v => v.Prefix, SendSpace); + ctx.SendNode(letClause, v => v.Markers, ctx.SendMarkers); + ctx.SendNode(letClause, v => v.Padding.Identifier, SendRightPadded); + ctx.SendNode(letClause, v => v.Expression, ctx.SendTree); + return letClause; + } + + public override J VisitJoinClause(Cs.JoinClause joinClause, SenderContext ctx) + { + ctx.SendValue(joinClause, v => v.Id); + ctx.SendNode(joinClause, v => v.Prefix, SendSpace); + ctx.SendNode(joinClause, v => v.Markers, ctx.SendMarkers); + ctx.SendNode(joinClause, v => v.Padding.Identifier, SendRightPadded); + ctx.SendNode(joinClause, v => v.Padding.InExpression, SendRightPadded); + ctx.SendNode(joinClause, v => v.Padding.LeftExpression, SendRightPadded); + ctx.SendNode(joinClause, v => v.RightExpression, ctx.SendTree); + ctx.SendNode(joinClause, v => v.Padding.Into, SendLeftPadded); + return joinClause; + } + + public override J VisitJoinIntoClause(Cs.JoinIntoClause joinIntoClause, SenderContext ctx) + { + ctx.SendValue(joinIntoClause, v => v.Id); + ctx.SendNode(joinIntoClause, v => v.Prefix, SendSpace); + ctx.SendNode(joinIntoClause, v => v.Markers, ctx.SendMarkers); + ctx.SendNode(joinIntoClause, v => v.Identifier, ctx.SendTree); + return joinIntoClause; + } + + public override J VisitWhereClause(Cs.WhereClause whereClause, SenderContext ctx) + { + ctx.SendValue(whereClause, v => v.Id); + ctx.SendNode(whereClause, v => v.Prefix, SendSpace); + ctx.SendNode(whereClause, v => v.Markers, ctx.SendMarkers); + ctx.SendNode(whereClause, v => v.Condition, ctx.SendTree); + return whereClause; + } + + public override J VisitOrderByClause(Cs.OrderByClause orderByClause, SenderContext ctx) + { + ctx.SendValue(orderByClause, v => v.Id); + ctx.SendNode(orderByClause, v => v.Prefix, SendSpace); + ctx.SendNode(orderByClause, v => v.Markers, ctx.SendMarkers); + ctx.SendNodes(orderByClause, v => v.Padding.Orderings, SendRightPadded, t => t.Element.Id); + return orderByClause; + } + + public override J VisitQueryContinuation(Cs.QueryContinuation queryContinuation, SenderContext ctx) + { + ctx.SendValue(queryContinuation, v => v.Id); + ctx.SendNode(queryContinuation, v => v.Prefix, SendSpace); + ctx.SendNode(queryContinuation, v => v.Markers, ctx.SendMarkers); + ctx.SendNode(queryContinuation, v => v.Identifier, ctx.SendTree); + ctx.SendNode(queryContinuation, v => v.Body, ctx.SendTree); + return queryContinuation; + } + + public override J VisitOrdering(Cs.Ordering ordering, SenderContext ctx) + { + ctx.SendValue(ordering, v => v.Id); + ctx.SendNode(ordering, v => v.Prefix, SendSpace); + ctx.SendNode(ordering, v => v.Markers, ctx.SendMarkers); + ctx.SendNode(ordering, v => v.Padding.Expression, SendRightPadded); + ctx.SendValue(ordering, v => v.Direction); + return ordering; + } + + public override J VisitSelectClause(Cs.SelectClause selectClause, SenderContext ctx) + { + ctx.SendValue(selectClause, v => v.Id); + ctx.SendNode(selectClause, v => v.Prefix, SendSpace); + ctx.SendNode(selectClause, v => v.Markers, ctx.SendMarkers); + ctx.SendNode(selectClause, v => v.Expression, ctx.SendTree); + return selectClause; + } + + public override J VisitGroupClause(Cs.GroupClause groupClause, SenderContext ctx) + { + ctx.SendValue(groupClause, v => v.Id); + ctx.SendNode(groupClause, v => v.Prefix, SendSpace); + ctx.SendNode(groupClause, v => v.Markers, ctx.SendMarkers); + ctx.SendNode(groupClause, v => v.Padding.GroupExpression, SendRightPadded); + ctx.SendNode(groupClause, v => v.Key, ctx.SendTree); + return groupClause; + } + + public override J VisitIndexerDeclaration(Cs.IndexerDeclaration indexerDeclaration, SenderContext ctx) + { + ctx.SendValue(indexerDeclaration, v => v.Id); + ctx.SendNode(indexerDeclaration, v => v.Prefix, SendSpace); + ctx.SendNode(indexerDeclaration, v => v.Markers, ctx.SendMarkers); + ctx.SendNodes(indexerDeclaration, v => v.Modifiers, ctx.SendTree, t => t.Id); + ctx.SendNode(indexerDeclaration, v => v.TypeExpression, ctx.SendTree); + ctx.SendNode(indexerDeclaration, v => v.Indexer, ctx.SendTree); + ctx.SendNode(indexerDeclaration, v => v.Padding.Parameters, SendContainer); + ctx.SendNode(indexerDeclaration, v => v.Padding.ExpressionBody, SendLeftPadded); + ctx.SendNode(indexerDeclaration, v => v.Accessors, ctx.SendTree); + return indexerDeclaration; + } + + public override J VisitDelegateDeclaration(Cs.DelegateDeclaration delegateDeclaration, SenderContext ctx) + { + ctx.SendValue(delegateDeclaration, v => v.Id); + ctx.SendNode(delegateDeclaration, v => v.Prefix, SendSpace); + ctx.SendNode(delegateDeclaration, v => v.Markers, ctx.SendMarkers); + ctx.SendNodes(delegateDeclaration, v => v.Modifiers, ctx.SendTree, t => t.Id); + ctx.SendNode(delegateDeclaration, v => v.Padding.ReturnType, SendLeftPadded); + ctx.SendNode(delegateDeclaration, v => v.Identifier, ctx.SendTree); + ctx.SendNode(delegateDeclaration, v => v.Padding.TypeParameters, SendContainer); + ctx.SendNode(delegateDeclaration, v => v.Padding.Parameters, SendContainer); + ctx.SendNode(delegateDeclaration, v => v.Padding.TypeParameterConstraintClauses, SendContainer); + return delegateDeclaration; + } + + public override J VisitConversionOperatorDeclaration(Cs.ConversionOperatorDeclaration conversionOperatorDeclaration, SenderContext ctx) + { + ctx.SendValue(conversionOperatorDeclaration, v => v.Id); + ctx.SendNode(conversionOperatorDeclaration, v => v.Prefix, SendSpace); + ctx.SendNode(conversionOperatorDeclaration, v => v.Markers, ctx.SendMarkers); + ctx.SendNodes(conversionOperatorDeclaration, v => v.Modifiers, ctx.SendTree, t => t.Id); + ctx.SendNode(conversionOperatorDeclaration, v => v.Padding.Kind, SendLeftPadded); + ctx.SendNode(conversionOperatorDeclaration, v => v.Padding.ReturnType, SendLeftPadded); + ctx.SendNode(conversionOperatorDeclaration, v => v.Padding.Parameters, SendContainer); + ctx.SendNode(conversionOperatorDeclaration, v => v.Padding.ExpressionBody, SendLeftPadded); + ctx.SendNode(conversionOperatorDeclaration, v => v.Body, ctx.SendTree); + return conversionOperatorDeclaration; + } + + public override J VisitTypeParameter(Cs.TypeParameter typeParameter, SenderContext ctx) + { + ctx.SendValue(typeParameter, v => v.Id); + ctx.SendNode(typeParameter, v => v.Prefix, SendSpace); + ctx.SendNode(typeParameter, v => v.Markers, ctx.SendMarkers); + ctx.SendNodes(typeParameter, v => v.AttributeLists, ctx.SendTree, t => t.Id); + ctx.SendNode(typeParameter, v => v.Padding.Variance, SendLeftPadded); + ctx.SendNode(typeParameter, v => v.Name, ctx.SendTree); + return typeParameter; + } + + public override J VisitEnumDeclaration(Cs.EnumDeclaration enumDeclaration, SenderContext ctx) + { + ctx.SendValue(enumDeclaration, v => v.Id); + ctx.SendNode(enumDeclaration, v => v.Prefix, SendSpace); + ctx.SendNode(enumDeclaration, v => v.Markers, ctx.SendMarkers); + ctx.SendNodes(enumDeclaration, v => v.AttributeLists, ctx.SendTree, t => t.Id); + ctx.SendNodes(enumDeclaration, v => v.Modifiers, ctx.SendTree, t => t.Id); + ctx.SendNode(enumDeclaration, v => v.Padding.Name, SendLeftPadded); + ctx.SendNode(enumDeclaration, v => v.Padding.BaseType, SendLeftPadded); + ctx.SendNode(enumDeclaration, v => v.Padding.Members, SendContainer); + return enumDeclaration; + } + + public override J VisitEnumMemberDeclaration(Cs.EnumMemberDeclaration enumMemberDeclaration, SenderContext ctx) + { + ctx.SendValue(enumMemberDeclaration, v => v.Id); + ctx.SendNode(enumMemberDeclaration, v => v.Prefix, SendSpace); + ctx.SendNode(enumMemberDeclaration, v => v.Markers, ctx.SendMarkers); + ctx.SendNodes(enumMemberDeclaration, v => v.AttributeLists, ctx.SendTree, t => t.Id); + ctx.SendNode(enumMemberDeclaration, v => v.Name, ctx.SendTree); + ctx.SendNode(enumMemberDeclaration, v => v.Padding.Initializer, SendLeftPadded); + return enumMemberDeclaration; + } + + public override J VisitAliasQualifiedName(Cs.AliasQualifiedName aliasQualifiedName, SenderContext ctx) + { + ctx.SendValue(aliasQualifiedName, v => v.Id); + ctx.SendNode(aliasQualifiedName, v => v.Prefix, SendSpace); + ctx.SendNode(aliasQualifiedName, v => v.Markers, ctx.SendMarkers); + ctx.SendNode(aliasQualifiedName, v => v.Padding.Alias, SendRightPadded); + ctx.SendNode(aliasQualifiedName, v => v.Name, ctx.SendTree); + return aliasQualifiedName; + } + + public override J VisitArrayType(Cs.ArrayType arrayType, SenderContext ctx) + { + ctx.SendValue(arrayType, v => v.Id); + ctx.SendNode(arrayType, v => v.Prefix, SendSpace); + ctx.SendNode(arrayType, v => v.Markers, ctx.SendMarkers); + ctx.SendNode(arrayType, v => v.TypeExpression, ctx.SendTree); + ctx.SendNodes(arrayType, v => v.Dimensions, ctx.SendTree, t => t.Id); + ctx.SendTypedValue(arrayType, v => v.Type); + return arrayType; + } + public override J VisitAnnotatedType(J.AnnotatedType annotatedType, SenderContext ctx) { ctx.SendValue(annotatedType, v => v.Id); diff --git a/Rewrite/src/Rewrite.Remote.Codec/Java/JavaReceiver.g.cs b/Rewrite/src/Rewrite.Remote.Codec/Java/JavaReceiver.g.cs index 8697302..ecfb4f4 100644 --- a/Rewrite/src/Rewrite.Remote.Codec/Java/JavaReceiver.g.cs +++ b/Rewrite/src/Rewrite.Remote.Codec/Java/JavaReceiver.g.cs @@ -811,7 +811,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(NameTree), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer) + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)! ); } @@ -823,7 +823,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(J.ArrayDimension), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -834,8 +834,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree)!, - ctx.ReceiveNodes(default(IList), ctx.ReceiveTree), - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded), + ctx.ReceiveNodes(default(IList?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, ctx.ReceiveValue(default(JavaType))! ); } @@ -847,7 +847,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded) + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)! ); } @@ -859,7 +859,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -872,7 +872,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -885,7 +885,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -907,7 +907,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree) + ctx.ReceiveNode(default(J.Identifier?), ctx.ReceiveTree)! ); } @@ -920,7 +920,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(J.Case.Types))!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded) + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)! ); } @@ -934,13 +934,13 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNode(default(J.ClassDeclaration.Kind), ctx.ReceiveTree)!, ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer), - ctx.ReceiveNode(default(JContainer), ReceiveContainer), - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded), - ctx.ReceiveNode(default(JContainer), ReceiveContainer), - ctx.ReceiveNode(default(JContainer), ReceiveContainer), + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, ctx.ReceiveNode(default(J.Block), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType.FullyQualified)) + ctx.ReceiveValue(default(JavaType.FullyQualified?))! ); } @@ -962,11 +962,11 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveValue(default(string))!, - ctx.ReceiveValue(default(FileAttributes)), - ctx.ReceiveValue(default(string)), - ctx.ReceiveValue(default(bool)), - ctx.ReceiveValue(default(Checksum)), - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded), + ctx.ReceiveValue(default(FileAttributes?))!, + ctx.ReceiveValue(default(string?))!, + ctx.ReceiveValue(default(bool))!, + ctx.ReceiveValue(default(Checksum?))!, + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)!, ctx.ReceiveNodes(default(IList>), ReceiveRightPadded)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNode(default(Space), ReceiveSpace)! @@ -979,7 +979,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree) + ctx.ReceiveNode(default(J.Identifier?), ctx.ReceiveTree)! ); } @@ -1011,7 +1011,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(J.NewClass), ctx.ReceiveTree) + ctx.ReceiveNode(default(J.NewClass?), ctx.ReceiveTree)! ); } @@ -1022,7 +1022,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNodes(default(IList>), ReceiveRightPadded)!, - ctx.ReceiveValue(default(bool)) + ctx.ReceiveValue(default(bool))! ); } @@ -1034,7 +1034,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -1102,8 +1102,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveValue(default(string))!, - ctx.ReceiveValue(default(JavaType)), - ctx.ReceiveValue(default(JavaType.Variable)) + ctx.ReceiveValue(default(JavaType?))!, + ctx.ReceiveValue(default(JavaType.Variable?))! ); } @@ -1115,7 +1115,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(J.ControlParentheses), ReceiveControlParentheses)!, ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, - ctx.ReceiveNode(default(J.If.Else), ctx.ReceiveTree) + ctx.ReceiveNode(default(J.If.Else?), ctx.ReceiveTree)! ); } @@ -1137,7 +1137,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(J.FieldAccess), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded) + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)! ); } @@ -1149,8 +1149,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, ctx.ReceiveNode(default(J), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(J), ctx.ReceiveTree), - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveNode(default(J?), ctx.ReceiveTree)!, + ctx.ReceiveValue(default(JavaType?))! ); } @@ -1184,7 +1184,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(J.Lambda.Parameters), ctx.ReceiveTree)!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(J), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -1194,7 +1194,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveValue(default(bool)), + ctx.ReceiveValue(default(bool))!, ctx.ReceiveNodes(default(IList>), ReceiveRightPadded)! ); } @@ -1205,9 +1205,9 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveValue(default(object)), - ctx.ReceiveValue(default(string)), - ctx.ReceiveValues(default(IList)), + ctx.ReceiveValue(default(object?))!, + ctx.ReceiveValue(default(string?))!, + ctx.ReceiveValues(default(IList?))!, ctx.ReceiveValue(default(JavaType.Primitive))! ); } @@ -1219,11 +1219,11 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer), + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, - ctx.ReceiveValue(default(JavaType)), - ctx.ReceiveValue(default(JavaType.Method)), - ctx.ReceiveValue(default(JavaType.Variable)) + ctx.ReceiveValue(default(JavaType?))!, + ctx.ReceiveValue(default(JavaType.Method?))!, + ctx.ReceiveValue(default(JavaType.Variable?))! ); } @@ -1235,14 +1235,14 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(J.TypeParameters), ctx.ReceiveTree), - ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree), + ctx.ReceiveNode(default(J.TypeParameters?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(TypeTree?), ctx.ReceiveTree)!, ctx.ReceiveNode(default(J.MethodDeclaration.IdentifierWithAnnotations), ReceiveMethodIdentifierWithAnnotations)!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer), - ctx.ReceiveNode(default(J.Block), ctx.ReceiveTree), - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded), - ctx.ReceiveValue(default(JavaType.Method)) + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveNode(default(J.Block?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, + ctx.ReceiveValue(default(JavaType.Method?))! ); } @@ -1252,11 +1252,11 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded), - ctx.ReceiveNode(default(JContainer), ReceiveContainer), + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)!, + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, - ctx.ReceiveValue(default(JavaType.Method)) + ctx.ReceiveValue(default(JavaType.Method?))! ); } @@ -1266,7 +1266,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveValue(default(string)), + ctx.ReceiveValue(default(string?))!, ctx.ReceiveValue(default(J.Modifier.Types))!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)! ); @@ -1288,10 +1288,10 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree), + ctx.ReceiveNode(default(TypeTree?), ctx.ReceiveTree)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer), - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveValue(default(JavaType?))! ); } @@ -1311,12 +1311,12 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(JRightPadded), ReceiveRightPadded), + ctx.ReceiveNode(default(JRightPadded?), ReceiveRightPadded)!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, - ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree), + ctx.ReceiveNode(default(TypeTree?), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JContainer), ReceiveContainer)!, - ctx.ReceiveNode(default(J.Block), ctx.ReceiveTree), - ctx.ReceiveValue(default(JavaType.Method)) + ctx.ReceiveNode(default(J.Block?), ctx.ReceiveTree)!, + ctx.ReceiveValue(default(JavaType.Method?))! ); } @@ -1349,8 +1349,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(NameTree), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer), - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, + ctx.ReceiveValue(default(JavaType?))! ); } @@ -1390,7 +1390,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(Expression), ctx.ReceiveTree) + ctx.ReceiveNode(default(Expression?), ctx.ReceiveTree)! ); } @@ -1436,7 +1436,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -1456,10 +1456,10 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer), + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)!, ctx.ReceiveNode(default(J.Block), ctx.ReceiveTree)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded) + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)! ); } @@ -1470,7 +1470,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(TypedTree), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(bool)) + ctx.ReceiveValue(default(bool))! ); } @@ -1505,7 +1505,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(JContainer), ReceiveContainer) + ctx.ReceiveNode(default(JContainer?), ReceiveContainer)! ); } @@ -1528,7 +1528,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded)!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)!, - ctx.ReceiveValue(default(JavaType)) + ctx.ReceiveValue(default(JavaType?))! ); } @@ -1540,8 +1540,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, ctx.ReceiveNodes(default(IList), ctx.ReceiveTree)!, - ctx.ReceiveNode(default(TypeTree), ctx.ReceiveTree), - ctx.ReceiveNode(default(Space), ReceiveSpace), + ctx.ReceiveNode(default(TypeTree?), ctx.ReceiveTree)!, + ctx.ReceiveNode(default(Space?), ReceiveSpace)!, ctx.ReceiveNodes(default(IList>), ReceiveLeftPadded)!, ctx.ReceiveNodes(default(IList>), ReceiveRightPadded)! ); @@ -1555,8 +1555,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, ctx.ReceiveNode(default(J.Identifier), ctx.ReceiveTree)!, ctx.ReceiveNodes(default(IList>), ReceiveLeftPadded)!, - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded), - ctx.ReceiveValue(default(JavaType.Variable)) + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, + ctx.ReceiveValue(default(JavaType.Variable?))! ); } @@ -1577,8 +1577,8 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveNode(default(JLeftPadded), ReceiveLeftPadded), - ctx.ReceiveNode(default(NameTree), ctx.ReceiveTree) + ctx.ReceiveNode(default(JLeftPadded?), ReceiveLeftPadded)!, + ctx.ReceiveNode(default(NameTree?), ctx.ReceiveTree)! ); } @@ -1588,7 +1588,7 @@ public Rewrite.Core.Tree Create(string type, ReceiverContext ctx) where T : R ctx.ReceiveValue(default(Guid))!, ctx.ReceiveNode(default(Space), ReceiveSpace)!, ctx.ReceiveNode(default(Markers), ctx.ReceiveMarkers)!, - ctx.ReceiveValue(default(bool)), + ctx.ReceiveValue(default(bool))!, ctx.ReceiveNode(default(Expression), ctx.ReceiveTree)! ); } diff --git a/Rewrite/src/Rewrite.Test.Engine.Remote/RemotingFixture.cs b/Rewrite/src/Rewrite.Test.Engine.Remote/RemotingFixture.cs index 5783baa..12d0eed 100644 --- a/Rewrite/src/Rewrite.Test.Engine.Remote/RemotingFixture.cs +++ b/Rewrite/src/Rewrite.Test.Engine.Remote/RemotingFixture.cs @@ -103,7 +103,10 @@ public RemotingFixture() catch (SocketException) { // start new server process +#if EMBEDDED_SERVER StartJavaRemotingServer(); +#endif + for (var i = 0; i < 5; i++) { try diff --git a/Rewrite/src/Rewrite.Test/RewriteTest.cs b/Rewrite/src/Rewrite.Test/RewriteTest.cs index ebb9ffb..bc46703 100644 --- a/Rewrite/src/Rewrite.Test/RewriteTest.cs +++ b/Rewrite/src/Rewrite.Test/RewriteTest.cs @@ -1,5 +1,7 @@ using System.Reflection; using System.Text; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; using Rewrite.Core; using Rewrite.Core.Quark; using Xunit.Abstractions; @@ -111,8 +113,7 @@ public void RewriteRun(Action spec, params SourceSpec[] sourceSpecs) foreach (var sourceSpecsForParser in sourceSpecsByParser) { - var inputs = - new Dictionary(sourceSpecsForParser.Value.Count); + var inputs = new Dictionary(sourceSpecsForParser.Value.Count); var parser = sourceSpecsForParser.Key.Build(); foreach (var sourceSpec in sourceSpecsForParser.Value) @@ -175,8 +176,7 @@ public void RewriteRun(Action spec, params SourceSpec[] sourceSpecs) sourceSpecIter.MoveNext().Should().BeTrue(); var nextSpec = sourceSpecIter.Current; - markers = nextSpec.Markers.MarkerList.Aggregate(markers, - (current, marker) => current.SetByType(marker)); + markers = nextSpec.Markers.MarkerList.Aggregate(markers, (current, marker) => current.SetByType(marker)); sourceFile = (sourceFile as MutableTree)?.WithMarkers(markers); if (sourceFile != null) @@ -295,3 +295,14 @@ public static string ReadFully(Stream stream, Encoding encoding) return reader.ReadToEnd(); } } +public class WhitespaceRewriter : CSharpSyntaxRewriter +{ + int _i = 0; + public override SyntaxToken VisitToken(SyntaxToken token) + { + var trailingTrivia = token.TrailingTrivia.Where(x => x.IsKind(SyntaxKind.EndOfLineTrivia)); + return base.VisitToken(token + .WithLeadingTrivia(SyntaxFactory.Comment($"/*{_i++}*/")) + .WithTrailingTrivia(trailingTrivia)); + } +} diff --git a/Rewrite/src/Rewrite.Test/StringAssertionExtensions.cs b/Rewrite/src/Rewrite.Test/StringAssertionExtensions.cs index a933a5e..d718a31 100644 --- a/Rewrite/src/Rewrite.Test/StringAssertionExtensions.cs +++ b/Rewrite/src/Rewrite.Test/StringAssertionExtensions.cs @@ -18,7 +18,7 @@ public static void ShouldBeSameAs(this string? newText, string? oldText) Assert.Fail($"Expected string to be the same but are different\n{result}"); } } - public static string? GetDifferences(string oldText, string newText) + public static string? GetDifferences(this string oldText, string newText) { string AddVisibleCrLf(string str) => Regex.Replace(str.Replace("\r", "\u240D").Replace("\n", "\u2424"), "([\u240D\u2424]+)", "$1\n");// + (AnsiColor.ColorizeText("<-EOF", AnsiColor.Foreground(Terminal256ColorCodes.Yellow1C226))); @@ -33,7 +33,7 @@ string AddVisibleCrLf(string str) => var result = new StringBuilder(); var oldLastLineIndex = diff.OldText.Lines.Last(x => x.Type != ChangeType.Imaginary).Position; - var newLastLineIndex = diff.NewText.Lines.Last(x => x.Type != ChangeType.Imaginary).Position; + // var newLastLineIndex = diff.NewText.Lines.Last(x => x.Type != ChangeType.Imaginary).Position; for (int i = 0; i < diff.OldText.Lines.Count ; i++) { var oldLine = diff.OldText.Lines[i]; diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/FindClass.cs b/Rewrite/tests/Rewrite.CSharp.Tests/FindClass.cs index 034224e..67da197 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/FindClass.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/FindClass.cs @@ -18,11 +18,11 @@ public class FindClass([Option(displayName: "Description", description: "A speci return new FindClassVisitor(description); } - private class FindClassVisitor(string? description = null) : JavaVisitor + private class FindClassVisitor(string? description = null) : CSharpVisitor { - public override J VisitClassDeclaration(J.ClassDeclaration classDeclaration, ExecutionContext ctx) + public override Cs VisitClassDeclaration(Cs.ClassDeclaration classDeclaration, ExecutionContext ctx) { - var tree = (MutableTree)base.VisitClassDeclaration(classDeclaration, ctx)!; + var tree = (MutableTree)base.VisitClassDeclaration(classDeclaration, ctx)!; return tree.WithMarkers(tree.Markers.AddIfAbsent(new SearchResult(RandomId(), description))); } } diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/PlayTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/PlayTests.cs index 687159d..18bbc8c 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/PlayTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/PlayTests.cs @@ -35,15 +35,17 @@ public void MyTest() { var root = new CSharpParser.Builder().Build().Parse( """ - public class Foo - { - void Bar() - } + /*1*/ + a/*2*/ + .FirstOrDefault()/*3*/?/*4*/ + ./*5*/GetCustomAttribute(1)/*6*/?/*7*/./*8*/Name; """ ); - var methodDeclaration = root.Descendents().OfType().First(); - var newRoot = root.ReplaceNode(methodDeclaration, methodDeclaration.WithName(methodDeclaration.Name.WithSimpleName("Hello"))); - _output.WriteLine(newRoot.ToString()); + if (root is ParseError) + { + + } + _output.WriteLine(root.ToString()); } [Fact] diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Solutions/SolutionTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Solutions/SolutionTests.cs index 2f11512..81a4aeb 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Solutions/SolutionTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Solutions/SolutionTests.cs @@ -24,41 +24,50 @@ public SolutionTests(ITestOutputHelper output) [Exploratory] public async Task UnknownSyntaxReport() { - var fixtures = Fixtures.Select(x => (solutionOrProjectPath: (AbsolutePath)x[0], root: (AbsolutePath)x[1])); + var fixtures = Fixtures.Select(fixture => (solutionOrProjectPath: (AbsolutePath)fixture[0], root: (AbsolutePath)fixture[1])); var sourceFiles = (await Task.WhenAll(fixtures.Select(async x => - { - var (solutionOrProjectPath, root) = x; - _output.WriteLine(solutionOrProjectPath); - var cancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(1000)).Token; - var solutionParser = new SolutionParser(); - var executionContext = new InMemoryExecutionContext(exception => _output.WriteLine(exception.ToString())); - IEnumerable sourceFiles; - if (solutionOrProjectPath.Extension == ".sln") - { - var solution = await solutionParser.LoadSolutionAsync(solutionOrProjectPath, cancellationToken); - - var projectPaths = solution.Projects.Select(x => x.FilePath!).ToList(); - sourceFiles = projectPaths - .SelectMany(projectPath => solutionParser.ParseProjectSources(solution, projectPath, root, executionContext)); - } - else { - var projectParser = new ProjectParser(solutionOrProjectPath, root); - sourceFiles = projectParser.ParseSourceFiles(); - } - - return sourceFiles; - }))) - .SelectMany(x => x); + var (solutionOrProjectPath, root) = x; + _output.WriteLine(solutionOrProjectPath); + var cancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(1000)).Token; + var solutionParser = new SolutionParser(); + var executionContext = new InMemoryExecutionContext(exception => _output.WriteLine(exception.ToString())); + IEnumerable sourceFiles; + if (solutionOrProjectPath.Extension == ".sln") + { + var solution = await solutionParser.LoadSolutionAsync(solutionOrProjectPath, cancellationToken); + var projectPaths = solution.Projects.Select(x => x.FilePath!).ToList(); + sourceFiles = projectPaths + .SelectMany(projectPath => solutionParser.ParseProjectSources(solution, projectPath, root, executionContext)) + .ToList(); + } + else + { + var projectParser = new ProjectParser(solutionOrProjectPath, root); + sourceFiles = projectParser.ParseSourceFiles(); + } + return sourceFiles.Select(x => (ProjectPath: root, SourceTree: x)).ToList(); + }))) + .SelectMany(x => x) + .ToList(); - var report = sourceFiles - .SelectMany(x => + var brokenIdp = sourceFiles + .Select(x => { - return x.Descendents().OfType(); + var file = x.ProjectPath / x.SourceTree.SourcePath; + var before = File.ReadAllText(file); + var after = x.SourceTree.ToString(); + return (file, before, after, x.SourceTree); }) + .Where(x => x.before != x.after) + .Take(20) + .ToList(); + + var report = sourceFiles.Select(x => x.SourceTree) + .SelectMany(x => x.Descendents().OfType()) .Select(x => x.UnknownSource.Markers.OfType().Select(y => y.TreeType).First()) .GroupBy(x => x) .Select(x => new @@ -72,7 +81,21 @@ public async Task UnknownSyntaxReport() { _output.WriteLine($"{unknownSyntax.Kind}: {unknownSyntax.Count}"); } + _output.WriteLine("============="); + _output.WriteLine($"Broken {brokenIdp.Count} / {sourceFiles.Count} Total ({brokenIdp.Count * 100 / sourceFiles.Count }%)."); + foreach (var (file, before,after, tree) in brokenIdp.Where(x => x.after != null)) + { + _output.WriteLine(file); + if (tree is ParseError) + { + _output.WriteLine(after); + } + else + { + _output.WriteLine(before.GetDifferences(after!)); + } + } } [Theory] diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/AliasTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/AliasTests.cs new file mode 100644 index 0000000..19443ec --- /dev/null +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/AliasTests.cs @@ -0,0 +1,50 @@ +using System.Diagnostics; +using Rewrite.Test.CSharp; +using Rewrite.Test; + +namespace Rewrite.CSharp.Tests.Tree; + +using static Assertions; + +public class AliasTests(ITestOutputHelper output) : RewriteTest(output) +{ + [Fact] + public void AliasInvocation() + { + RewriteRun( + CSharp( + """ + using C = System.Console; + + /*1*/C/*2*/::/*3*/WriteLine("Hello"); + """ + ) + ); + } + + [Fact] + public void AliasMember() + { + RewriteRun( + CSharp( + """ + using C = System.String; + + /*1*/C/*2*/::/*3*/Empty; + """ + ) + ); + } + + [Fact] + public void GlobalAlias() + { + RewriteRun( + CSharp( + """ + global :: Something(); + """ + ) + ); + } +} diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ArrayAccessTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ArrayAccessTests.cs index 0933d28..5bb096e 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ArrayAccessTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ArrayAccessTests.cs @@ -20,7 +20,18 @@ public void OneDimensional() ) ); } - + [Fact] + [KnownBug("Need custom LST")] + public void MultiDimensional() + { + RewriteRun( + CSharp( + """ + return a[0, 1]; + """ + ) + ); + } [Fact] public void Space() { diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ArrayTypeTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ArrayTypeTests.cs index 54ec833..18a4ae5 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ArrayTypeTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ArrayTypeTests.cs @@ -20,13 +20,12 @@ public void OneDimensional() } [Fact] - [KnownBug("Requires new LST type for Cs.ArrayType to support matrix type arrays")] public void TwoDimensional() { RewriteRun( CSharp( """ - int [,] _arr; + int [,] _arr = new int [0,0]; """ ) ); diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/AttributeTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/AttributeTests.cs index 4125f57..fa79760 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/AttributeTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/AttributeTests.cs @@ -64,6 +64,19 @@ public class Foo; ); } + [Fact] + public void NamedProperty() + { + RewriteRun( + CSharp( + """ + [Fact(Skip = "yes")] + class Foo; + """ + ) + ); + } + [Fact] public void CompilationUnit() { diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ClassDeclarationTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ClassDeclarationTests.cs index 91886bf..8527407 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ClassDeclarationTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ClassDeclarationTests.cs @@ -159,4 +159,33 @@ public void TypeParameterWithMultipleConstraints() ) ); } + + [Fact] + public void MultipleTypeConstraints() + { + RewriteRun( + CSharp( + """ + public interface IRepository + where TId : IEquatable + where T : class, ITableObject + { + } + """ + ) + ); + } + + [Fact] + public void ClassDeclarationWithAttribute() + { + RewriteRun( + CSharp( + """ + [Obsolete] + public class Foo; + """ + ) + ); + } } diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ConversionOperatorTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ConversionOperatorTests.cs new file mode 100644 index 0000000..a45cd6c --- /dev/null +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ConversionOperatorTests.cs @@ -0,0 +1,176 @@ +using Rewrite.Test.CSharp; +using Rewrite.Test; + +namespace Rewrite.CSharp.Tests.Tree; + +using static Assertions; + +public class ConversionOperatorTests(ITestOutputHelper output) : RewriteTest(output) +{ + [Fact] + public void ImplicitConversion() + { + RewriteRun( + CSharp( + """ + public class Money + { + public decimal Amount { get; } + + public static implicit operator decimal(Money money) + { + return money.Amount; + } + } + """ + ) + ); + } + + [Fact] + public void ExplicitConversion() + { + RewriteRun( + CSharp( + """ + public class Temperature + { + public double Celsius { get; } + + public static explicit operator int(Temperature temp) + { + return (int)temp.Celsius; + } + } + """ + ) + ); + } + + [Fact] + public void ConversionWithGenerics() + { + RewriteRun( + CSharp( + """ + public class Wrapper + { + private T value; + + public static implicit operator T(Wrapper wrapper) + { + return wrapper.value; + } + } + """ + ) + ); + } + + [Fact] + public void ConversionBetweenClasses() + { + RewriteRun( + CSharp( + """ + public class Dollars + { + public decimal Value { get; } + } + + public class Euros + { + public decimal Value { get; } + + public static explicit operator Dollars(Euros euros) + { + return new Dollars { Value = euros.Value * 1.1m }; + } + } + """ + ) + ); + } + + [Fact] + public void ConversionWithNullable() + { + RewriteRun( + CSharp( + """ + public class OptionalValue + { + public int? Value { get; } + + public static implicit operator int?(OptionalValue optional) + { + return optional?.Value; + } + } + """ + ) + ); + } + + [Fact] + public void ConversionOperatorWithAttributes() + { + RewriteRun( + CSharp( + """ + public class Vector + { + public double X { get; } + public double Y { get; } + + [Obsolete("Use explicit cast instead")] + public static implicit operator double(Vector vector) + { + return Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y); + } + } + """ + ) + ); + } + + [Fact] + public void ConversionWithConstraints() + { + RewriteRun( + CSharp( + """ + public class Container where T : struct + { + private T value; + + public static explicit operator T(Container container) + { + return container.value; + } + } + """ + ) + ); + } + + + [Fact] + public void MultipleConversionOperators() + { + RewriteRun( + CSharp( + """ + public class Distance + { + private readonly double _meters; + + public static implicit operator double(Distance d) => d._meters; + public static explicit operator int(Distance d) => (int)d._meters; + public static explicit operator float(Distance d) => (float)d._meters; + } + """ + ) + ); + } +} diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DefaultExpressionTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DefaultExpressionTests.cs index 26f996f..b0612a8 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DefaultExpressionTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DefaultExpressionTests.cs @@ -24,7 +24,7 @@ public void DefaultOperator() RewriteRun( CSharp( @" - int i = default ( int ); + int i = default ( int? ); " ) ); diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DelegateDeclarationTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DelegateDeclarationTests.cs new file mode 100644 index 0000000..e9783c5 --- /dev/null +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DelegateDeclarationTests.cs @@ -0,0 +1,120 @@ +using Rewrite.Test.CSharp; +using Rewrite.Test; + +namespace Rewrite.CSharp.Tests.Tree; + +using static Assertions; + +public class DelegateDeclarationTests(ITestOutputHelper output) : RewriteTest(output) +{ + [Fact] + public void SimpleDelegateDeclaration() + { + RewriteRun( + CSharp( + """ + public delegate void SimpleDelegate(); + """ + ) + ); + } + + [Fact] + public void DelegateWithParameters() + { + RewriteRun( + CSharp( + """ + public delegate int CalculateDelegate(int x, int y); + """ + ) + ); + } + + [Fact] + public void GenericDelegate() + { + RewriteRun( + CSharp( + """ + public delegate T GenericDelegate(T input); + """ + ) + ); + } + + [Fact] + public void DelegateWithMultipleTypeParameters() + { + RewriteRun( + CSharp( + """ + public delegate TResult TransformDelegate(TInput input); + """ + ) + ); + } + + [Fact] + public void DelegateWithConstraints() + { + RewriteRun( + CSharp( + """ + public delegate T ConstrainedDelegate() where T : class, new(); + """ + ) + ); + } + + [Fact] + public void DelegateWithNullableParameter() + { + RewriteRun( + CSharp( + """ + public delegate void NullableDelegate(string? text); + """ + ) + ); + } + + [Fact] + public void DelegateWithRefParameter() + { + RewriteRun( + CSharp( + """ + public delegate void RefDelegate(ref int number); + """ + ) + ); + } + + [Fact] + public void DelegateWithOutParameter() + { + RewriteRun( + CSharp( + """ + public delegate bool TryParseDelegate(string input, out int result); + """ + ) + ); + } + + [Fact] + public void NestedDelegate() + { + RewriteRun( + CSharp( + """ + public class Container + { + private delegate void NestedDelegate(int x); + } + """ + ) + ); + } +} diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DestructorTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DestructorTests.cs new file mode 100644 index 0000000..2cd9b35 --- /dev/null +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DestructorTests.cs @@ -0,0 +1,100 @@ +using Rewrite.Test.CSharp; +using Rewrite.RewriteCSharp.Tree; +using Rewrite.Test; + +namespace Rewrite.CSharp.Tests.Tree; + +using static Assertions; + +public class DestructorTests(ITestOutputHelper output) : RewriteTest(output) +{ + [Fact] + public void BasicDestructor() + { + RewriteRun( + CSharp(""" + public class A + { + ~A() + { + } + } + """)); + } + + [Fact] + public void DestructorWithBody() + { + RewriteRun( + CSharp(""" + class Resource + { + ~Resource() + { + Dispose(false); + GC.SuppressFinalize(this); + } + } + """)); + } + + [Fact] + public void PartialDestructor() + { + RewriteRun( + CSharp(""" + partial class C + { + ~C() + { + } + } + """)); + } + + [Fact] + public void NestedClassDestructor() + { + RewriteRun( + CSharp(""" + public class Outer + { + private class Inner + { + ~Inner() + { + } + } + } + """)); + } + + [Fact] + public void DestructorWithAttributes() + { + RewriteRun( + CSharp(""" + public class D + { + [Conditional] + ~D() + { + } + } + """)); + } + + [Fact] + public void ExpressionBodiedDestructor() + { + RewriteRun( + CSharp(""" + public class E + { + ~E() => Dispose(); + } + """)); + } +} + + diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DirectiveTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DirectiveTests.cs new file mode 100644 index 0000000..4340708 --- /dev/null +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DirectiveTests.cs @@ -0,0 +1,35 @@ +using Rewrite.Test.CSharp; +using Rewrite.Test; + +namespace Rewrite.CSharp.Tests.Tree; + +using static Assertions; + +public class DirectiveTests(ITestOutputHelper output) : RewriteTest(output) +{ + [Fact] + void ConditionalPragma() + { + RewriteRun( + CSharp( + """ + #if NET40 + a(); + #endif + """ + ) + ); + } + [Fact] + void NullableDirective() + { + RewriteRun( + CSharp( + """ + #nullable enable + int a; + """ + ) + ); + } +} diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DoWhileTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DoWhileTests.cs new file mode 100644 index 0000000..f003e5d --- /dev/null +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/DoWhileTests.cs @@ -0,0 +1,35 @@ +using System.Diagnostics; +using Rewrite.Test.CSharp; +using Rewrite.Test; + +namespace Rewrite.CSharp.Tests.Tree; + +using static Assertions; + +public class DoWhileTests(ITestOutputHelper output) : RewriteTest(output) +{ + [Fact] + public void BasicDoWhile() + { + RewriteRun( + CSharp( + """ + do { } while ( true ) ; + """ + ) + ); + } + + [Fact] + public void NonBlockStatement() + { + RewriteRun( + CSharp( + """ + do Console.WriteLine("test"); while ( true ) ; + """ + ) + ); + } + +} diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/EnumDeclarationTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/EnumDeclarationTests.cs index acd0471..ebcb76c 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/EnumDeclarationTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/EnumDeclarationTests.cs @@ -39,4 +39,41 @@ public enum A : int ) ); } + + [Fact] + public void EnumWithValues() + { + RewriteRun( + CSharp( + """ + [Test] + public enum A + { + a = 1, + b + } + """ + ) + ); + } + + + [Fact] + public void EnumWithAttributes() + { + RewriteRun( + CSharp( + """ + [Test] + public enum A + { + [Value(1)] + a, + [Value(2)] + b + } + """ + ) + ); + } } diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ForEachLoopTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ForEachLoopTests.cs index 0361e03..307452a 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ForEachLoopTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ForEachLoopTests.cs @@ -63,4 +63,18 @@ void MultiVariableForEachLoop() ) ); } + + [Fact] + void ForEachAwait() + { + RewriteRun( + CSharp( + """ + await foreach (var a in b) + { + + } + """ + )); + } } diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ForLoopTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ForLoopTests.cs index 3d9273b..c1175b8 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ForLoopTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/ForLoopTests.cs @@ -7,6 +7,7 @@ namespace Rewrite.CSharp.Tests.Tree; public class ForLoopTests(ITestOutputHelper output) : RewriteTest(output) { + [Fact] void ForLoopMultipleInit() { diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/IndexerTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/IndexerTests.cs new file mode 100644 index 0000000..e887500 --- /dev/null +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/IndexerTests.cs @@ -0,0 +1,129 @@ +using Rewrite.Test.CSharp; +using Rewrite.RewriteCSharp.Tree; +using Rewrite.Test; + +namespace Rewrite.CSharp.Tests.Tree; + +using static Assertions; + +public class IndexerTests(ITestOutputHelper output) : RewriteTest(output) +{ + [Fact] + public void BasicIndexer() + { + RewriteRun( + CSharp(""" + class A + { + public int this[int index] + { + get { return 0; } + set { } + } + } + """)); + } + + [Fact] + public void IndexerWithMultipleParameters() + { + RewriteRun( + CSharp(""" + class M + { + abstract int this[int r, int c] + { + get; + set; + } + } + """)); + } + + [Fact] + public void ReadOnlyIndexer() + { + RewriteRun( + CSharp(""" + class ReadOnlyList + { + public string this[int index] => items[index]; + } + """)); + } + + [Fact] + public void IndexerWithAttributes() + { + RewriteRun( + CSharp(""" + class C + { + [Obsolete] + public object this[string name] + { + get { return null; } + } + } + """)); + } + + [Fact] + public void InterfaceIndexer() + { + RewriteRun( + CSharp(""" + interface IContainer + { + string this[int index] { get; set; } + } + """)); + } + + [Fact] + public void IndexerWithModifiers() + { + RewriteRun( + CSharp(""" + class Collection + { + protected internal virtual string this[int i] + { + get { return null; } + private set { } + } + } + """)); + } + + [Fact] + public void AutoImplementedIndexer() + { + RewriteRun( + CSharp(""" + class SimpleList + { + public double this[int i] { get; set; } + } + """)); + } + + [Fact] + public void ExpressionBodiedIndexer() + { + RewriteRun( + CSharp(""" + class Container + { + private string[] items; + public string this[int i] + { + get => items[i]; + set => items[i] = value; + } + } + """)); + } +} + + diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/InterfaceDeclarationTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/InterfaceDeclarationTests.cs index 02c2938..10930e4 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/InterfaceDeclarationTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/InterfaceDeclarationTests.cs @@ -34,10 +34,10 @@ interface Baz : Foo; ", spec => spec.AfterRecipe = cu => { - var bar = cu.Descendents().OfType().First(x => x.Name == "Baz"); - bar.DeclarationKind.Should().Be(J.ClassDeclaration.Kind.Types.Interface); - bar.Extends.Should().BeNull(); - bar.Implements.Should().NotBeNull(); + var bar = cu.Descendents().OfType().First(x => x.Name == "Baz"); + bar.Kind.KindType.Should().Be(J.ClassDeclaration.Kind.Types.Interface); + bar.Extendings.Should().BeNull(); + bar.Implementings.Should().NotBeNull(); } ) ); @@ -55,10 +55,10 @@ interface Baz : Foo, Bar; ", spec => spec.AfterRecipe = cu => { - var bar = cu.Descendents().OfType().First(x => x.Name == "Baz"); - bar.DeclarationKind.Should().Be(J.ClassDeclaration.Kind.Types.Interface); - bar.Extends.Should().BeNull(); - bar.Implements.Should().NotBeNull(); + var bar = cu.Descendents().OfType().First(x => x.Name == "Baz"); + bar.Kind.KindType.Should().Be(J.ClassDeclaration.Kind.Types.Interface); + bar.Extendings.Should().BeNull(); + bar.Implementings.Should().NotBeNull(); } ) ); @@ -107,4 +107,17 @@ interface Foo ) ); } + + [Fact] + public void InterfaceWithWithoutBodyWithTypeParamsInOut() + { + RewriteRun( + CSharp( + @" + // comment + interface Foo; + " + ) + ); + } } diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/IsExpressionPatternTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/IsExpressionPatternTests.cs index ef6cb6b..5059751 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/IsExpressionPatternTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/IsExpressionPatternTests.cs @@ -139,4 +139,16 @@ private void IsArray() ) ); } + + [Fact] + private void PropertyNameNested() + { + RewriteRun( + CSharp( + """ + return organization is { Permissions.ManageUsers: true }; + """ + ) + ); + } } diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/LinqTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/LinqTests.cs new file mode 100644 index 0000000..aee4b16 --- /dev/null +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/LinqTests.cs @@ -0,0 +1,124 @@ +using FluentAssertions; +using Rewrite.Test.CSharp; +using Rewrite.RewriteJava.Tree; +using Rewrite.Test; + +namespace Rewrite.CSharp.Tests.Tree; + +using static Assertions; + +public class LinqTests(ITestOutputHelper output) : RewriteTest(output) +{ + [Fact] + public void SimpleSelectClause() + { + RewriteRun( + CSharp( + """ + var query = from x in numbers + select x; + """ + ) + ); + } + + [Fact] + public void SelectWithProjection() + { + RewriteRun( + CSharp( + """ + var query = from person in people + select new { Name = person.Name, Age = person.Age }; + """ + ) + ); + } + + [Fact] + public void SimpleGroupBy() + { + RewriteRun( + CSharp( + """ + var query = from p in people + group p by p.State; + """ + ) + ); + } + + [Fact] + public void GroupByWithProjection() + { + RewriteRun( + CSharp( + """ + var query = from p in people + group p by new { p.State, p.City }; + """ + ) + ); + } + + [Fact] + public void SimpleOrderBy() + { + RewriteRun( + CSharp( + """ + var query = from p in people + orderby p.Age + select p; + """ + ) + ); + } + + [Fact] + public void OrderByWithDirection() + { + RewriteRun( + CSharp( + """ + var query = from p in people + orderby p.Age descending + select p; + """ + ) + ); + } + + [Fact] + public void MultipleOrderings() + { + RewriteRun( + CSharp( + """ + var query = from p in people + orderby p.LastName ascending, p.FirstName ascending, p.Age descending + select p; + """ + ) + ); + } + + [Fact] + public void ComplexLinqQuery() + { + RewriteRun( + CSharp( + """ + var query = from p in people + where p.Age > 21 + group p by p.State into g + orderby g.Key + select new { + State = g.Key, + Count = g.Count() + }; + """ + ) + ); + } +} diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/MethodDeclarationTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/MethodDeclarationTests.cs index bfdbb43..7e0b053 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/MethodDeclarationTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/MethodDeclarationTests.cs @@ -33,6 +33,48 @@ public class Foo ); } + [Fact] + public void MethodDeclarationWithDefaultParameters() + { + RewriteRun( + CSharp( + """ + public class C + { + M ( int i = 1 ) + { + } + } + """, + spec => spec.AfterRecipe = cu => + { + var ctor = cu.Descendents().OfType().First(); + ctor.Parameters.Should().HaveCount(1); + ctor.Modifiers.Should().BeEmpty(); + ctor.Body.Should().NotBeNull(); + } + ) + ); + } + + [Fact] + public void MethodWithAttributes() + { + RewriteRun( + CSharp( + """ + public class Foo + { + [Obsolete] + Foo(int i) + { + } + } + """ + ) + ); + } + [Fact] public void ConstructorDelegation() { @@ -54,7 +96,6 @@ public class Foo } [Fact] - [KnownBug("Cannot perform the requested operation, the next CBOR data item is of major type '3'.")] public void ConstructorDelegation2() { RewriteRun(CSharp( @@ -127,7 +168,7 @@ public void M(bool b = true) """, spec => spec.AfterRecipe = cu => { - var ctor = cu.Descendents().OfType().First(); + var ctor = cu.Descendents().OfType().First(); ctor.Parameters.Should().HaveCount(1); var vd = (ctor.Parameters[0] as J.VariableDeclarations)!; vd.Variables.Should().HaveCount(1); @@ -173,6 +214,24 @@ public override string ToString() ); } + [Fact] + public void ExplicitInterfaceImplementation() + { + RewriteRun( + CSharp( + """ + public abstract class C + { + object ICloneable.Clone() => Clone(); + } + """ + ) + ); + } + + + + [Fact] public void ArrowSyntaxMethodDeclaration() { @@ -195,16 +254,9 @@ public void ArrowLocalFunctionDeclaration() RewriteRun( CSharp( @" - public class Foo + void M() { - public static int LocalFunctionFactorial(int n) - { - return nthFactorial(n); - - int nthFactorial(int number) => number < 2 - ? 1 - : number * nthFactorial(number - 1); - } + int LM(int number) => number < 2 ? 1 : 2; } " ) diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/MethodInvocationTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/MethodInvocationTests.cs index 51ae7c3..997ce42 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/MethodInvocationTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/MethodInvocationTests.cs @@ -38,6 +38,18 @@ public class T ); } + [Fact] + public void InvocationSpacing() + { + RewriteRun( + CSharp( + @" + a.GetField . GetCustomAttribute(); + " + ) + ); + } + [Fact] public void InvocationWithNamedParameters() { diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/NullSafeExpressionTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/NullSafeExpressionTests.cs index 36ece37..ac8065e 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/NullSafeExpressionTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/NullSafeExpressionTests.cs @@ -125,4 +125,17 @@ public static void Method(string p) ) ); } + + [Fact] + public void MultiLevelWithSpaces() + { + var src = CSharp( + """ + /*1*/a ? . + b() ? . + c() . + d; + + """); + } } diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/PropertyDeclarationTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/PropertyDeclarationTests.cs index 87a41ff..6a5025c 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/PropertyDeclarationTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/PropertyDeclarationTests.cs @@ -89,21 +89,17 @@ void ExpressionBodyAccessorsPropertyDeclaration() RewriteRun( CSharp( """ - public class Date + class C { - private int _month = 7; // Backing store + int _m; - public int Month + public int M { - get => _month /*space*/ ; // comment - set// comment store - /*123*/ { // comment store - if ((value > 0) && (value < 13)) - { - _month = value; - /* comment store*/ } // comment store - } // comment store - // comment store + get => _m; + set + { + _m = value; + } } } """ @@ -117,10 +113,10 @@ void ExpressionBodyPropertyDeclaration() RewriteRun( CSharp( """ - class Manager + class M { - private string _name; - public string Name => _name != null ? _name : "NA" /*space*/ ; /// commment + string _n; + public string Name => _n != null ? _n : "NA" ; } """ ) diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/TupleTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/TupleTests.cs index 4673a23..d06f6fa 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/TupleTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/TupleTests.cs @@ -83,4 +83,20 @@ void M() var lst = src.Parse(); lst.ToString().ShouldBeSameAs(src.Before); } + + [Fact] + public void TupleWithNullables() + { + RewriteRun(CSharp( + """ + public class T + { + void M() + { + (int? x, int y) myTuple; + } + } + """ + )); + } } diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/UnaryTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/UnaryTests.cs index ac55de0..3d62b17 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/UnaryTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/UnaryTests.cs @@ -58,4 +58,40 @@ class Test { ) ); } + + [Fact] + void IndexExpression() + { + RewriteRun( + CSharp( + """ + a[^1]; + """ + ) + ); + } + + [Fact] + void AddressOfExpression() + { + RewriteRun( + CSharp( + """ + var a = &a; + """ + ) + ); + } + + [Fact] + void PointerType() + { + RewriteRun( + CSharp( + """ + int* a; + """ + ) + ); + } } diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/UsingTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/UsingTests.cs index 83b952d..2671fef 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Tree/UsingTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Tree/UsingTests.cs @@ -1,5 +1,3 @@ -using System.Diagnostics; -using Microsoft.CodeAnalysis.CSharp.Syntax; using Rewrite.Test.CSharp; using Rewrite.Test; @@ -7,23 +5,17 @@ namespace Rewrite.CSharp.Tests.Tree; using static Assertions; -public class UsingTests(ITestOutputHelper output) : RewriteTest(output) +public class UsingStatementTests(ITestOutputHelper output) : RewriteTest(output) { [Fact] - public void Simple() + public void BasicUsing() { RewriteRun( CSharp( """ - class Foo + using (var file = File.OpenRead("test.txt")) { - void M() - { - using (System.IO.StreamWriter file = new System.IO.StreamWriter("/path/to/your/file.txt", true)) - { - file.WriteLine("Hello World"); - } - } + // do something } """ ) @@ -31,22 +23,28 @@ void M() } [Fact] - public void Multiple() + public void UsingDeclaration() { RewriteRun( CSharp( """ - using System.IO; + using var file = File.OpenRead("test.txt"); + // rest of the code + """ + ) + ); + } - class Foo + [Fact] + public void MultipleResources() + { + RewriteRun( + CSharp( + """ + using (var reader = new StreamReader("test.txt")) + using (var writer = new StreamWriter("output.txt")) { - void M() - { - using (StreamReader reader1 = new StreamReader("file1.txt"), reader2 = new StreamReader("file2.txt")) - { - // code - } - } + // do something } """ ) @@ -54,47 +52,107 @@ void M() } [Fact] - public void Multiple2() + public void UsingWithoutBraces() { - var src = CSharp( - """ - using System.IO; + RewriteRun( + CSharp( + """ + using (var stream = new MemoryStream()) + stream.WriteByte(0); + """ + ) + ); + } - class Foo - { - void M() + [Fact] + public void NestedUsing() + { + RewriteRun( + CSharp( + """ + using (var outer = new MemoryStream()) { - using /*1%*/ (/*2%*/ StreamReader reader1 = new StreamReader("file1.txt") /*3%*/ ) - using (StreamReader reader2 = new StreamReader("file2.txt")) /*4%*/ + using (var inner = new MemoryStream()) { - // code + } } - } - """); + """ + ) + ); + } - var lst = src.Parse(); - lst.ToString().ShouldBeSameAs(src.Before); - // _output.WriteLine(lst.RenderLstTree()); + [Fact] + public void UsingWithMultipleDeclarations() + { + RewriteRun( + CSharp( + """ + using (Stream stream = File.OpenRead("input.txt"), output = File.Create("output.txt")) + { + // do something with both streams + } + """ + ) + ); } [Fact] - public void NoBraces() + public void UsingWithExplicitType() { RewriteRun( CSharp( """ - using System.IO; + using (Stream stream = new MemoryStream()) + { + // explicit type declaration + } + """ + ) + ); + } - class Foo + [Fact] + public void UsingWithNull() + { + RewriteRun( + CSharp( + """ + using (Stream stream = null) { - void M() - { - using /*1%*/ StreamReader reader = new StreamReader("file1.txt")/*2%*/ ; - } + // using with null resource } """ ) ); } + + [Fact] + public void UsingWithAwait() + { + RewriteRun( + CSharp( + """ + await using (var resource = await GetResourceAsync()) + { + // async operations + } + """ + ) + ); + } + + [Fact] + public void UsingDeclarationWithAwait() + { + RewriteRun( + CSharp( + """ + int a; + await using var resource = await GetResourceAsync(); + // rest of async code + """ + ) + ); + } } diff --git a/rewrite-csharp-remote/src/main/java/org/openrewrite/csharp/remote/CSharpReceiver.java b/rewrite-csharp-remote/src/main/java/org/openrewrite/csharp/remote/CSharpReceiver.java index 80468dd..13445f1 100644 --- a/rewrite-csharp-remote/src/main/java/org/openrewrite/csharp/remote/CSharpReceiver.java +++ b/rewrite-csharp-remote/src/main/java/org/openrewrite/csharp/remote/CSharpReceiver.java @@ -213,7 +213,7 @@ public Cs.ExpressionStatement visitExpressionStatement(Cs.ExpressionStatement ex expressionStatement = expressionStatement.withId(ctx.receiveNonNullValue(expressionStatement.getId(), UUID.class)); expressionStatement = expressionStatement.withPrefix(ctx.receiveNonNullNode(expressionStatement.getPrefix(), CSharpReceiver::receiveSpace)); expressionStatement = expressionStatement.withMarkers(ctx.receiveNonNullNode(expressionStatement.getMarkers(), ctx::receiveMarkers)); - expressionStatement = expressionStatement.withExpression(ctx.receiveNonNullNode(expressionStatement.getExpression(), ctx::receiveTree)); + expressionStatement = expressionStatement.getPadding().withExpression(ctx.receiveNonNullNode(expressionStatement.getPadding().getExpression(), CSharpReceiver::receiveRightPaddedTree)); return expressionStatement; } @@ -330,8 +330,17 @@ public Cs.ClassDeclaration visitClassDeclaration(Cs.ClassDeclaration classDeclar classDeclaration = classDeclaration.withId(ctx.receiveNonNullValue(classDeclaration.getId(), UUID.class)); classDeclaration = classDeclaration.withPrefix(ctx.receiveNonNullNode(classDeclaration.getPrefix(), CSharpReceiver::receiveSpace)); classDeclaration = classDeclaration.withMarkers(ctx.receiveNonNullNode(classDeclaration.getMarkers(), ctx::receiveMarkers)); - classDeclaration = classDeclaration.withClassDeclarationCore(ctx.receiveNonNullNode(classDeclaration.getClassDeclarationCore(), ctx::receiveTree)); - classDeclaration = classDeclaration.getPadding().withTypeParameterConstraintClauses(ctx.receiveNonNullNode(classDeclaration.getPadding().getTypeParameterConstraintClauses(), CSharpReceiver::receiveContainer)); + classDeclaration = classDeclaration.withAttributeList(ctx.receiveNonNullNodes(classDeclaration.getAttributeList(), ctx::receiveTree)); + classDeclaration = classDeclaration.withModifiers(ctx.receiveNonNullNodes(classDeclaration.getModifiers(), ctx::receiveTree)); + classDeclaration = classDeclaration.getPadding().withKind(ctx.receiveNonNullNode(classDeclaration.getPadding().getKind(), CSharpReceiver::receiveClassDeclarationKind)); + classDeclaration = classDeclaration.withName(ctx.receiveNonNullNode(classDeclaration.getName(), ctx::receiveTree)); + classDeclaration = classDeclaration.getPadding().withTypeParameters(ctx.receiveNode(classDeclaration.getPadding().getTypeParameters(), CSharpReceiver::receiveContainer)); + classDeclaration = classDeclaration.getPadding().withPrimaryConstructor(ctx.receiveNode(classDeclaration.getPadding().getPrimaryConstructor(), CSharpReceiver::receiveContainer)); + classDeclaration = classDeclaration.getPadding().withExtendings(ctx.receiveNode(classDeclaration.getPadding().getExtendings(), CSharpReceiver::receiveLeftPaddedTree)); + classDeclaration = classDeclaration.getPadding().withImplementings(ctx.receiveNode(classDeclaration.getPadding().getImplementings(), CSharpReceiver::receiveContainer)); + classDeclaration = classDeclaration.withBody(ctx.receiveNode(classDeclaration.getBody(), ctx::receiveTree)); + classDeclaration = classDeclaration.getPadding().withTypeParameterConstraintClauses(ctx.receiveNode(classDeclaration.getPadding().getTypeParameterConstraintClauses(), CSharpReceiver::receiveContainer)); + classDeclaration = classDeclaration.withType(ctx.receiveValue(classDeclaration.getType(), JavaType.FullyQualified.class)); return classDeclaration; } @@ -340,7 +349,15 @@ public Cs.MethodDeclaration visitMethodDeclaration(Cs.MethodDeclaration methodDe methodDeclaration = methodDeclaration.withId(ctx.receiveNonNullValue(methodDeclaration.getId(), UUID.class)); methodDeclaration = methodDeclaration.withPrefix(ctx.receiveNonNullNode(methodDeclaration.getPrefix(), CSharpReceiver::receiveSpace)); methodDeclaration = methodDeclaration.withMarkers(ctx.receiveNonNullNode(methodDeclaration.getMarkers(), ctx::receiveMarkers)); - methodDeclaration = methodDeclaration.withMethodDeclarationCore(ctx.receiveNonNullNode(methodDeclaration.getMethodDeclarationCore(), ctx::receiveTree)); + methodDeclaration = methodDeclaration.withAttributes(ctx.receiveNonNullNodes(methodDeclaration.getAttributes(), ctx::receiveTree)); + methodDeclaration = methodDeclaration.withModifiers(ctx.receiveNonNullNodes(methodDeclaration.getModifiers(), ctx::receiveTree)); + methodDeclaration = methodDeclaration.getPadding().withTypeParameters(ctx.receiveNode(methodDeclaration.getPadding().getTypeParameters(), CSharpReceiver::receiveContainer)); + methodDeclaration = methodDeclaration.withReturnTypeExpression(ctx.receiveNonNullNode(methodDeclaration.getReturnTypeExpression(), ctx::receiveTree)); + methodDeclaration = methodDeclaration.getPadding().withExplicitInterfaceSpecifier(ctx.receiveNode(methodDeclaration.getPadding().getExplicitInterfaceSpecifier(), CSharpReceiver::receiveRightPaddedTree)); + methodDeclaration = methodDeclaration.withName(ctx.receiveNonNullNode(methodDeclaration.getName(), ctx::receiveTree)); + methodDeclaration = methodDeclaration.getPadding().withParameters(ctx.receiveNonNullNode(methodDeclaration.getPadding().getParameters(), CSharpReceiver::receiveContainer)); + methodDeclaration = methodDeclaration.withBody(ctx.receiveNode(methodDeclaration.getBody(), ctx::receiveTree)); + methodDeclaration = methodDeclaration.withMethodType(ctx.receiveValue(methodDeclaration.getMethodType(), JavaType.Method.class)); methodDeclaration = methodDeclaration.getPadding().withTypeParameterConstraintClauses(ctx.receiveNonNullNode(methodDeclaration.getPadding().getTypeParameterConstraintClauses(), CSharpReceiver::receiveContainer)); return methodDeclaration; } @@ -351,7 +368,7 @@ public Cs.UsingStatement visitUsingStatement(Cs.UsingStatement usingStatement, R usingStatement = usingStatement.withPrefix(ctx.receiveNonNullNode(usingStatement.getPrefix(), CSharpReceiver::receiveSpace)); usingStatement = usingStatement.withMarkers(ctx.receiveNonNullNode(usingStatement.getMarkers(), ctx::receiveMarkers)); usingStatement = usingStatement.withAwaitKeyword(ctx.receiveNode(usingStatement.getAwaitKeyword(), ctx::receiveTree)); - usingStatement = usingStatement.getPadding().withExpression(ctx.receiveNonNullNode(usingStatement.getPadding().getExpression(), CSharpReceiver::receiveContainer)); + usingStatement = usingStatement.getPadding().withExpression(ctx.receiveNonNullNode(usingStatement.getPadding().getExpression(), CSharpReceiver::receiveLeftPaddedTree)); usingStatement = usingStatement.withStatement(ctx.receiveNonNullNode(usingStatement.getStatement(), ctx::receiveTree)); return usingStatement; } @@ -479,8 +496,7 @@ public Cs.DestructorDeclaration visitDestructorDeclaration(Cs.DestructorDeclarat destructorDeclaration = destructorDeclaration.withId(ctx.receiveNonNullValue(destructorDeclaration.getId(), UUID.class)); destructorDeclaration = destructorDeclaration.withPrefix(ctx.receiveNonNullNode(destructorDeclaration.getPrefix(), CSharpReceiver::receiveSpace)); destructorDeclaration = destructorDeclaration.withMarkers(ctx.receiveNonNullNode(destructorDeclaration.getMarkers(), ctx::receiveMarkers)); - destructorDeclaration = destructorDeclaration.withInitializer(ctx.receiveNode(destructorDeclaration.getInitializer(), ctx::receiveTree)); - destructorDeclaration = destructorDeclaration.withConstructorCore(ctx.receiveNonNullNode(destructorDeclaration.getConstructorCore(), ctx::receiveTree)); + destructorDeclaration = destructorDeclaration.withMethodCore(ctx.receiveNonNullNode(destructorDeclaration.getMethodCore(), ctx::receiveTree)); return destructorDeclaration; } @@ -826,6 +842,225 @@ public Cs.RangeExpression visitRangeExpression(Cs.RangeExpression rangeExpressio return rangeExpression; } + @Override + public Cs.QueryExpression visitQueryExpression(Cs.QueryExpression queryExpression, ReceiverContext ctx) { + queryExpression = queryExpression.withId(ctx.receiveNonNullValue(queryExpression.getId(), UUID.class)); + queryExpression = queryExpression.withPrefix(ctx.receiveNonNullNode(queryExpression.getPrefix(), CSharpReceiver::receiveSpace)); + queryExpression = queryExpression.withMarkers(ctx.receiveNonNullNode(queryExpression.getMarkers(), ctx::receiveMarkers)); + queryExpression = queryExpression.withFromClause(ctx.receiveNonNullNode(queryExpression.getFromClause(), ctx::receiveTree)); + queryExpression = queryExpression.withBody(ctx.receiveNonNullNode(queryExpression.getBody(), ctx::receiveTree)); + return queryExpression; + } + + @Override + public Cs.QueryBody visitQueryBody(Cs.QueryBody queryBody, ReceiverContext ctx) { + queryBody = queryBody.withId(ctx.receiveNonNullValue(queryBody.getId(), UUID.class)); + queryBody = queryBody.withPrefix(ctx.receiveNonNullNode(queryBody.getPrefix(), CSharpReceiver::receiveSpace)); + queryBody = queryBody.withMarkers(ctx.receiveNonNullNode(queryBody.getMarkers(), ctx::receiveMarkers)); + queryBody = queryBody.withClauses(ctx.receiveNonNullNodes(queryBody.getClauses(), ctx::receiveTree)); + queryBody = queryBody.withSelectOrGroup(ctx.receiveNode(queryBody.getSelectOrGroup(), ctx::receiveTree)); + queryBody = queryBody.withContinuation(ctx.receiveNode(queryBody.getContinuation(), ctx::receiveTree)); + return queryBody; + } + + @Override + public Cs.FromClause visitFromClause(Cs.FromClause fromClause, ReceiverContext ctx) { + fromClause = fromClause.withId(ctx.receiveNonNullValue(fromClause.getId(), UUID.class)); + fromClause = fromClause.withPrefix(ctx.receiveNonNullNode(fromClause.getPrefix(), CSharpReceiver::receiveSpace)); + fromClause = fromClause.withMarkers(ctx.receiveNonNullNode(fromClause.getMarkers(), ctx::receiveMarkers)); + fromClause = fromClause.withTypeIdentifier(ctx.receiveNode(fromClause.getTypeIdentifier(), ctx::receiveTree)); + fromClause = fromClause.getPadding().withIdentifier(ctx.receiveNonNullNode(fromClause.getPadding().getIdentifier(), CSharpReceiver::receiveRightPaddedTree)); + fromClause = fromClause.withExpression(ctx.receiveNonNullNode(fromClause.getExpression(), ctx::receiveTree)); + return fromClause; + } + + @Override + public Cs.LetClause visitLetClause(Cs.LetClause letClause, ReceiverContext ctx) { + letClause = letClause.withId(ctx.receiveNonNullValue(letClause.getId(), UUID.class)); + letClause = letClause.withPrefix(ctx.receiveNonNullNode(letClause.getPrefix(), CSharpReceiver::receiveSpace)); + letClause = letClause.withMarkers(ctx.receiveNonNullNode(letClause.getMarkers(), ctx::receiveMarkers)); + letClause = letClause.getPadding().withIdentifier(ctx.receiveNonNullNode(letClause.getPadding().getIdentifier(), CSharpReceiver::receiveRightPaddedTree)); + letClause = letClause.withExpression(ctx.receiveNonNullNode(letClause.getExpression(), ctx::receiveTree)); + return letClause; + } + + @Override + public Cs.JoinClause visitJoinClause(Cs.JoinClause joinClause, ReceiverContext ctx) { + joinClause = joinClause.withId(ctx.receiveNonNullValue(joinClause.getId(), UUID.class)); + joinClause = joinClause.withPrefix(ctx.receiveNonNullNode(joinClause.getPrefix(), CSharpReceiver::receiveSpace)); + joinClause = joinClause.withMarkers(ctx.receiveNonNullNode(joinClause.getMarkers(), ctx::receiveMarkers)); + joinClause = joinClause.getPadding().withIdentifier(ctx.receiveNonNullNode(joinClause.getPadding().getIdentifier(), CSharpReceiver::receiveRightPaddedTree)); + joinClause = joinClause.getPadding().withInExpression(ctx.receiveNonNullNode(joinClause.getPadding().getInExpression(), CSharpReceiver::receiveRightPaddedTree)); + joinClause = joinClause.getPadding().withLeftExpression(ctx.receiveNonNullNode(joinClause.getPadding().getLeftExpression(), CSharpReceiver::receiveRightPaddedTree)); + joinClause = joinClause.withRightExpression(ctx.receiveNonNullNode(joinClause.getRightExpression(), ctx::receiveTree)); + joinClause = joinClause.getPadding().withInto(ctx.receiveNode(joinClause.getPadding().getInto(), CSharpReceiver::receiveLeftPaddedTree)); + return joinClause; + } + + @Override + public Cs.JoinIntoClause visitJoinIntoClause(Cs.JoinIntoClause joinIntoClause, ReceiverContext ctx) { + joinIntoClause = joinIntoClause.withId(ctx.receiveNonNullValue(joinIntoClause.getId(), UUID.class)); + joinIntoClause = joinIntoClause.withPrefix(ctx.receiveNonNullNode(joinIntoClause.getPrefix(), CSharpReceiver::receiveSpace)); + joinIntoClause = joinIntoClause.withMarkers(ctx.receiveNonNullNode(joinIntoClause.getMarkers(), ctx::receiveMarkers)); + joinIntoClause = joinIntoClause.withIdentifier(ctx.receiveNonNullNode(joinIntoClause.getIdentifier(), ctx::receiveTree)); + return joinIntoClause; + } + + @Override + public Cs.WhereClause visitWhereClause(Cs.WhereClause whereClause, ReceiverContext ctx) { + whereClause = whereClause.withId(ctx.receiveNonNullValue(whereClause.getId(), UUID.class)); + whereClause = whereClause.withPrefix(ctx.receiveNonNullNode(whereClause.getPrefix(), CSharpReceiver::receiveSpace)); + whereClause = whereClause.withMarkers(ctx.receiveNonNullNode(whereClause.getMarkers(), ctx::receiveMarkers)); + whereClause = whereClause.withCondition(ctx.receiveNonNullNode(whereClause.getCondition(), ctx::receiveTree)); + return whereClause; + } + + @Override + public Cs.OrderByClause visitOrderByClause(Cs.OrderByClause orderByClause, ReceiverContext ctx) { + orderByClause = orderByClause.withId(ctx.receiveNonNullValue(orderByClause.getId(), UUID.class)); + orderByClause = orderByClause.withPrefix(ctx.receiveNonNullNode(orderByClause.getPrefix(), CSharpReceiver::receiveSpace)); + orderByClause = orderByClause.withMarkers(ctx.receiveNonNullNode(orderByClause.getMarkers(), ctx::receiveMarkers)); + orderByClause = orderByClause.getPadding().withOrderings(ctx.receiveNonNullNodes(orderByClause.getPadding().getOrderings(), CSharpReceiver::receiveRightPaddedTree)); + return orderByClause; + } + + @Override + public Cs.QueryContinuation visitQueryContinuation(Cs.QueryContinuation queryContinuation, ReceiverContext ctx) { + queryContinuation = queryContinuation.withId(ctx.receiveNonNullValue(queryContinuation.getId(), UUID.class)); + queryContinuation = queryContinuation.withPrefix(ctx.receiveNonNullNode(queryContinuation.getPrefix(), CSharpReceiver::receiveSpace)); + queryContinuation = queryContinuation.withMarkers(ctx.receiveNonNullNode(queryContinuation.getMarkers(), ctx::receiveMarkers)); + queryContinuation = queryContinuation.withIdentifier(ctx.receiveNonNullNode(queryContinuation.getIdentifier(), ctx::receiveTree)); + queryContinuation = queryContinuation.withBody(ctx.receiveNonNullNode(queryContinuation.getBody(), ctx::receiveTree)); + return queryContinuation; + } + + @Override + public Cs.Ordering visitOrdering(Cs.Ordering ordering, ReceiverContext ctx) { + ordering = ordering.withId(ctx.receiveNonNullValue(ordering.getId(), UUID.class)); + ordering = ordering.withPrefix(ctx.receiveNonNullNode(ordering.getPrefix(), CSharpReceiver::receiveSpace)); + ordering = ordering.withMarkers(ctx.receiveNonNullNode(ordering.getMarkers(), ctx::receiveMarkers)); + ordering = ordering.getPadding().withExpression(ctx.receiveNonNullNode(ordering.getPadding().getExpression(), CSharpReceiver::receiveRightPaddedTree)); + ordering = ordering.withDirection(ctx.receiveValue(ordering.getDirection(), Cs.Ordering.DirectionKind.class)); + return ordering; + } + + @Override + public Cs.SelectClause visitSelectClause(Cs.SelectClause selectClause, ReceiverContext ctx) { + selectClause = selectClause.withId(ctx.receiveNonNullValue(selectClause.getId(), UUID.class)); + selectClause = selectClause.withPrefix(ctx.receiveNonNullNode(selectClause.getPrefix(), CSharpReceiver::receiveSpace)); + selectClause = selectClause.withMarkers(ctx.receiveNonNullNode(selectClause.getMarkers(), ctx::receiveMarkers)); + selectClause = selectClause.withExpression(ctx.receiveNonNullNode(selectClause.getExpression(), ctx::receiveTree)); + return selectClause; + } + + @Override + public Cs.GroupClause visitGroupClause(Cs.GroupClause groupClause, ReceiverContext ctx) { + groupClause = groupClause.withId(ctx.receiveNonNullValue(groupClause.getId(), UUID.class)); + groupClause = groupClause.withPrefix(ctx.receiveNonNullNode(groupClause.getPrefix(), CSharpReceiver::receiveSpace)); + groupClause = groupClause.withMarkers(ctx.receiveNonNullNode(groupClause.getMarkers(), ctx::receiveMarkers)); + groupClause = groupClause.getPadding().withGroupExpression(ctx.receiveNonNullNode(groupClause.getPadding().getGroupExpression(), CSharpReceiver::receiveRightPaddedTree)); + groupClause = groupClause.withKey(ctx.receiveNonNullNode(groupClause.getKey(), ctx::receiveTree)); + return groupClause; + } + + @Override + public Cs.IndexerDeclaration visitIndexerDeclaration(Cs.IndexerDeclaration indexerDeclaration, ReceiverContext ctx) { + indexerDeclaration = indexerDeclaration.withId(ctx.receiveNonNullValue(indexerDeclaration.getId(), UUID.class)); + indexerDeclaration = indexerDeclaration.withPrefix(ctx.receiveNonNullNode(indexerDeclaration.getPrefix(), CSharpReceiver::receiveSpace)); + indexerDeclaration = indexerDeclaration.withMarkers(ctx.receiveNonNullNode(indexerDeclaration.getMarkers(), ctx::receiveMarkers)); + indexerDeclaration = indexerDeclaration.withModifiers(ctx.receiveNonNullNodes(indexerDeclaration.getModifiers(), ctx::receiveTree)); + indexerDeclaration = indexerDeclaration.withTypeExpression(ctx.receiveNonNullNode(indexerDeclaration.getTypeExpression(), ctx::receiveTree)); + indexerDeclaration = indexerDeclaration.withIndexer(ctx.receiveNonNullNode(indexerDeclaration.getIndexer(), ctx::receiveTree)); + indexerDeclaration = indexerDeclaration.getPadding().withParameters(ctx.receiveNonNullNode(indexerDeclaration.getPadding().getParameters(), CSharpReceiver::receiveContainer)); + indexerDeclaration = indexerDeclaration.getPadding().withExpressionBody(ctx.receiveNode(indexerDeclaration.getPadding().getExpressionBody(), CSharpReceiver::receiveLeftPaddedTree)); + indexerDeclaration = indexerDeclaration.withAccessors(ctx.receiveNode(indexerDeclaration.getAccessors(), ctx::receiveTree)); + return indexerDeclaration; + } + + @Override + public Cs.DelegateDeclaration visitDelegateDeclaration(Cs.DelegateDeclaration delegateDeclaration, ReceiverContext ctx) { + delegateDeclaration = delegateDeclaration.withId(ctx.receiveNonNullValue(delegateDeclaration.getId(), UUID.class)); + delegateDeclaration = delegateDeclaration.withPrefix(ctx.receiveNonNullNode(delegateDeclaration.getPrefix(), CSharpReceiver::receiveSpace)); + delegateDeclaration = delegateDeclaration.withMarkers(ctx.receiveNonNullNode(delegateDeclaration.getMarkers(), ctx::receiveMarkers)); + delegateDeclaration = delegateDeclaration.withModifiers(ctx.receiveNonNullNodes(delegateDeclaration.getModifiers(), ctx::receiveTree)); + delegateDeclaration = delegateDeclaration.getPadding().withReturnType(ctx.receiveNonNullNode(delegateDeclaration.getPadding().getReturnType(), CSharpReceiver::receiveLeftPaddedTree)); + delegateDeclaration = delegateDeclaration.withIdentifier(ctx.receiveNonNullNode(delegateDeclaration.getIdentifier(), ctx::receiveTree)); + delegateDeclaration = delegateDeclaration.getPadding().withTypeParameters(ctx.receiveNode(delegateDeclaration.getPadding().getTypeParameters(), CSharpReceiver::receiveContainer)); + delegateDeclaration = delegateDeclaration.getPadding().withParameters(ctx.receiveNonNullNode(delegateDeclaration.getPadding().getParameters(), CSharpReceiver::receiveContainer)); + delegateDeclaration = delegateDeclaration.getPadding().withTypeParameterConstraintClauses(ctx.receiveNode(delegateDeclaration.getPadding().getTypeParameterConstraintClauses(), CSharpReceiver::receiveContainer)); + return delegateDeclaration; + } + + @Override + public Cs.ConversionOperatorDeclaration visitConversionOperatorDeclaration(Cs.ConversionOperatorDeclaration conversionOperatorDeclaration, ReceiverContext ctx) { + conversionOperatorDeclaration = conversionOperatorDeclaration.withId(ctx.receiveNonNullValue(conversionOperatorDeclaration.getId(), UUID.class)); + conversionOperatorDeclaration = conversionOperatorDeclaration.withPrefix(ctx.receiveNonNullNode(conversionOperatorDeclaration.getPrefix(), CSharpReceiver::receiveSpace)); + conversionOperatorDeclaration = conversionOperatorDeclaration.withMarkers(ctx.receiveNonNullNode(conversionOperatorDeclaration.getMarkers(), ctx::receiveMarkers)); + conversionOperatorDeclaration = conversionOperatorDeclaration.withModifiers(ctx.receiveNonNullNodes(conversionOperatorDeclaration.getModifiers(), ctx::receiveTree)); + conversionOperatorDeclaration = conversionOperatorDeclaration.getPadding().withKind(ctx.receiveNonNullNode(conversionOperatorDeclaration.getPadding().getKind(), leftPaddedValueReceiver(org.openrewrite.csharp.tree.Cs.ConversionOperatorDeclaration.ExplicitImplicit.class))); + conversionOperatorDeclaration = conversionOperatorDeclaration.getPadding().withReturnType(ctx.receiveNonNullNode(conversionOperatorDeclaration.getPadding().getReturnType(), CSharpReceiver::receiveLeftPaddedTree)); + conversionOperatorDeclaration = conversionOperatorDeclaration.getPadding().withParameters(ctx.receiveNonNullNode(conversionOperatorDeclaration.getPadding().getParameters(), CSharpReceiver::receiveContainer)); + conversionOperatorDeclaration = conversionOperatorDeclaration.getPadding().withExpressionBody(ctx.receiveNode(conversionOperatorDeclaration.getPadding().getExpressionBody(), CSharpReceiver::receiveLeftPaddedTree)); + conversionOperatorDeclaration = conversionOperatorDeclaration.withBody(ctx.receiveNode(conversionOperatorDeclaration.getBody(), ctx::receiveTree)); + return conversionOperatorDeclaration; + } + + @Override + public Cs.TypeParameter visitTypeParameter(Cs.TypeParameter typeParameter, ReceiverContext ctx) { + typeParameter = typeParameter.withId(ctx.receiveNonNullValue(typeParameter.getId(), UUID.class)); + typeParameter = typeParameter.withPrefix(ctx.receiveNonNullNode(typeParameter.getPrefix(), CSharpReceiver::receiveSpace)); + typeParameter = typeParameter.withMarkers(ctx.receiveNonNullNode(typeParameter.getMarkers(), ctx::receiveMarkers)); + typeParameter = typeParameter.withAttributeLists(ctx.receiveNonNullNodes(typeParameter.getAttributeLists(), ctx::receiveTree)); + typeParameter = typeParameter.getPadding().withVariance(ctx.receiveNode(typeParameter.getPadding().getVariance(), leftPaddedValueReceiver(org.openrewrite.csharp.tree.Cs.TypeParameter.VarianceKind.class))); + typeParameter = typeParameter.withName(ctx.receiveNonNullNode(typeParameter.getName(), ctx::receiveTree)); + return typeParameter; + } + + @Override + public Cs.EnumDeclaration visitEnumDeclaration(Cs.EnumDeclaration enumDeclaration, ReceiverContext ctx) { + enumDeclaration = enumDeclaration.withId(ctx.receiveNonNullValue(enumDeclaration.getId(), UUID.class)); + enumDeclaration = enumDeclaration.withPrefix(ctx.receiveNonNullNode(enumDeclaration.getPrefix(), CSharpReceiver::receiveSpace)); + enumDeclaration = enumDeclaration.withMarkers(ctx.receiveNonNullNode(enumDeclaration.getMarkers(), ctx::receiveMarkers)); + enumDeclaration = enumDeclaration.withAttributeLists(ctx.receiveNodes(enumDeclaration.getAttributeLists(), ctx::receiveTree)); + enumDeclaration = enumDeclaration.withModifiers(ctx.receiveNonNullNodes(enumDeclaration.getModifiers(), ctx::receiveTree)); + enumDeclaration = enumDeclaration.getPadding().withName(ctx.receiveNonNullNode(enumDeclaration.getPadding().getName(), CSharpReceiver::receiveLeftPaddedTree)); + enumDeclaration = enumDeclaration.getPadding().withBaseType(ctx.receiveNode(enumDeclaration.getPadding().getBaseType(), CSharpReceiver::receiveLeftPaddedTree)); + enumDeclaration = enumDeclaration.getPadding().withMembers(ctx.receiveNode(enumDeclaration.getPadding().getMembers(), CSharpReceiver::receiveContainer)); + return enumDeclaration; + } + + @Override + public Cs.EnumMemberDeclaration visitEnumMemberDeclaration(Cs.EnumMemberDeclaration enumMemberDeclaration, ReceiverContext ctx) { + enumMemberDeclaration = enumMemberDeclaration.withId(ctx.receiveNonNullValue(enumMemberDeclaration.getId(), UUID.class)); + enumMemberDeclaration = enumMemberDeclaration.withPrefix(ctx.receiveNonNullNode(enumMemberDeclaration.getPrefix(), CSharpReceiver::receiveSpace)); + enumMemberDeclaration = enumMemberDeclaration.withMarkers(ctx.receiveNonNullNode(enumMemberDeclaration.getMarkers(), ctx::receiveMarkers)); + enumMemberDeclaration = enumMemberDeclaration.withAttributeLists(ctx.receiveNonNullNodes(enumMemberDeclaration.getAttributeLists(), ctx::receiveTree)); + enumMemberDeclaration = enumMemberDeclaration.withName(ctx.receiveNonNullNode(enumMemberDeclaration.getName(), ctx::receiveTree)); + enumMemberDeclaration = enumMemberDeclaration.getPadding().withInitializer(ctx.receiveNode(enumMemberDeclaration.getPadding().getInitializer(), CSharpReceiver::receiveLeftPaddedTree)); + return enumMemberDeclaration; + } + + @Override + public Cs.AliasQualifiedName visitAliasQualifiedName(Cs.AliasQualifiedName aliasQualifiedName, ReceiverContext ctx) { + aliasQualifiedName = aliasQualifiedName.withId(ctx.receiveNonNullValue(aliasQualifiedName.getId(), UUID.class)); + aliasQualifiedName = aliasQualifiedName.withPrefix(ctx.receiveNonNullNode(aliasQualifiedName.getPrefix(), CSharpReceiver::receiveSpace)); + aliasQualifiedName = aliasQualifiedName.withMarkers(ctx.receiveNonNullNode(aliasQualifiedName.getMarkers(), ctx::receiveMarkers)); + aliasQualifiedName = aliasQualifiedName.getPadding().withAlias(ctx.receiveNonNullNode(aliasQualifiedName.getPadding().getAlias(), CSharpReceiver::receiveRightPaddedTree)); + aliasQualifiedName = aliasQualifiedName.withName(ctx.receiveNonNullNode(aliasQualifiedName.getName(), ctx::receiveTree)); + return aliasQualifiedName; + } + + @Override + public Cs.ArrayType visitArrayType(Cs.ArrayType arrayType, ReceiverContext ctx) { + arrayType = arrayType.withId(ctx.receiveNonNullValue(arrayType.getId(), UUID.class)); + arrayType = arrayType.withPrefix(ctx.receiveNonNullNode(arrayType.getPrefix(), CSharpReceiver::receiveSpace)); + arrayType = arrayType.withMarkers(ctx.receiveNonNullNode(arrayType.getMarkers(), ctx::receiveMarkers)); + arrayType = arrayType.withTypeExpression(ctx.receiveNode(arrayType.getTypeExpression(), ctx::receiveTree)); + arrayType = arrayType.withDimensions(ctx.receiveNonNullNodes(arrayType.getDimensions(), ctx::receiveTree)); + arrayType = arrayType.withType(ctx.receiveValue(arrayType.getType(), JavaType.class)); + return arrayType; + } + @Override public J.AnnotatedType visitAnnotatedType(J.AnnotatedType annotatedType, ReceiverContext ctx) { annotatedType = annotatedType.withId(ctx.receiveNonNullValue(annotatedType.getId(), UUID.class)); @@ -1612,6 +1847,26 @@ protected Function computeValue(Class type) { if (type == Cs.CheckedStatement.class) return Factory::createCsCheckedStatement; if (type == Cs.UnsafeStatement.class) return Factory::createCsUnsafeStatement; if (type == Cs.RangeExpression.class) return Factory::createCsRangeExpression; + if (type == Cs.QueryExpression.class) return Factory::createCsQueryExpression; + if (type == Cs.QueryBody.class) return Factory::createCsQueryBody; + if (type == Cs.FromClause.class) return Factory::createCsFromClause; + if (type == Cs.LetClause.class) return Factory::createCsLetClause; + if (type == Cs.JoinClause.class) return Factory::createCsJoinClause; + if (type == Cs.JoinIntoClause.class) return Factory::createCsJoinIntoClause; + if (type == Cs.WhereClause.class) return Factory::createCsWhereClause; + if (type == Cs.OrderByClause.class) return Factory::createCsOrderByClause; + if (type == Cs.QueryContinuation.class) return Factory::createCsQueryContinuation; + if (type == Cs.Ordering.class) return Factory::createCsOrdering; + if (type == Cs.SelectClause.class) return Factory::createCsSelectClause; + if (type == Cs.GroupClause.class) return Factory::createCsGroupClause; + if (type == Cs.IndexerDeclaration.class) return Factory::createCsIndexerDeclaration; + if (type == Cs.DelegateDeclaration.class) return Factory::createCsDelegateDeclaration; + if (type == Cs.ConversionOperatorDeclaration.class) return Factory::createCsConversionOperatorDeclaration; + if (type == Cs.TypeParameter.class) return Factory::createCsTypeParameter; + if (type == Cs.EnumDeclaration.class) return Factory::createCsEnumDeclaration; + if (type == Cs.EnumMemberDeclaration.class) return Factory::createCsEnumMemberDeclaration; + if (type == Cs.AliasQualifiedName.class) return Factory::createCsAliasQualifiedName; + if (type == Cs.ArrayType.class) return Factory::createCsArrayType; if (type == J.AnnotatedType.class) return Factory::createJAnnotatedType; if (type == J.Annotation.class) return Factory::createJAnnotation; if (type == J.ArrayAccess.class) return Factory::createJArrayAccess; @@ -1830,7 +2085,7 @@ private static Cs.ExpressionStatement createCsExpressionStatement(ReceiverContex ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), - ctx.receiveNonNullNode(null, ctx::receiveTree) + ctx.receiveNonNullNode(null, CSharpReceiver::receiveRightPaddedTree) ); } @@ -1947,8 +2202,17 @@ private static Cs.ClassDeclaration createCsClassDeclaration(ReceiverContext ctx) ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNodes(null, ctx::receiveTree), + ctx.receiveNonNullNodes(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveClassDeclarationKind), ctx.receiveNonNullNode(null, ctx::receiveTree), - ctx.receiveNonNullNode(null, CSharpReceiver::receiveContainer) + ctx.receiveNode(null, CSharpReceiver::receiveContainer), + ctx.receiveNode(null, CSharpReceiver::receiveContainer), + ctx.receiveNode(null, CSharpReceiver::receiveLeftPaddedTree), + ctx.receiveNode(null, CSharpReceiver::receiveContainer), + ctx.receiveNode(null, ctx::receiveTree), + ctx.receiveNode(null, CSharpReceiver::receiveContainer), + ctx.receiveValue(null, JavaType.FullyQualified.class) ); } @@ -1957,7 +2221,15 @@ private static Cs.MethodDeclaration createCsMethodDeclaration(ReceiverContext ct ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNodes(null, ctx::receiveTree), + ctx.receiveNonNullNodes(null, ctx::receiveTree), + ctx.receiveNode(null, CSharpReceiver::receiveContainer), ctx.receiveNonNullNode(null, ctx::receiveTree), + ctx.receiveNode(null, CSharpReceiver::receiveRightPaddedTree), + ctx.receiveNonNullNode(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveContainer), + ctx.receiveNode(null, ctx::receiveTree), + ctx.receiveValue(null, JavaType.Method.class), ctx.receiveNonNullNode(null, CSharpReceiver::receiveContainer) ); } @@ -1968,7 +2240,7 @@ private static Cs.UsingStatement createCsUsingStatement(ReceiverContext ctx) { ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNode(null, ctx::receiveTree), - ctx.receiveNonNullNode(null, CSharpReceiver::receiveContainer), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveLeftPaddedTree), ctx.receiveNonNullNode(null, ctx::receiveTree) ); } @@ -2096,7 +2368,6 @@ private static Cs.DestructorDeclaration createCsDestructorDeclaration(ReceiverCo ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), - ctx.receiveNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, ctx::receiveTree) ); } @@ -2443,6 +2714,225 @@ private static Cs.RangeExpression createCsRangeExpression(ReceiverContext ctx) { ); } + private static Cs.QueryExpression createCsQueryExpression(ReceiverContext ctx) { + return new Cs.QueryExpression( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNode(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, ctx::receiveTree) + ); + } + + private static Cs.QueryBody createCsQueryBody(ReceiverContext ctx) { + return new Cs.QueryBody( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNodes(null, ctx::receiveTree), + ctx.receiveNode(null, ctx::receiveTree), + ctx.receiveNode(null, ctx::receiveTree) + ); + } + + private static Cs.FromClause createCsFromClause(ReceiverContext ctx) { + return new Cs.FromClause( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNode(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveRightPaddedTree), + ctx.receiveNonNullNode(null, ctx::receiveTree) + ); + } + + private static Cs.LetClause createCsLetClause(ReceiverContext ctx) { + return new Cs.LetClause( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveRightPaddedTree), + ctx.receiveNonNullNode(null, ctx::receiveTree) + ); + } + + private static Cs.JoinClause createCsJoinClause(ReceiverContext ctx) { + return new Cs.JoinClause( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveRightPaddedTree), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveRightPaddedTree), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveRightPaddedTree), + ctx.receiveNonNullNode(null, ctx::receiveTree), + ctx.receiveNode(null, CSharpReceiver::receiveLeftPaddedTree) + ); + } + + private static Cs.JoinIntoClause createCsJoinIntoClause(ReceiverContext ctx) { + return new Cs.JoinIntoClause( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNode(null, ctx::receiveTree) + ); + } + + private static Cs.WhereClause createCsWhereClause(ReceiverContext ctx) { + return new Cs.WhereClause( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNode(null, ctx::receiveTree) + ); + } + + private static Cs.OrderByClause createCsOrderByClause(ReceiverContext ctx) { + return new Cs.OrderByClause( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNodes(null, CSharpReceiver::receiveRightPaddedTree) + ); + } + + private static Cs.QueryContinuation createCsQueryContinuation(ReceiverContext ctx) { + return new Cs.QueryContinuation( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNode(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, ctx::receiveTree) + ); + } + + private static Cs.Ordering createCsOrdering(ReceiverContext ctx) { + return new Cs.Ordering( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveRightPaddedTree), + ctx.receiveValue(null, Cs.Ordering.DirectionKind.class) + ); + } + + private static Cs.SelectClause createCsSelectClause(ReceiverContext ctx) { + return new Cs.SelectClause( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNode(null, ctx::receiveTree) + ); + } + + private static Cs.GroupClause createCsGroupClause(ReceiverContext ctx) { + return new Cs.GroupClause( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveRightPaddedTree), + ctx.receiveNonNullNode(null, ctx::receiveTree) + ); + } + + private static Cs.IndexerDeclaration createCsIndexerDeclaration(ReceiverContext ctx) { + return new Cs.IndexerDeclaration( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNodes(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveContainer), + ctx.receiveNode(null, CSharpReceiver::receiveLeftPaddedTree), + ctx.receiveNode(null, ctx::receiveTree) + ); + } + + private static Cs.DelegateDeclaration createCsDelegateDeclaration(ReceiverContext ctx) { + return new Cs.DelegateDeclaration( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNodes(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveLeftPaddedTree), + ctx.receiveNonNullNode(null, ctx::receiveTree), + ctx.receiveNode(null, CSharpReceiver::receiveContainer), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveContainer), + ctx.receiveNode(null, CSharpReceiver::receiveContainer) + ); + } + + private static Cs.ConversionOperatorDeclaration createCsConversionOperatorDeclaration(ReceiverContext ctx) { + return new Cs.ConversionOperatorDeclaration( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNodes(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, leftPaddedValueReceiver(org.openrewrite.csharp.tree.Cs.ConversionOperatorDeclaration.ExplicitImplicit.class)), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveLeftPaddedTree), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveContainer), + ctx.receiveNode(null, CSharpReceiver::receiveLeftPaddedTree), + ctx.receiveNode(null, ctx::receiveTree) + ); + } + + private static Cs.TypeParameter createCsTypeParameter(ReceiverContext ctx) { + return new Cs.TypeParameter( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNodes(null, ctx::receiveTree), + ctx.receiveNode(null, leftPaddedValueReceiver(org.openrewrite.csharp.tree.Cs.TypeParameter.VarianceKind.class)), + ctx.receiveNonNullNode(null, ctx::receiveTree) + ); + } + + private static Cs.EnumDeclaration createCsEnumDeclaration(ReceiverContext ctx) { + return new Cs.EnumDeclaration( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNodes(null, ctx::receiveTree), + ctx.receiveNonNullNodes(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveLeftPaddedTree), + ctx.receiveNode(null, CSharpReceiver::receiveLeftPaddedTree), + ctx.receiveNode(null, CSharpReceiver::receiveContainer) + ); + } + + private static Cs.EnumMemberDeclaration createCsEnumMemberDeclaration(ReceiverContext ctx) { + return new Cs.EnumMemberDeclaration( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNodes(null, ctx::receiveTree), + ctx.receiveNonNullNode(null, ctx::receiveTree), + ctx.receiveNode(null, CSharpReceiver::receiveLeftPaddedTree) + ); + } + + private static Cs.AliasQualifiedName createCsAliasQualifiedName(ReceiverContext ctx) { + return new Cs.AliasQualifiedName( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveRightPaddedTree), + ctx.receiveNonNullNode(null, ctx::receiveTree) + ); + } + + private static Cs.ArrayType createCsArrayType(ReceiverContext ctx) { + return new Cs.ArrayType( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, CSharpReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNode(null, ctx::receiveTree), + ctx.receiveNonNullNodes(null, ctx::receiveTree), + ctx.receiveValue(null, JavaType.class) + ); + } + private static J.AnnotatedType createJAnnotatedType(ReceiverContext ctx) { return new J.AnnotatedType( ctx.receiveNonNullValue(null, UUID.class), diff --git a/rewrite-csharp-remote/src/main/java/org/openrewrite/csharp/remote/CSharpSender.java b/rewrite-csharp-remote/src/main/java/org/openrewrite/csharp/remote/CSharpSender.java index 804ef1e..30b6a4f 100644 --- a/rewrite-csharp-remote/src/main/java/org/openrewrite/csharp/remote/CSharpSender.java +++ b/rewrite-csharp-remote/src/main/java/org/openrewrite/csharp/remote/CSharpSender.java @@ -195,7 +195,7 @@ public Cs.ExpressionStatement visitExpressionStatement(Cs.ExpressionStatement ex ctx.sendValue(expressionStatement, Cs.ExpressionStatement::getId); ctx.sendNode(expressionStatement, Cs.ExpressionStatement::getPrefix, CSharpSender::sendSpace); ctx.sendNode(expressionStatement, Cs.ExpressionStatement::getMarkers, ctx::sendMarkers); - ctx.sendNode(expressionStatement, Cs.ExpressionStatement::getExpression, ctx::sendTree); + ctx.sendNode(expressionStatement, e -> e.getPadding().getExpression(), CSharpSender::sendRightPadded); return expressionStatement; } @@ -312,8 +312,17 @@ public Cs.ClassDeclaration visitClassDeclaration(Cs.ClassDeclaration classDeclar ctx.sendValue(classDeclaration, Cs.ClassDeclaration::getId); ctx.sendNode(classDeclaration, Cs.ClassDeclaration::getPrefix, CSharpSender::sendSpace); ctx.sendNode(classDeclaration, Cs.ClassDeclaration::getMarkers, ctx::sendMarkers); - ctx.sendNode(classDeclaration, Cs.ClassDeclaration::getClassDeclarationCore, ctx::sendTree); + ctx.sendNodes(classDeclaration, Cs.ClassDeclaration::getAttributeList, ctx::sendTree, Tree::getId); + ctx.sendNodes(classDeclaration, Cs.ClassDeclaration::getModifiers, ctx::sendTree, Tree::getId); + ctx.sendNode(classDeclaration, e -> e.getPadding().getKind(), this::sendClassDeclarationKind); + ctx.sendNode(classDeclaration, Cs.ClassDeclaration::getName, ctx::sendTree); + ctx.sendNode(classDeclaration, e -> e.getPadding().getTypeParameters(), CSharpSender::sendContainer); + ctx.sendNode(classDeclaration, e -> e.getPadding().getPrimaryConstructor(), CSharpSender::sendContainer); + ctx.sendNode(classDeclaration, e -> e.getPadding().getExtendings(), CSharpSender::sendLeftPadded); + ctx.sendNode(classDeclaration, e -> e.getPadding().getImplementings(), CSharpSender::sendContainer); + ctx.sendNode(classDeclaration, Cs.ClassDeclaration::getBody, ctx::sendTree); ctx.sendNode(classDeclaration, e -> e.getPadding().getTypeParameterConstraintClauses(), CSharpSender::sendContainer); + ctx.sendTypedValue(classDeclaration, Cs.ClassDeclaration::getType); return classDeclaration; } @@ -322,7 +331,15 @@ public Cs.MethodDeclaration visitMethodDeclaration(Cs.MethodDeclaration methodDe ctx.sendValue(methodDeclaration, Cs.MethodDeclaration::getId); ctx.sendNode(methodDeclaration, Cs.MethodDeclaration::getPrefix, CSharpSender::sendSpace); ctx.sendNode(methodDeclaration, Cs.MethodDeclaration::getMarkers, ctx::sendMarkers); - ctx.sendNode(methodDeclaration, Cs.MethodDeclaration::getMethodDeclarationCore, ctx::sendTree); + ctx.sendNodes(methodDeclaration, Cs.MethodDeclaration::getAttributes, ctx::sendTree, Tree::getId); + ctx.sendNodes(methodDeclaration, Cs.MethodDeclaration::getModifiers, ctx::sendTree, Tree::getId); + ctx.sendNode(methodDeclaration, e -> e.getPadding().getTypeParameters(), CSharpSender::sendContainer); + ctx.sendNode(methodDeclaration, Cs.MethodDeclaration::getReturnTypeExpression, ctx::sendTree); + ctx.sendNode(methodDeclaration, e -> e.getPadding().getExplicitInterfaceSpecifier(), CSharpSender::sendRightPadded); + ctx.sendNode(methodDeclaration, Cs.MethodDeclaration::getName, ctx::sendTree); + ctx.sendNode(methodDeclaration, e -> e.getPadding().getParameters(), CSharpSender::sendContainer); + ctx.sendNode(methodDeclaration, Cs.MethodDeclaration::getBody, ctx::sendTree); + ctx.sendTypedValue(methodDeclaration, Cs.MethodDeclaration::getMethodType); ctx.sendNode(methodDeclaration, e -> e.getPadding().getTypeParameterConstraintClauses(), CSharpSender::sendContainer); return methodDeclaration; } @@ -333,7 +350,7 @@ public Cs.UsingStatement visitUsingStatement(Cs.UsingStatement usingStatement, S ctx.sendNode(usingStatement, Cs.UsingStatement::getPrefix, CSharpSender::sendSpace); ctx.sendNode(usingStatement, Cs.UsingStatement::getMarkers, ctx::sendMarkers); ctx.sendNode(usingStatement, Cs.UsingStatement::getAwaitKeyword, ctx::sendTree); - ctx.sendNode(usingStatement, e -> e.getPadding().getExpression(), CSharpSender::sendContainer); + ctx.sendNode(usingStatement, e -> e.getPadding().getExpression(), CSharpSender::sendLeftPadded); ctx.sendNode(usingStatement, Cs.UsingStatement::getStatement, ctx::sendTree); return usingStatement; } @@ -461,8 +478,7 @@ public Cs.DestructorDeclaration visitDestructorDeclaration(Cs.DestructorDeclarat ctx.sendValue(destructorDeclaration, Cs.DestructorDeclaration::getId); ctx.sendNode(destructorDeclaration, Cs.DestructorDeclaration::getPrefix, CSharpSender::sendSpace); ctx.sendNode(destructorDeclaration, Cs.DestructorDeclaration::getMarkers, ctx::sendMarkers); - ctx.sendNode(destructorDeclaration, Cs.DestructorDeclaration::getInitializer, ctx::sendTree); - ctx.sendNode(destructorDeclaration, Cs.DestructorDeclaration::getConstructorCore, ctx::sendTree); + ctx.sendNode(destructorDeclaration, Cs.DestructorDeclaration::getMethodCore, ctx::sendTree); return destructorDeclaration; } @@ -808,6 +824,225 @@ public Cs.RangeExpression visitRangeExpression(Cs.RangeExpression rangeExpressio return rangeExpression; } + @Override + public Cs.QueryExpression visitQueryExpression(Cs.QueryExpression queryExpression, SenderContext ctx) { + ctx.sendValue(queryExpression, Cs.QueryExpression::getId); + ctx.sendNode(queryExpression, Cs.QueryExpression::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(queryExpression, Cs.QueryExpression::getMarkers, ctx::sendMarkers); + ctx.sendNode(queryExpression, Cs.QueryExpression::getFromClause, ctx::sendTree); + ctx.sendNode(queryExpression, Cs.QueryExpression::getBody, ctx::sendTree); + return queryExpression; + } + + @Override + public Cs.QueryBody visitQueryBody(Cs.QueryBody queryBody, SenderContext ctx) { + ctx.sendValue(queryBody, Cs.QueryBody::getId); + ctx.sendNode(queryBody, Cs.QueryBody::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(queryBody, Cs.QueryBody::getMarkers, ctx::sendMarkers); + ctx.sendNodes(queryBody, Cs.QueryBody::getClauses, ctx::sendTree, Tree::getId); + ctx.sendNode(queryBody, Cs.QueryBody::getSelectOrGroup, ctx::sendTree); + ctx.sendNode(queryBody, Cs.QueryBody::getContinuation, ctx::sendTree); + return queryBody; + } + + @Override + public Cs.FromClause visitFromClause(Cs.FromClause fromClause, SenderContext ctx) { + ctx.sendValue(fromClause, Cs.FromClause::getId); + ctx.sendNode(fromClause, Cs.FromClause::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(fromClause, Cs.FromClause::getMarkers, ctx::sendMarkers); + ctx.sendNode(fromClause, Cs.FromClause::getTypeIdentifier, ctx::sendTree); + ctx.sendNode(fromClause, e -> e.getPadding().getIdentifier(), CSharpSender::sendRightPadded); + ctx.sendNode(fromClause, Cs.FromClause::getExpression, ctx::sendTree); + return fromClause; + } + + @Override + public Cs.LetClause visitLetClause(Cs.LetClause letClause, SenderContext ctx) { + ctx.sendValue(letClause, Cs.LetClause::getId); + ctx.sendNode(letClause, Cs.LetClause::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(letClause, Cs.LetClause::getMarkers, ctx::sendMarkers); + ctx.sendNode(letClause, e -> e.getPadding().getIdentifier(), CSharpSender::sendRightPadded); + ctx.sendNode(letClause, Cs.LetClause::getExpression, ctx::sendTree); + return letClause; + } + + @Override + public Cs.JoinClause visitJoinClause(Cs.JoinClause joinClause, SenderContext ctx) { + ctx.sendValue(joinClause, Cs.JoinClause::getId); + ctx.sendNode(joinClause, Cs.JoinClause::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(joinClause, Cs.JoinClause::getMarkers, ctx::sendMarkers); + ctx.sendNode(joinClause, e -> e.getPadding().getIdentifier(), CSharpSender::sendRightPadded); + ctx.sendNode(joinClause, e -> e.getPadding().getInExpression(), CSharpSender::sendRightPadded); + ctx.sendNode(joinClause, e -> e.getPadding().getLeftExpression(), CSharpSender::sendRightPadded); + ctx.sendNode(joinClause, Cs.JoinClause::getRightExpression, ctx::sendTree); + ctx.sendNode(joinClause, e -> e.getPadding().getInto(), CSharpSender::sendLeftPadded); + return joinClause; + } + + @Override + public Cs.JoinIntoClause visitJoinIntoClause(Cs.JoinIntoClause joinIntoClause, SenderContext ctx) { + ctx.sendValue(joinIntoClause, Cs.JoinIntoClause::getId); + ctx.sendNode(joinIntoClause, Cs.JoinIntoClause::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(joinIntoClause, Cs.JoinIntoClause::getMarkers, ctx::sendMarkers); + ctx.sendNode(joinIntoClause, Cs.JoinIntoClause::getIdentifier, ctx::sendTree); + return joinIntoClause; + } + + @Override + public Cs.WhereClause visitWhereClause(Cs.WhereClause whereClause, SenderContext ctx) { + ctx.sendValue(whereClause, Cs.WhereClause::getId); + ctx.sendNode(whereClause, Cs.WhereClause::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(whereClause, Cs.WhereClause::getMarkers, ctx::sendMarkers); + ctx.sendNode(whereClause, Cs.WhereClause::getCondition, ctx::sendTree); + return whereClause; + } + + @Override + public Cs.OrderByClause visitOrderByClause(Cs.OrderByClause orderByClause, SenderContext ctx) { + ctx.sendValue(orderByClause, Cs.OrderByClause::getId); + ctx.sendNode(orderByClause, Cs.OrderByClause::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(orderByClause, Cs.OrderByClause::getMarkers, ctx::sendMarkers); + ctx.sendNodes(orderByClause, e -> e.getPadding().getOrderings(), CSharpSender::sendRightPadded, e -> e.getElement().getId()); + return orderByClause; + } + + @Override + public Cs.QueryContinuation visitQueryContinuation(Cs.QueryContinuation queryContinuation, SenderContext ctx) { + ctx.sendValue(queryContinuation, Cs.QueryContinuation::getId); + ctx.sendNode(queryContinuation, Cs.QueryContinuation::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(queryContinuation, Cs.QueryContinuation::getMarkers, ctx::sendMarkers); + ctx.sendNode(queryContinuation, Cs.QueryContinuation::getIdentifier, ctx::sendTree); + ctx.sendNode(queryContinuation, Cs.QueryContinuation::getBody, ctx::sendTree); + return queryContinuation; + } + + @Override + public Cs.Ordering visitOrdering(Cs.Ordering ordering, SenderContext ctx) { + ctx.sendValue(ordering, Cs.Ordering::getId); + ctx.sendNode(ordering, Cs.Ordering::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(ordering, Cs.Ordering::getMarkers, ctx::sendMarkers); + ctx.sendNode(ordering, e -> e.getPadding().getExpression(), CSharpSender::sendRightPadded); + ctx.sendValue(ordering, Cs.Ordering::getDirection); + return ordering; + } + + @Override + public Cs.SelectClause visitSelectClause(Cs.SelectClause selectClause, SenderContext ctx) { + ctx.sendValue(selectClause, Cs.SelectClause::getId); + ctx.sendNode(selectClause, Cs.SelectClause::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(selectClause, Cs.SelectClause::getMarkers, ctx::sendMarkers); + ctx.sendNode(selectClause, Cs.SelectClause::getExpression, ctx::sendTree); + return selectClause; + } + + @Override + public Cs.GroupClause visitGroupClause(Cs.GroupClause groupClause, SenderContext ctx) { + ctx.sendValue(groupClause, Cs.GroupClause::getId); + ctx.sendNode(groupClause, Cs.GroupClause::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(groupClause, Cs.GroupClause::getMarkers, ctx::sendMarkers); + ctx.sendNode(groupClause, e -> e.getPadding().getGroupExpression(), CSharpSender::sendRightPadded); + ctx.sendNode(groupClause, Cs.GroupClause::getKey, ctx::sendTree); + return groupClause; + } + + @Override + public Cs.IndexerDeclaration visitIndexerDeclaration(Cs.IndexerDeclaration indexerDeclaration, SenderContext ctx) { + ctx.sendValue(indexerDeclaration, Cs.IndexerDeclaration::getId); + ctx.sendNode(indexerDeclaration, Cs.IndexerDeclaration::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(indexerDeclaration, Cs.IndexerDeclaration::getMarkers, ctx::sendMarkers); + ctx.sendNodes(indexerDeclaration, Cs.IndexerDeclaration::getModifiers, ctx::sendTree, Tree::getId); + ctx.sendNode(indexerDeclaration, Cs.IndexerDeclaration::getTypeExpression, ctx::sendTree); + ctx.sendNode(indexerDeclaration, Cs.IndexerDeclaration::getIndexer, ctx::sendTree); + ctx.sendNode(indexerDeclaration, e -> e.getPadding().getParameters(), CSharpSender::sendContainer); + ctx.sendNode(indexerDeclaration, e -> e.getPadding().getExpressionBody(), CSharpSender::sendLeftPadded); + ctx.sendNode(indexerDeclaration, Cs.IndexerDeclaration::getAccessors, ctx::sendTree); + return indexerDeclaration; + } + + @Override + public Cs.DelegateDeclaration visitDelegateDeclaration(Cs.DelegateDeclaration delegateDeclaration, SenderContext ctx) { + ctx.sendValue(delegateDeclaration, Cs.DelegateDeclaration::getId); + ctx.sendNode(delegateDeclaration, Cs.DelegateDeclaration::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(delegateDeclaration, Cs.DelegateDeclaration::getMarkers, ctx::sendMarkers); + ctx.sendNodes(delegateDeclaration, Cs.DelegateDeclaration::getModifiers, ctx::sendTree, Tree::getId); + ctx.sendNode(delegateDeclaration, e -> e.getPadding().getReturnType(), CSharpSender::sendLeftPadded); + ctx.sendNode(delegateDeclaration, Cs.DelegateDeclaration::getIdentifier, ctx::sendTree); + ctx.sendNode(delegateDeclaration, e -> e.getPadding().getTypeParameters(), CSharpSender::sendContainer); + ctx.sendNode(delegateDeclaration, e -> e.getPadding().getParameters(), CSharpSender::sendContainer); + ctx.sendNode(delegateDeclaration, e -> e.getPadding().getTypeParameterConstraintClauses(), CSharpSender::sendContainer); + return delegateDeclaration; + } + + @Override + public Cs.ConversionOperatorDeclaration visitConversionOperatorDeclaration(Cs.ConversionOperatorDeclaration conversionOperatorDeclaration, SenderContext ctx) { + ctx.sendValue(conversionOperatorDeclaration, Cs.ConversionOperatorDeclaration::getId); + ctx.sendNode(conversionOperatorDeclaration, Cs.ConversionOperatorDeclaration::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(conversionOperatorDeclaration, Cs.ConversionOperatorDeclaration::getMarkers, ctx::sendMarkers); + ctx.sendNodes(conversionOperatorDeclaration, Cs.ConversionOperatorDeclaration::getModifiers, ctx::sendTree, Tree::getId); + ctx.sendNode(conversionOperatorDeclaration, e -> e.getPadding().getKind(), CSharpSender::sendLeftPadded); + ctx.sendNode(conversionOperatorDeclaration, e -> e.getPadding().getReturnType(), CSharpSender::sendLeftPadded); + ctx.sendNode(conversionOperatorDeclaration, e -> e.getPadding().getParameters(), CSharpSender::sendContainer); + ctx.sendNode(conversionOperatorDeclaration, e -> e.getPadding().getExpressionBody(), CSharpSender::sendLeftPadded); + ctx.sendNode(conversionOperatorDeclaration, Cs.ConversionOperatorDeclaration::getBody, ctx::sendTree); + return conversionOperatorDeclaration; + } + + @Override + public Cs.TypeParameter visitTypeParameter(Cs.TypeParameter typeParameter, SenderContext ctx) { + ctx.sendValue(typeParameter, Cs.TypeParameter::getId); + ctx.sendNode(typeParameter, Cs.TypeParameter::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(typeParameter, Cs.TypeParameter::getMarkers, ctx::sendMarkers); + ctx.sendNodes(typeParameter, Cs.TypeParameter::getAttributeLists, ctx::sendTree, Tree::getId); + ctx.sendNode(typeParameter, e -> e.getPadding().getVariance(), CSharpSender::sendLeftPadded); + ctx.sendNode(typeParameter, Cs.TypeParameter::getName, ctx::sendTree); + return typeParameter; + } + + @Override + public Cs.EnumDeclaration visitEnumDeclaration(Cs.EnumDeclaration enumDeclaration, SenderContext ctx) { + ctx.sendValue(enumDeclaration, Cs.EnumDeclaration::getId); + ctx.sendNode(enumDeclaration, Cs.EnumDeclaration::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(enumDeclaration, Cs.EnumDeclaration::getMarkers, ctx::sendMarkers); + ctx.sendNodes(enumDeclaration, Cs.EnumDeclaration::getAttributeLists, ctx::sendTree, Tree::getId); + ctx.sendNodes(enumDeclaration, Cs.EnumDeclaration::getModifiers, ctx::sendTree, Tree::getId); + ctx.sendNode(enumDeclaration, e -> e.getPadding().getName(), CSharpSender::sendLeftPadded); + ctx.sendNode(enumDeclaration, e -> e.getPadding().getBaseType(), CSharpSender::sendLeftPadded); + ctx.sendNode(enumDeclaration, e -> e.getPadding().getMembers(), CSharpSender::sendContainer); + return enumDeclaration; + } + + @Override + public Cs.EnumMemberDeclaration visitEnumMemberDeclaration(Cs.EnumMemberDeclaration enumMemberDeclaration, SenderContext ctx) { + ctx.sendValue(enumMemberDeclaration, Cs.EnumMemberDeclaration::getId); + ctx.sendNode(enumMemberDeclaration, Cs.EnumMemberDeclaration::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(enumMemberDeclaration, Cs.EnumMemberDeclaration::getMarkers, ctx::sendMarkers); + ctx.sendNodes(enumMemberDeclaration, Cs.EnumMemberDeclaration::getAttributeLists, ctx::sendTree, Tree::getId); + ctx.sendNode(enumMemberDeclaration, Cs.EnumMemberDeclaration::getName, ctx::sendTree); + ctx.sendNode(enumMemberDeclaration, e -> e.getPadding().getInitializer(), CSharpSender::sendLeftPadded); + return enumMemberDeclaration; + } + + @Override + public Cs.AliasQualifiedName visitAliasQualifiedName(Cs.AliasQualifiedName aliasQualifiedName, SenderContext ctx) { + ctx.sendValue(aliasQualifiedName, Cs.AliasQualifiedName::getId); + ctx.sendNode(aliasQualifiedName, Cs.AliasQualifiedName::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(aliasQualifiedName, Cs.AliasQualifiedName::getMarkers, ctx::sendMarkers); + ctx.sendNode(aliasQualifiedName, e -> e.getPadding().getAlias(), CSharpSender::sendRightPadded); + ctx.sendNode(aliasQualifiedName, Cs.AliasQualifiedName::getName, ctx::sendTree); + return aliasQualifiedName; + } + + @Override + public Cs.ArrayType visitArrayType(Cs.ArrayType arrayType, SenderContext ctx) { + ctx.sendValue(arrayType, Cs.ArrayType::getId); + ctx.sendNode(arrayType, Cs.ArrayType::getPrefix, CSharpSender::sendSpace); + ctx.sendNode(arrayType, Cs.ArrayType::getMarkers, ctx::sendMarkers); + ctx.sendNode(arrayType, Cs.ArrayType::getTypeExpression, ctx::sendTree); + ctx.sendNodes(arrayType, Cs.ArrayType::getDimensions, ctx::sendTree, Tree::getId); + ctx.sendTypedValue(arrayType, Cs.ArrayType::getType); + return arrayType; + } + @Override public J.AnnotatedType visitAnnotatedType(J.AnnotatedType annotatedType, SenderContext ctx) { ctx.sendValue(annotatedType, J.AnnotatedType::getId); diff --git a/rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpIsoVisitor.java b/rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpIsoVisitor.java index 30e0c5a..543caed 100644 --- a/rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpIsoVisitor.java +++ b/rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpIsoVisitor.java @@ -404,6 +404,106 @@ public Cs.RangeExpression visitRangeExpression(Cs.RangeExpression rangeExpressio return (Cs.RangeExpression) super.visitRangeExpression(rangeExpression, p); } + @Override + public Cs.QueryExpression visitQueryExpression(Cs.QueryExpression queryExpression, P p) { + return (Cs.QueryExpression) super.visitQueryExpression(queryExpression, p); + } + + @Override + public Cs.QueryBody visitQueryBody(Cs.QueryBody queryBody, P p) { + return (Cs.QueryBody) super.visitQueryBody(queryBody, p); + } + + @Override + public Cs.FromClause visitFromClause(Cs.FromClause fromClause, P p) { + return (Cs.FromClause) super.visitFromClause(fromClause, p); + } + + @Override + public Cs.LetClause visitLetClause(Cs.LetClause letClause, P p) { + return (Cs.LetClause) super.visitLetClause(letClause, p); + } + + @Override + public Cs.JoinClause visitJoinClause(Cs.JoinClause joinClause, P p) { + return (Cs.JoinClause) super.visitJoinClause(joinClause, p); + } + + @Override + public Cs.JoinIntoClause visitJoinIntoClause(Cs.JoinIntoClause joinIntoClause, P p) { + return (Cs.JoinIntoClause) super.visitJoinIntoClause(joinIntoClause, p); + } + + @Override + public Cs.WhereClause visitWhereClause(Cs.WhereClause whereClause, P p) { + return (Cs.WhereClause) super.visitWhereClause(whereClause, p); + } + + @Override + public Cs.OrderByClause visitOrderByClause(Cs.OrderByClause orderByClause, P p) { + return (Cs.OrderByClause) super.visitOrderByClause(orderByClause, p); + } + + @Override + public Cs.QueryContinuation visitQueryContinuation(Cs.QueryContinuation queryContinuation, P p) { + return (Cs.QueryContinuation) super.visitQueryContinuation(queryContinuation, p); + } + + @Override + public Cs.Ordering visitOrdering(Cs.Ordering ordering, P p) { + return (Cs.Ordering) super.visitOrdering(ordering, p); + } + + @Override + public Cs.SelectClause visitSelectClause(Cs.SelectClause selectClause, P p) { + return (Cs.SelectClause) super.visitSelectClause(selectClause, p); + } + + @Override + public Cs.GroupClause visitGroupClause(Cs.GroupClause groupClause, P p) { + return (Cs.GroupClause) super.visitGroupClause(groupClause, p); + } + + @Override + public Cs.IndexerDeclaration visitIndexerDeclaration(Cs.IndexerDeclaration indexerDeclaration, P p) { + return (Cs.IndexerDeclaration) super.visitIndexerDeclaration(indexerDeclaration, p); + } + + @Override + public Cs.DelegateDeclaration visitDelegateDeclaration(Cs.DelegateDeclaration delegateDeclaration, P p) { + return (Cs.DelegateDeclaration) super.visitDelegateDeclaration(delegateDeclaration, p); + } + + @Override + public Cs.ConversionOperatorDeclaration visitConversionOperatorDeclaration(Cs.ConversionOperatorDeclaration conversionOperatorDeclaration, P p) { + return (Cs.ConversionOperatorDeclaration) super.visitConversionOperatorDeclaration(conversionOperatorDeclaration, p); + } + + @Override + public Cs.TypeParameter visitTypeParameter(Cs.TypeParameter typeParameter, P p) { + return (Cs.TypeParameter) super.visitTypeParameter(typeParameter, p); + } + + @Override + public Cs.EnumDeclaration visitEnumDeclaration(Cs.EnumDeclaration enumDeclaration, P p) { + return (Cs.EnumDeclaration) super.visitEnumDeclaration(enumDeclaration, p); + } + + @Override + public Cs.EnumMemberDeclaration visitEnumMemberDeclaration(Cs.EnumMemberDeclaration enumMemberDeclaration, P p) { + return (Cs.EnumMemberDeclaration) super.visitEnumMemberDeclaration(enumMemberDeclaration, p); + } + + @Override + public Cs.AliasQualifiedName visitAliasQualifiedName(Cs.AliasQualifiedName aliasQualifiedName, P p) { + return (Cs.AliasQualifiedName) super.visitAliasQualifiedName(aliasQualifiedName, p); + } + + @Override + public Cs.ArrayType visitArrayType(Cs.ArrayType arrayType, P p) { + return (Cs.ArrayType) super.visitArrayType(arrayType, p); + } + @Override public J.AnnotatedType visitAnnotatedType(J.AnnotatedType annotatedType, P p) { return (J.AnnotatedType) super.visitAnnotatedType(annotatedType, p); diff --git a/rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpPrinter.java b/rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpPrinter.java index f801947..51b1863 100644 --- a/rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpPrinter.java +++ b/rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpPrinter.java @@ -31,6 +31,7 @@ import org.openrewrite.marker.Marker; import org.openrewrite.marker.Markers; +import javax.swing.plaf.nimbus.State; import java.util.List; import java.util.function.UnaryOperator; @@ -47,6 +48,133 @@ public J visit(@Nullable Tree tree, PrintOutputCapture

p) { } } + @Override + public Cs visitArrayType(Cs.ArrayType newArray, PrintOutputCapture

p) { + beforeSyntax(newArray, CsSpace.Location.ARRAY_TYPE_PREFIX, p); + visit(newArray.getTypeExpression(), p); + visit(newArray.getDimensions(), p); + afterSyntax(newArray, p); + return newArray; + } + + @Override + public J visitAliasQualifiedName(Cs.AliasQualifiedName node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.ALIAS_QUALIFIED_NAME_PREFIX, p); + visitRightPadded(node.getPadding().getAlias(), CsRightPadded.Location.ALIAS_QUALIFIED_NAME_ALIAS, p); + p.append("::"); + visit(node.getName(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitTypeParameter(Cs.TypeParameter node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.TYPE_PARAMETER_PREFIX, p); + visit(node.getAttributeLists(), p); + visitLeftPaddedEnum(node.getPadding().getVariance(), CsLeftPadded.Location.TYPE_PARAMETER_VARIANCE, p); + visit(node.getName(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitQueryExpression(Cs.QueryExpression node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.QUERY_EXPRESSION_PREFIX, p); + visit(node.getFromClause(), p); + visit(node.getBody(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitQueryContinuation(Cs.QueryContinuation node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.QUERY_CONTINUATION_PREFIX, p); + p.append("into"); + visit(node.getIdentifier(), p); + visit(node.getBody(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitFromClause(Cs.FromClause node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.FROM_CLAUSE_PREFIX, p); + p.append("from"); + visit(node.getTypeIdentifier(), p); + visitRightPadded(node.getPadding().getIdentifier(), CsRightPadded.Location.FROM_CLAUSE_IDENTIFIER, p); + p.append("in"); + visit(node.getExpression(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitQueryBody(Cs.QueryBody node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.QUERY_BODY_PREFIX, p); + for (J clause : node.getClauses()) { + visit(clause, p); + } + visit(node.getSelectOrGroup(), p); + visit(node.getContinuation(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitLetClause(Cs.LetClause node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.LET_CLAUSE_PREFIX, p); + p.append("let"); + visitRightPadded(node.getPadding().getIdentifier(), CsRightPadded.Location.LET_CLAUSE_IDENTIFIER, p); + p.append("="); + visit(node.getExpression(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitJoinClause(Cs.JoinClause node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.JOIN_CLAUSE_PREFIX, p); + p.append("join"); + visitRightPadded(node.getPadding().getIdentifier(), CsRightPadded.Location.JOIN_CLAUSE_IDENTIFIER, p); + p.append("in"); + visitRightPadded(node.getPadding().getInExpression(), CsRightPadded.Location.JOIN_CLAUSE_IN_EXPRESSION, p); + p.append("on"); + visitRightPadded(node.getPadding().getLeftExpression(), CsRightPadded.Location.JOIN_CLAUSE_LEFT_EXPRESSION, p); + p.append("equals"); + visit(node.getRightExpression(), p); + visitLeftPadded("into", node.getPadding().getInto(), CsLeftPadded.Location.JOIN_CLAUSE_INTO, p); + visit(node.getInto(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitWhereClause(Cs.WhereClause node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.WHERE_CLAUSE_PREFIX, p); + p.append("where"); + visit(node.getCondition(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitJoinIntoClause(Cs.JoinIntoClause node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.JOIN_INTO_CLAUSE_PREFIX, p); + p.append("into"); + visit(node.getIdentifier(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitOrderByClause(Cs.OrderByClause node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.JOIN_INTO_CLAUSE_PREFIX, p); + p.append("orderby"); + visitRightPadded(node.getPadding().getOrderings(), CsRightPadded.Location.ORDER_BY_CLAUSE_ORDERINGS, ",", p); + afterSyntax(node, p); + return node; + } + public J visitForEachVariableLoop(Cs.ForEachVariableLoop forEachLoop, PrintOutputCapture

p) { beforeSyntax(forEachLoop, Space.Location.FOR_EACH_LOOP_PREFIX, p); p.append("foreach"); @@ -61,6 +189,38 @@ public J visitForEachVariableLoop(Cs.ForEachVariableLoop forEachLoop, PrintOutpu return forEachLoop; } + @Override + public Cs visitGroupClause(Cs.GroupClause node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.GROUP_CLAUSE_PREFIX, p); + p.append("group"); + visitRightPadded(node.getPadding().getGroupExpression(), CsRightPadded.Location.GROUP_CLAUSE_GROUP_EXPRESSION, "by", p); + visit(node.getKey(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitSelectClause(Cs.SelectClause node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.SELECT_CLAUSE_PREFIX, p); + p.append("select"); + visit(node.getExpression(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitOrdering(Cs.Ordering node, PrintOutputCapture

p) { + String direction = null; + if(node.getDirection() != null){ + direction = node.getDirection().toString().toLowerCase(); + } + beforeSyntax(node, CsSpace.Location.ORDERING_PREFIX, p); + visitRightPadded(node.getPadding().getExpression(), CsRightPadded.Location.ORDERING_EXPRESSION, p); + p.append(direction); + afterSyntax(node, p); + return node; + } + protected void visitRightPadded(JRightPadded rightPadded, CsRightPadded.Location location, String suffix, PrintOutputCapture

p) { if (rightPadded != null) { beforeSyntax(Space.EMPTY, rightPadded.getMarkers(), (CsSpace.Location) null, p); @@ -458,13 +618,12 @@ public J visitSingleVariableDesignation(Cs.SingleVariableDesignation node, Print public J visitUsingStatement(Cs.UsingStatement usingStatement, PrintOutputCapture

p) { beforeSyntax(usingStatement, CsSpace.Location.NAMED_ARGUMENT_PREFIX, p); - p.append("using"); if (usingStatement.getAwaitKeyword() != null) { visit(usingStatement.getAwaitKeyword(), p); } - visitContainer("(", usingStatement.getPadding().getExpression(), CsContainer.Location.USING_STATEMENT_EXPRESSION, "", ")", p); + visitLeftPadded("using", usingStatement.getPadding().getExpression(), CsLeftPadded.Location.USING_STATEMENT_EXPRESSION, p); visit(usingStatement.getStatement(), p); afterSyntax(usingStatement, p); return usingStatement; @@ -474,9 +633,19 @@ public J visitUsingStatement(Cs.UsingStatement usingStatement, PrintOutputCaptur public Cs visitUnary(Cs.Unary unary, PrintOutputCapture

p) { beforeSyntax(unary, Space.Location.UNARY_PREFIX, p); - switch (unary.getOperator()) - { - default: + switch (unary.getOperator()) { + case FromEnd: + p.append("^"); + visit(unary.getExpression(), p); + break; + case PointerIndirection: + visit(unary.getExpression(), p); + p.append("*"); + break; + case AddressOf: + p.append("&"); + visit(unary.getExpression(), p); + break; case SuppressNullableWarning: visit(unary.getExpression(), p); p.append("!"); @@ -508,21 +677,67 @@ public Cs visitCompilationUnit(Cs.CompilationUnit compilationUnit, PrintOutputCa } @Override - public J visitClassDeclaration(Cs.ClassDeclaration classDeclaration, PrintOutputCapture

p) - { - delegate.visit(classDeclaration.getClassDeclarationCore(), p); - return classDeclaration; + public J visitClassDeclaration(Cs.ClassDeclaration node, PrintOutputCapture

p) { + String kind = ""; + switch (node.getPadding().getKind().getType()) { + case Class: + case Annotation: + kind = "class"; + break; + case Enum: + kind = "enum"; + break; + case Interface: + kind = "interface"; + break; + case Record: + kind = "record"; + break; + case Value: + kind = "struct"; + break; + } + + + + beforeSyntax(node, Space.Location.CLASS_DECLARATION_PREFIX, p); + visit(node.getAttributeList(), p); + visit(node.getModifiers(), p); + + visitSpace(node.getPadding().getKind().getPrefix(), Space.Location.CLASS_KIND, p); + p.append(kind); + visit(node.getName(), p); + visitContainer("<", node.getPadding().getTypeParameters(), CsContainer.Location.CLASS_DECLARATION_TYPE_PARAMETERS, ",", ">", p); + visitContainer("(", node.getPadding().getPrimaryConstructor(), CsContainer.Location.CLASS_DECLARATION_PRIMARY_CONSTRUCTOR, ",", ")", p); + visitLeftPadded(":", node.getPadding().getExtendings(), CsLeftPadded.Location.CLASS_DECLARATION_EXTENDINGS, p); + visitContainer(node.getPadding().getExtendings() == null ? ":" : ",", node.getPadding().getImplementings(), CsContainer.Location.CLASS_DECLARATION_IMPLEMENTINGS, ",", "", p); + visitContainer("", node.getPadding().getTypeParameterConstraintClauses(), CsContainer.Location.CLASS_DECLARATION_TYPE_PARAMETERS, "", "", p); + + visit(node.getBody(), p); + afterSyntax(node, p); + return node; } @Override - public J visitMethodDeclaration(Cs.MethodDeclaration methodDeclaration, PrintOutputCapture

p) - { - delegate.visitMethodDeclaration(methodDeclaration.getMethodDeclarationCore(), p); - if (methodDeclaration.getMethodDeclarationCore().getBody() == null) - { - p.append(";"); + public J visitMethodDeclaration(Cs.MethodDeclaration node, PrintOutputCapture

p) { + beforeSyntax(node, Space.Location.METHOD_DECLARATION_PREFIX, p); + visitSpace(Space.EMPTY, Space.Location.ANNOTATIONS, p); + + visit(node.getModifiers(), p); + visit(node.getReturnTypeExpression(), p); + visitRightPadded(node.getPadding().getExplicitInterfaceSpecifier(), CsRightPadded.Location.METHOD_DECLARATION_EXPLICIT_INTERFACE_SPECIFIER, ".", p); + visit(node.getName(), p); + + visitContainer("<", node.getPadding().getTypeParameters(), CsContainer.Location.METHOD_DECLARATION_TYPE_PARAMETERS, ",", ">", p); + + if (!node.getMarkers().findFirst(CompactConstructor.class).isPresent()) { + visitContainer("(", node.getPadding().getParameters(), CsContainer.Location.METHOD_DECLARATION_PARAMETERS, ",", ")", p); } - return methodDeclaration; + + visitContainer(node.getPadding().getTypeParameterConstraintClauses(), CsContainer.Location.METHOD_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES, p); + visit(node.getBody(), p); + afterSyntax(node, p); + return node; } @Override @@ -627,10 +842,25 @@ public J visitCollectionExpression(Cs.CollectionExpression collectionExpression, return collectionExpression; } + @Override + public J visitEnumDeclaration(Cs.EnumDeclaration node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.ENUM_DECLARATION_PREFIX, p); + visit(node.getAttributeLists(), p); + visit(node.getModifiers(), p); + visitLeftPadded("enum", node.getPadding().getName(), CsLeftPadded.Location.ENUM_DECLARATION_NAME, p); + if (node.getBaseType() != null) { + visitLeftPadded(":", node.getPadding().getBaseType(), CsLeftPadded.Location.ENUM_DECLARATION_BASE_TYPE, p); + } + visitContainer("{", node.getPadding().getMembers(), CsContainer.Location.ENUM_DECLARATION_MEMBERS, ",", "}", p); + afterSyntax(node, p); + return node; + } + @Override public J visitExpressionStatement(Cs.ExpressionStatement expressionStatement, PrintOutputCapture

p) { beforeSyntax(expressionStatement, CsSpace.Location.AWAIT_EXPRESSION_PREFIX, p); - visit(expressionStatement.getExpression(), p); + visitRightPadded(expressionStatement.getPadding().getExpression(), CsRightPadded.Location.EXPRESSION_STATEMENT_EXPRESSION, p); + p.append(";"); afterSyntax(expressionStatement, p); return expressionStatement; } @@ -700,44 +930,6 @@ public J visitNullSafeExpression(Cs.NullSafeExpression nullSafeExpression, Print return nullSafeExpression; } - @Override - public Cs visitConstructor(Cs.Constructor constructor, PrintOutputCapture

p) - { - J.MethodDeclaration method = constructor.getConstructorCore(); - beforeSyntax(method, Space.Location.METHOD_DECLARATION_PREFIX, p); - visitSpace(Space.EMPTY, Space.Location.ANNOTATIONS, p); - visit(method.getLeadingAnnotations(), p); - for (J.Modifier modifier : method.getModifiers()) - { - delegate.visitModifier(modifier, p); - } - - visit(method.getAnnotations().getName().getAnnotations(), p); - visit(method.getName(), p); - - - if (!method.getMarkers().findFirst(CompactConstructor.class).isPresent()) { - visitContainer("(", method.getPadding().getParameters(), CsContainer.Location.METHOD_DECLARATION_PARAMETERS, ",", ")", p); - } - - visit(constructor.getInitializer(), p); - - visit(method.getBody(), p); - afterSyntax(constructor, p); - return constructor; - } - - @Override - public Cs visitConstructorInitializer(Cs.ConstructorInitializer node, PrintOutputCapture

p) - { - beforeSyntax(node, Space.Location.METHOD_DECLARATION_PREFIX, p); - p.append(":"); - visit(node.getKeyword(), p); - visitContainer("(", node.getPadding().getArguments(), CsContainer.Location.CONSTRUCTOR_INITIALIZER_ARGUMENTS, ",", ")", p); - afterSyntax(node, p); - return node; - } - @Override public J visitPropertyDeclaration(Cs.PropertyDeclaration propertyDeclaration, PrintOutputCapture

p) { @@ -784,6 +976,118 @@ public J visitUsingDirective(Cs.UsingDirective usingDirective, PrintOutputCaptur return usingDirective; } + @Override + public J visitConversionOperatorDeclaration(Cs.ConversionOperatorDeclaration node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.CONVERSION_OPERATOR_DECLARATION_PREFIX, p); + for (J modifier : node.getModifiers()) { + visit(modifier, p); + } + visitLeftPadded(node.getPadding().getKind(), CsLeftPadded.Location.CONVERSION_OPERATOR_DECLARATION_KIND, p); + p.append(node.getKind().toString().toLowerCase()); + visitLeftPadded("operator", node.getPadding().getReturnType(), CsLeftPadded.Location.CONVERSION_OPERATOR_DECLARATION_RETURN_TYPE, p); + visitContainer("(", node.getPadding().getParameters(), CsContainer.Location.CONVERSION_OPERATOR_DECLARATION_PARAMETERS, ",", ")", p); + visit(node.getExpressionBody(), p); + visit(node.getBody(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitEnumMemberDeclaration(Cs.EnumMemberDeclaration node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.ENUM_MEMBER_DECLARATION_PREFIX, p); + visit(node.getAttributeLists(), p); + visit(node.getName(), p); + visitLeftPadded("=", node.getPadding().getInitializer(), CsLeftPadded.Location.ENUM_MEMBER_DECLARATION_INITIALIZER, p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitIndexerDeclaration(Cs.IndexerDeclaration node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.INDEXER_DECLARATION_PREFIX, p); + for (J modifier : node.getModifiers()) { + visit(modifier, p); + } + visit(node.getTypeExpression(), p); + visit(node.getIndexer(), p); + visitContainer("[", node.getPadding().getParameters(), CsContainer.Location.INDEXER_DECLARATION_PARAMETERS, ",", "]", p); + visitLeftPadded("", node.getPadding().getExpressionBody(), CsLeftPadded.Location.INDEXER_DECLARATION_EXPRESSION_BODY, p); + visit(node.getAccessors(), p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitDelegateDeclaration(Cs.DelegateDeclaration node, PrintOutputCapture

p) { + beforeSyntax(node, CsSpace.Location.DELEGATE_DECLARATION_PREFIX, p); + for (J modifier : node.getModifiers()) { + visit(modifier, p); + } + visitLeftPadded("delegate", node.getPadding().getReturnType(), CsLeftPadded.Location.DELEGATE_DECLARATION_RETURN_TYPE, p); + visit(node.getIdentifier(), p); + visitContainer("<", node.getPadding().getTypeParameters(), CsContainer.Location.CONVERSION_OPERATOR_DECLARATION_PARAMETERS, ",", ">", p); + visitContainer("(", node.getPadding().getParameters(), CsContainer.Location.CONVERSION_OPERATOR_DECLARATION_PARAMETERS, ",", ")", p); + visitContainer(node.getPadding().getTypeParameterConstraintClauses(), CsContainer.Location.DELEGATE_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES, p); + afterSyntax(node, p); + return node; + } + + @Override + public J visitDestructorDeclaration(Cs.DestructorDeclaration node, PrintOutputCapture

p) { + J.MethodDeclaration method = node.getMethodCore(); + beforeSyntax(method, CsSpace.Location.DESTRUCTOR_DECLARATION_PREFIX, p); + visitSpace(Space.EMPTY, Space.Location.ANNOTATIONS, p); + visit(method.getLeadingAnnotations(), p); + for (J.Modifier modifier : method.getModifiers()) { + delegate.visit(modifier, p); + } + visit(method.getAnnotations().getName().getAnnotations(), p); + p.append("~"); + visit(method.getName(), p); + visitContainer("(", method.getPadding().getParameters(), CsContainer.Location.METHOD_DECLARATION_PARAMETERS, ",", ")", p); + visit(method.getBody(), p); + afterSyntax(node, p); + return node; + } + + @Override + public Cs visitConstructor(Cs.Constructor constructor, PrintOutputCapture

p) + { + J.MethodDeclaration method = constructor.getConstructorCore(); + beforeSyntax(method, Space.Location.METHOD_DECLARATION_PREFIX, p); + visitSpace(Space.EMPTY, Space.Location.ANNOTATIONS, p); + visit(method.getLeadingAnnotations(), p); + for (J.Modifier modifier : method.getModifiers()) + { + delegate.visit(modifier, p); + } + + visit(method.getAnnotations().getName().getAnnotations(), p); + visit(method.getName(), p); + + + if (!method.getMarkers().findFirst(CompactConstructor.class).isPresent()) { + visitContainer("(", method.getPadding().getParameters(), CsContainer.Location.METHOD_DECLARATION_PARAMETERS, ",", ")", p); + } + + visit(constructor.getInitializer(), p); + + visit(method.getBody(), p); + afterSyntax(constructor, p); + return constructor; + } + + @Override + public Cs visitConstructorInitializer(Cs.ConstructorInitializer node, PrintOutputCapture

p) + { + beforeSyntax(node, Space.Location.METHOD_DECLARATION_PREFIX, p); + p.append(":"); + visit(node.getKeyword(), p); + visitContainer("(", node.getPadding().getArguments(), CsContainer.Location.CONSTRUCTOR_INITIALIZER_ARGUMENTS, ",", ")", p); + afterSyntax(node, p); + return node; + } + @Override public Cs visitLambda(Cs.Lambda lambda, PrintOutputCapture

p) { @@ -814,6 +1118,12 @@ public Space visitSpace(Space space, Space.Location loc, PrintOutputCapture

p return delegate.visitSpace(space, loc, p); } + protected void visitLeftPaddedEnum(@Nullable JLeftPadded leftPadded, CsLeftPadded.Location location, PrintOutputCapture

p) { + if (leftPadded == null) + return; + visitLeftPadded(leftPadded, location, p); + p.append(leftPadded.getElement().toString().toLowerCase()); + } protected void visitLeftPadded(@Nullable String prefix, @Nullable JLeftPadded leftPadded, CsLeftPadded.Location location, PrintOutputCapture

p) { if (leftPadded != null) { beforeSyntax(leftPadded.getBefore(), leftPadded.getMarkers(), location.getBeforeLocation(), p); @@ -1032,10 +1342,6 @@ public J visitBlock(J.Block block, PrintOutputCapture

p) { if (block.getMarkers().findFirst(SingleExpressionBlock.class).isPresent()) { p.append("=>"); visitStatements(block.getPadding().getStatements(), JRightPadded.Location.BLOCK_STATEMENT, p); - if (!(block.getStatements().get(0) instanceof Cs.ExpressionStatement)) // expression statements print their own semicolon - { - p.append(";"); - } visitSpace(block.getEnd(), Space.Location.BLOCK_END, p); } else if (!block.getMarkers().findFirst(OmitBraces.class).isPresent() || !block.getStatements().isEmpty()) { p.append('{'); @@ -1246,7 +1552,43 @@ public M visitMarker(Marker marker, PrintOutputCapture

p) @Override protected void printStatementTerminator(Statement s, PrintOutputCapture

p) { - if (s instanceof Cs.ExpressionStatement || s instanceof Cs.AssignmentOperation || s instanceof Cs.Yield) { + if (s instanceof Cs.ExpressionStatement || + (s instanceof Cs.AwaitExpression && + ((Cs.AwaitExpression) s).getExpression() instanceof J.ForEachLoop && + ((J.ForEachLoop) ((Cs.AwaitExpression) s).getExpression()).getBody() instanceof J.Block)) { + return; + } + + if(s instanceof Cs.AwaitExpression) + { + Cs.AwaitExpression awaitExpression = (Cs.AwaitExpression) s; + if(awaitExpression.getExpression() instanceof J.ForEachLoop) + { + J.ForEachLoop loop = (J.ForEachLoop) awaitExpression.getExpression(); + if(loop.getBody() instanceof J.Block){ + p.append(';'); + } + } + } + + boolean usingStatementRequiresSemicolon = false; + if(s instanceof Cs.UsingStatement) + { + Cs.UsingStatement usingStatement = (Cs.UsingStatement) s; + Statement usingBody = usingStatement.getStatement(); + if(!(usingBody instanceof J.Block) && + !(usingStatement.getStatement() instanceof Cs.UsingStatement) && + !(usingStatement.getStatement() instanceof Cs.ExpressionStatement)) + { + usingStatementRequiresSemicolon = true; + } + } + + if (s instanceof Cs.AssignmentOperation || + s instanceof Cs.Yield || + s instanceof Cs.DelegateDeclaration || + usingStatementRequiresSemicolon || + (s instanceof Cs.PropertyDeclaration && ((Cs.PropertyDeclaration) s).getInitializer() != null)) { p.append(';'); } else if (s instanceof Cs.PropertyDeclaration && (((Cs.PropertyDeclaration) s).getInitializer() != null)) { p.append(';'); diff --git a/rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpVisitor.java b/rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpVisitor.java index 284a95b..1467d61 100644 --- a/rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpVisitor.java +++ b/rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpVisitor.java @@ -145,6 +145,12 @@ public J visitAttributeList(Cs.AttributeList attributeList, P p) { public J visitAwaitExpression(Cs.AwaitExpression awaitExpression, P p) { awaitExpression = awaitExpression.withPrefix(visitSpace(awaitExpression.getPrefix(), CsSpace.Location.AWAIT_EXPRESSION_PREFIX, p)); + Statement tempStatement = (Statement) visitStatement(awaitExpression, p); + if (!(tempStatement instanceof Cs.AwaitExpression)) + { + return tempStatement; + } + awaitExpression = (Cs.AwaitExpression) tempStatement; Expression tempExpression = (Expression) visitExpression(awaitExpression, p); if (!(tempExpression instanceof Cs.AwaitExpression)) { @@ -210,7 +216,7 @@ public J visitExpressionStatement(Cs.ExpressionStatement expressionStatement, P } expressionStatement = (Cs.ExpressionStatement) tempStatement; expressionStatement = expressionStatement.withMarkers(visitMarkers(expressionStatement.getMarkers(), p)); - expressionStatement = expressionStatement.withExpression(visitAndCast(expressionStatement.getExpression(), p)); + expressionStatement = expressionStatement.getPadding().withExpression(visitRightPadded(expressionStatement.getPadding().getExpression(), CsRightPadded.Location.EXPRESSION_STATEMENT_EXPRESSION, p)); return expressionStatement; } @@ -368,7 +374,15 @@ public J visitClassDeclaration(Cs.ClassDeclaration classDeclaration, P p) { } classDeclaration = (Cs.ClassDeclaration) tempStatement; classDeclaration = classDeclaration.withMarkers(visitMarkers(classDeclaration.getMarkers(), p)); - classDeclaration = classDeclaration.withClassDeclarationCore(visitAndCast(classDeclaration.getClassDeclarationCore(), p)); + classDeclaration = classDeclaration.withAttributeList(ListUtils.map(classDeclaration.getAttributeList(), el -> (Cs.AttributeList)visit(el, p))); + classDeclaration = classDeclaration.withModifiers(ListUtils.map(classDeclaration.getModifiers(), el -> (J.Modifier)visit(el, p))); + classDeclaration = classDeclaration.getPadding().withKind(visitAndCast(classDeclaration.getPadding().getKind(), p)); + classDeclaration = classDeclaration.withName(visitAndCast(classDeclaration.getName(), p)); + classDeclaration = classDeclaration.getPadding().withTypeParameters(visitContainer(classDeclaration.getPadding().getTypeParameters(), CsContainer.Location.CLASS_DECLARATION_TYPE_PARAMETERS, p)); + classDeclaration = classDeclaration.getPadding().withPrimaryConstructor(visitContainer(classDeclaration.getPadding().getPrimaryConstructor(), CsContainer.Location.CLASS_DECLARATION_PRIMARY_CONSTRUCTOR, p)); + classDeclaration = classDeclaration.getPadding().withExtendings(visitLeftPadded(classDeclaration.getPadding().getExtendings(), CsLeftPadded.Location.CLASS_DECLARATION_EXTENDINGS, p)); + classDeclaration = classDeclaration.getPadding().withImplementings(visitContainer(classDeclaration.getPadding().getImplementings(), CsContainer.Location.CLASS_DECLARATION_IMPLEMENTINGS, p)); + classDeclaration = classDeclaration.withBody(visitAndCast(classDeclaration.getBody(), p)); classDeclaration = classDeclaration.getPadding().withTypeParameterConstraintClauses(visitContainer(classDeclaration.getPadding().getTypeParameterConstraintClauses(), CsContainer.Location.CLASS_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES, p)); return classDeclaration; } @@ -382,7 +396,14 @@ public J visitMethodDeclaration(Cs.MethodDeclaration methodDeclaration, P p) { } methodDeclaration = (Cs.MethodDeclaration) tempStatement; methodDeclaration = methodDeclaration.withMarkers(visitMarkers(methodDeclaration.getMarkers(), p)); - methodDeclaration = methodDeclaration.withMethodDeclarationCore(visitAndCast(methodDeclaration.getMethodDeclarationCore(), p)); + methodDeclaration = methodDeclaration.withAttributes(ListUtils.map(methodDeclaration.getAttributes(), el -> (Cs.AttributeList)visit(el, p))); + methodDeclaration = methodDeclaration.withModifiers(ListUtils.map(methodDeclaration.getModifiers(), el -> (J.Modifier)visit(el, p))); + methodDeclaration = methodDeclaration.getPadding().withTypeParameters(visitContainer(methodDeclaration.getPadding().getTypeParameters(), CsContainer.Location.METHOD_DECLARATION_TYPE_PARAMETERS, p)); + methodDeclaration = methodDeclaration.withReturnTypeExpression(visitAndCast(methodDeclaration.getReturnTypeExpression(), p)); + methodDeclaration = methodDeclaration.getPadding().withExplicitInterfaceSpecifier(visitRightPadded(methodDeclaration.getPadding().getExplicitInterfaceSpecifier(), CsRightPadded.Location.METHOD_DECLARATION_EXPLICIT_INTERFACE_SPECIFIER, p)); + methodDeclaration = methodDeclaration.withName(visitAndCast(methodDeclaration.getName(), p)); + methodDeclaration = methodDeclaration.getPadding().withParameters(visitContainer(methodDeclaration.getPadding().getParameters(), CsContainer.Location.METHOD_DECLARATION_PARAMETERS, p)); + methodDeclaration = methodDeclaration.withBody(visitAndCast(methodDeclaration.getBody(), p)); methodDeclaration = methodDeclaration.getPadding().withTypeParameterConstraintClauses(visitContainer(methodDeclaration.getPadding().getTypeParameterConstraintClauses(), CsContainer.Location.METHOD_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES, p)); return methodDeclaration; } @@ -397,7 +418,7 @@ public J visitUsingStatement(Cs.UsingStatement usingStatement, P p) { usingStatement = (Cs.UsingStatement) tempStatement; usingStatement = usingStatement.withMarkers(visitMarkers(usingStatement.getMarkers(), p)); usingStatement = usingStatement.withAwaitKeyword(visitAndCast(usingStatement.getAwaitKeyword(), p)); - usingStatement = usingStatement.getPadding().withExpression(visitContainer(usingStatement.getPadding().getExpression(), CsContainer.Location.USING_STATEMENT_EXPRESSION, p)); + usingStatement = usingStatement.getPadding().withExpression(visitLeftPadded(usingStatement.getPadding().getExpression(), CsLeftPadded.Location.USING_STATEMENT_EXPRESSION, p)); usingStatement = usingStatement.withStatement(visitAndCast(usingStatement.getStatement(), p)); return usingStatement; } @@ -537,8 +558,7 @@ public J visitDestructorDeclaration(Cs.DestructorDeclaration destructorDeclarati } destructorDeclaration = (Cs.DestructorDeclaration) tempStatement; destructorDeclaration = destructorDeclaration.withMarkers(visitMarkers(destructorDeclaration.getMarkers(), p)); - destructorDeclaration = destructorDeclaration.withInitializer(visitAndCast(destructorDeclaration.getInitializer(), p)); - destructorDeclaration = destructorDeclaration.withConstructorCore(visitAndCast(destructorDeclaration.getConstructorCore(), p)); + destructorDeclaration = destructorDeclaration.withMethodCore(visitAndCast(destructorDeclaration.getMethodCore(), p)); return destructorDeclaration; } @@ -997,6 +1017,231 @@ public J visitRangeExpression(Cs.RangeExpression rangeExpression, P p) { return rangeExpression; } + public J visitQueryExpression(Cs.QueryExpression queryExpression, P p) { + queryExpression = queryExpression.withPrefix(visitSpace(queryExpression.getPrefix(), CsSpace.Location.QUERY_EXPRESSION_PREFIX, p)); + Expression tempExpression = (Expression) visitExpression(queryExpression, p); + if (!(tempExpression instanceof Cs.QueryExpression)) + { + return tempExpression; + } + queryExpression = (Cs.QueryExpression) tempExpression; + queryExpression = queryExpression.withMarkers(visitMarkers(queryExpression.getMarkers(), p)); + queryExpression = queryExpression.withFromClause(visitAndCast(queryExpression.getFromClause(), p)); + queryExpression = queryExpression.withBody(visitAndCast(queryExpression.getBody(), p)); + return queryExpression; + } + + public J visitQueryBody(Cs.QueryBody queryBody, P p) { + queryBody = queryBody.withPrefix(visitSpace(queryBody.getPrefix(), CsSpace.Location.QUERY_BODY_PREFIX, p)); + queryBody = queryBody.withMarkers(visitMarkers(queryBody.getMarkers(), p)); + queryBody = queryBody.withClauses(ListUtils.map(queryBody.getClauses(), el -> (Cs.QueryClause)visit(el, p))); + queryBody = queryBody.withSelectOrGroup(visitAndCast(queryBody.getSelectOrGroup(), p)); + queryBody = queryBody.withContinuation(visitAndCast(queryBody.getContinuation(), p)); + return queryBody; + } + + public J visitFromClause(Cs.FromClause fromClause, P p) { + fromClause = fromClause.withPrefix(visitSpace(fromClause.getPrefix(), CsSpace.Location.FROM_CLAUSE_PREFIX, p)); + Expression tempExpression = (Expression) visitExpression(fromClause, p); + if (!(tempExpression instanceof Cs.FromClause)) + { + return tempExpression; + } + fromClause = (Cs.FromClause) tempExpression; + fromClause = fromClause.withMarkers(visitMarkers(fromClause.getMarkers(), p)); + fromClause = fromClause.withTypeIdentifier(visitAndCast(fromClause.getTypeIdentifier(), p)); + fromClause = fromClause.getPadding().withIdentifier(visitRightPadded(fromClause.getPadding().getIdentifier(), CsRightPadded.Location.FROM_CLAUSE_IDENTIFIER, p)); + fromClause = fromClause.withExpression(visitAndCast(fromClause.getExpression(), p)); + return fromClause; + } + + public J visitLetClause(Cs.LetClause letClause, P p) { + letClause = letClause.withPrefix(visitSpace(letClause.getPrefix(), CsSpace.Location.LET_CLAUSE_PREFIX, p)); + letClause = letClause.withMarkers(visitMarkers(letClause.getMarkers(), p)); + letClause = letClause.getPadding().withIdentifier(visitRightPadded(letClause.getPadding().getIdentifier(), CsRightPadded.Location.LET_CLAUSE_IDENTIFIER, p)); + letClause = letClause.withExpression(visitAndCast(letClause.getExpression(), p)); + return letClause; + } + + public J visitJoinClause(Cs.JoinClause joinClause, P p) { + joinClause = joinClause.withPrefix(visitSpace(joinClause.getPrefix(), CsSpace.Location.JOIN_CLAUSE_PREFIX, p)); + joinClause = joinClause.withMarkers(visitMarkers(joinClause.getMarkers(), p)); + joinClause = joinClause.getPadding().withIdentifier(visitRightPadded(joinClause.getPadding().getIdentifier(), CsRightPadded.Location.JOIN_CLAUSE_IDENTIFIER, p)); + joinClause = joinClause.getPadding().withInExpression(visitRightPadded(joinClause.getPadding().getInExpression(), CsRightPadded.Location.JOIN_CLAUSE_IN_EXPRESSION, p)); + joinClause = joinClause.getPadding().withLeftExpression(visitRightPadded(joinClause.getPadding().getLeftExpression(), CsRightPadded.Location.JOIN_CLAUSE_LEFT_EXPRESSION, p)); + joinClause = joinClause.withRightExpression(visitAndCast(joinClause.getRightExpression(), p)); + joinClause = joinClause.getPadding().withInto(visitLeftPadded(joinClause.getPadding().getInto(), CsLeftPadded.Location.JOIN_CLAUSE_INTO, p)); + return joinClause; + } + + public J visitJoinIntoClause(Cs.JoinIntoClause joinIntoClause, P p) { + joinIntoClause = joinIntoClause.withPrefix(visitSpace(joinIntoClause.getPrefix(), CsSpace.Location.JOIN_INTO_CLAUSE_PREFIX, p)); + joinIntoClause = joinIntoClause.withMarkers(visitMarkers(joinIntoClause.getMarkers(), p)); + joinIntoClause = joinIntoClause.withIdentifier(visitAndCast(joinIntoClause.getIdentifier(), p)); + return joinIntoClause; + } + + public J visitWhereClause(Cs.WhereClause whereClause, P p) { + whereClause = whereClause.withPrefix(visitSpace(whereClause.getPrefix(), CsSpace.Location.WHERE_CLAUSE_PREFIX, p)); + whereClause = whereClause.withMarkers(visitMarkers(whereClause.getMarkers(), p)); + whereClause = whereClause.withCondition(visitAndCast(whereClause.getCondition(), p)); + return whereClause; + } + + public J visitOrderByClause(Cs.OrderByClause orderByClause, P p) { + orderByClause = orderByClause.withPrefix(visitSpace(orderByClause.getPrefix(), CsSpace.Location.ORDER_BY_CLAUSE_PREFIX, p)); + orderByClause = orderByClause.withMarkers(visitMarkers(orderByClause.getMarkers(), p)); + orderByClause = orderByClause.getPadding().withOrderings(ListUtils.map(orderByClause.getPadding().getOrderings(), el -> visitRightPadded(el, CsRightPadded.Location.ORDER_BY_CLAUSE_ORDERINGS, p))); + return orderByClause; + } + + public J visitQueryContinuation(Cs.QueryContinuation queryContinuation, P p) { + queryContinuation = queryContinuation.withPrefix(visitSpace(queryContinuation.getPrefix(), CsSpace.Location.QUERY_CONTINUATION_PREFIX, p)); + queryContinuation = queryContinuation.withMarkers(visitMarkers(queryContinuation.getMarkers(), p)); + queryContinuation = queryContinuation.withIdentifier(visitAndCast(queryContinuation.getIdentifier(), p)); + queryContinuation = queryContinuation.withBody(visitAndCast(queryContinuation.getBody(), p)); + return queryContinuation; + } + + public J visitOrdering(Cs.Ordering ordering, P p) { + ordering = ordering.withPrefix(visitSpace(ordering.getPrefix(), CsSpace.Location.ORDERING_PREFIX, p)); + ordering = ordering.withMarkers(visitMarkers(ordering.getMarkers(), p)); + ordering = ordering.getPadding().withExpression(visitRightPadded(ordering.getPadding().getExpression(), CsRightPadded.Location.ORDERING_EXPRESSION, p)); + return ordering; + } + + public J visitSelectClause(Cs.SelectClause selectClause, P p) { + selectClause = selectClause.withPrefix(visitSpace(selectClause.getPrefix(), CsSpace.Location.SELECT_CLAUSE_PREFIX, p)); + selectClause = selectClause.withMarkers(visitMarkers(selectClause.getMarkers(), p)); + selectClause = selectClause.withExpression(visitAndCast(selectClause.getExpression(), p)); + return selectClause; + } + + public J visitGroupClause(Cs.GroupClause groupClause, P p) { + groupClause = groupClause.withPrefix(visitSpace(groupClause.getPrefix(), CsSpace.Location.GROUP_CLAUSE_PREFIX, p)); + groupClause = groupClause.withMarkers(visitMarkers(groupClause.getMarkers(), p)); + groupClause = groupClause.getPadding().withGroupExpression(visitRightPadded(groupClause.getPadding().getGroupExpression(), CsRightPadded.Location.GROUP_CLAUSE_GROUP_EXPRESSION, p)); + groupClause = groupClause.withKey(visitAndCast(groupClause.getKey(), p)); + return groupClause; + } + + public J visitIndexerDeclaration(Cs.IndexerDeclaration indexerDeclaration, P p) { + indexerDeclaration = indexerDeclaration.withPrefix(visitSpace(indexerDeclaration.getPrefix(), CsSpace.Location.INDEXER_DECLARATION_PREFIX, p)); + Statement tempStatement = (Statement) visitStatement(indexerDeclaration, p); + if (!(tempStatement instanceof Cs.IndexerDeclaration)) + { + return tempStatement; + } + indexerDeclaration = (Cs.IndexerDeclaration) tempStatement; + indexerDeclaration = indexerDeclaration.withMarkers(visitMarkers(indexerDeclaration.getMarkers(), p)); + indexerDeclaration = indexerDeclaration.withModifiers(ListUtils.map(indexerDeclaration.getModifiers(), el -> (J.Modifier)visit(el, p))); + indexerDeclaration = indexerDeclaration.withTypeExpression(visitAndCast(indexerDeclaration.getTypeExpression(), p)); + indexerDeclaration = indexerDeclaration.withIndexer(visitAndCast(indexerDeclaration.getIndexer(), p)); + indexerDeclaration = indexerDeclaration.getPadding().withParameters(visitContainer(indexerDeclaration.getPadding().getParameters(), CsContainer.Location.INDEXER_DECLARATION_PARAMETERS, p)); + indexerDeclaration = indexerDeclaration.getPadding().withExpressionBody(visitLeftPadded(indexerDeclaration.getPadding().getExpressionBody(), CsLeftPadded.Location.INDEXER_DECLARATION_EXPRESSION_BODY, p)); + indexerDeclaration = indexerDeclaration.withAccessors(visitAndCast(indexerDeclaration.getAccessors(), p)); + return indexerDeclaration; + } + + public J visitDelegateDeclaration(Cs.DelegateDeclaration delegateDeclaration, P p) { + delegateDeclaration = delegateDeclaration.withPrefix(visitSpace(delegateDeclaration.getPrefix(), CsSpace.Location.DELEGATE_DECLARATION_PREFIX, p)); + Statement tempStatement = (Statement) visitStatement(delegateDeclaration, p); + if (!(tempStatement instanceof Cs.DelegateDeclaration)) + { + return tempStatement; + } + delegateDeclaration = (Cs.DelegateDeclaration) tempStatement; + delegateDeclaration = delegateDeclaration.withMarkers(visitMarkers(delegateDeclaration.getMarkers(), p)); + delegateDeclaration = delegateDeclaration.withModifiers(ListUtils.map(delegateDeclaration.getModifiers(), el -> (J.Modifier)visit(el, p))); + delegateDeclaration = delegateDeclaration.getPadding().withReturnType(visitLeftPadded(delegateDeclaration.getPadding().getReturnType(), CsLeftPadded.Location.DELEGATE_DECLARATION_RETURN_TYPE, p)); + delegateDeclaration = delegateDeclaration.withIdentifier(visitAndCast(delegateDeclaration.getIdentifier(), p)); + delegateDeclaration = delegateDeclaration.getPadding().withTypeParameters(visitContainer(delegateDeclaration.getPadding().getTypeParameters(), CsContainer.Location.DELEGATE_DECLARATION_TYPE_PARAMETERS, p)); + delegateDeclaration = delegateDeclaration.getPadding().withParameters(visitContainer(delegateDeclaration.getPadding().getParameters(), CsContainer.Location.DELEGATE_DECLARATION_PARAMETERS, p)); + delegateDeclaration = delegateDeclaration.getPadding().withTypeParameterConstraintClauses(visitContainer(delegateDeclaration.getPadding().getTypeParameterConstraintClauses(), CsContainer.Location.DELEGATE_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES, p)); + return delegateDeclaration; + } + + public J visitConversionOperatorDeclaration(Cs.ConversionOperatorDeclaration conversionOperatorDeclaration, P p) { + conversionOperatorDeclaration = conversionOperatorDeclaration.withPrefix(visitSpace(conversionOperatorDeclaration.getPrefix(), CsSpace.Location.CONVERSION_OPERATOR_DECLARATION_PREFIX, p)); + Statement tempStatement = (Statement) visitStatement(conversionOperatorDeclaration, p); + if (!(tempStatement instanceof Cs.ConversionOperatorDeclaration)) + { + return tempStatement; + } + conversionOperatorDeclaration = (Cs.ConversionOperatorDeclaration) tempStatement; + conversionOperatorDeclaration = conversionOperatorDeclaration.withMarkers(visitMarkers(conversionOperatorDeclaration.getMarkers(), p)); + conversionOperatorDeclaration = conversionOperatorDeclaration.withModifiers(ListUtils.map(conversionOperatorDeclaration.getModifiers(), el -> (J.Modifier)visit(el, p))); + conversionOperatorDeclaration = conversionOperatorDeclaration.getPadding().withKind(visitLeftPadded(conversionOperatorDeclaration.getPadding().getKind(), CsLeftPadded.Location.CONVERSION_OPERATOR_DECLARATION_KIND, p)); + conversionOperatorDeclaration = conversionOperatorDeclaration.getPadding().withReturnType(visitLeftPadded(conversionOperatorDeclaration.getPadding().getReturnType(), CsLeftPadded.Location.CONVERSION_OPERATOR_DECLARATION_RETURN_TYPE, p)); + conversionOperatorDeclaration = conversionOperatorDeclaration.getPadding().withParameters(visitContainer(conversionOperatorDeclaration.getPadding().getParameters(), CsContainer.Location.CONVERSION_OPERATOR_DECLARATION_PARAMETERS, p)); + conversionOperatorDeclaration = conversionOperatorDeclaration.getPadding().withExpressionBody(visitLeftPadded(conversionOperatorDeclaration.getPadding().getExpressionBody(), CsLeftPadded.Location.CONVERSION_OPERATOR_DECLARATION_EXPRESSION_BODY, p)); + conversionOperatorDeclaration = conversionOperatorDeclaration.withBody(visitAndCast(conversionOperatorDeclaration.getBody(), p)); + return conversionOperatorDeclaration; + } + + public J visitTypeParameter(Cs.TypeParameter typeParameter, P p) { + typeParameter = typeParameter.withPrefix(visitSpace(typeParameter.getPrefix(), CsSpace.Location.TYPE_PARAMETER_PREFIX, p)); + typeParameter = typeParameter.withMarkers(visitMarkers(typeParameter.getMarkers(), p)); + typeParameter = typeParameter.withAttributeLists(ListUtils.map(typeParameter.getAttributeLists(), el -> (Cs.AttributeList)visit(el, p))); + typeParameter = typeParameter.getPadding().withVariance(visitLeftPadded(typeParameter.getPadding().getVariance(), CsLeftPadded.Location.TYPE_PARAMETER_VARIANCE, p)); + typeParameter = typeParameter.withName(visitAndCast(typeParameter.getName(), p)); + return typeParameter; + } + + public J visitEnumDeclaration(Cs.EnumDeclaration enumDeclaration, P p) { + enumDeclaration = enumDeclaration.withPrefix(visitSpace(enumDeclaration.getPrefix(), CsSpace.Location.ENUM_DECLARATION_PREFIX, p)); + Statement tempStatement = (Statement) visitStatement(enumDeclaration, p); + if (!(tempStatement instanceof Cs.EnumDeclaration)) + { + return tempStatement; + } + enumDeclaration = (Cs.EnumDeclaration) tempStatement; + enumDeclaration = enumDeclaration.withMarkers(visitMarkers(enumDeclaration.getMarkers(), p)); + enumDeclaration = enumDeclaration.withAttributeLists(ListUtils.map(enumDeclaration.getAttributeLists(), el -> (Cs.AttributeList)visit(el, p))); + enumDeclaration = enumDeclaration.withModifiers(ListUtils.map(enumDeclaration.getModifiers(), el -> (J.Modifier)visit(el, p))); + enumDeclaration = enumDeclaration.getPadding().withName(visitLeftPadded(enumDeclaration.getPadding().getName(), CsLeftPadded.Location.ENUM_DECLARATION_NAME, p)); + enumDeclaration = enumDeclaration.getPadding().withBaseType(visitLeftPadded(enumDeclaration.getPadding().getBaseType(), CsLeftPadded.Location.ENUM_DECLARATION_BASE_TYPE, p)); + enumDeclaration = enumDeclaration.getPadding().withMembers(visitContainer(enumDeclaration.getPadding().getMembers(), CsContainer.Location.ENUM_DECLARATION_MEMBERS, p)); + return enumDeclaration; + } + + public J visitEnumMemberDeclaration(Cs.EnumMemberDeclaration enumMemberDeclaration, P p) { + enumMemberDeclaration = enumMemberDeclaration.withPrefix(visitSpace(enumMemberDeclaration.getPrefix(), CsSpace.Location.ENUM_MEMBER_DECLARATION_PREFIX, p)); + enumMemberDeclaration = enumMemberDeclaration.withMarkers(visitMarkers(enumMemberDeclaration.getMarkers(), p)); + enumMemberDeclaration = enumMemberDeclaration.withAttributeLists(ListUtils.map(enumMemberDeclaration.getAttributeLists(), el -> (Cs.AttributeList)visit(el, p))); + enumMemberDeclaration = enumMemberDeclaration.withName(visitAndCast(enumMemberDeclaration.getName(), p)); + enumMemberDeclaration = enumMemberDeclaration.getPadding().withInitializer(visitLeftPadded(enumMemberDeclaration.getPadding().getInitializer(), CsLeftPadded.Location.ENUM_MEMBER_DECLARATION_INITIALIZER, p)); + return enumMemberDeclaration; + } + + public J visitAliasQualifiedName(Cs.AliasQualifiedName aliasQualifiedName, P p) { + aliasQualifiedName = aliasQualifiedName.withPrefix(visitSpace(aliasQualifiedName.getPrefix(), CsSpace.Location.ALIAS_QUALIFIED_NAME_PREFIX, p)); + Expression tempExpression = (Expression) visitExpression(aliasQualifiedName, p); + if (!(tempExpression instanceof Cs.AliasQualifiedName)) + { + return tempExpression; + } + aliasQualifiedName = (Cs.AliasQualifiedName) tempExpression; + aliasQualifiedName = aliasQualifiedName.withMarkers(visitMarkers(aliasQualifiedName.getMarkers(), p)); + aliasQualifiedName = aliasQualifiedName.getPadding().withAlias(visitRightPadded(aliasQualifiedName.getPadding().getAlias(), CsRightPadded.Location.ALIAS_QUALIFIED_NAME_ALIAS, p)); + aliasQualifiedName = aliasQualifiedName.withName(visitAndCast(aliasQualifiedName.getName(), p)); + return aliasQualifiedName; + } + + public J visitArrayType(Cs.ArrayType arrayType, P p) { + arrayType = arrayType.withPrefix(visitSpace(arrayType.getPrefix(), CsSpace.Location.ARRAY_TYPE_PREFIX, p)); + Expression tempExpression = (Expression) visitExpression(arrayType, p); + if (!(tempExpression instanceof Cs.ArrayType)) + { + return tempExpression; + } + arrayType = (Cs.ArrayType) tempExpression; + arrayType = arrayType.withMarkers(visitMarkers(arrayType.getMarkers(), p)); + arrayType = arrayType.withTypeExpression(visitAndCast(arrayType.getTypeExpression(), p)); + arrayType = arrayType.withDimensions(ListUtils.map(arrayType.getDimensions(), el -> (J.ArrayDimension)visit(el, p))); + return arrayType; + } + public JContainer visitContainer(@Nullable JContainer container, CsContainer.Location loc, P p) { if (container == null) { diff --git a/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/Cs.java b/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/Cs.java index 7b1208e..d99d20f 100644 --- a/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/Cs.java +++ b/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/Cs.java @@ -15,6 +15,7 @@ */ package org.openrewrite.csharp.tree; +import com.fasterxml.jackson.annotation.JsonCreator; import lombok.*; import lombok.experimental.FieldDefaults; import lombok.experimental.NonFinal; @@ -27,8 +28,10 @@ import org.openrewrite.internal.NamingService; import org.openrewrite.java.JavaPrinter; import org.openrewrite.java.JavaTypeVisitor; +import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.internal.TypesInUse; import org.openrewrite.java.tree.*; +import org.openrewrite.marker.Marker; import org.openrewrite.marker.Markers; import java.beans.Transient; @@ -43,6 +46,7 @@ import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; +import java.util.stream.Collectors; import static java.util.Collections.singletonList; @@ -901,7 +905,7 @@ public AttributeList withAttributes(List> attributes) { @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) @RequiredArgsConstructor @With - final class AwaitExpression implements Cs, Expression { + final class AwaitExpression implements Cs, Expression, Statement { @EqualsAndHashCode.Include UUID id; @@ -909,7 +913,7 @@ final class AwaitExpression implements Cs, Expression { Space prefix; Markers markers; - Expression expression; + J expression; @Nullable JavaType type; @@ -920,8 +924,8 @@ public

J acceptCSharp(CSharpVisitor

v, P p) { } @Override - public CoordinateBuilder.Expression getCoordinates() { - return new CoordinateBuilder.Expression(this); + public CoordinateBuilder.Statement getCoordinates() { + return new CoordinateBuilder.Statement(this); } } @@ -1231,31 +1235,76 @@ public CollectionExpression withElements(List> elements } } - @Getter - @ToString @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) @RequiredArgsConstructor - @With + @AllArgsConstructor(access = AccessLevel.PRIVATE) final class ExpressionStatement implements Cs, Statement { + @Nullable + @NonFinal + transient WeakReference padding; + @With @EqualsAndHashCode.Include + @Getter UUID id; + + @With + @Getter Space prefix; + + @With + @Getter Markers markers; - Expression expression; + JRightPadded expression; + + public Expression getExpression() { + return expression.getElement(); + } + + public ExpressionStatement withExpression(Expression expression) { + return getPadding().withExpression(this.expression.withElement(expression)); + } @Override public

J acceptCSharp(CSharpVisitor

v, P p) { return v.visitExpressionStatement(this, p); } - @Transient @Override + @Transient public CoordinateBuilder.Statement getCoordinates() { return new CoordinateBuilder.Statement(this); } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final ExpressionStatement t; + + public JRightPadded getExpression() { + return t.expression; + } + + public ExpressionStatement withExpression(JRightPadded expression) { + return t.expression == expression ? t : new ExpressionStatement(t.id, t.prefix, t.markers, expression); + } + } } @ToString @@ -2172,7 +2221,7 @@ public String toString() { @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) - final class ClassDeclaration implements Cs, Statement { + final class ClassDeclaration implements Cs, Statement, TypedTree { @Nullable @NonFinal transient WeakReference padding; @@ -2190,27 +2239,125 @@ final class ClassDeclaration implements Cs, Statement { @Getter Markers markers; + @With + @Getter + List attributeList; + + @With + @Getter + List modifiers; + + J.ClassDeclaration.Kind kind; + + public J.ClassDeclaration.Kind.Type getKind() { + return kind.getType(); + } + + public Cs.ClassDeclaration withKind(J.ClassDeclaration.Kind.Type type) { + J.ClassDeclaration.Kind k = getPadding().getKind(); + if (k.getType() == type) { + return this; + } else { + return getPadding().withKind(k.withType(type)); + } + } + + @With + @Getter + Identifier name; + + @Nullable + JContainer typeParameters; + + public @Nullable List getTypeParameters() { + return typeParameters == null ? null : typeParameters.getElements(); + } + + public Cs.ClassDeclaration withTypeParameters(@Nullable List typeParameters) { + return getPadding().withTypeParameters(JContainer.withElementsNullable(this.typeParameters, typeParameters)); + } + + @Nullable + JContainer primaryConstructor; + + public @Nullable List getPrimaryConstructor() { + return primaryConstructor == null ? null : primaryConstructor.getElements(); + } + + public Cs.ClassDeclaration withPrimaryConstructor(@Nullable List primaryConstructor) { + return getPadding().withPrimaryConstructor(JContainer.withElementsNullable(this.primaryConstructor, primaryConstructor)); + } + + @Nullable + JLeftPadded extendings; + + public @Nullable TypeTree getExtendings() { + return extendings == null ? null : extendings.getElement(); + } + + public Cs.ClassDeclaration withExtendings(@Nullable TypeTree extendings) { + return getPadding().withExtendings(JLeftPadded.withElement(this.extendings, extendings)); + } + + @Nullable + JContainer implementings; + + public @Nullable List getImplementings() { + return implementings == null ? null : implementings.getElements(); + } + + public Cs.ClassDeclaration withImplementings(@Nullable List implementings) { + return getPadding().withImplementings(JContainer.withElementsNullable(this.implementings, implementings)); + } @With @Getter - J.ClassDeclaration classDeclarationCore; + @Nullable + Block body; + @Nullable JContainer typeParameterConstraintClauses; + @Nullable public List getTypeParameterConstraintClauses() { - return typeParameterConstraintClauses.getElements(); + return typeParameterConstraintClauses == null ? null : typeParameterConstraintClauses.getElements(); } - public Cs.ClassDeclaration withTypeParameterConstraintClauses(List typeParameterConstraintClauses) { + public Cs.ClassDeclaration withTypeParameterConstraintClauses(@Nullable List typeParameterConstraintClauses) { return getPadding().withTypeParameterConstraintClauses(JContainer.withElementsNullable(this.typeParameterConstraintClauses, typeParameterConstraintClauses)); } + @Getter + JavaType.@Nullable FullyQualified type; + + @SuppressWarnings("unchecked") + @Override + public Cs.ClassDeclaration withType(@Nullable JavaType type) { + if (type == this.type) { + return this; + } + + if (type != null && !(type instanceof JavaType.FullyQualified)) { + throw new IllegalArgumentException("A class can only be type attributed with a fully qualified type name"); + } + + return new Cs.ClassDeclaration(id, prefix, markers, attributeList, modifiers, kind, name, typeParameters, primaryConstructor, extendings, implementings, body, typeParameterConstraintClauses, (JavaType.FullyQualified) type); + } + @Override public

J acceptCSharp(CSharpVisitor

v, P p) { return v.visitClassDeclaration(this, p); } + @Override + @Transient + public CoordinateBuilder.ClassDeclaration getCoordinates() { + //todo: Setup coordinate builder - atm it's private +// return new CoordinateBuilder.ClassDeclaration(this); + return null; + } + public Padding getPadding() { Padding p; if (this.padding == null) { @@ -2226,37 +2373,79 @@ public Padding getPadding() { return p; } - @Override - public CoordinateBuilder.Statement getCoordinates() { - return new CoordinateBuilder.Statement(this); - } - @RequiredArgsConstructor public static class Padding { private final Cs.ClassDeclaration t; + public @Nullable JContainer getPrimaryConstructor() { + return t.primaryConstructor; + } + + public Cs.ClassDeclaration withPrimaryConstructor(@Nullable JContainer primaryConstructor) { + return t.primaryConstructor == primaryConstructor ? t : new Cs.ClassDeclaration(t.id, t.prefix, t.markers, t.attributeList, t.modifiers, t.kind, t.name, t.typeParameters, primaryConstructor, t.extendings, t.implementings, t.body, t.typeParameterConstraintClauses, t.type); + } + + public @Nullable JLeftPadded getExtendings() { + return t.extendings; + } + + public Cs.ClassDeclaration withExtendings(@Nullable JLeftPadded extendings) { + return t.extendings == extendings ? t : new Cs.ClassDeclaration(t.id, t.prefix, t.markers, t.attributeList, t.modifiers, t.kind, t.name, t.typeParameters, t.primaryConstructor, extendings, t.implementings, t.body, t.typeParameterConstraintClauses, t.type); + } + + public @Nullable JContainer getImplementings() { + return t.implementings; + } + + public Cs.ClassDeclaration withImplementings(@Nullable JContainer implementings) { + return t.implementings == implementings ? t : new Cs.ClassDeclaration(t.id, t.prefix, t.markers, t.attributeList, t.modifiers, t.kind, t.name, t.typeParameters, t.primaryConstructor, t.extendings, implementings, t.body, t.typeParameterConstraintClauses, t.type); + } + + + + public J.ClassDeclaration.Kind getKind() { + return t.kind; + } + + public Cs.ClassDeclaration withKind(J.ClassDeclaration.Kind kind) { + return t.kind == kind ? t : new Cs.ClassDeclaration(t.id, t.prefix, t.markers, t.attributeList, t.modifiers, kind, t.name, t.typeParameters, t.primaryConstructor, t.extendings, t.implementings, t.body, t.typeParameterConstraintClauses, t.type); + } + + public @Nullable JContainer getTypeParameters() { + return t.typeParameters; + } + + public Cs.ClassDeclaration withTypeParameters(@Nullable JContainer typeParameters) { + return t.typeParameters == typeParameters ? t : new Cs.ClassDeclaration(t.id, t.prefix, t.markers, t.attributeList, t.modifiers, t.kind, t.name, typeParameters, t.primaryConstructor, t.extendings, t.implementings, t.body, t.typeParameterConstraintClauses, t.type); + } + public @Nullable JContainer getTypeParameterConstraintClauses() { return t.typeParameterConstraintClauses; } public Cs.ClassDeclaration withTypeParameterConstraintClauses(@Nullable JContainer typeParameterConstraintClauses) { - return t.typeParameterConstraintClauses == typeParameterConstraintClauses ? t : new Cs.ClassDeclaration(t.id, t.prefix, t.markers, t.classDeclarationCore, typeParameterConstraintClauses); + return t.typeParameterConstraintClauses == typeParameterConstraintClauses ? t : new Cs.ClassDeclaration(t.id, t.prefix, t.markers, t.attributeList, t.modifiers, t.kind, t.name, t.typeParameters, t.primaryConstructor, t.extendings, t.implementings, t.body, typeParameterConstraintClauses, t.type); } } } + + // CS specific method exists to allow for modelling for the following not possible in J version: + // - implicit interface implementations + // - Cs.AttributeList that may appear before any of the type variables + // - generics constraints that appear on the end of the method declaration @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) - final class MethodDeclaration implements Cs, Statement { + final class MethodDeclaration implements Cs, Statement, TypedTree { @Nullable @NonFinal transient WeakReference padding; @With - @Getter @EqualsAndHashCode.Include + @Getter UUID id; @With @@ -2267,10 +2456,64 @@ final class MethodDeclaration implements Cs, Statement { @Getter Markers markers; + @With + @Getter + List attributes; + + @With + @Getter + List modifiers; + + @Nullable + JContainer typeParameters; + + @With + @Getter + TypeTree returnTypeExpression; + + @Nullable + JRightPadded explicitInterfaceSpecifier; + + public TypeTree getExplicitInterfaceSpecifier() { + return explicitInterfaceSpecifier.getElement(); + } + public Cs.MethodDeclaration withExplicitInterfaceSpecifier(TypeTree explicitInterfaceSpecifier) { + return getPadding().withExplicitInterfaceSpecifier(this.explicitInterfaceSpecifier.withElement(explicitInterfaceSpecifier)); + } + + + @With + @Getter + Identifier name; + + JContainer parameters; + + public List getParameters() { + return parameters.getElements(); + } + public Cs.MethodDeclaration withParameters(List parameters) { + return getPadding().withParameters(JContainer.withElements(this.parameters, parameters)); + } + + + /** + * Null for abstract method declarations and interface method declarations. + */ @With @Getter - J.MethodDeclaration methodDeclarationCore; + @Nullable + Block body; + + @Getter + JavaType.@Nullable Method methodType; + + public Cs.MethodDeclaration withMethodType(JavaType.@Nullable Method type) { + if (type == this.methodType) { + return this; + } + return new Cs.MethodDeclaration(id, prefix, markers, attributes, modifiers, typeParameters, returnTypeExpression, explicitInterfaceSpecifier, name, parameters, body, type, typeParameterConstraintClauses); + } JContainer typeParameterConstraintClauses; @@ -2282,11 +2525,27 @@ public Cs.MethodDeclaration withTypeParameterConstraintClauses(List J acceptCSharp(CSharpVisitor

v, P p) { return v.visitMethodDeclaration(this, p); } + @Override + @Transient + public CoordinateBuilder.Statement getCoordinates() { + return new CoordinateBuilder.Statement(this); + } public Padding getPadding() { Padding p; @@ -2303,26 +2562,47 @@ public Padding getPadding() { return p; } - @Override - public CoordinateBuilder.Statement getCoordinates() { - return new CoordinateBuilder.Statement(this); - } - @RequiredArgsConstructor public static class Padding { private final Cs.MethodDeclaration t; + public JContainer getParameters() { + return t.parameters; + } + + public Cs.MethodDeclaration withParameters(JContainer parameters) { + return t.parameters == parameters ? t : new Cs.MethodDeclaration(t.id, t.prefix, t.markers, t.attributes, t.modifiers, t.typeParameters, t.returnTypeExpression, t.explicitInterfaceSpecifier, t.name, parameters, t.body, t.methodType, t.typeParameterConstraintClauses); + } + + @Nullable + public JRightPadded getExplicitInterfaceSpecifier() { + return t.explicitInterfaceSpecifier; + } + + public Cs.MethodDeclaration withExplicitInterfaceSpecifier(JRightPadded explicitInterfaceSpecifier) { + return t.explicitInterfaceSpecifier == explicitInterfaceSpecifier ? t : new Cs.MethodDeclaration(t.id, t.prefix, t.markers, t.attributes, t.modifiers, t.typeParameters, t.returnTypeExpression, explicitInterfaceSpecifier, t.name, t.parameters, t.body, t.methodType, t.typeParameterConstraintClauses); + } + + + public @Nullable JContainer getTypeParameters() { + return t.typeParameters; + } + + public Cs.MethodDeclaration withTypeParameters(@Nullable JContainer typeParameters) { + return t.typeParameters == typeParameters ? t : new Cs.MethodDeclaration(t.id, t.prefix, t.markers, t.attributes, t.modifiers, typeParameters, t.returnTypeExpression, t.explicitInterfaceSpecifier, t.name, t.parameters, t.body, t.methodType, t.typeParameterConstraintClauses); + } + public @Nullable JContainer getTypeParameterConstraintClauses() { return t.typeParameterConstraintClauses; } public Cs.MethodDeclaration withTypeParameterConstraintClauses(@Nullable JContainer typeParameterConstraintClauses) { - return t.typeParameterConstraintClauses == typeParameterConstraintClauses ? t : new Cs.MethodDeclaration(t.id, t.prefix, t.markers, t.methodDeclarationCore, typeParameterConstraintClauses); + return t.typeParameterConstraintClauses == typeParameterConstraintClauses ? t : new Cs.MethodDeclaration(t.id, t.prefix, t.markers, t.attributes, t.modifiers, t.typeParameters, t.returnTypeExpression, t.explicitInterfaceSpecifier, t.name, t.parameters, t.body, t.methodType, typeParameterConstraintClauses); } } + } - //region UsingStatement @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) @RequiredArgsConstructor @@ -2350,15 +2630,14 @@ final class UsingStatement implements Cs, Statement { @Getter Keyword awaitKeyword; + JLeftPadded expression; - JContainer expression; - - public List getExpression() { - return expression.getElements(); + public Expression getExpression() { + return expression.getElement(); } - public UsingStatement withExpression(List expression) { - return getPadding().withExpression(JContainer.withElements(this.expression, expression)); + public UsingStatement withExpression(Expression expression) { + return getPadding().withExpression(this.expression.withElement(expression)); } /** @@ -2398,12 +2677,11 @@ public Padding getPadding() { public static class Padding { private final UsingStatement t; - - public JContainer getExpression() { + public JLeftPadded getExpression() { return t.expression; } - public UsingStatement withExpression(JContainer expression) { + public UsingStatement withExpression(JLeftPadded expression) { return t.expression == expression ? t : new UsingStatement(t.id, t.prefix, t.markers, t.awaitKeyword, expression, t.statement); } } @@ -3287,12 +3565,7 @@ public class DestructorDeclaration implements Cs, Statement { @Getter @With - @Nullable - ConstructorInitializer initializer; - - @Getter - @With - J.MethodDeclaration constructorCore; + J.MethodDeclaration methodCore; @Override public

J acceptCSharp(CSharpVisitor

v, P p) { @@ -3369,7 +3642,19 @@ public enum Type { /** * Represent x! syntax */ - SuppressNullableWarning; + SuppressNullableWarning, + /** + * Represent *int pointer types syntax + */ + PointerIndirection, + /** + * Represent &a for pointer value access + */ + AddressOf, + /** + * Represent [^3] syntax + */ + FromEnd; // [^3] public boolean isModifying() { switch (this) { @@ -3453,13 +3738,13 @@ final class ConstructorInitializer implements Cs { @Getter Keyword keyword; - JContainer arguments; + JContainer arguments; - public List getArguments() { + public List getArguments() { return arguments.getElements(); } - public ConstructorInitializer withArguments(List arguments) { + public ConstructorInitializer withArguments(List arguments) { return getPadding().withArguments(JContainer.withElements(this.arguments, arguments)); } @@ -3487,11 +3772,11 @@ public Padding getPadding() { public static class Padding { private final ConstructorInitializer t; - public JContainer getArguments() { + public JContainer getArguments() { return t.arguments; } - public ConstructorInitializer withArguments(JContainer arguments) { + public ConstructorInitializer withArguments(JContainer arguments) { return t.arguments == arguments ? t : new ConstructorInitializer(t.id, t.prefix, t.markers, t.keyword, arguments); } } @@ -5442,7 +5727,7 @@ final class Subpattern implements Cs { @With @Getter @Nullable - Identifier name; + Expression name; /** *

@@ -6655,4 +6940,2206 @@ public RangeExpression withStart(@Nullable JRightPadded start) {
             }
         }
     }
+
+
+    /**
+     * Represents a C# LINQ query expression that provides SQL-like syntax for working with collections.
+     * 

+ * For example: + *

+     *     // Simple query
+     *     from user in users
+     *     where user.Age > 18
+     *     select user.Name
+     *
+     *     // Query with multiple clauses
+     *     from c in customers
+     *     join o in orders on c.Id equals o.CustomerId
+     *     where o.Total > 1000
+     *     orderby o.Date
+     *     select new { c.Name, o.Total }
+     *
+     *     // Query with multiple from clauses
+     *     from c in customers
+     *     from o in c.Orders
+     *     where o.Total > 1000
+     *     select new { c.Name, o.Total }
+     * 
+ */ + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @AllArgsConstructor(access = AccessLevel.PUBLIC) + final class QueryExpression implements Cs, Expression { + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * from user in users
+         * ^^^^^^^^^^^^^^^^^^
+         * 
+ */ + @With + @Getter + FromClause fromClause; + + /** + *
+         * from user in users
+         * where user.Age > 18
+         * select user.Name
+         * ^^^^^^^^^^^^^^^^^ excluding the from clause
+         * 
+ */ + @With + @Getter + QueryBody body; + + + @Override + public @Nullable JavaType getType() { + return fromClause.getType(); + } + + @Override + public QueryExpression withType(@Nullable JavaType type) { + return withFromClause(fromClause.withType(type)); + } + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitQueryExpression(this, p); + } + + @Override + public CoordinateBuilder.Expression getCoordinates() { + return new CoordinateBuilder.Expression(this); + } + } + + + public interface SelectOrGroupClause extends Cs + { + + } + + /** + * Represents the body of a LINQ query expression, consisting of the query clauses and a final select or group clause. + *

+ * For example: + *

+     *     // Body of query includes everything after initial 'from':
+     *     from c in customers
+     *     where c.Age > 18       // Clauses part
+     *     orderby c.LastName     // Clauses part
+     *     select c.Name          // SelectOrGroup part
+     *     into oldCustomers      // Continuation part
+     *     where oldCustomers...
+     *
+     *     // Another example with join:
+     *     from o in orders
+     *     join c in customers    // Clauses part
+     *         on o.CustomerId equals c.Id
+     *     where o.Total > 1000   // Clauses part
+     *     select new { o, c }    // SelectOrGroup part
+     * 
+ */ + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @AllArgsConstructor(access = AccessLevel.PUBLIC) + final class QueryBody implements Cs { + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * from c in customers
+         * where c.Age > 18
+         * ^^^^^^^^^^^^^^^^
+         * orderby c.LastName
+         * ^^^^^^^^^^^^^^^^^^
+         * select c.Name
+         * 
+ */ + @With + @Getter + List clauses; + + /** + *
+         * from c in customers
+         * where c.Age > 18
+         * select c.Name
+         * ^^^^^^^^^^^^^ the final select or group clause
+         * 
+ */ + @With + @Getter + @Nullable + SelectOrGroupClause selectOrGroup; + + /** + *
+         * from c in customers
+         * select c
+         * into temp            // Continuation starts here
+         * where temp.Age > 18
+         * select temp.Name
+         * 
+ */ + @With + @Getter + @Nullable + QueryContinuation continuation; + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitQueryBody(this, p); + } + } + + interface QueryClause extends Cs + { + + } + /** + * Represents a LINQ from clause that introduces a range variable and its source collection. + * This is typically the initial clause of a LINQ query. + *

+ * For example: + *

+     *     // Simple from clause
+     *     from user in users
+     *
+     *     // With type
+     *     from Customer c in customers
+     *
+     *     // With pattern match
+     *     from (x, y) in points
+     *
+     *     // With type and pattern
+     *     from (int x, int y) in coordinates
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + final class FromClause implements Cs, QueryClause, Expression { + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * from Customer c in customers
+         *     ^^^^^^^^^
+         * 
+ */ + @With + @Getter + @Nullable + TypeTree typeIdentifier; + + /** + *
+         * from Customer c in customers
+         *              ^^
+         * 
+ */ + JRightPadded identifier; + + /** + *
+         * from user in users
+         *             ^^^^^^
+         * 
+ */ + @With + @Getter + Expression expression; + + public Expression getIdentifier() { + return identifier.getElement(); + } + + public FromClause withIdentifier(Identifier identifier) { + return getPadding().withIdentifier(this.identifier.withElement(identifier)); + } + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitFromClause(this, p); + } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @Override + public @Nullable JavaType getType() { + return expression.getType(); + } + + @Override + public FromClause withType(@Nullable JavaType type) { + return this.withExpression(expression.withType(type)); + } + + @Override + public CoordinateBuilder.Expression getCoordinates() { + return new CoordinateBuilder.Expression(this); + } + + @RequiredArgsConstructor + public static class Padding { + private final FromClause t; + + public JRightPadded getIdentifier() { + return t.identifier; + } + + public FromClause withIdentifier(JRightPadded identifier) { + return t.identifier == identifier ? t : new FromClause(t.id, t.prefix, t.markers, t.typeIdentifier, identifier, t.expression); + } + } + } + /** + * Represents a let clause in a C# LINQ query expression that introduces + * a new range variable based on a computation. + *

+ * For example: + *

+     *     // Simple let clause
+     *     from n in numbers
+     *     let square = n * n
+     *     select square
+     *
+     *     // Multiple let clauses
+     *     from s in strings
+     *     let length = s.Length
+     *     let upperCase = s.ToUpper()
+     *     select new { s, length, upperCase }
+     *
+     *     // Let with complex expressions
+     *     from p in people
+     *     let fullName = p.FirstName + " " + p.LastName
+     *     let age = DateTime.Now.Year - p.BirthYear
+     *     select new { fullName, age }
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + final class LetClause implements Cs, QueryClause { + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * let square = n * n
+         *    ^^^^^^^^^
+         * 
+ */ + JRightPadded identifier; + + /** + *
+         * let square = n * n
+         *             ^^^^^^
+         * 
+ */ + @With + @Getter + Expression expression; + + public J.Identifier getIdentifier() { + return identifier.getElement(); + } + + public LetClause withIdentifier(J.Identifier identifier) { + return getPadding().withIdentifier(JRightPadded.withElement(this.identifier, identifier)); + } + + + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitLetClause(this, p); + } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final LetClause t; + + public JRightPadded getIdentifier() { + return t.identifier; + } + + public LetClause withIdentifier(JRightPadded identifier) { + return t.identifier == identifier ? t : new LetClause(t.id, t.prefix, t.markers, identifier, t.expression); + } + } + } + + /** + * Represents a C# join clause in a LINQ query expression. + *

+ * For example: + *

+     * // Simple join
+     * join customer in customers on order.CustomerId equals customer.Id
+     *
+     * // Join with into (group join)
+     * join category in categories
+     *   on product.CategoryId equals category.Id
+     *   into productCategories
+     *
+     * // Multiple joins
+     * from order in orders
+     * join customer in customers
+     *   on order.CustomerId equals customer.Id
+     * join employee in employees
+     *   on order.EmployeeId equals employee.Id
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + final class JoinClause implements Cs, QueryClause { + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * join customer in customers
+         *     ^^^^^^^^^^^^
+         * 
+ */ + JRightPadded identifier; + + /** + *
+         * join customer in customers on order.CustomerId equals customer.Id
+         *                 ^^^^^^^^^^^^^
+         * 
+ */ + JRightPadded inExpression; + + /** + *
+         * join customer in customers on order.CustomerId equals customer.Id
+         *                              ^^^^^^^^^^^^^^^^^^^^^^^^
+         * 
+ */ + JRightPadded leftExpression; + + /** + *
+         * join customer in customers on order.CustomerId equals customer.Id
+         *                                                      ^^^^^^^^^^^^
+         * 
+ */ + @With + @Getter + Expression rightExpression; + + /** + *
+         * join category in categories on product.CategoryId equals category.Id into productCategories
+         *                                                                     ^^^^^^^^^^^^^^^^^^^^^^^
+         * 
+ */ + @Nullable + JLeftPadded into; + + public Identifier getIdentifier() { + return identifier.getElement(); + } + + public JoinClause withIdentifier(Identifier identifier) { + return getPadding().withIdentifier(this.identifier.withElement(identifier)); + } + + public Expression getInExpression() { + return inExpression.getElement(); + } + + public JoinClause withInExpression(Expression inExpression) { + return getPadding().withInExpression(this.inExpression.withElement(inExpression)); + } + + public Expression getLeftExpression() { + return leftExpression.getElement(); + } + + public JoinClause withLeftExpression(Expression leftExpression) { + return getPadding().withLeftExpression(this.leftExpression.withElement(leftExpression)); + } + + + public @Nullable JoinIntoClause getInto() { + return into == null ? null : into.getElement(); + } + + public JoinClause withInto(@Nullable JoinIntoClause into) { + return getPadding().withInto(this.into.withElement(into)); + } + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitJoinClause(this, p); + } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final JoinClause t; + + public JRightPadded getIdentifier() { + return t.identifier; + } + + public JoinClause withIdentifier(JRightPadded identifier) { + return t.identifier == identifier ? t : + new JoinClause(t.id, t.prefix, t.markers, identifier, t.inExpression, + t.leftExpression, t.rightExpression, t.into); + } + + public JRightPadded getInExpression() { + return t.inExpression; + } + + public JoinClause withInExpression(JRightPadded inExpression) { + return t.inExpression == inExpression ? t : + new JoinClause(t.id, t.prefix, t.markers, t.identifier, inExpression, + t.leftExpression, t.rightExpression, t.into); + } + + public JRightPadded getLeftExpression() { + return t.leftExpression; + } + + public JoinClause withLeftExpression(JRightPadded leftExpression) { + return t.leftExpression == leftExpression ? t : + new JoinClause(t.id, t.prefix, t.markers, t.identifier, t.inExpression, + leftExpression, t.rightExpression, t.into); + } + + public @Nullable JLeftPadded getInto() { + return t.into; + } + + public JoinClause withInto(@Nullable JLeftPadded into) { + return t.into == into ? t : + new JoinClause(t.id, t.prefix, t.markers, t.identifier, t.inExpression, + t.leftExpression, t.rightExpression, into); + } + } + } + + /** + * Represents the 'into' portion of a group join clause in C# LINQ syntax. + * Used to specify the identifier that will hold the grouped results. + *

+ * For example: + *

+     * // Group join using into clause
+     * join category in categories
+     *    on product.CategoryId equals category.Id
+     *    into productCategories
+     *
+     * // Multiple group joins
+     * join orders in db.Orders
+     *    on customer.Id equals orders.CustomerId
+     *    into customerOrders
+     * join returns in db.Returns
+     *    on customer.Id equals returns.CustomerId
+     *    into customerReturns
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @AllArgsConstructor(access = AccessLevel.PUBLIC) + final class JoinIntoClause implements Cs, QueryClause { + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * into productCategories
+         *     ^^^^^^^^^^^^^^^^^^
+         * 
+ */ + @With + @Getter + Identifier identifier; + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitJoinIntoClause(this, p); + } + } + + /** + * Represents a C# LINQ where clause that filters elements in a query based on a condition. + *

+ * For example: + *

+     *     // Simple where clause
+     *     from p in people
+     *     where p.Age >= 18
+     *     select p
+     *
+     *     // Multiple where clauses
+     *     from p in people
+     *     where p.Age >= 18
+     *     where p.Name.StartsWith("J")
+     *     select p
+     *
+     *     // Where with complex condition
+     *     from o in orders
+     *     where o.Total > 1000 && o.Status == "Pending"
+     *     select o
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @AllArgsConstructor(access = AccessLevel.PUBLIC) + final class WhereClause implements Cs, QueryClause { + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * where p.Age >= 18
+         *      ^^^^^^^^^^^^
+         * 
+ */ + @With + @Getter + Expression condition; + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitWhereClause(this, p); + } + } + + /** + * Represents a C# LINQ orderby clause that specifies the ordering of results in a query. + *

+ * For example: + *

+     *     // Simple orderby with single key
+     *     from p in people
+     *     orderby p.LastName
+     *     select p
+     *
+     *     // Multiple orderings
+     *     from p in people
+     *     orderby p.LastName ascending, p.FirstName descending
+     *     select p
+     *
+     *     // Orderby with complex key expressions
+     *     from o in orders
+     *     orderby o.Customer.Name, o.Total * 1.08
+     *     select o
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + final class OrderByClause implements Cs, QueryClause { + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * orderby p.LastName ascending, p.FirstName descending
+         *         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+         * 
+ */ + List> orderings; + + public List getOrderings() { + return JRightPadded.getElements(orderings); + } + + public OrderByClause withOrderings(List orderings) { + return getPadding().withOrderings(JRightPadded.withElements(this.orderings, orderings)); + } + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitOrderByClause(this, p); + } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final OrderByClause t; + + public List> getOrderings() { + return t.orderings; + } + + public OrderByClause withOrderings(List> orderings) { + return t.orderings == orderings ? t : new OrderByClause(t.id, t.prefix, t.markers, orderings); + } + } + } + + /** + * Represents a LINQ query continuation using the 'into' keyword, which allows query results to be + * further processed in subsequent query clauses. + *

+ * For example: + *

+     *     // Query continuation with grouping
+     *     from c in customers
+     *     group c by c.Country into g
+     *     select new { Country = g.Key, Count = g.Count() }
+     *
+     *     // Multiple continuations
+     *     from n in numbers
+     *     group n by n % 2 into g
+     *     select new { Modulo = g.Key, Items = g } into r
+     *     where r.Items.Count() > 2
+     *     select r
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @AllArgsConstructor(access = AccessLevel.PUBLIC) + final class QueryContinuation implements Cs { + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * group c by c.Country into g
+         *                         ^^^
+         * 
+ */ + @With + @Getter + J.Identifier identifier; + + /** + *
+         * group c by c.Country into g
+         * select new { Country = g.Key }
+         * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+         * 
+ */ + @With + @Getter + QueryBody body; + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitQueryContinuation(this, p); + } + } + + + /** + * Represents a single ordering clause within C# orderby expression. + *

+     * orderby name ascending
+     * orderby age descending, name ascending
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + final class Ordering implements Cs { + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * orderby name ascending
+         *        ^^^^
+         * 
+ */ + JRightPadded expression; + + public Expression getExpression() { + return expression.getElement(); + } + + public Ordering withExpression(Expression expression) { + return getPadding().withExpression(this.expression.withElement(expression)); + } + + /** + *
+         * orderby name ascending
+         *             ^^^^^^^^^
+         * 
+ */ + @With + @Getter + @Nullable + DirectionKind direction; + + public enum DirectionKind { + Ascending, + Descending + } + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitOrdering(this, p); + } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final Ordering t; + + public JRightPadded getExpression() { + return t.expression; + } + + public Ordering withExpression(JRightPadded expression) { + return t.expression == expression ? t : new Ordering(t.id, t.prefix, t.markers, expression, t.direction); + } + } + } + + /** + * Represents a select clause in a LINQ expression in C#. + *

+     * // Simple select
+     * select item
+     *
+     * // Select with projection
+     * select new { Name = p.Name, Age = p.Age }
+     * 
+ */ + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @AllArgsConstructor(access = AccessLevel.PUBLIC) + final class SelectClause implements Cs, SelectOrGroupClause { + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * select item
+         *        ^^^^
+         * 
+ */ + @With + @Getter + Expression expression; + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitSelectClause(this, p); + } + } + + /** + * Represents a group clause in a LINQ query. + *

+     * // Simple group by
+     * group item by key
+     *
+     * // Group by with complex key
+     * group customer by new { customer.State, customer.City }
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + final class GroupClause implements Cs, SelectOrGroupClause { + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * group item by key
+         *       ^^^^
+         * 
+ */ + JRightPadded groupExpression; + + public Expression getGroupExpression() { + return groupExpression.getElement(); + } + + public GroupClause withGroupExpression(Expression groupExpression) { + return getPadding().withGroupExpression(this.groupExpression.withElement(groupExpression)); + } + + /** + *
+         * group item by key
+         *              ^^^
+         * 
+ */ + @With + @Getter + Expression key; + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitGroupClause(this, p); + } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final GroupClause t; + + public JRightPadded getGroupExpression() { + return t.groupExpression; + } + + public GroupClause withGroupExpression(JRightPadded groupExpression) { + return t.groupExpression == groupExpression ? t : new GroupClause(t.id, t.prefix, t.markers, groupExpression, t.key); + } + } + } + /** + * Represents a C# indexer declaration which allows objects to be indexed like arrays. + *

+     * // Simple indexer
+     * public int this[int index] { get { } set { } }
+     *
+     * // Indexer with multiple parameters
+     * public string this[int x, int y] { get; set; }
+     *
+     * // Readonly indexer
+     * public MyType this[string key] { get; }
+     *
+     * // Interface indexer
+     * string this[int index] { get; set; }
+     *
+     * // Protected indexer with expression body
+     * protected internal int this[int i] => array[i];
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + final class IndexerDeclaration implements Cs, Statement, TypedTree { + + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + @With + @Getter + List modifiers; + + /** + *
+         * public int this[int index]
+         *        ^^^
+         * 
+ */ + @With + @Getter + TypeTree typeExpression; + + /** + *
+         * public TypeName ISomeType.this[int index]
+         *                 ^^^^^^^^^^^^^^
+         * 
+ * Either FieldAccess (when interface qualified) or Identifier ("this") + */ + @Getter + @With + Expression indexer; + + /** + *
+         * public int this[int index] { get; set; }
+         *               ^^^^^^^^^^
+         * 
+ */ + JContainer parameters; + + /** + *
+         * public int this[int index] => array[index];
+         *                            ^^^^^^^^^^^^^^^^
+         * 
+ */ + @Nullable + JLeftPadded expressionBody; + + /** + *
+         * public int this[int index] { get; set; }
+         *                           ^^^^^^^^^^^^
+         * 
+ */ + @Nullable + @With + @Getter + Block accessors; + + @Override + public JavaType getType() { + return typeExpression.getType(); + } + + @Override + public IndexerDeclaration withType(@Nullable JavaType type) { + return withTypeExpression(typeExpression.withType(type)); + } + + + public List getParameters() { + return parameters.getElements(); + } + + public IndexerDeclaration withParameters(List parameters) { + return getPadding().withParameters(JContainer.withElements(this.parameters, parameters)); + } + + public @Nullable Expression getExpressionBody() { + return expressionBody != null ? expressionBody.getElement() : null; + } + + public IndexerDeclaration withExpressionBody(@Nullable Expression expressionBody) { + return getPadding().withExpressionBody(JLeftPadded.withElement(this.expressionBody, expressionBody)); + } + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitIndexerDeclaration(this, p); + } + + @Override + public CoordinateBuilder.Statement getCoordinates() { + return new CoordinateBuilder.Statement(this); + } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final IndexerDeclaration t; + + public JContainer getParameters() { + return t.parameters; + } + + public IndexerDeclaration withParameters(JContainer parameters) { + return t.parameters == parameters ? t : new IndexerDeclaration(t.id, t.prefix, t.markers, + t.modifiers, t.typeExpression, t.indexer, parameters, + t.expressionBody, t.accessors); + } + + public @Nullable JLeftPadded getExpressionBody() { + return t.expressionBody; + } + + public IndexerDeclaration withExpressionBody(@Nullable JLeftPadded expressionBody) { + return t.expressionBody == expressionBody ? t : new IndexerDeclaration(t.id, t.prefix, t.markers, + t.modifiers, t.typeExpression, t.indexer, t.parameters, + expressionBody, t.accessors); + } + } + } + + /** + * Represents a C# delegate declaration which defines a type that can reference methods. + * Delegates act as type-safe function pointers and provide the foundation for events in C#. + *

+ * For example: + *

+     * // Simple non-generic delegate with single parameter
+     * public delegate void Logger(string message);
+     *
+     * // Generic delegate
+     * public delegate T Factory() where T : class, new();
+     *
+     * // Delegate with multiple parameters and constraint
+     * public delegate TResult Convert(T input)
+     *     where T : struct
+     *     where TResult : class;
+     *
+     * // Static delegate (C# 11+)
+     * public static delegate int StaticHandler(string msg);
+     *
+     * // Protected access
+     * protected delegate bool Validator(T item);
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + final class DelegateDeclaration implements Cs, Statement { + + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * public delegate void MyDelegate(string message);
+         * ^^^^^^
+         * 
+ */ + @With + @Getter + List modifiers; + + /** + *
+         * public delegate void MyDelegate(string message);
+         *               ^^^^
+         * 
+ */ + JLeftPadded returnType; + + public TypeTree getReturnType() { + return returnType.getElement(); + } + + public DelegateDeclaration withReturnType(TypeTree returnType) { + return getPadding().withReturnType(this.returnType.withElement(returnType)); + } + + /** + *
+         * public delegate void MyDelegate(string message);
+         *                     ^^^^^^^^^^^
+         * 
+ */ + @With + @Getter + Identifier identifier; + + /** + *
+         * public delegate T GenericDelegate(T item);
+         *                                  ^^^
+         * 
+ */ + @Nullable + JContainer typeParameters; + + /** + *
+         * public delegate void MyDelegate(string message);
+         *                                ^^^^^^^^^^^^^^^^
+         * 
+ */ + JContainer parameters; + + /** + *
+         * public delegate T Factory() where T : class;
+         *                               ^^^^^^^^^^^^^^^^
+         * 
+ */ + @Nullable + JContainer typeParameterConstraintClauses; + + public List getTypeParameters() { + return typeParameters == null ? Collections.emptyList() : typeParameters.getElements(); + } + + public DelegateDeclaration withTypeParameters(@Nullable List typeParameters) { + return getPadding().withTypeParameters(JContainer.withElementsNullable(this.typeParameters, typeParameters)); + } + + public List getParameters() { + return parameters.getElements(); + } + + public DelegateDeclaration withParameters(List parameters) { + return getPadding().withParameters(JContainer.withElements(this.parameters, parameters)); + } + + public List getTypeParameterConstraintClauses() { + return typeParameterConstraintClauses == null ? Collections.emptyList() : typeParameterConstraintClauses.getElements(); + } + + public DelegateDeclaration withTypeParameterConstraintClauses(@Nullable List clauses) { + return getPadding().withTypeParameterConstraintClauses(JContainer.withElementsNullable(this.typeParameterConstraintClauses, clauses)); + } + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitDelegateDeclaration(this, p); + } + + @Override + public CoordinateBuilder.Statement getCoordinates() { + return new CoordinateBuilder.Statement(this); + } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final DelegateDeclaration t; + + public JLeftPadded getReturnType() { + return t.returnType; + } + + public DelegateDeclaration withReturnType(JLeftPadded returnType) { + return t.returnType == returnType ? t : new DelegateDeclaration(t.id, t.prefix, t.markers, + t.modifiers, returnType, t.identifier, t.typeParameters, + t.parameters, t.typeParameterConstraintClauses); + } + + public @Nullable JContainer getTypeParameters() { + return t.typeParameters; + } + + public DelegateDeclaration withTypeParameters(@Nullable JContainer typeParameters) { + return t.typeParameters == typeParameters ? t : new DelegateDeclaration(t.id, t.prefix, t.markers, + t.modifiers, t.returnType, t.identifier, typeParameters, + t.parameters, t.typeParameterConstraintClauses); + } + + public JContainer getParameters() { + return t.parameters; + } + + public DelegateDeclaration withParameters(JContainer parameters) { + return t.parameters == parameters ? t : new DelegateDeclaration(t.id, t.prefix, t.markers, + t.modifiers, t.returnType, t.identifier, t.typeParameters, + parameters, t.typeParameterConstraintClauses); + } + + public @Nullable JContainer getTypeParameterConstraintClauses() { + return t.typeParameterConstraintClauses; + } + + public DelegateDeclaration withTypeParameterConstraintClauses(@Nullable JContainer clauses) { + return t.typeParameterConstraintClauses == clauses ? t : new DelegateDeclaration(t.id, t.prefix, t.markers, + t.modifiers, t.returnType, t.identifier, t.typeParameters, + t.parameters, clauses); + } + } + } + + /** + * Represents a C# operator conversion declaration that defines custom type conversion behavior. + *

+     * // Implicit conversion
+     * public static implicit operator string(MyType t) => t.ToString();
+     *
+     * // Explicit conversion
+     * public static explicit operator int(MyType t) { return t.Value; }
+     *
+     * // With expression body
+     * public static explicit operator double(MyType t) => t.Value;
+     *
+     * // With block body
+     * public static implicit operator bool(MyType t) {
+     *     return t.Value != 0;
+     * }
+     */
+    @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
+    @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
+    @RequiredArgsConstructor
+    @AllArgsConstructor(access = AccessLevel.PRIVATE)
+    final class ConversionOperatorDeclaration implements Cs, Statement {
+
+        @Nullable
+        @NonFinal
+        transient WeakReference padding;
+
+        @With
+        @EqualsAndHashCode.Include
+        @Getter
+        UUID id;
+
+        @With
+        @Getter
+        Space prefix;
+
+        @With
+        @Getter
+        Markers markers;
+
+        /**
+         * 
+         * public static implicit operator string(MyType t)
+         * ^^^^^^^^^^^^^
+         * 
+ */ + @With + @Getter + List modifiers; + + /** + *
+         * public static implicit operator string(MyType t)
+         *               ^^^^^^^^
+         * 
+ */ + JLeftPadded kind; + + public ExplicitImplicit getKind() { + return kind.getElement(); + } + + public ConversionOperatorDeclaration withKind(ExplicitImplicit kind) { + return getPadding().withKind(this.kind.withElement(kind)); + } + + /** + *
+         * public static implicit operator string(MyType t)
+         *                                ^^^^^^^
+         * 
+ */ + JLeftPadded returnType; + + public TypeTree getReturnType() { + return returnType.getElement(); + } + + public ConversionOperatorDeclaration withReturnType(TypeTree returnType) { + return getPadding().withReturnType(this.returnType.withElement(returnType)); + } + + /** + *
+         * public static implicit operator string(MyType t)
+         *                                      ^^^^^^^^^
+         * 
+ */ + JContainer parameters; + + /** + *
+         * public static implicit operator string(MyType t) => t.ToString();
+         *                                                 ^^^^^^^^^^^^^^^
+         * 
+ */ + @Nullable + JLeftPadded expressionBody; + + /** + *
+         * public static implicit operator string(MyType t) { return t.ToString(); }
+         *                                                 ^^^^^^^^^^^^^^^^^^^^^^^
+         * 
+ */ + @With + @Getter + @Nullable + Block body; + + public enum ExplicitImplicit { + Implicit, + Explicit + } + + public List getParameters() { + return parameters.getElements(); + } + + public ConversionOperatorDeclaration withParameters(List parameters) { + return getPadding().withParameters(JContainer.withElements(this.parameters, parameters)); + } + + public @Nullable Expression getExpressionBody() { + return expressionBody != null ? expressionBody.getElement() : null; + } + + public ConversionOperatorDeclaration withExpressionBody(@Nullable Expression expressionBody) { + return getPadding().withExpressionBody(JLeftPadded.withElement(this.expressionBody, expressionBody)); + } + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitConversionOperatorDeclaration(this, p); + } + + @Override + public CoordinateBuilder.Statement getCoordinates() { + return new CoordinateBuilder.Statement(this); + } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final ConversionOperatorDeclaration t; + + public JLeftPadded getReturnType() { + return t.returnType; + } + + public ConversionOperatorDeclaration withReturnType(JLeftPadded returnType) { + return t.returnType == returnType ? t : new ConversionOperatorDeclaration(t.id, t.prefix, t.markers, + t.modifiers, t.kind, returnType, t.parameters, + t.expressionBody, t.body); + } + + public JLeftPadded getKind() { + return t.kind; + } + + public ConversionOperatorDeclaration withKind(JLeftPadded kind) { + return t.kind == kind ? t : new ConversionOperatorDeclaration(t.id, t.prefix, t.markers, + t.modifiers, kind, t.returnType, t.parameters, + t.expressionBody, t.body); + } + + public JContainer getParameters() { + return t.parameters; + } + + public ConversionOperatorDeclaration withParameters(JContainer parameters) { + return t.parameters == parameters ? t : new ConversionOperatorDeclaration(t.id, t.prefix, t.markers, + t.modifiers, t.kind, t.returnType, parameters, + t.expressionBody, t.body); + } + + public @Nullable JLeftPadded getExpressionBody() { + return t.expressionBody; + } + + public ConversionOperatorDeclaration withExpressionBody(@Nullable JLeftPadded expressionBody) { + return t.expressionBody == expressionBody ? t : new ConversionOperatorDeclaration(t.id, t.prefix, t.markers, + t.modifiers, t.kind, t.returnType, t.parameters, + expressionBody, t.body); + } + } + } + + /** + * Represents a C# type parameter in generic type declarations, including optional variance and constraints. + *

+ * For example: + *

+     *     // Simple type parameter
+     *     class Container<T>
+     *
+     *     // Type parameter with variance
+     *     interface IEnumerable<out T>
+     *
+     *     // Type parameter with attributes
+     *     class Handler<[Category("A")] T>
+     *
+     *     // Type parameter with variance and attributes
+     *     interface IComparer<[NotNull] in T>
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + final class TypeParameter implements Cs { + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + @With + @Getter + List attributeLists; + + /** + *
+         * interface IEnumerable
+         *                      ^^^
+         * 
+ */ + @Nullable + JLeftPadded variance; + + /** + *
+         * class Container
+         *                 ^
+         * 
+ */ + @With + @Getter + Identifier name; + + public enum VarianceKind { + In, + Out + } + + public @Nullable VarianceKind getVariance() { + return variance == null ? null : variance.getElement(); + } + + public Cs.TypeParameter withVariance(@Nullable VarianceKind variance) { + return getPadding().withVariance(JLeftPadded.withElement(this.variance, variance)); + } + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitTypeParameter(this, p); + } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final Cs.TypeParameter t; + + public @Nullable JLeftPadded getVariance() { + return t.variance; + } + + public Cs.TypeParameter withVariance(@Nullable JLeftPadded variance) { + return t.variance == variance ? t : new Cs.TypeParameter(t.id, t.prefix, t.markers, t.attributeLists, variance, t.name); + } + } + } + + /** + * Represents a C# enum declaration, including optional modifiers, attributes, and enum members. + *

+ * For example: + *

+     *     // Simple enum
+     *     public enum Colors { Red, Green, Blue }
+     *
+     *     // Enum with base type
+     *     enum Flags : byte { None, All }
+     *
+     *     // Enum with attributes and explicit values
+     *     [Flags]
+     *     internal enum Permissions {
+     *         None = 0,
+     *         Read = 1,
+     *         Write = 2,
+     *         ReadWrite = Read | Write
+     *     }
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + final class EnumDeclaration implements Cs, Statement { + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + @With + @Getter + @Nullable + List attributeLists; + + @With + @Getter + List modifiers; + + /** + *
+         * public enum Colors { Red, Green }
+         *            ^^^^^^
+         * 
+ */ + JLeftPadded name; + + public Identifier getName() { + return name.getElement(); + } + + public EnumDeclaration withName(Identifier name) { + return getPadding().withName(JLeftPadded.withElement(this.name, name)); + } + + /** + *
+         * enum Flags : byte { None }
+         *           ^^^^^^^
+         * 
+ */ + @Nullable + JLeftPadded baseType; + + /** + *
+         * enum Colors { Red, Green, Blue }
+         *             ^^^^^^^^^^^^^^^^^^
+         * 
+ */ + @Nullable + JContainer members; + + public @Nullable TypeTree getBaseType() { + return baseType == null ? null : baseType.getElement(); + } + + public EnumDeclaration withBaseType(@Nullable TypeTree baseType) { + return getPadding().withBaseType(JLeftPadded.withElement(this.baseType, baseType)); + } + + public @Nullable List getMembers() { + return members.getElements(); + } + + public EnumDeclaration withMembers(@Nullable List members) { + + return getPadding().withMembers(members != null ? JContainer.withElements(this.members, members) : null); + } + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitEnumDeclaration(this, p); + } + + @Override + public CoordinateBuilder.Statement getCoordinates() { + return new CoordinateBuilder.Statement(this); + } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final EnumDeclaration t; + + public @Nullable JLeftPadded getName() { + return t.name; + } + + public EnumDeclaration withName(JLeftPadded name) { + return t.name == name ? t : new EnumDeclaration(t.id, t.prefix, t.markers, t.attributeLists, t.modifiers, name, t.baseType, t.members); + } + + public @Nullable JLeftPadded getBaseType() { + return t.baseType; + } + + public EnumDeclaration withBaseType(@Nullable JLeftPadded baseType) { + return t.baseType == baseType ? t : new EnumDeclaration(t.id, t.prefix, t.markers, t.attributeLists, t.modifiers, t.name, baseType, t.members); + } + + public JContainer getMembers() { + return t.members; + } + + public EnumDeclaration withMembers(JContainer members) { + return t.members == members ? t : new EnumDeclaration(t.id, t.prefix, t.markers, t.attributeLists, t.modifiers, t.name, t.baseType, members); + } + } + } + + /** + * Represents a C# enum member declaration, including optional attributes and initializer. + *

+ * For example: + *

+     *     // Simple enum member
+     *     Red,
+     *
+     *     // Member with initializer
+     *     Green = 2,
+     *
+     *     // Member with attributes and expression initializer
+     *     [Obsolete]
+     *     Blue = Red | Green,
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + final class EnumMemberDeclaration implements Cs { + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + @With + @Getter + List attributeLists; + + /** + *
+         * Red = 1
+         * ^^^
+         * 
+ */ + @With + @Getter + Identifier name; + + /** + *
+         * Red = 1
+         *     ^^^
+         * 
+ */ + @Nullable + JLeftPadded initializer; + + public @Nullable Expression getInitializer() { + return initializer == null ? null : initializer.getElement(); + } + + public EnumMemberDeclaration withInitializer(@Nullable Expression initializer) { + return getPadding().withInitializer(JLeftPadded.withElement(this.initializer, initializer)); + } + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitEnumMemberDeclaration(this, p); + } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final EnumMemberDeclaration t; + + public @Nullable JLeftPadded getInitializer() { + return t.initializer; + } + + public EnumMemberDeclaration withInitializer(@Nullable JLeftPadded initializer) { + return t.initializer == initializer ? t : new EnumMemberDeclaration(t.id, t.prefix, t.markers, t.attributeLists, t.name, initializer); + } + } + } + + /** + * Represents a C# alias qualified name, which uses an extern alias to qualify a name. + *

+ * For example: + *

+     *     // Using LibA to qualify TypeName
+     *     LibA::TypeName
+     *
+     *     // Using LibB to qualify namespace
+     *     LibB::System.Collections
+     * 
+ */ + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @RequiredArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + final class AliasQualifiedName implements Cs, TypeTree, Expression, Marker { + @Nullable + @NonFinal + transient WeakReference padding; + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + /** + *
+         * LibA::TypeName
+         * ^^^^
+         * 
+ */ + JRightPadded alias; + + /** + *
+         * LibA::TypeName
+         *      ^^^^^^^^
+         * 
+ * In case of method invocation, whole expression gets placed here + */ + @With + @Getter + Expression name; + + public Identifier getAlias() { + return alias.getElement(); + } + + public AliasQualifiedName withAlias(Identifier alias) { + return getPadding().withAlias(JRightPadded.withElement(this.alias, alias)); + } + + @Override + public JavaType getType() { + return name.getType(); + } + + @Override + public AliasQualifiedName withType(@Nullable JavaType type) { + return withName(name.withType(type)); + } + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitAliasQualifiedName(this, p); + } + + @Override + public CoordinateBuilder.Expression getCoordinates() { + return new CoordinateBuilder.Expression(this); + } + + public Padding getPadding() { + Padding p; + if (this.padding == null) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } else { + p = this.padding.get(); + if (p == null || p.t != this) { + p = new Padding(this); + this.padding = new WeakReference<>(p); + } + } + return p; + } + + @RequiredArgsConstructor + public static class Padding { + private final AliasQualifiedName t; + + public JRightPadded getAlias() { + return t.alias; + } + + public AliasQualifiedName withAlias(JRightPadded alias) { + return t.alias == alias ? t : new AliasQualifiedName(t.id, t.prefix, t.markers, alias, t.name); + } + } + } + + @ToString + @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) + @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) + @AllArgsConstructor(access = AccessLevel.PUBLIC) + final class ArrayType implements Cs, Expression, TypeTree { + + @With + @EqualsAndHashCode.Include + @Getter + UUID id; + + @With + @Getter + Space prefix; + + @With + @Getter + Markers markers; + + @With + @Nullable + @Getter + TypeTree typeExpression; + + @With + @Getter + List dimensions; + + + @With + @Nullable + @Getter + JavaType type; + + @Override + public

J acceptCSharp(CSharpVisitor

v, P p) { + return v.visitArrayType(this, p); + } + + @Override + @Transient + public CoordinateBuilder.Expression getCoordinates() { + return new CoordinateBuilder.Expression(this); + } + + + + } } diff --git a/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsContainer.java b/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsContainer.java index f448345..ad7cf4b 100644 --- a/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsContainer.java +++ b/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsContainer.java @@ -42,7 +42,17 @@ public enum Location { SWITCH_STATEMENT_SECTIONS(CsSpace.Location.SWITCH_STATEMENT_SECTIONS, CsRightPadded.Location.SWITCH_STATEMENT_SECTIONS), SWITCH_STATEMENT_EXPRESSION(CsSpace.Location.SWITCH_STATEMENT_EXPRESSION, CsRightPadded.Location.SWITCH_STATEMENT_EXPRESSION), SWITCH_EXPRESSION_ARMS(CsSpace.Location.SWITCH_EXPRESSION_ARMS, CsRightPadded.Location.SWITCH_EXPRESSION_ARMS), - PARENTHESIZED_PATTERN_PATTERN(CsSpace.Location.PARENTHESIZED_PATTERN_PATTERN, CsRightPadded.Location.PARENTHESIZED_PATTERN_PATTERN); + PARENTHESIZED_PATTERN_PATTERN(CsSpace.Location.PARENTHESIZED_PATTERN_PATTERN, CsRightPadded.Location.PARENTHESIZED_PATTERN_PATTERN), + INDEXER_DECLARATION_PARAMETERS(CsSpace.Location.INDEXER_DECLARATION_PARAMETERS, CsRightPadded.Location.INDEXER_DECLARATION_PARAMETERS), + DELEGATE_DECLARATION_TYPE_PARAMETERS(CsSpace.Location.DELEGATE_DECLARATION_TYPE_PARAMETERS, CsRightPadded.Location.DELEGATE_DECLARATION_TYPE_PARAMETERS), + DELEGATE_DECLARATION_PARAMETERS(CsSpace.Location.DELEGATE_DECLARATION_PARAMETERS, CsRightPadded.Location.DELEGATE_DECLARATION_PARAMETERS), + DELEGATE_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES(CsSpace.Location.DELEGATE_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES, CsRightPadded.Location.DELEGATE_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES), + CONVERSION_OPERATOR_DECLARATION_PARAMETERS(CsSpace.Location.CONVERSION_OPERATOR_DECLARATION_PARAMETERS, CsRightPadded.Location.CONVERSION_OPERATOR_DECLARATION_PARAMETERS), + CLASS_DECLARATION_TYPE_PARAMETERS(CsSpace.Location.CLASS_DECLARATION_TYPE_PARAMETERS, CsRightPadded.Location.CLASS_DECLARATION_TYPE_PARAMETERS), + CLASS_DECLARATION_PRIMARY_CONSTRUCTOR(CsSpace.Location.CLASS_DECLARATION_PRIMARY_CONSTRUCTOR, CsRightPadded.Location.CLASS_DECLARATION_PRIMARY_CONSTRUCTOR), + CLASS_DECLARATION_IMPLEMENTINGS(CsSpace.Location.CLASS_DECLARATION_IMPLEMENTINGS, CsRightPadded.Location.CLASS_DECLARATION_IMPLEMENTINGS), + METHOD_DECLARATION_TYPE_PARAMETERS(CsSpace.Location.METHOD_DECLARATION_TYPE_PARAMETERS, CsRightPadded.Location.METHOD_DECLARATION_TYPE_PARAMETERS), + ENUM_DECLARATION_MEMBERS(CsSpace.Location.ENUM_DECLARATION_MEMBERS, CsRightPadded.Location.ENUM_DECLARATION_MEMBERS); private final CsSpace.Location beforeLocation; private final CsRightPadded.Location elementLocation; diff --git a/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsLeftPadded.java b/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsLeftPadded.java index 1f74b11..b6781e8 100644 --- a/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsLeftPadded.java +++ b/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsLeftPadded.java @@ -31,7 +31,19 @@ public enum Location { IS_PATTERN_PATTERN(CsSpace.Location.IS_PATTERN_PATTERN), BINARY_PATTERN_OPERATOR(CsSpace.Location.BINARY_PATTERN_OPERATOR), RELATIONAL_PATTERN_OPERATOR(CsSpace.Location.RELATIONAL_PATTERN_OPERATOR), - SUBPATTERN_PATTERN(CsSpace.Location.SUBPATTERN_PATTERN); + SUBPATTERN_PATTERN(CsSpace.Location.SUBPATTERN_PATTERN), + INDEXER_DECLARATION_EXPRESSION_BODY(CsSpace.Location.INDEXER_DECLARATION_EXPRESSION_BODY), + JOIN_CLAUSE_INTO(CsSpace.Location.JOIN_CLAUSE_INTO), + CONVERSION_OPERATOR_DECLARATION_KIND(CsSpace.Location.CONVERSION_OPERATOR_DECLARATION_KIND), + CONVERSION_OPERATOR_DECLARATION_EXPRESSION_BODY(CsSpace.Location.CONVERSION_OPERATOR_DECLARATION_EXPRESSION_BODY), + USING_STATEMENT_EXPRESSION(CsSpace.Location.USING_STATEMENT_EXPRESSION), + CLASS_DECLARATION_EXTENDINGS(CsSpace.Location.CLASS_DECLARATION_EXTENDINGS), + ENUM_MEMBER_DECLARATION_INITIALIZER(CsSpace.Location.ENUM_MEMBER_DECLARATION_INITIALIZER), + ENUM_DECLARATION_NAME(CsSpace.Location.ENUM_DECLARATION_NAME), + ENUM_DECLARATION_BASE_TYPE(CsSpace.Location.ENUM_DECLARATION_BASE_TYPE), + TYPE_PARAMETER_VARIANCE(CsSpace.Location.TYPE_PARAMETER_VARIANCE), + CONVERSION_OPERATOR_DECLARATION_RETURN_TYPE(CsSpace.Location.CONVERSION_OPERATOR_DECLARATION_RETURN_TYPE), + DELEGATE_DECLARATION_RETURN_TYPE(CsSpace.Location.DELEGATE_DECLARATION_RETURN_TYPE); private CsSpace.Location beforeLocation; diff --git a/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsRightPadded.java b/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsRightPadded.java index e8ac979..56f6a5f 100644 --- a/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsRightPadded.java +++ b/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsRightPadded.java @@ -76,7 +76,29 @@ enum Location { FOR_EACH_VARIABLE_LOOP_BODY(CsSpace.Location.FOR_EACH_VARIABLE_LOOP_BODY), FOR_EACH_VARIABLE_LOOP_CONTROL_ITERABLE(CsSpace.Location.FOR_EACH_VARIABLE_LOOP_CONTROL_ITERABLE), FOR_EACH_VARIABLE_LOOP_CONTROL_VARIABLE(CsSpace.Location.FOR_EACH_VARIABLE_LOOP_CONTROL_VARIABLE), - PARENTHESIZED_PATTERN_PATTERN(CsSpace.Location.PARENTHESIZED_PATTERN_PATTERN); + PARENTHESIZED_PATTERN_PATTERN(CsSpace.Location.PARENTHESIZED_PATTERN_PATTERN), + INDEXER_DECLARATION_PARAMETERS(CsSpace.Location.INDEXER_DECLARATION_PARAMETERS), + INDEXER_DECLARATION_INTERFACE_SPECIFIER(CsSpace.Location.INDEXER_DECLARATION_INTERFACE_SPECIFIER), + GROUP_CLAUSE_GROUP_EXPRESSION(CsSpace.Location.GROUP_CLAUSE_GROUP_EXPRESSION), + ORDERING_EXPRESSION(CsSpace.Location.ORDERING_EXPRESSION), + ORDER_BY_CLAUSE_ORDERINGS(CsSpace.Location.ORDER_BY_CLAUSE_ORDERINGS), + JOIN_CLAUSE_LEFT_EXPRESSION(CsSpace.Location.JOIN_CLAUSE_LEFT_EXPRESSION), + JOIN_CLAUSE_IN_EXPRESSION(CsSpace.Location.JOIN_CLAUSE_IN_EXPRESSION), + JOIN_CLAUSE_IDENTIFIER(CsSpace.Location.JOIN_CLAUSE_IDENTIFIER), + LET_CLAUSE_IDENTIFIER(CsSpace.Location.LET_CLAUSE_IDENTIFIER), + FROM_CLAUSE_IDENTIFIER(CsSpace.Location.FROM_CLAUSE_IDENTIFIER), + DELEGATE_DECLARATION_TYPE_PARAMETERS(CsSpace.Location.DELEGATE_DECLARATION_TYPE_PARAMETERS), + DELEGATE_DECLARATION_PARAMETERS(CsSpace.Location.DELEGATE_DECLARATION_PARAMETERS), + DELEGATE_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES(CsSpace.Location.DELEGATE_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES), + CONVERSION_OPERATOR_DECLARATION_PARAMETERS(CsSpace.Location.CONVERSION_OPERATOR_DECLARATION_PARAMETERS), + CLASS_DECLARATION_TYPE_PARAMETERS(CsSpace.Location.CLASS_DECLARATION_TYPE_PARAMETERS), + CLASS_DECLARATION_PRIMARY_CONSTRUCTOR(CsSpace.Location.CLASS_DECLARATION_PRIMARY_CONSTRUCTOR), + CLASS_DECLARATION_IMPLEMENTINGS(CsSpace.Location.CLASS_DECLARATION_IMPLEMENTINGS), + METHOD_DECLARATION_EXPLICIT_INTERFACE_SPECIFIER(CsSpace.Location.METHOD_DECLARATION_EXPLICIT_INTERFACE_SPECIFIER), + METHOD_DECLARATION_TYPE_PARAMETERS(CsSpace.Location.METHOD_DECLARATION_TYPE_PARAMETERS), + ALIAS_QUALIFIED_NAME_ALIAS(CsSpace.Location.ALIAS_QUALIFIED_NAME_ALIAS), + ENUM_DECLARATION_MEMBERS(CsSpace.Location.ENUM_DECLARATION_MEMBERS), + EXPRESSION_STATEMENT_EXPRESSION(CsSpace.Location.EXPRESSION_STATEMENT_EXPRESSION); private final CsSpace.Location afterLocation; diff --git a/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsSpace.java b/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsSpace.java index 95d33da..4197a45 100644 --- a/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsSpace.java +++ b/rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/CsSpace.java @@ -108,7 +108,7 @@ public enum Location { TUPLE_EXPRESSION_ARGUMENTS, TUPLE_EXPRESSION_PREFIX, METHOD_DECLARATION_PARAMETERS, - CONSTRUCTOR_INITIALIZER_ARGUMENTS, CONSTRUCTOR_PREFIX, UNARY_PREFIX, UNARY_OPERATOR, CONSTRUCTOR_INITIALIZER_PREFIX, TUPLE_ELEMENT_PREFIX, TUPLE_TYPE_PREFIX, TUPLE_TYPE_ELEMENTS, NEW_CLASS_PREFIX, INITIALIZER_EXPRESSION_EXPRESSIONS, IMPLICIT_ELEMENT_ACCESS_PREFIX, IMPLICIT_ELEMENT_ACCESS_ARGUMENT_LIST, INITIALIZER_EXPRESSION_PREFIX, IS_PATTERN_PREFIX, SUBPATTERN_PATTERN, SUBPATTERN_PREFIX, IS_PATTERN_PATTERN, PROPERTY_PATTERN_CLAUSE_SUBPATTERNS, PROPERTY_PATTERN_CLAUSE_PREFIX, POSITIONAL_PATTERN_CLAUSE_SUBPATTERNS, POSITIONAL_PATTERN_CLAUSE_PREFIX, VAR_PATTERN_PREFIX, UNARY_PATTERN_PREFIX, TYPE_PATTERN_PREFIX, SLICE_PATTERN_PREFIX, RELATIONAL_PATTERN_OPERATOR, RELATIONAL_PATTERN_PREFIX, RECURSIVE_PATTERN_PREFIX, PARENTHESIZED_PATTERN_PREFIX, LIST_PATTERN_PATTERNS, LIST_PATTERN_PREFIX, DISCARD_PATTERN_PREFIX, CONSTANT_PATTERN_PREFIX, BINARY_PATTERN_OPERATOR, BINARY_PATTERN_PREFIX, YIELD_PREFIX, DEFAULT_EXPRESSION_TYPE_OPERATOR, SWITCH_EXPRESSION_ARM_EXPRESSION, SWITCH_EXPRESSION_ARM_WHEN_EXPRESSION, SWITCH_EXPRESSION_ARM_PREFIX, CASE_PATTERN_SWITCH_LABEL_COLON_TOKEN, DEFAULT_SWITCH_LABEL_PREFIX, CASE_PATTERN_SWITCH_LABEL_WHEN_CLAUSE, CASE_PATTERN_SWITCH_LABEL_PREFIX, LOCK_STATEMENT_STATEMENT, LOCK_STATEMENT_PREFIX, FIXED_STATEMENT_PREFIX, RANGE_EXPRESSION_START, RANGE_EXPRESSION_PREFIX, CHECKED_STATEMENT_PREFIX, UNSAFE_STATEMENT_PREFIX, SWITCH_SECTION_STATEMENTS, SWITCH_SECTION_PREFIX, SWITCH_STATEMENT_SECTIONS, SWITCH_STATEMENT_EXPRESSION, SWITCH_STATEMENT_PREFIX, SWITCH_EXPRESSION_ARMS, SWITCH_EXPRESSION_EXPRESSION, SWITCH_EXPRESSION_PREFIX, FOR_EACH_VARIABLE_LOOP_CONTROL_ITERABLE, FOR_EACH_VARIABLE_LOOP_CONTROL_VARIABLE, FOR_EACH_VARIABLE_LOOP_BODY, FOR_EACH_VARIABLE_LOOP_PREFIX, DESTRUCTOR_DECLARATION_PREFIX, DEFAULT_EXPRESSION_PREFIX, PARENTHESIZED_PATTERN_PATTERN, DEFAULT_SWITCH_LABEL_COLON_TOKEN, FOR_EACH_VARIABLE_LOOP_CONTROL_PREFIX; + CONSTRUCTOR_INITIALIZER_ARGUMENTS, CONSTRUCTOR_PREFIX, UNARY_PREFIX, UNARY_OPERATOR, CONSTRUCTOR_INITIALIZER_PREFIX, TUPLE_ELEMENT_PREFIX, TUPLE_TYPE_PREFIX, TUPLE_TYPE_ELEMENTS, NEW_CLASS_PREFIX, INITIALIZER_EXPRESSION_EXPRESSIONS, IMPLICIT_ELEMENT_ACCESS_PREFIX, IMPLICIT_ELEMENT_ACCESS_ARGUMENT_LIST, INITIALIZER_EXPRESSION_PREFIX, IS_PATTERN_PREFIX, SUBPATTERN_PATTERN, SUBPATTERN_PREFIX, IS_PATTERN_PATTERN, PROPERTY_PATTERN_CLAUSE_SUBPATTERNS, PROPERTY_PATTERN_CLAUSE_PREFIX, POSITIONAL_PATTERN_CLAUSE_SUBPATTERNS, POSITIONAL_PATTERN_CLAUSE_PREFIX, VAR_PATTERN_PREFIX, UNARY_PATTERN_PREFIX, TYPE_PATTERN_PREFIX, SLICE_PATTERN_PREFIX, RELATIONAL_PATTERN_OPERATOR, RELATIONAL_PATTERN_PREFIX, RECURSIVE_PATTERN_PREFIX, PARENTHESIZED_PATTERN_PREFIX, LIST_PATTERN_PATTERNS, LIST_PATTERN_PREFIX, DISCARD_PATTERN_PREFIX, CONSTANT_PATTERN_PREFIX, BINARY_PATTERN_OPERATOR, BINARY_PATTERN_PREFIX, YIELD_PREFIX, DEFAULT_EXPRESSION_TYPE_OPERATOR, SWITCH_EXPRESSION_ARM_EXPRESSION, SWITCH_EXPRESSION_ARM_WHEN_EXPRESSION, SWITCH_EXPRESSION_ARM_PREFIX, CASE_PATTERN_SWITCH_LABEL_COLON_TOKEN, DEFAULT_SWITCH_LABEL_PREFIX, CASE_PATTERN_SWITCH_LABEL_WHEN_CLAUSE, CASE_PATTERN_SWITCH_LABEL_PREFIX, LOCK_STATEMENT_STATEMENT, LOCK_STATEMENT_PREFIX, FIXED_STATEMENT_PREFIX, RANGE_EXPRESSION_START, RANGE_EXPRESSION_PREFIX, CHECKED_STATEMENT_PREFIX, UNSAFE_STATEMENT_PREFIX, SWITCH_SECTION_STATEMENTS, SWITCH_SECTION_PREFIX, SWITCH_STATEMENT_SECTIONS, SWITCH_STATEMENT_EXPRESSION, SWITCH_STATEMENT_PREFIX, SWITCH_EXPRESSION_ARMS, SWITCH_EXPRESSION_EXPRESSION, SWITCH_EXPRESSION_PREFIX, FOR_EACH_VARIABLE_LOOP_CONTROL_ITERABLE, FOR_EACH_VARIABLE_LOOP_CONTROL_VARIABLE, FOR_EACH_VARIABLE_LOOP_BODY, FOR_EACH_VARIABLE_LOOP_PREFIX, DESTRUCTOR_DECLARATION_PREFIX, DEFAULT_EXPRESSION_PREFIX, PARENTHESIZED_PATTERN_PATTERN, DEFAULT_SWITCH_LABEL_COLON_TOKEN, FOR_EACH_VARIABLE_LOOP_CONTROL_PREFIX, CONVERSION_OPERATOR_DECLARATION_PREFIX, DELEGATE_DECLARATION_PREFIX, INDEXER_DECLARATION_PREFIX, INDEXER_DECLARATION_PARAMETERS, INDEXER_DECLARATION_EXPRESSION_BODY, INDEXER_DECLARATION_INTERFACE_SPECIFIER, GROUP_CLAUSE_GROUP_EXPRESSION, GROUP_CLAUSE_PREFIX, SELECT_CLAUSE_PREFIX, ORDERING_PREFIX, ORDERING_EXPRESSION, QUERY_CONTINUATION_PREFIX, ORDER_BY_CLAUSE_PREFIX, WHERE_CLAUSE_PREFIX, ORDER_BY_CLAUSE_ORDERINGS, JOIN_INTO_CLAUSE_PREFIX, JOIN_CLAUSE_INTO, JOIN_CLAUSE_LEFT_EXPRESSION, JOIN_CLAUSE_IN_EXPRESSION, JOIN_CLAUSE_IDENTIFIER, JOIN_CLAUSE_PREFIX, LET_CLAUSE_PREFIX, LET_CLAUSE_IDENTIFIER, FROM_CLAUSE_IDENTIFIER, FROM_CLAUSE_PREFIX, QUERY_BODY_PREFIX, QUERY_EXPRESSION_PREFIX, DELEGATE_DECLARATION_TYPE_PARAMETERS, DELEGATE_DECLARATION_PARAMETERS, DELEGATE_DECLARATION_TYPE_PARAMETER_CONSTRAINT_CLAUSES, CONVERSION_OPERATOR_DECLARATION_KIND, CONVERSION_OPERATOR_DECLARATION_PARAMETERS, CONVERSION_OPERATOR_DECLARATION_EXPRESSION_BODY, CLASS_DECLARATION_TYPE_PARAMETERS, CLASS_DECLARATION_PRIMARY_CONSTRUCTOR, CLASS_DECLARATION_EXTENDINGS, CLASS_DECLARATION_IMPLEMENTINGS, METHOD_DECLARATION_EXPLICIT_INTERFACE_SPECIFIER, METHOD_DECLARATION_TYPE_PARAMETERS, ENUM_MEMBER_DECLARATION_PREFIX, ENUM_MEMBER_DECLARATION_INITIALIZER, ALIAS_QUALIFIED_NAME_PREFIX, ALIAS_QUALIFIED_NAME_ALIAS, ARRAY_TYPE_PREFIX, ENUM_DECLARATION_PREFIX, ENUM_DECLARATION_NAME, ENUM_DECLARATION_BASE_TYPE, ENUM_DECLARATION_MEMBERS, TYPE_PARAMETER_PREFIX, TYPE_PARAMETER_VARIANCE, CONVERSION_OPERATOR_DECLARATION_RETURN_TYPE, DELEGATE_DECLARATION_RETURN_TYPE, EXPRESSION_STATEMENT_EXPRESSION; }