@openrewrite/rewrite 8.63.0 → 8.63.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/java/index.d.ts +1 -0
  2. package/dist/java/index.d.ts.map +1 -1
  3. package/dist/java/index.js +1 -0
  4. package/dist/java/index.js.map +1 -1
  5. package/dist/java/rpc.d.ts +2 -0
  6. package/dist/java/rpc.d.ts.map +1 -1
  7. package/dist/java/rpc.js +749 -410
  8. package/dist/java/rpc.js.map +1 -1
  9. package/dist/java/tree.d.ts +1 -1
  10. package/dist/java/tree.d.ts.map +1 -1
  11. package/dist/java/type-visitor.d.ts +48 -0
  12. package/dist/java/type-visitor.d.ts.map +1 -0
  13. package/dist/java/type-visitor.js +260 -0
  14. package/dist/java/type-visitor.js.map +1 -0
  15. package/dist/java/type.d.ts +2 -0
  16. package/dist/java/type.d.ts.map +1 -1
  17. package/dist/java/type.js +0 -317
  18. package/dist/java/type.js.map +1 -1
  19. package/dist/java/visitor.d.ts.map +1 -1
  20. package/dist/java/visitor.js +579 -363
  21. package/dist/java/visitor.js.map +1 -1
  22. package/dist/javascript/preconditions.d.ts +1 -1
  23. package/dist/javascript/preconditions.d.ts.map +1 -1
  24. package/dist/javascript/preconditions.js +7 -6
  25. package/dist/javascript/preconditions.js.map +1 -1
  26. package/dist/javascript/rpc.js +430 -350
  27. package/dist/javascript/rpc.js.map +1 -1
  28. package/dist/javascript/tree.d.ts +1 -1
  29. package/dist/javascript/tree.d.ts.map +1 -1
  30. package/dist/javascript/type-mapping.d.ts.map +1 -1
  31. package/dist/javascript/type-mapping.js +7 -0
  32. package/dist/javascript/type-mapping.js.map +1 -1
  33. package/dist/javascript/visitor.d.ts.map +1 -1
  34. package/dist/javascript/visitor.js +504 -309
  35. package/dist/javascript/visitor.js.map +1 -1
  36. package/dist/json/visitor.d.ts.map +1 -1
  37. package/dist/json/visitor.js +46 -21
  38. package/dist/json/visitor.js.map +1 -1
  39. package/dist/rpc/queue.d.ts +7 -4
  40. package/dist/rpc/queue.d.ts.map +1 -1
  41. package/dist/rpc/queue.js +22 -32
  42. package/dist/rpc/queue.js.map +1 -1
  43. package/dist/rpc/request/generate.d.ts.map +1 -1
  44. package/dist/rpc/request/generate.js +2 -3
  45. package/dist/rpc/request/generate.js.map +1 -1
  46. package/dist/rpc/request/get-languages.d.ts.map +1 -1
  47. package/dist/rpc/request/get-languages.js +4 -3
  48. package/dist/rpc/request/get-languages.js.map +1 -1
  49. package/dist/rpc/request/get-object.d.ts +1 -1
  50. package/dist/rpc/request/get-object.d.ts.map +1 -1
  51. package/dist/rpc/request/get-object.js +8 -7
  52. package/dist/rpc/request/get-object.js.map +1 -1
  53. package/dist/rpc/request/get-recipes.d.ts.map +1 -1
  54. package/dist/rpc/request/get-recipes.js +2 -2
  55. package/dist/rpc/request/get-recipes.js.map +1 -1
  56. package/dist/rpc/request/index.d.ts +1 -0
  57. package/dist/rpc/request/index.d.ts.map +1 -1
  58. package/dist/rpc/request/index.js +1 -0
  59. package/dist/rpc/request/index.js.map +1 -1
  60. package/dist/rpc/request/install-recipes.d.ts.map +1 -1
  61. package/dist/rpc/request/install-recipes.js +30 -21
  62. package/dist/rpc/request/install-recipes.js.map +1 -1
  63. package/dist/rpc/request/metrics.d.ts +10 -10
  64. package/dist/rpc/request/metrics.d.ts.map +1 -1
  65. package/dist/rpc/request/metrics.js +38 -31
  66. package/dist/rpc/request/metrics.js.map +1 -1
  67. package/dist/rpc/request/parse.d.ts.map +1 -1
  68. package/dist/rpc/request/parse.js +10 -12
  69. package/dist/rpc/request/parse.js.map +1 -1
  70. package/dist/rpc/request/prepare-recipe.d.ts.map +1 -1
  71. package/dist/rpc/request/prepare-recipe.js +4 -4
  72. package/dist/rpc/request/prepare-recipe.js.map +1 -1
  73. package/dist/rpc/request/print.d.ts +1 -1
  74. package/dist/rpc/request/print.d.ts.map +1 -1
  75. package/dist/rpc/request/print.js +10 -6
  76. package/dist/rpc/request/print.js.map +1 -1
  77. package/dist/rpc/request/trace-get-object.d.ts +5 -0
  78. package/dist/rpc/request/trace-get-object.d.ts.map +1 -0
  79. package/dist/rpc/request/trace-get-object.js +3 -0
  80. package/dist/rpc/request/trace-get-object.js.map +1 -0
  81. package/dist/rpc/request/visit.d.ts.map +1 -1
  82. package/dist/rpc/request/visit.js +2 -3
  83. package/dist/rpc/request/visit.js.map +1 -1
  84. package/dist/rpc/rewrite-rpc.d.ts +2 -3
  85. package/dist/rpc/rewrite-rpc.d.ts.map +1 -1
  86. package/dist/rpc/rewrite-rpc.js +14 -5
  87. package/dist/rpc/rewrite-rpc.js.map +1 -1
  88. package/dist/rpc/server.d.ts.map +1 -1
  89. package/dist/rpc/server.js +15 -44
  90. package/dist/rpc/server.js.map +1 -1
  91. package/dist/rpc/trace.d.ts +1 -1
  92. package/dist/rpc/trace.d.ts.map +1 -1
  93. package/dist/rpc/trace.js +3 -3
  94. package/dist/rpc/trace.js.map +1 -1
  95. package/dist/util.d.ts +6 -0
  96. package/dist/util.d.ts.map +1 -1
  97. package/dist/util.js +14 -0
  98. package/dist/util.js.map +1 -1
  99. package/dist/version.txt +1 -1
  100. package/package.json +1 -1
  101. package/src/java/index.ts +1 -0
  102. package/src/java/rpc.ts +726 -537
  103. package/src/java/tree.ts +1 -1
  104. package/src/java/type-visitor.ts +241 -0
  105. package/src/java/type.ts +13 -277
  106. package/src/java/visitor.ts +581 -378
  107. package/src/javascript/preconditions.ts +7 -6
  108. package/src/javascript/rpc.ts +431 -360
  109. package/src/javascript/tree.ts +1 -1
  110. package/src/javascript/type-mapping.ts +7 -0
  111. package/src/javascript/visitor.ts +505 -310
  112. package/src/json/visitor.ts +47 -22
  113. package/src/rpc/queue.ts +20 -17
  114. package/src/rpc/request/generate.ts +31 -25
  115. package/src/rpc/request/get-languages.ts +18 -10
  116. package/src/rpc/request/get-object.ts +42 -34
  117. package/src/rpc/request/get-recipes.ts +15 -8
  118. package/src/rpc/request/index.ts +1 -0
  119. package/src/rpc/request/install-recipes.ts +96 -79
  120. package/src/rpc/request/metrics.ts +54 -48
  121. package/src/rpc/request/parse.ts +31 -25
  122. package/src/rpc/request/prepare-recipe.ts +31 -23
  123. package/src/rpc/request/print.ts +28 -14
  124. package/src/rpc/request/trace-get-object.ts +4 -0
  125. package/src/rpc/request/visit.ts +22 -16
  126. package/src/rpc/rewrite-rpc.ts +23 -10
  127. package/src/rpc/server.ts +17 -52
  128. package/src/rpc/trace.ts +3 -3
  129. package/src/util.ts +14 -0
  130. package/dist/rpc/chrome-profiler.d.ts +0 -25
  131. package/dist/rpc/chrome-profiler.d.ts.map +0 -1
  132. package/dist/rpc/chrome-profiler.js +0 -405
  133. package/dist/rpc/chrome-profiler.js.map +0 -1
  134. package/src/rpc/chrome-profiler.ts +0 -373
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import {Cursor, isTree, SourceFile} from "../tree";
17
- import {mapAsync} from "../util";
17
+ import {mapAsync, updateIfChanged} from "../util";
18
18
  import {produceAsync, TreeVisitor, ValidImmerRecipeReturnType} from "../visitor";
19
19
  import {Expression, isSpace, J, NameTree, Statement, TypedTree, TypeTree} from "./tree";
20
20
  import {createDraft, Draft, finishDraft} from "immer";
@@ -82,10 +82,13 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
82
82
  }
83
83
  annotatedType = expression as J.AnnotatedType;
84
84
 
85
- return this.produceJava<J.AnnotatedType>(annotatedType, p, async draft => {
86
- draft.annotations = await mapAsync(annotatedType.annotations, a => this.visitDefined<J.Annotation>(a, p));
87
- draft.typeExpression = await this.visitDefined(annotatedType.typeExpression, p) as TypedTree;
88
- });
85
+ const updates = {
86
+ prefix: await this.visitSpace(annotatedType.prefix, p),
87
+ markers: await this.visitMarkers(annotatedType.markers, p),
88
+ annotations: await mapAsync(annotatedType.annotations, a => this.visitDefined<J.Annotation>(a, p)),
89
+ typeExpression: await this.visitDefined(annotatedType.typeExpression, p) as TypedTree
90
+ };
91
+ return updateIfChanged(annotatedType, updates);
89
92
  }
90
93
 
91
94
  protected async visitAnnotation(annotation: J.Annotation, p: P): Promise<J | undefined> {
@@ -95,10 +98,13 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
95
98
  }
96
99
  annotation = expression as J.Annotation;
97
100
 
98
- return this.produceJava<J.Annotation>(annotation, p, async draft => {
99
- draft.annotationType = await this.visitTypeName(annotation.annotationType, p);
100
- draft.arguments = await this.visitOptionalContainer(annotation.arguments, p);
101
- });
101
+ const updates = {
102
+ prefix: await this.visitSpace(annotation.prefix, p),
103
+ markers: await this.visitMarkers(annotation.markers, p),
104
+ annotationType: await this.visitTypeName(annotation.annotationType, p),
105
+ arguments: await this.visitOptionalContainer(annotation.arguments, p)
106
+ };
107
+ return updateIfChanged(annotation, updates);
102
108
  }
103
109
 
104
110
  protected async visitArrayAccess(arrayAccess: J.ArrayAccess, p: P): Promise<J | undefined> {
@@ -108,18 +114,25 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
108
114
  }
109
115
  arrayAccess = expression as J.ArrayAccess;
110
116
 
111
- return this.produceJava<J.ArrayAccess>(arrayAccess, p, async draft => {
112
- draft.indexed = await this.visitDefined(arrayAccess.indexed, p) as Expression;
113
- draft.dimension = await this.visitDefined(arrayAccess.dimension, p) as J.ArrayDimension;
114
- });
117
+ const updates = {
118
+ prefix: await this.visitSpace(arrayAccess.prefix, p),
119
+ markers: await this.visitMarkers(arrayAccess.markers, p),
120
+ indexed: await this.visitDefined(arrayAccess.indexed, p) as Expression,
121
+ dimension: await this.visitDefined(arrayAccess.dimension, p) as J.ArrayDimension
122
+ };
123
+ return updateIfChanged(arrayAccess, updates);
115
124
  }
116
125
 
117
126
  protected async visitArrayDimension(arrayDimension: J.ArrayDimension, p: P): Promise<J | undefined> {
118
- return this.produceJava<J.ArrayDimension>(arrayDimension, p, async draft => {
119
- draft.index = await this.visitRightPadded(arrayDimension.index, p);
120
- });
127
+ const updates = {
128
+ prefix: await this.visitSpace(arrayDimension.prefix, p),
129
+ markers: await this.visitMarkers(arrayDimension.markers, p),
130
+ index: await this.visitRightPadded(arrayDimension.index, p)
131
+ };
132
+ return updateIfChanged(arrayDimension, updates);
121
133
  }
122
134
 
135
+
123
136
  protected async visitArrayType(arrayType: J.ArrayType, p: P): Promise<J | undefined> {
124
137
  const expression = await this.visitExpression(arrayType, p);
125
138
  if (!expression?.kind || expression.kind !== J.Kind.ArrayType) {
@@ -127,14 +140,17 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
127
140
  }
128
141
  arrayType = expression as J.ArrayType;
129
142
 
130
- return this.produceJava<J.ArrayType>(arrayType, p, async draft => {
131
- draft.elementType = await this.visitDefined(arrayType.elementType, p) as TypedTree;
132
- if (arrayType.annotations) {
133
- draft.annotations = await mapAsync(arrayType.annotations, a => this.visitDefined<J.Annotation>(a, p));
134
- }
135
- draft.dimension = await this.visitLeftPadded(arrayType.dimension, p);
136
- draft.type = await this.visitType(arrayType.type, p);
137
- });
143
+ const updates: any = {
144
+ prefix: await this.visitSpace(arrayType.prefix, p),
145
+ markers: await this.visitMarkers(arrayType.markers, p),
146
+ elementType: await this.visitDefined(arrayType.elementType, p) as TypedTree,
147
+ dimension: await this.visitLeftPadded(arrayType.dimension, p),
148
+ type: await this.visitType(arrayType.type, p)
149
+ };
150
+ if (arrayType.annotations) {
151
+ updates.annotations = await mapAsync(arrayType.annotations, a => this.visitDefined<J.Annotation>(a, p));
152
+ }
153
+ return updateIfChanged(arrayType, updates);
138
154
  }
139
155
 
140
156
  protected async visitAssert(anAssert: J.Assert, p: P): Promise<J | undefined> {
@@ -144,10 +160,13 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
144
160
  }
145
161
  anAssert = statement as J.Assert;
146
162
 
147
- return this.produceJava<J.Assert>(anAssert, p, async draft => {
148
- draft.condition = await this.visitDefined(anAssert.condition, p) as Expression;
149
- draft.detail = await this.visitOptionalLeftPadded(anAssert.detail, p);
150
- });
163
+ const updates = {
164
+ prefix: await this.visitSpace(anAssert.prefix, p),
165
+ markers: await this.visitMarkers(anAssert.markers, p),
166
+ condition: await this.visitDefined(anAssert.condition, p) as Expression,
167
+ detail: await this.visitOptionalLeftPadded(anAssert.detail, p)
168
+ };
169
+ return updateIfChanged(anAssert, updates);
151
170
  }
152
171
 
153
172
  protected async visitAssignment(assignment: J.Assignment, p: P): Promise<J | undefined> {
@@ -163,11 +182,14 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
163
182
  }
164
183
  assignment = statement as J.Assignment;
165
184
 
166
- return this.produceJava<J.Assignment>(assignment, p, async draft => {
167
- draft.variable = await this.visitDefined(assignment.variable, p) as Expression;
168
- draft.assignment = await this.visitLeftPadded(assignment.assignment, p);
169
- draft.type = await this.visitType(assignment.type, p);
170
- });
185
+ const updates = {
186
+ prefix: await this.visitSpace(assignment.prefix, p),
187
+ markers: await this.visitMarkers(assignment.markers, p),
188
+ variable: await this.visitDefined(assignment.variable, p) as Expression,
189
+ assignment: await this.visitLeftPadded(assignment.assignment, p),
190
+ type: await this.visitType(assignment.type, p)
191
+ };
192
+ return updateIfChanged(assignment, updates);
171
193
  }
172
194
 
173
195
  protected async visitAssignmentOperation(assignOp: J.AssignmentOperation, p: P): Promise<J | undefined> {
@@ -177,12 +199,15 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
177
199
  }
178
200
  assignOp = expression as J.AssignmentOperation;
179
201
 
180
- return this.produceJava<J.AssignmentOperation>(assignOp, p, async draft => {
181
- draft.variable = await this.visitDefined(assignOp.variable, p) as Expression;
182
- draft.operator = await this.visitLeftPadded(assignOp.operator, p);
183
- draft.assignment = await this.visitDefined(assignOp.assignment, p) as Expression;
184
- draft.type = await this.visitType(assignOp.type, p);
185
- });
202
+ const updates = {
203
+ prefix: await this.visitSpace(assignOp.prefix, p),
204
+ markers: await this.visitMarkers(assignOp.markers, p),
205
+ variable: await this.visitDefined(assignOp.variable, p) as Expression,
206
+ operator: await this.visitLeftPadded(assignOp.operator, p),
207
+ assignment: await this.visitDefined(assignOp.assignment, p) as Expression,
208
+ type: await this.visitType(assignOp.type, p)
209
+ };
210
+ return updateIfChanged(assignOp, updates);
186
211
  }
187
212
 
188
213
  protected async visitBinary(binary: J.Binary, p: P): Promise<J | undefined> {
@@ -192,20 +217,26 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
192
217
  }
193
218
  binary = expression as J.Binary;
194
219
 
195
- return this.produceJava<J.Binary>(binary, p, async draft => {
196
- draft.left = await this.visitDefined(binary.left, p) as Expression;
197
- draft.operator = await this.visitLeftPadded(binary.operator, p);
198
- draft.right = await this.visitDefined(binary.right, p) as Expression;
199
- draft.type = await this.visitType(binary.type, p);
200
- });
220
+ const updates = {
221
+ prefix: await this.visitSpace(binary.prefix, p),
222
+ markers: await this.visitMarkers(binary.markers, p),
223
+ left: await this.visitDefined(binary.left, p) as Expression,
224
+ operator: await this.visitLeftPadded(binary.operator, p),
225
+ right: await this.visitDefined(binary.right, p) as Expression,
226
+ type: await this.visitType(binary.type, p)
227
+ };
228
+ return updateIfChanged(binary, updates);
201
229
  }
202
230
 
203
231
  protected async visitBlock(block: J.Block, p: P): Promise<J | undefined> {
204
- return this.produceJava<J.Block>(block, p, async draft => {
205
- draft.static = await this.visitRightPadded(block.static, p);
206
- draft.statements = await mapAsync(block.statements, stmt => this.visitRightPadded(stmt, p));
207
- draft.end = await this.visitSpace(block.end, p);
208
- });
232
+ const updates = {
233
+ prefix: await this.visitSpace(block.prefix, p),
234
+ markers: await this.visitMarkers(block.markers, p),
235
+ static: await this.visitRightPadded(block.static, p),
236
+ statements: await mapAsync(block.statements, stmt => this.visitRightPadded(stmt, p)),
237
+ end: await this.visitSpace(block.end, p)
238
+ };
239
+ return updateIfChanged(block, updates);
209
240
  }
210
241
 
211
242
  protected async visitBreak(breakStatement: J.Break, p: P): Promise<J | undefined> {
@@ -215,11 +246,14 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
215
246
  }
216
247
  breakStatement = statement as J.Break;
217
248
 
218
- return this.produceJava<J.Break>(breakStatement, p, async draft => {
219
- if (breakStatement.label) {
220
- draft.label = await this.visitDefined(breakStatement.label, p) as J.Identifier;
221
- }
222
- });
249
+ const updates: any = {
250
+ prefix: await this.visitSpace(breakStatement.prefix, p),
251
+ markers: await this.visitMarkers(breakStatement.markers, p)
252
+ };
253
+ if (breakStatement.label) {
254
+ updates.label = await this.visitDefined(breakStatement.label, p) as J.Identifier;
255
+ }
256
+ return updateIfChanged(breakStatement, updates);
223
257
  }
224
258
 
225
259
  protected async visitCase(aCase: J.Case, p: P): Promise<J | undefined> {
@@ -229,14 +263,17 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
229
263
  }
230
264
  aCase = statement as J.Case;
231
265
 
232
- return this.produceJava<J.Case>(aCase, p, async draft => {
233
- draft.caseLabels = await this.visitContainer(aCase.caseLabels, p);
234
- draft.statements = await this.visitContainer(aCase.statements, p);
235
- draft.body = await this.visitOptionalRightPadded(aCase.body, p);
236
- if (aCase.guard) {
237
- draft.guard = await this.visitDefined(aCase.guard, p) as Expression;
238
- }
239
- });
266
+ const updates: any = {
267
+ prefix: await this.visitSpace(aCase.prefix, p),
268
+ markers: await this.visitMarkers(aCase.markers, p),
269
+ caseLabels: await this.visitContainer(aCase.caseLabels, p),
270
+ statements: await this.visitContainer(aCase.statements, p),
271
+ body: await this.visitOptionalRightPadded(aCase.body, p)
272
+ };
273
+ if (aCase.guard) {
274
+ updates.guard = await this.visitDefined(aCase.guard, p) as Expression;
275
+ }
276
+ return updateIfChanged(aCase, updates);
240
277
  }
241
278
 
242
279
  protected async visitClassDeclaration(classDecl: J.ClassDeclaration, p: P): Promise<J | undefined> {
@@ -246,34 +283,43 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
246
283
  }
247
284
  classDecl = statement as J.ClassDeclaration;
248
285
 
249
- return this.produceJava<J.ClassDeclaration>(classDecl, p, async draft => {
250
- draft.leadingAnnotations = await mapAsync(classDecl.leadingAnnotations, a => this.visitDefined<J.Annotation>(a, p));
251
- draft.modifiers = await mapAsync(classDecl.modifiers, m => this.visitDefined<J.Modifier>(m, p));
252
- draft.classKind = await this.visitDefined(classDecl.classKind, p) as J.ClassDeclaration.Kind;
253
- draft.name = await this.visitDefined(classDecl.name, p) as J.Identifier;
254
- draft.typeParameters = await this.visitOptionalContainer(classDecl.typeParameters, p);
255
- draft.primaryConstructor = await this.visitOptionalContainer(classDecl.primaryConstructor, p);
256
- draft.extends = await this.visitOptionalLeftPadded(classDecl.extends, p);
257
- draft.implements = await this.visitOptionalContainer(classDecl.implements, p);
258
- draft.permitting = await this.visitOptionalContainer(classDecl.permitting, p);
259
- draft.body = await this.visitDefined(classDecl.body, p) as J.Block;
260
- draft.type = await this.visitType(classDecl.type, p) as Type.Class | undefined;
261
- });
286
+ const updates: any = {
287
+ prefix: await this.visitSpace(classDecl.prefix, p),
288
+ markers: await this.visitMarkers(classDecl.markers, p),
289
+ leadingAnnotations: await mapAsync(classDecl.leadingAnnotations, a => this.visitDefined<J.Annotation>(a, p)),
290
+ modifiers: await mapAsync(classDecl.modifiers, m => this.visitDefined<J.Modifier>(m, p)),
291
+ classKind: await this.visitDefined(classDecl.classKind, p) as J.ClassDeclaration.Kind,
292
+ name: await this.visitDefined(classDecl.name, p) as J.Identifier,
293
+ typeParameters: await this.visitOptionalContainer(classDecl.typeParameters, p),
294
+ primaryConstructor: await this.visitOptionalContainer(classDecl.primaryConstructor, p),
295
+ extends: await this.visitOptionalLeftPadded(classDecl.extends, p),
296
+ implements: await this.visitOptionalContainer(classDecl.implements, p),
297
+ permitting: await this.visitOptionalContainer(classDecl.permitting, p),
298
+ body: await this.visitDefined(classDecl.body, p) as J.Block,
299
+ type: await this.visitType(classDecl.type, p) as Type.Class | undefined
300
+ };
301
+ return updateIfChanged(classDecl, updates);
262
302
  }
263
303
 
264
304
  protected async visitClassDeclarationKind(kind: J.ClassDeclaration.Kind, p: P): Promise<J | undefined> {
265
- return this.produceJava<J.ClassDeclaration.Kind>(kind, p, async draft => {
266
- draft.annotations = await mapAsync(kind.annotations, a => this.visitDefined<J.Annotation>(a, p));
267
- });
305
+ const updates: any = {
306
+ prefix: await this.visitSpace(kind.prefix, p),
307
+ markers: await this.visitMarkers(kind.markers, p),
308
+ annotations: await mapAsync(kind.annotations, a => this.visitDefined<J.Annotation>(a, p))
309
+ };
310
+ return updateIfChanged(kind, updates);
268
311
  }
269
312
 
270
313
  protected async visitCompilationUnit(cu: J.CompilationUnit, p: P): Promise<J | undefined> {
271
- return this.produceJava<J.CompilationUnit>(cu, p, async draft => {
272
- draft.packageDeclaration = await this.visitRightPadded(cu.packageDeclaration, p) as J.RightPadded<J.Package>;
273
- draft.imports = await mapAsync(cu.imports, imp => this.visitRightPadded(imp, p));
274
- draft.classes = await mapAsync(cu.classes, cls => this.visitDefined(cls, p) as Promise<J.ClassDeclaration>);
275
- draft.eof = await this.visitSpace(cu.eof, p);
276
- });
314
+ const updates: any = {
315
+ prefix: await this.visitSpace(cu.prefix, p),
316
+ markers: await this.visitMarkers(cu.markers, p),
317
+ packageDeclaration: await this.visitRightPadded(cu.packageDeclaration, p) as J.RightPadded<J.Package>,
318
+ imports: await mapAsync(cu.imports, imp => this.visitRightPadded(imp, p)),
319
+ classes: await mapAsync(cu.classes, cls => this.visitDefined(cls, p) as Promise<J.ClassDeclaration>),
320
+ eof: await this.visitSpace(cu.eof, p)
321
+ };
322
+ return updateIfChanged(cu, updates);
277
323
  }
278
324
 
279
325
  protected async visitContinue(continueStatement: J.Continue, p: P): Promise<J | undefined> {
@@ -283,25 +329,34 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
283
329
  }
284
330
  continueStatement = statement as J.Continue;
285
331
 
286
- return this.produceJava<J.Continue>(continueStatement, p, async draft => {
287
- if (continueStatement.label) {
288
- draft.label = await this.visitDefined(continueStatement.label, p) as J.Identifier;
289
- }
290
- });
332
+ const updates: any = {
333
+ prefix: await this.visitSpace(continueStatement.prefix, p),
334
+ markers: await this.visitMarkers(continueStatement.markers, p)
335
+ };
336
+ if (continueStatement.label) {
337
+ updates.label = await this.visitDefined(continueStatement.label, p) as J.Identifier;
338
+ }
339
+ return updateIfChanged(continueStatement, updates);
291
340
  }
292
341
 
293
342
  protected async visitControlParentheses<T extends J>(controlParens: J.ControlParentheses<T>, p: P): Promise<J | undefined> {
294
- return this.produceJava<J.ControlParentheses<T>>(controlParens, p, async draft => {
295
- (draft.tree as J.RightPadded<J>) = await this.visitRightPadded(controlParens.tree, p);
296
- });
343
+ const updates: any = {
344
+ prefix: await this.visitSpace(controlParens.prefix, p),
345
+ markers: await this.visitMarkers(controlParens.markers, p),
346
+ tree: await this.visitRightPadded(controlParens.tree, p)
347
+ };
348
+ return updateIfChanged(controlParens, updates);
297
349
  }
298
350
 
299
351
  protected async visitDeconstructionPattern(pattern: J.DeconstructionPattern, p: P): Promise<J | undefined> {
300
- return this.produceJava<J.DeconstructionPattern>(pattern, p, async draft => {
301
- draft.deconstructor = await this.visitDefined(pattern.deconstructor, p) as Expression;
302
- draft.nested = await this.visitContainer(pattern.nested, p);
303
- draft.type = await this.visitType(pattern.type, p);
304
- });
352
+ const updates: any = {
353
+ prefix: await this.visitSpace(pattern.prefix, p),
354
+ markers: await this.visitMarkers(pattern.markers, p),
355
+ deconstructor: await this.visitDefined(pattern.deconstructor, p) as Expression,
356
+ nested: await this.visitContainer(pattern.nested, p),
357
+ type: await this.visitType(pattern.type, p)
358
+ };
359
+ return updateIfChanged(pattern, updates);
305
360
  }
306
361
 
307
362
  protected async visitDoWhileLoop(doWhileLoop: J.DoWhileLoop, p: P): Promise<J | undefined> {
@@ -311,10 +366,13 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
311
366
  }
312
367
  doWhileLoop = statement as J.DoWhileLoop;
313
368
 
314
- return this.produceJava<J.DoWhileLoop>(doWhileLoop, p, async draft => {
315
- draft.body = await this.visitRightPadded(doWhileLoop.body, p);
316
- draft.whileCondition = await this.visitLeftPadded(doWhileLoop.whileCondition, p);
317
- });
369
+ const updates: any = {
370
+ prefix: await this.visitSpace(doWhileLoop.prefix, p),
371
+ markers: await this.visitMarkers(doWhileLoop.markers, p),
372
+ body: await this.visitRightPadded(doWhileLoop.body, p),
373
+ whileCondition: await this.visitLeftPadded(doWhileLoop.whileCondition, p)
374
+ };
375
+ return updateIfChanged(doWhileLoop, updates);
318
376
  }
319
377
 
320
378
  protected async visitEmpty(empty: J.Empty, p: P): Promise<J | undefined> {
@@ -330,17 +388,24 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
330
388
  }
331
389
  empty = statement as J.Empty;
332
390
 
333
- return this.produceJava<J.Empty>(empty, p);
391
+ const updates: any = {
392
+ prefix: await this.visitSpace(empty.prefix, p),
393
+ markers: await this.visitMarkers(empty.markers, p)
394
+ };
395
+ return updateIfChanged(empty, updates);
334
396
  }
335
397
 
336
398
  protected async visitEnumValue(enumValue: J.EnumValue, p: P): Promise<J | undefined> {
337
- return this.produceJava<J.EnumValue>(enumValue, p, async draft => {
338
- draft.annotations = await mapAsync(enumValue.annotations, a => this.visitDefined<J.Annotation>(a, p));
339
- draft.name = await this.visitDefined(enumValue.name, p) as J.Identifier;
340
- if (enumValue.initializer) {
341
- draft.initializer = await this.visitDefined(enumValue.initializer, p) as J.NewClass;
342
- }
343
- });
399
+ const updates: any = {
400
+ prefix: await this.visitSpace(enumValue.prefix, p),
401
+ markers: await this.visitMarkers(enumValue.markers, p),
402
+ annotations: await mapAsync(enumValue.annotations, a => this.visitDefined<J.Annotation>(a, p)),
403
+ name: await this.visitDefined(enumValue.name, p) as J.Identifier
404
+ };
405
+ if (enumValue.initializer) {
406
+ updates.initializer = await this.visitDefined(enumValue.initializer, p) as J.NewClass;
407
+ }
408
+ return updateIfChanged(enumValue, updates);
344
409
  }
345
410
 
346
411
  protected async visitEnumValueSet(enumValueSet: J.EnumValueSet, p: P): Promise<J | undefined> {
@@ -350,9 +415,12 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
350
415
  }
351
416
  enumValueSet = statement as J.EnumValueSet;
352
417
 
353
- return this.produceJava<J.EnumValueSet>(enumValueSet, p, async draft => {
354
- draft.enums = await mapAsync(enumValueSet.enums, e => this.visitRightPadded(e, p));
355
- });
418
+ const updates: any = {
419
+ prefix: await this.visitSpace(enumValueSet.prefix, p),
420
+ markers: await this.visitMarkers(enumValueSet.markers, p),
421
+ enums: await mapAsync(enumValueSet.enums, e => this.visitRightPadded(e, p))
422
+ };
423
+ return updateIfChanged(enumValueSet, updates);
356
424
  }
357
425
 
358
426
  protected async visitErroneous(erroneous: J.Erroneous, p: P): Promise<J | undefined> {
@@ -368,7 +436,11 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
368
436
  }
369
437
  erroneous = statement as J.Erroneous;
370
438
 
371
- return this.produceJava<J.Erroneous>(erroneous, p);
439
+ const updates: any = {
440
+ prefix: await this.visitSpace(erroneous.prefix, p),
441
+ markers: await this.visitMarkers(erroneous.markers, p)
442
+ };
443
+ return updateIfChanged(erroneous, updates);
372
444
  }
373
445
 
374
446
  protected async visitFieldAccess(fieldAccess: J.FieldAccess, p: P): Promise<J | undefined> {
@@ -384,11 +456,14 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
384
456
  }
385
457
  fieldAccess = statement as J.FieldAccess;
386
458
 
387
- return this.produceJava<J.FieldAccess>(fieldAccess, p, async draft => {
388
- draft.target = await this.visitDefined(fieldAccess.target, p) as Expression;
389
- draft.name = await this.visitLeftPadded(fieldAccess.name, p);
390
- draft.type = await this.visitType(fieldAccess.type, p);
391
- });
459
+ const updates: any = {
460
+ prefix: await this.visitSpace(fieldAccess.prefix, p),
461
+ markers: await this.visitMarkers(fieldAccess.markers, p),
462
+ target: await this.visitDefined(fieldAccess.target, p) as Expression,
463
+ name: await this.visitLeftPadded(fieldAccess.name, p),
464
+ type: await this.visitType(fieldAccess.type, p)
465
+ };
466
+ return updateIfChanged(fieldAccess, updates);
392
467
  }
393
468
 
394
469
  protected async visitForEachLoop(forLoop: J.ForEachLoop, p: P): Promise<J | undefined> {
@@ -398,17 +473,23 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
398
473
  }
399
474
  forLoop = statement as J.ForEachLoop;
400
475
 
401
- return this.produceJava<J.ForEachLoop>(forLoop, p, async draft => {
402
- draft.control = await this.visitDefined(forLoop.control, p) as J.ForEachLoop.Control;
403
- draft.body = await this.visitRightPadded(forLoop.body, p);
404
- });
476
+ const updates: any = {
477
+ prefix: await this.visitSpace(forLoop.prefix, p),
478
+ markers: await this.visitMarkers(forLoop.markers, p),
479
+ control: await this.visitDefined(forLoop.control, p) as J.ForEachLoop.Control,
480
+ body: await this.visitRightPadded(forLoop.body, p)
481
+ };
482
+ return updateIfChanged(forLoop, updates);
405
483
  }
406
484
 
407
485
  protected async visitForEachLoopControl(control: J.ForEachLoop.Control, p: P): Promise<J | undefined> {
408
- return this.produceJava<J.ForEachLoop.Control>(control, p, async draft => {
409
- draft.variable = await this.visitRightPadded(control.variable, p);
410
- draft.iterable = await this.visitRightPadded(control.iterable, p);
411
- });
486
+ const updates: any = {
487
+ prefix: await this.visitSpace(control.prefix, p),
488
+ markers: await this.visitMarkers(control.markers, p),
489
+ variable: await this.visitRightPadded(control.variable, p),
490
+ iterable: await this.visitRightPadded(control.iterable, p)
491
+ };
492
+ return updateIfChanged(control, updates);
412
493
  }
413
494
 
414
495
  protected async visitForLoop(forLoop: J.ForLoop, p: P): Promise<J | undefined> {
@@ -418,18 +499,24 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
418
499
  }
419
500
  forLoop = statement as J.ForLoop;
420
501
 
421
- return this.produceJava<J.ForLoop>(forLoop, p, async draft => {
422
- draft.control = await this.visitDefined(forLoop.control, p) as J.ForLoop.Control;
423
- draft.body = await this.visitRightPadded(forLoop.body, p);
424
- });
502
+ const updates: any = {
503
+ prefix: await this.visitSpace(forLoop.prefix, p),
504
+ markers: await this.visitMarkers(forLoop.markers, p),
505
+ control: await this.visitDefined(forLoop.control, p) as J.ForLoop.Control,
506
+ body: await this.visitRightPadded(forLoop.body, p)
507
+ };
508
+ return updateIfChanged(forLoop, updates);
425
509
  }
426
510
 
427
511
  protected async visitForLoopControl(control: J.ForLoop.Control, p: P): Promise<J | undefined> {
428
- return this.produceJava<J.ForLoop.Control>(control, p, async draft => {
429
- draft.init = await mapAsync(control.init, i => this.visitRightPadded(i, p));
430
- draft.condition = await this.visitOptionalRightPadded(control.condition, p);
431
- draft.update = await mapAsync(control.update, u => this.visitRightPadded(u, p));
432
- });
512
+ const updates: any = {
513
+ prefix: await this.visitSpace(control.prefix, p),
514
+ markers: await this.visitMarkers(control.markers, p),
515
+ init: await mapAsync(control.init, i => this.visitRightPadded(i, p)),
516
+ condition: await this.visitOptionalRightPadded(control.condition, p),
517
+ update: await mapAsync(control.update, u => this.visitRightPadded(u, p))
518
+ };
519
+ return updateIfChanged(control, updates);
433
520
  }
434
521
 
435
522
  protected async visitIdentifier(ident: J.Identifier, p: P): Promise<J | undefined> {
@@ -439,11 +526,14 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
439
526
  }
440
527
  ident = expression as J.Identifier;
441
528
 
442
- return this.produceJava<J.Identifier>(ident, p, async draft => {
443
- draft.annotations = await mapAsync(ident.annotations, a => this.visitDefined<J.Annotation>(a, p));
444
- draft.type = await this.visitType(ident.type, p);
445
- draft.fieldType = await this.visitType(ident.fieldType, p) as Type.Variable | undefined;
446
- });
529
+ const updates: any = {
530
+ prefix: await this.visitSpace(ident.prefix, p),
531
+ markers: await this.visitMarkers(ident.markers, p),
532
+ annotations: await mapAsync(ident.annotations, a => this.visitDefined<J.Annotation>(a, p)),
533
+ type: await this.visitType(ident.type, p),
534
+ fieldType: await this.visitType(ident.fieldType, p) as Type.Variable | undefined
535
+ };
536
+ return updateIfChanged(ident, updates);
447
537
  }
448
538
 
449
539
  protected async visitIf(iff: J.If, p: P): Promise<J | undefined> {
@@ -453,27 +543,36 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
453
543
  }
454
544
  iff = statement as J.If;
455
545
 
456
- return this.produceJava<J.If>(iff, p, async draft => {
457
- draft.ifCondition = await this.visitDefined(iff.ifCondition, p) as J.ControlParentheses<Expression>;
458
- draft.thenPart = await this.visitRightPadded(iff.thenPart, p);
459
- if (iff.elsePart) {
460
- draft.elsePart = await this.visitDefined(iff.elsePart, p) as J.If.Else;
461
- }
462
- });
546
+ const updates: any = {
547
+ prefix: await this.visitSpace(iff.prefix, p),
548
+ markers: await this.visitMarkers(iff.markers, p),
549
+ ifCondition: await this.visitDefined(iff.ifCondition, p) as J.ControlParentheses<Expression>,
550
+ thenPart: await this.visitRightPadded(iff.thenPart, p)
551
+ };
552
+ if (iff.elsePart) {
553
+ updates.elsePart = await this.visitDefined(iff.elsePart, p) as J.If.Else;
554
+ }
555
+ return updateIfChanged(iff, updates);
463
556
  }
464
557
 
465
558
  protected async visitElse(anElse: J.If.Else, p: P): Promise<J | undefined> {
466
- return this.produceJava<J.If.Else>(anElse, p, async draft => {
467
- draft.body = await this.visitRightPadded(anElse.body, p);
468
- });
559
+ const updates: any = {
560
+ prefix: await this.visitSpace(anElse.prefix, p),
561
+ markers: await this.visitMarkers(anElse.markers, p),
562
+ body: await this.visitRightPadded(anElse.body, p)
563
+ };
564
+ return updateIfChanged(anElse, updates);
469
565
  }
470
566
 
471
567
  protected async visitImport(anImport: J.Import, p: P): Promise<J | undefined> {
472
- return this.produceJava<J.Import>(anImport, p, async draft => {
473
- draft.static = await this.visitLeftPadded(anImport.static, p);
474
- draft.qualid = await this.visitDefined(anImport.qualid, p) as J.FieldAccess;
475
- draft.alias = await this.visitOptionalLeftPadded(anImport.alias, p);
476
- });
568
+ const updates: any = {
569
+ prefix: await this.visitSpace(anImport.prefix, p),
570
+ markers: await this.visitMarkers(anImport.markers, p),
571
+ static: await this.visitLeftPadded(anImport.static, p),
572
+ qualid: await this.visitDefined(anImport.qualid, p) as J.FieldAccess,
573
+ alias: await this.visitOptionalLeftPadded(anImport.alias, p)
574
+ };
575
+ return updateIfChanged(anImport, updates);
477
576
  }
478
577
 
479
578
  protected async visitInstanceOf(instanceOf: J.InstanceOf, p: P): Promise<J | undefined> {
@@ -483,17 +582,20 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
483
582
  }
484
583
  instanceOf = expression as J.InstanceOf;
485
584
 
486
- return this.produceJava<J.InstanceOf>(instanceOf, p, async draft => {
487
- draft.expression = await this.visitRightPadded(instanceOf.expression, p);
488
- draft.class = await this.visitDefined(instanceOf.class, p) as J;
489
- if (instanceOf.pattern) {
490
- draft.pattern = await this.visitDefined(instanceOf.pattern, p) as J;
491
- }
492
- draft.type = await this.visitType(instanceOf.type, p);
493
- if (instanceOf.modifier) {
494
- draft.modifier = await this.visitDefined(instanceOf.modifier, p) as J.Modifier;
495
- }
496
- });
585
+ const updates: any = {
586
+ prefix: await this.visitSpace(instanceOf.prefix, p),
587
+ markers: await this.visitMarkers(instanceOf.markers, p),
588
+ expression: await this.visitRightPadded(instanceOf.expression, p),
589
+ class: await this.visitDefined(instanceOf.class, p) as J,
590
+ type: await this.visitType(instanceOf.type, p)
591
+ };
592
+ if (instanceOf.pattern) {
593
+ updates.pattern = await this.visitDefined(instanceOf.pattern, p) as J;
594
+ }
595
+ if (instanceOf.modifier) {
596
+ updates.modifier = await this.visitDefined(instanceOf.modifier, p) as J.Modifier;
597
+ }
598
+ return updateIfChanged(instanceOf, updates);
497
599
  }
498
600
 
499
601
  protected async visitIntersectionType(intersectionType: J.IntersectionType, p: P): Promise<J | undefined> {
@@ -503,9 +605,12 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
503
605
  }
504
606
  intersectionType = expression as J.IntersectionType;
505
607
 
506
- return this.produceJava<J.IntersectionType>(intersectionType, p, async draft => {
507
- draft.bounds = await this.visitContainer(intersectionType.bounds, p);
508
- });
608
+ const updates: any = {
609
+ prefix: await this.visitSpace(intersectionType.prefix, p),
610
+ markers: await this.visitMarkers(intersectionType.markers, p),
611
+ bounds: await this.visitContainer(intersectionType.bounds, p)
612
+ };
613
+ return updateIfChanged(intersectionType, updates);
509
614
  }
510
615
 
511
616
  protected async visitLabel(label: J.Label, p: P): Promise<J | undefined> {
@@ -515,10 +620,13 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
515
620
  }
516
621
  label = statement as J.Label;
517
622
 
518
- return this.produceJava<J.Label>(label, p, async draft => {
519
- draft.label = await this.visitRightPadded(label.label, p);
520
- draft.statement = await this.visitDefined(label.statement, p) as Statement;
521
- });
623
+ const updates: any = {
624
+ prefix: await this.visitSpace(label.prefix, p),
625
+ markers: await this.visitMarkers(label.markers, p),
626
+ label: await this.visitRightPadded(label.label, p),
627
+ statement: await this.visitDefined(label.statement, p) as Statement
628
+ };
629
+ return updateIfChanged(label, updates);
522
630
  }
523
631
 
524
632
  protected async visitLambda(lambda: J.Lambda, p: P): Promise<J | undefined> {
@@ -534,18 +642,24 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
534
642
  }
535
643
  lambda = statement as J.Lambda;
536
644
 
537
- return this.produceJava<J.Lambda>(lambda, p, async draft => {
538
- draft.parameters = await this.visitDefined(lambda.parameters, p) as J.Lambda.Parameters;
539
- draft.arrow = await this.visitSpace(lambda.arrow, p);
540
- draft.body = await this.visitDefined(lambda.body, p) as Statement | Expression;
541
- draft.type = await this.visitType(lambda.type, p);
542
- });
645
+ const updates: any = {
646
+ prefix: await this.visitSpace(lambda.prefix, p),
647
+ markers: await this.visitMarkers(lambda.markers, p),
648
+ parameters: await this.visitDefined(lambda.parameters, p) as J.Lambda.Parameters,
649
+ arrow: await this.visitSpace(lambda.arrow, p),
650
+ body: await this.visitDefined(lambda.body, p) as Statement | Expression,
651
+ type: await this.visitType(lambda.type, p)
652
+ };
653
+ return updateIfChanged(lambda, updates);
543
654
  }
544
655
 
545
656
  protected async visitLambdaParameters(params: J.Lambda.Parameters, p: P): Promise<J | undefined> {
546
- return this.produceJava<J.Lambda.Parameters>(params, p, async draft => {
547
- draft.parameters = await mapAsync(params.parameters, param => this.visitRightPadded(param, p));
548
- });
657
+ const updates: any = {
658
+ prefix: await this.visitSpace(params.prefix, p),
659
+ markers: await this.visitMarkers(params.markers, p),
660
+ parameters: await mapAsync(params.parameters, param => this.visitRightPadded(param, p))
661
+ };
662
+ return updateIfChanged(params, updates);
549
663
  }
550
664
 
551
665
  protected async visitLiteral(literal: J.Literal, p: P): Promise<J | undefined> {
@@ -555,9 +669,12 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
555
669
  }
556
670
  literal = expression as J.Literal;
557
671
 
558
- return this.produceJava<J.Literal>(literal, p, async draft => {
559
- draft.type = await this.visitType(literal.type, p) as Type.Primitive | undefined;
560
- });
672
+ const updates: any = {
673
+ prefix: await this.visitSpace(literal.prefix, p),
674
+ markers: await this.visitMarkers(literal.markers, p),
675
+ type: await this.visitType(literal.type, p) as Type.Primitive | undefined
676
+ };
677
+ return updateIfChanged(literal, updates);
561
678
  }
562
679
 
563
680
  protected async visitMemberReference(memberRef: J.MemberReference, p: P): Promise<J | undefined> {
@@ -567,14 +684,17 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
567
684
  }
568
685
  memberRef = expression as J.MemberReference;
569
686
 
570
- return this.produceJava<J.MemberReference>(memberRef, p, async draft => {
571
- draft.containing = await this.visitRightPadded(memberRef.containing, p);
572
- draft.typeParameters = await this.visitOptionalContainer(memberRef.typeParameters, p);
573
- draft.reference = await this.visitLeftPadded(memberRef.reference, p);
574
- draft.type = await this.visitType(memberRef.type, p);
575
- draft.methodType = await this.visitType(memberRef.methodType, p) as Type.Method | undefined;
576
- draft.variableType = await this.visitType(memberRef.variableType, p) as Type.Variable | undefined;
577
- });
687
+ const updates: any = {
688
+ prefix: await this.visitSpace(memberRef.prefix, p),
689
+ markers: await this.visitMarkers(memberRef.markers, p),
690
+ containing: await this.visitRightPadded(memberRef.containing, p),
691
+ typeParameters: await this.visitOptionalContainer(memberRef.typeParameters, p),
692
+ reference: await this.visitLeftPadded(memberRef.reference, p),
693
+ type: await this.visitType(memberRef.type, p),
694
+ methodType: await this.visitType(memberRef.methodType, p) as Type.Method | undefined,
695
+ variableType: await this.visitType(memberRef.variableType, p) as Type.Variable | undefined
696
+ };
697
+ return updateIfChanged(memberRef, updates);
578
698
  }
579
699
 
580
700
  protected async visitMethodDeclaration(method: J.MethodDeclaration, p: P): Promise<J | undefined> {
@@ -584,26 +704,26 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
584
704
  }
585
705
  method = statement as J.MethodDeclaration;
586
706
 
587
- return this.produceJava<J.MethodDeclaration>(method, p, async draft => {
588
- draft.leadingAnnotations = await mapAsync(method.leadingAnnotations, a => this.visitDefined<J.Annotation>(a, p));
589
- draft.modifiers = await mapAsync(method.modifiers, m => this.visitDefined<J.Modifier>(m, p));
590
-
591
- if (method.typeParameters) {
592
- draft.typeParameters = await this.visitDefined(method.typeParameters, p) as J.TypeParameters;
593
- }
594
-
595
- if (method.returnTypeExpression) {
596
- draft.returnTypeExpression = await this.visitDefined(method.returnTypeExpression, p) as TypedTree;
597
- }
598
-
599
- draft.nameAnnotations = await mapAsync(method.nameAnnotations, a => this.visitDefined<J.Annotation>(a, p));
600
- draft.name = await this.visitDefined(method.name, p);
601
- draft.parameters = await this.visitContainer(method.parameters, p);
602
- draft.throws = method.throws && await this.visitContainer(method.throws, p);
603
- draft.body = method.body && await this.visitDefined(method.body, p) as J.Block;
604
- draft.defaultValue = await this.visitOptionalLeftPadded(method.defaultValue, p);
605
- draft.methodType = await this.visitType(method.methodType, p) as Type.Method | undefined;
606
- });
707
+ const updates: any = {
708
+ prefix: await this.visitSpace(method.prefix, p),
709
+ markers: await this.visitMarkers(method.markers, p),
710
+ leadingAnnotations: await mapAsync(method.leadingAnnotations, a => this.visitDefined<J.Annotation>(a, p)),
711
+ modifiers: await mapAsync(method.modifiers, m => this.visitDefined<J.Modifier>(m, p)),
712
+ nameAnnotations: await mapAsync(method.nameAnnotations, a => this.visitDefined<J.Annotation>(a, p)),
713
+ name: await this.visitDefined(method.name, p),
714
+ parameters: await this.visitContainer(method.parameters, p),
715
+ throws: method.throws && await this.visitContainer(method.throws, p),
716
+ body: method.body && await this.visitDefined(method.body, p) as J.Block,
717
+ defaultValue: await this.visitOptionalLeftPadded(method.defaultValue, p),
718
+ methodType: await this.visitType(method.methodType, p) as Type.Method | undefined
719
+ };
720
+ if (method.typeParameters) {
721
+ updates.typeParameters = await this.visitDefined(method.typeParameters, p) as J.TypeParameters;
722
+ }
723
+ if (method.returnTypeExpression) {
724
+ updates.returnTypeExpression = await this.visitDefined(method.returnTypeExpression, p) as TypedTree;
725
+ }
726
+ return updateIfChanged(method, updates);
607
727
  }
608
728
 
609
729
  protected async visitMethodInvocation(method: J.MethodInvocation, p: P): Promise<J | undefined> {
@@ -619,25 +739,34 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
619
739
  }
620
740
  method = statement as J.MethodInvocation;
621
741
 
622
- return this.produceJava<J.MethodInvocation>(method, p, async draft => {
623
- draft.select = await this.visitOptionalRightPadded(method.select, p);
624
- draft.typeParameters = await this.visitOptionalContainer(method.typeParameters, p);
625
- draft.name = await this.visitDefined(method.name, p) as J.Identifier;
626
- draft.arguments = await this.visitContainer(method.arguments, p);
627
- draft.methodType = await this.visitType(method.methodType, p) as Type.Method | undefined;
628
- });
742
+ const updates: any = {
743
+ prefix: await this.visitSpace(method.prefix, p),
744
+ markers: await this.visitMarkers(method.markers, p),
745
+ select: await this.visitOptionalRightPadded(method.select, p),
746
+ typeParameters: await this.visitOptionalContainer(method.typeParameters, p),
747
+ name: await this.visitDefined(method.name, p) as J.Identifier,
748
+ arguments: await this.visitContainer(method.arguments, p),
749
+ methodType: await this.visitType(method.methodType, p) as Type.Method | undefined
750
+ };
751
+ return updateIfChanged(method, updates);
629
752
  }
630
753
 
631
754
  protected async visitModifier(modifier: J.Modifier, p: P): Promise<J | undefined> {
632
- return this.produceJava<J.Modifier>(modifier, p, async draft => {
633
- draft.annotations = await mapAsync(modifier.annotations, a => this.visitDefined<J.Annotation>(a, p));
634
- });
755
+ const updates: any = {
756
+ prefix: await this.visitSpace(modifier.prefix, p),
757
+ markers: await this.visitMarkers(modifier.markers, p),
758
+ annotations: await mapAsync(modifier.annotations, a => this.visitDefined<J.Annotation>(a, p))
759
+ };
760
+ return updateIfChanged(modifier, updates);
635
761
  }
636
762
 
637
763
  protected async visitMultiCatch(multiCatch: J.MultiCatch, p: P): Promise<J | undefined> {
638
- return this.produceJava<J.MultiCatch>(multiCatch, p, async draft => {
639
- draft.alternatives = await mapAsync(multiCatch.alternatives, alt => this.visitRightPadded(alt, p));
640
- });
764
+ const updates: any = {
765
+ prefix: await this.visitSpace(multiCatch.prefix, p),
766
+ markers: await this.visitMarkers(multiCatch.markers, p),
767
+ alternatives: await mapAsync(multiCatch.alternatives, alt => this.visitRightPadded(alt, p))
768
+ };
769
+ return updateIfChanged(multiCatch, updates);
641
770
  }
642
771
 
643
772
  protected async visitNewArray(newArray: J.NewArray, p: P): Promise<J | undefined> {
@@ -647,17 +776,17 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
647
776
  }
648
777
  newArray = expression as J.NewArray;
649
778
 
650
- return this.produceJava<J.NewArray>(newArray, p, async draft => {
651
- if (newArray.typeExpression) {
652
- draft.typeExpression = await this.visitDefined(newArray.typeExpression, p) as TypedTree;
653
- }
654
-
655
- draft.dimensions = await mapAsync(newArray.dimensions, dim =>
656
- this.visitDefined<J.ArrayDimension>(dim, p));
657
-
658
- draft.initializer = await this.visitOptionalContainer(newArray.initializer, p);
659
- draft.type = await this.visitType(newArray.type, p);
660
- });
779
+ const updates: any = {
780
+ prefix: await this.visitSpace(newArray.prefix, p),
781
+ markers: await this.visitMarkers(newArray.markers, p),
782
+ dimensions: await mapAsync(newArray.dimensions, dim => this.visitDefined<J.ArrayDimension>(dim, p)),
783
+ initializer: await this.visitOptionalContainer(newArray.initializer, p),
784
+ type: await this.visitType(newArray.type, p)
785
+ };
786
+ if (newArray.typeExpression) {
787
+ updates.typeExpression = await this.visitDefined(newArray.typeExpression, p) as TypedTree;
788
+ }
789
+ return updateIfChanged(newArray, updates);
661
790
  }
662
791
 
663
792
  protected async visitNewClass(newClass: J.NewClass, p: P): Promise<J | undefined> {
@@ -667,25 +796,23 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
667
796
  }
668
797
  newClass = expression as J.NewClass;
669
798
 
670
- return this.produceJava<J.NewClass>(newClass, p, async draft => {
671
- if (newClass.enclosing) {
672
- draft.enclosing = await this.visitRightPadded(newClass.enclosing, p);
673
- }
674
-
675
- draft.new = await this.visitSpace(newClass.new, p);
676
-
677
- if (newClass.class) {
678
- draft.class = await this.visitDefined(newClass.class, p) as TypedTree;
679
- }
680
-
681
- draft.arguments = await this.visitContainer(newClass.arguments, p);
682
-
683
- if (newClass.body) {
684
- draft.body = await this.visitDefined(newClass.body, p) as J.Block;
685
- }
686
-
687
- draft.constructorType = await this.visitType(newClass.constructorType, p) as Type.Method | undefined;
688
- });
799
+ const updates: any = {
800
+ prefix: await this.visitSpace(newClass.prefix, p),
801
+ markers: await this.visitMarkers(newClass.markers, p),
802
+ new: await this.visitSpace(newClass.new, p),
803
+ arguments: await this.visitContainer(newClass.arguments, p),
804
+ constructorType: await this.visitType(newClass.constructorType, p) as Type.Method | undefined
805
+ };
806
+ if (newClass.enclosing) {
807
+ updates.enclosing = await this.visitRightPadded(newClass.enclosing, p);
808
+ }
809
+ if (newClass.class) {
810
+ updates.class = await this.visitDefined(newClass.class, p) as TypedTree;
811
+ }
812
+ if (newClass.body) {
813
+ updates.body = await this.visitDefined(newClass.body, p) as J.Block;
814
+ }
815
+ return updateIfChanged(newClass, updates);
689
816
  }
690
817
 
691
818
  protected async visitNullableType(nullableType: J.NullableType, p: P): Promise<J | undefined> {
@@ -695,33 +822,45 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
695
822
  }
696
823
  nullableType = expression as J.NullableType;
697
824
 
698
- return this.produceJava<J.NullableType>(nullableType, p, async draft => {
699
- draft.annotations = await mapAsync(nullableType.annotations, a => this.visitDefined<J.Annotation>(a, p));
700
- draft.typeTree = await this.visitRightPadded(nullableType.typeTree, p);
701
- });
825
+ const updates: any = {
826
+ prefix: await this.visitSpace(nullableType.prefix, p),
827
+ markers: await this.visitMarkers(nullableType.markers, p),
828
+ annotations: await mapAsync(nullableType.annotations, a => this.visitDefined<J.Annotation>(a, p)),
829
+ typeTree: await this.visitRightPadded(nullableType.typeTree, p)
830
+ };
831
+ return updateIfChanged(nullableType, updates);
702
832
  }
703
833
 
704
834
  protected async visitPackage(aPackage: J.Package, p: P): Promise<J | undefined> {
705
- return this.produceJava<J.Package>(aPackage, p, async draft => {
706
- draft.expression = await this.visitDefined(aPackage.expression, p) as Expression;
707
- if (aPackage.annotations) {
708
- draft.annotations = await mapAsync(aPackage.annotations, a => this.visitDefined<J.Annotation>(a, p));
709
- }
710
- });
835
+ const updates: any = {
836
+ prefix: await this.visitSpace(aPackage.prefix, p),
837
+ markers: await this.visitMarkers(aPackage.markers, p),
838
+ expression: await this.visitDefined(aPackage.expression, p) as Expression
839
+ };
840
+ if (aPackage.annotations) {
841
+ updates.annotations = await mapAsync(aPackage.annotations, a => this.visitDefined<J.Annotation>(a, p));
842
+ }
843
+ return updateIfChanged(aPackage, updates);
711
844
  }
712
845
 
713
846
  protected async visitParameterizedType(parameterizedType: J.ParameterizedType, p: P): Promise<J | undefined> {
714
- return this.produceJava<J.ParameterizedType>(parameterizedType, p, async draft => {
715
- draft.class = await this.visitTypeName(parameterizedType.class, p);
716
- draft.typeParameters = await this.visitOptionalContainer(parameterizedType.typeParameters, p);
717
- draft.type = await this.visitType(parameterizedType.type, p);
718
- });
847
+ const updates: any = {
848
+ prefix: await this.visitSpace(parameterizedType.prefix, p),
849
+ markers: await this.visitMarkers(parameterizedType.markers, p),
850
+ class: await this.visitTypeName(parameterizedType.class, p),
851
+ typeParameters: await this.visitOptionalContainer(parameterizedType.typeParameters, p),
852
+ type: await this.visitType(parameterizedType.type, p)
853
+ };
854
+ return updateIfChanged(parameterizedType, updates);
719
855
  }
720
856
 
721
857
  protected async visitParentheses<T extends J>(parentheses: J.Parentheses<T>, p: P): Promise<J | undefined> {
722
- return this.produceJava<J.Parentheses<T>>(parentheses, p, async draft => {
723
- (draft.tree as J.RightPadded<J>) = await this.visitRightPadded(parentheses.tree, p);
724
- });
858
+ const updates: any = {
859
+ prefix: await this.visitSpace(parentheses.prefix, p),
860
+ markers: await this.visitMarkers(parentheses.markers, p),
861
+ tree: await this.visitRightPadded(parentheses.tree, p)
862
+ };
863
+ return updateIfChanged(parentheses, updates);
725
864
  }
726
865
 
727
866
  protected async visitParenthesizedTypeTree(parTypeTree: J.ParenthesizedTypeTree, p: P): Promise<J | undefined> {
@@ -731,10 +870,13 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
731
870
  }
732
871
  parTypeTree = expression as J.ParenthesizedTypeTree;
733
872
 
734
- return this.produceJava<J.ParenthesizedTypeTree>(parTypeTree, p, async draft => {
735
- draft.annotations = await mapAsync(parTypeTree.annotations, a => this.visitDefined<J.Annotation>(a, p));
736
- draft.parenthesizedType = await this.visitDefined(parTypeTree.parenthesizedType, p) as J.Parentheses<TypeTree>;
737
- });
873
+ const updates: any = {
874
+ prefix: await this.visitSpace(parTypeTree.prefix, p),
875
+ markers: await this.visitMarkers(parTypeTree.markers, p),
876
+ annotations: await mapAsync(parTypeTree.annotations, a => this.visitDefined<J.Annotation>(a, p)),
877
+ parenthesizedType: await this.visitDefined(parTypeTree.parenthesizedType, p) as J.Parentheses<TypeTree>
878
+ };
879
+ return updateIfChanged(parTypeTree, updates);
738
880
  }
739
881
 
740
882
  protected async visitPrimitive(primitive: J.Primitive, p: P): Promise<J | undefined> {
@@ -744,9 +886,12 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
744
886
  }
745
887
  primitive = expression as J.Primitive;
746
888
 
747
- return this.produceJava<J.Primitive>(primitive, p, async draft => {
748
- draft.type = await this.visitType(primitive.type, p) as Type.Primitive;
749
- });
889
+ const updates: any = {
890
+ prefix: await this.visitSpace(primitive.prefix, p),
891
+ markers: await this.visitMarkers(primitive.markers, p),
892
+ type: await this.visitType(primitive.type, p) as Type.Primitive
893
+ };
894
+ return updateIfChanged(primitive, updates);
750
895
  }
751
896
 
752
897
  protected async visitReturn(ret: J.Return, p: P): Promise<J | undefined> {
@@ -756,11 +901,14 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
756
901
  }
757
902
  ret = statement as J.Return;
758
903
 
759
- return this.produceJava<J.Return>(ret, p, async draft => {
760
- if (ret.expression) {
761
- draft.expression = await this.visitDefined(ret.expression, p) as Expression;
762
- }
763
- });
904
+ const updates: any = {
905
+ prefix: await this.visitSpace(ret.prefix, p),
906
+ markers: await this.visitMarkers(ret.markers, p)
907
+ };
908
+ if (ret.expression) {
909
+ updates.expression = await this.visitDefined(ret.expression, p) as Expression;
910
+ }
911
+ return updateIfChanged(ret, updates);
764
912
  }
765
913
 
766
914
  protected async visitSwitch(aSwitch: J.Switch, p: P): Promise<J | undefined> {
@@ -770,10 +918,13 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
770
918
  }
771
919
  aSwitch = statement as J.Switch;
772
920
 
773
- return this.produceJava<J.Switch>(aSwitch, p, async draft => {
774
- draft.selector = await this.visitDefined(aSwitch.selector, p) as J.ControlParentheses<Expression>;
775
- draft.cases = await this.visitDefined(aSwitch.cases, p) as J.Block;
776
- });
921
+ const updates: any = {
922
+ prefix: await this.visitSpace(aSwitch.prefix, p),
923
+ markers: await this.visitMarkers(aSwitch.markers, p),
924
+ selector: await this.visitDefined(aSwitch.selector, p) as J.ControlParentheses<Expression>,
925
+ cases: await this.visitDefined(aSwitch.cases, p) as J.Block
926
+ };
927
+ return updateIfChanged(aSwitch, updates);
777
928
  }
778
929
 
779
930
  protected async visitSwitchExpression(switchExpr: J.SwitchExpression, p: P): Promise<J | undefined> {
@@ -783,11 +934,14 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
783
934
  }
784
935
  switchExpr = expression as J.SwitchExpression;
785
936
 
786
- return this.produceJava<J.SwitchExpression>(switchExpr, p, async draft => {
787
- draft.selector = await this.visitDefined(switchExpr.selector, p) as J.ControlParentheses<Expression>;
788
- draft.cases = await this.visitDefined(switchExpr.cases, p) as J.Block;
789
- draft.type = await this.visitType(switchExpr.type, p);
790
- });
937
+ const updates: any = {
938
+ prefix: await this.visitSpace(switchExpr.prefix, p),
939
+ markers: await this.visitMarkers(switchExpr.markers, p),
940
+ selector: await this.visitDefined(switchExpr.selector, p) as J.ControlParentheses<Expression>,
941
+ cases: await this.visitDefined(switchExpr.cases, p) as J.Block,
942
+ type: await this.visitType(switchExpr.type, p)
943
+ };
944
+ return updateIfChanged(switchExpr, updates);
791
945
  }
792
946
 
793
947
  protected async visitSynchronized(sync: J.Synchronized, p: P): Promise<J | undefined> {
@@ -797,10 +951,13 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
797
951
  }
798
952
  sync = statement as J.Synchronized;
799
953
 
800
- return this.produceJava<J.Synchronized>(sync, p, async draft => {
801
- draft.lock = await this.visitDefined(sync.lock, p) as J.ControlParentheses<Expression>;
802
- draft.body = await this.visitDefined(sync.body, p) as J.Block;
803
- });
954
+ const updates: any = {
955
+ prefix: await this.visitSpace(sync.prefix, p),
956
+ markers: await this.visitMarkers(sync.markers, p),
957
+ lock: await this.visitDefined(sync.lock, p) as J.ControlParentheses<Expression>,
958
+ body: await this.visitDefined(sync.body, p) as J.Block
959
+ };
960
+ return updateIfChanged(sync, updates);
804
961
  }
805
962
 
806
963
  protected async visitTernary(ternary: J.Ternary, p: P): Promise<J | undefined> {
@@ -816,12 +973,15 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
816
973
  }
817
974
  ternary = statement as J.Ternary;
818
975
 
819
- return this.produceJava<J.Ternary>(ternary, p, async draft => {
820
- draft.condition = await this.visitDefined(ternary.condition, p) as Expression;
821
- draft.truePart = await this.visitLeftPadded(ternary.truePart, p);
822
- draft.falsePart = await this.visitLeftPadded(ternary.falsePart, p);
823
- draft.type = await this.visitType(ternary.type, p);
824
- });
976
+ const updates: any = {
977
+ prefix: await this.visitSpace(ternary.prefix, p),
978
+ markers: await this.visitMarkers(ternary.markers, p),
979
+ condition: await this.visitDefined(ternary.condition, p) as Expression,
980
+ truePart: await this.visitLeftPadded(ternary.truePart, p),
981
+ falsePart: await this.visitLeftPadded(ternary.falsePart, p),
982
+ type: await this.visitType(ternary.type, p)
983
+ };
984
+ return updateIfChanged(ternary, updates);
825
985
  }
826
986
 
827
987
  protected async visitThrow(thrown: J.Throw, p: P): Promise<J | undefined> {
@@ -831,9 +991,12 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
831
991
  }
832
992
  thrown = statement as J.Throw;
833
993
 
834
- return this.produceJava<J.Throw>(thrown, p, async draft => {
835
- draft.exception = await this.visitDefined(thrown.exception, p) as Expression;
836
- });
994
+ const updates: any = {
995
+ prefix: await this.visitSpace(thrown.prefix, p),
996
+ markers: await this.visitMarkers(thrown.markers, p),
997
+ exception: await this.visitDefined(thrown.exception, p) as Expression
998
+ };
999
+ return updateIfChanged(thrown, updates);
837
1000
  }
838
1001
 
839
1002
  protected async visitTry(tryable: J.Try, p: P): Promise<J | undefined> {
@@ -843,25 +1006,34 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
843
1006
  }
844
1007
  tryable = statement as J.Try;
845
1008
 
846
- return this.produceJava<J.Try>(tryable, p, async draft => {
847
- draft.resources = await this.visitOptionalContainer(tryable.resources, p);
848
- draft.body = await this.visitDefined(tryable.body, p) as J.Block;
849
- draft.catches = await mapAsync(tryable.catches, c => this.visitDefined<J.Try.Catch>(c, p));
850
- draft.finally = await this.visitOptionalLeftPadded(tryable.finally, p);
851
- });
1009
+ const updates: any = {
1010
+ prefix: await this.visitSpace(tryable.prefix, p),
1011
+ markers: await this.visitMarkers(tryable.markers, p),
1012
+ resources: await this.visitOptionalContainer(tryable.resources, p),
1013
+ body: await this.visitDefined(tryable.body, p) as J.Block,
1014
+ catches: await mapAsync(tryable.catches, c => this.visitDefined<J.Try.Catch>(c, p)),
1015
+ finally: await this.visitOptionalLeftPadded(tryable.finally, p)
1016
+ };
1017
+ return updateIfChanged(tryable, updates);
852
1018
  }
853
1019
 
854
1020
  protected async visitTryResource(resource: J.Try.Resource, p: P): Promise<J | undefined> {
855
- return this.produceJava<J.Try.Resource>(resource, p, async draft => {
856
- draft.variableDeclarations = await this.visitDefined(resource.variableDeclarations, p) as TypedTree;
857
- });
1021
+ const updates: any = {
1022
+ prefix: await this.visitSpace(resource.prefix, p),
1023
+ markers: await this.visitMarkers(resource.markers, p),
1024
+ variableDeclarations: await this.visitDefined(resource.variableDeclarations, p) as TypedTree
1025
+ };
1026
+ return updateIfChanged(resource, updates);
858
1027
  }
859
1028
 
860
1029
  protected async visitTryCatch(tryCatch: J.Try.Catch, p: P): Promise<J | undefined> {
861
- return this.produceJava<J.Try.Catch>(tryCatch, p, async draft => {
862
- draft.parameter = await this.visitDefined(tryCatch.parameter, p) as J.ControlParentheses<J.VariableDeclarations>;
863
- draft.body = await this.visitDefined(tryCatch.body, p) as J.Block;
864
- });
1030
+ const updates: any = {
1031
+ prefix: await this.visitSpace(tryCatch.prefix, p),
1032
+ markers: await this.visitMarkers(tryCatch.markers, p),
1033
+ parameter: await this.visitDefined(tryCatch.parameter, p) as J.ControlParentheses<J.VariableDeclarations>,
1034
+ body: await this.visitDefined(tryCatch.body, p) as J.Block
1035
+ };
1036
+ return updateIfChanged(tryCatch, updates);
865
1037
  }
866
1038
 
867
1039
  protected async visitTypeCast(typeCast: J.TypeCast, p: P): Promise<J | undefined> {
@@ -871,26 +1043,35 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
871
1043
  }
872
1044
  typeCast = expression as J.TypeCast;
873
1045
 
874
- return this.produceJava<J.TypeCast>(typeCast, p, async draft => {
875
- draft.class = await this.visitDefined(typeCast.class, p) as J.ControlParentheses<TypedTree>;
876
- draft.expression = await this.visitDefined(typeCast.expression, p) as Expression;
877
- });
1046
+ const updates: any = {
1047
+ prefix: await this.visitSpace(typeCast.prefix, p),
1048
+ markers: await this.visitMarkers(typeCast.markers, p),
1049
+ class: await this.visitDefined(typeCast.class, p) as J.ControlParentheses<TypedTree>,
1050
+ expression: await this.visitDefined(typeCast.expression, p) as Expression
1051
+ };
1052
+ return updateIfChanged(typeCast, updates);
878
1053
  }
879
1054
 
880
1055
  protected async visitTypeParameter(typeParam: J.TypeParameter, p: P): Promise<J | undefined> {
881
- return this.produceJava<J.TypeParameter>(typeParam, p, async draft => {
882
- draft.annotations = await mapAsync(typeParam.annotations, a => this.visitDefined<J.Annotation>(a, p));
883
- draft.modifiers = await mapAsync(typeParam.modifiers, m => this.visitDefined<J.Modifier>(m, p));
884
- draft.name = await this.visitDefined(typeParam.name, p) as J.Identifier;
885
- draft.bounds = await this.visitOptionalContainer(typeParam.bounds, p);
886
- });
1056
+ const updates: any = {
1057
+ prefix: await this.visitSpace(typeParam.prefix, p),
1058
+ markers: await this.visitMarkers(typeParam.markers, p),
1059
+ annotations: await mapAsync(typeParam.annotations, a => this.visitDefined<J.Annotation>(a, p)),
1060
+ modifiers: await mapAsync(typeParam.modifiers, m => this.visitDefined<J.Modifier>(m, p)),
1061
+ name: await this.visitDefined(typeParam.name, p) as J.Identifier,
1062
+ bounds: await this.visitOptionalContainer(typeParam.bounds, p)
1063
+ };
1064
+ return updateIfChanged(typeParam, updates);
887
1065
  }
888
1066
 
889
1067
  protected async visitTypeParameters(typeParams: J.TypeParameters, p: P): Promise<J | undefined> {
890
- return this.produceJava<J.TypeParameters>(typeParams, p, async draft => {
891
- draft.annotations = await mapAsync(typeParams.annotations, a => this.visitDefined<J.Annotation>(a, p));
892
- draft.typeParameters = await mapAsync(typeParams.typeParameters, tp => this.visitRightPadded(tp, p));
893
- });
1068
+ const updates: any = {
1069
+ prefix: await this.visitSpace(typeParams.prefix, p),
1070
+ markers: await this.visitMarkers(typeParams.markers, p),
1071
+ annotations: await mapAsync(typeParams.annotations, a => this.visitDefined<J.Annotation>(a, p)),
1072
+ typeParameters: await mapAsync(typeParams.typeParameters, tp => this.visitRightPadded(tp, p))
1073
+ };
1074
+ return updateIfChanged(typeParams, updates);
894
1075
  }
895
1076
 
896
1077
  protected async visitUnary(unary: J.Unary, p: P): Promise<J | undefined> {
@@ -906,11 +1087,14 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
906
1087
  }
907
1088
  unary = statement as J.Unary;
908
1089
 
909
- return this.produceJava<J.Unary>(unary, p, async draft => {
910
- draft.operator = await this.visitLeftPadded(unary.operator, p);
911
- draft.expression = await this.visitDefined(unary.expression, p) as Expression;
912
- draft.type = await this.visitType(unary.type, p);
913
- });
1090
+ const updates: any = {
1091
+ prefix: await this.visitSpace(unary.prefix, p),
1092
+ markers: await this.visitMarkers(unary.markers, p),
1093
+ operator: await this.visitLeftPadded(unary.operator, p),
1094
+ expression: await this.visitDefined(unary.expression, p) as Expression,
1095
+ type: await this.visitType(unary.type, p)
1096
+ };
1097
+ return updateIfChanged(unary, updates);
914
1098
  }
915
1099
 
916
1100
  protected async visitUnknown(unknown: J.Unknown, p: P): Promise<J | undefined> {
@@ -926,13 +1110,20 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
926
1110
  }
927
1111
  unknown = statement as J.Unknown;
928
1112
 
929
- return this.produceJava<J.Unknown>(unknown, p, async draft => {
930
- draft.source = await this.visitDefined(unknown.source, p) as J.UnknownSource;
931
- });
1113
+ const updates: any = {
1114
+ prefix: await this.visitSpace(unknown.prefix, p),
1115
+ markers: await this.visitMarkers(unknown.markers, p),
1116
+ source: await this.visitDefined(unknown.source, p) as J.UnknownSource
1117
+ };
1118
+ return updateIfChanged(unknown, updates);
932
1119
  }
933
1120
 
934
1121
  protected async visitUnknownSource(source: J.UnknownSource, p: P): Promise<J | undefined> {
935
- return this.produceJava<J.UnknownSource>(source, p);
1122
+ const updates: any = {
1123
+ prefix: await this.visitSpace(source.prefix, p),
1124
+ markers: await this.visitMarkers(source.markers, p)
1125
+ };
1126
+ return updateIfChanged(source, updates);
936
1127
  }
937
1128
 
938
1129
  protected async visitVariableDeclarations(varDecls: J.VariableDeclarations, p: P): Promise<J | undefined> {
@@ -942,29 +1133,32 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
942
1133
  }
943
1134
  varDecls = statement as J.VariableDeclarations;
944
1135
 
945
- return this.produceJava<J.VariableDeclarations>(varDecls, p, async draft => {
946
- draft.leadingAnnotations = await mapAsync(varDecls.leadingAnnotations, a => this.visitDefined<J.Annotation>(a, p));
947
- draft.modifiers = await mapAsync(varDecls.modifiers, m => this.visitDefined<J.Modifier>(m, p));
948
-
949
- if (varDecls.typeExpression) {
950
- draft.typeExpression = await this.visitDefined(varDecls.typeExpression, p) as TypedTree;
951
- }
952
-
953
- if (varDecls.varargs) {
954
- draft.varargs = await this.visitSpace(varDecls.varargs, p);
955
- }
956
-
957
- draft.variables = await mapAsync(varDecls.variables, v => this.visitRightPadded(v, p));
958
- });
1136
+ const updates: any = {
1137
+ prefix: await this.visitSpace(varDecls.prefix, p),
1138
+ markers: await this.visitMarkers(varDecls.markers, p),
1139
+ leadingAnnotations: await mapAsync(varDecls.leadingAnnotations, a => this.visitDefined<J.Annotation>(a, p)),
1140
+ modifiers: await mapAsync(varDecls.modifiers, m => this.visitDefined<J.Modifier>(m, p)),
1141
+ variables: await mapAsync(varDecls.variables, v => this.visitRightPadded(v, p))
1142
+ };
1143
+ if (varDecls.typeExpression) {
1144
+ updates.typeExpression = await this.visitDefined(varDecls.typeExpression, p) as TypedTree;
1145
+ }
1146
+ if (varDecls.varargs) {
1147
+ updates.varargs = await this.visitSpace(varDecls.varargs, p);
1148
+ }
1149
+ return updateIfChanged(varDecls, updates);
959
1150
  }
960
1151
 
961
1152
  protected async visitVariable(variable: J.VariableDeclarations.NamedVariable, p: P): Promise<J | undefined> {
962
- return this.produceJava<J.VariableDeclarations.NamedVariable>(variable, p, async draft => {
963
- draft.name = await this.visitDefined(variable.name, p) as J.Identifier;
964
- draft.dimensionsAfterName = await mapAsync(variable.dimensionsAfterName, dim => this.visitLeftPadded(dim, p));
965
- draft.initializer = await this.visitOptionalLeftPadded(variable.initializer, p);
966
- draft.variableType = await this.visitType(variable.variableType, p) as Type.Variable | undefined;
967
- });
1153
+ const updates: any = {
1154
+ prefix: await this.visitSpace(variable.prefix, p),
1155
+ markers: await this.visitMarkers(variable.markers, p),
1156
+ name: await this.visitDefined(variable.name, p) as J.Identifier,
1157
+ dimensionsAfterName: await mapAsync(variable.dimensionsAfterName, dim => this.visitLeftPadded(dim, p)),
1158
+ initializer: await this.visitOptionalLeftPadded(variable.initializer, p),
1159
+ variableType: await this.visitType(variable.variableType, p) as Type.Variable | undefined
1160
+ };
1161
+ return updateIfChanged(variable, updates);
968
1162
  }
969
1163
 
970
1164
  protected async visitWhileLoop(whileLoop: J.WhileLoop, p: P): Promise<J | undefined> {
@@ -974,10 +1168,13 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
974
1168
  }
975
1169
  whileLoop = statement as J.WhileLoop;
976
1170
 
977
- return this.produceJava<J.WhileLoop>(whileLoop, p, async draft => {
978
- draft.condition = await this.visitDefined(whileLoop.condition, p) as J.ControlParentheses<Expression>;
979
- draft.body = await this.visitRightPadded(whileLoop.body, p);
980
- });
1171
+ const updates: any = {
1172
+ prefix: await this.visitSpace(whileLoop.prefix, p),
1173
+ markers: await this.visitMarkers(whileLoop.markers, p),
1174
+ condition: await this.visitDefined(whileLoop.condition, p) as J.ControlParentheses<Expression>,
1175
+ body: await this.visitRightPadded(whileLoop.body, p)
1176
+ };
1177
+ return updateIfChanged(whileLoop, updates);
981
1178
  }
982
1179
 
983
1180
  protected async visitWildcard(wildcard: J.Wildcard, p: P): Promise<J | undefined> {
@@ -987,12 +1184,15 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
987
1184
  }
988
1185
  wildcard = expression as J.Wildcard;
989
1186
 
990
- return this.produceJava<J.Wildcard>(wildcard, p, async draft => {
991
- draft.bound = await this.visitOptionalLeftPadded(wildcard.bound, p);
992
- if (wildcard.boundedType) {
993
- draft.boundedType = await this.visitTypeName(wildcard.boundedType, p);
994
- }
995
- });
1187
+ const updates: any = {
1188
+ prefix: await this.visitSpace(wildcard.prefix, p),
1189
+ markers: await this.visitMarkers(wildcard.markers, p),
1190
+ bound: await this.visitOptionalLeftPadded(wildcard.bound, p)
1191
+ };
1192
+ if (wildcard.boundedType) {
1193
+ updates.boundedType = await this.visitTypeName(wildcard.boundedType, p);
1194
+ }
1195
+ return updateIfChanged(wildcard, updates);
996
1196
  }
997
1197
 
998
1198
  protected async visitYield(aYield: J.Yield, p: P): Promise<J | undefined> {
@@ -1002,9 +1202,12 @@ export class JavaVisitor<P> extends TreeVisitor<J, P> {
1002
1202
  }
1003
1203
  aYield = statement as J.Yield;
1004
1204
 
1005
- return this.produceJava<J.Yield>(aYield, p, async draft => {
1006
- draft.value = await this.visitDefined(aYield.value, p) as Expression;
1007
- });
1205
+ const updates: any = {
1206
+ prefix: await this.visitSpace(aYield.prefix, p),
1207
+ markers: await this.visitMarkers(aYield.markers, p),
1208
+ value: await this.visitDefined(aYield.value, p) as Expression
1209
+ };
1210
+ return updateIfChanged(aYield, updates);
1008
1211
  }
1009
1212
 
1010
1213
  protected async visitOptionalRightPadded<T extends J | boolean>(right: J.RightPadded<T> | undefined, p: P): Promise<J.RightPadded<T> | undefined> {