@openrewrite/rewrite 8.99.1 → 8.100.1

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 (140) hide show
  1. package/dist/java/rpc.d.ts.map +1 -1
  2. package/dist/java/rpc.js +6 -1
  3. package/dist/java/rpc.js.map +1 -1
  4. package/dist/javascript/add-import.d.ts.map +1 -1
  5. package/dist/javascript/add-import.js +3 -0
  6. package/dist/javascript/add-import.js.map +1 -1
  7. package/dist/javascript/binding.d.ts.map +1 -1
  8. package/dist/javascript/binding.js +8 -1
  9. package/dist/javascript/binding.js.map +1 -1
  10. package/dist/javascript/comparator.js +2 -1
  11. package/dist/javascript/comparator.js.map +1 -1
  12. package/dist/javascript/format/format.d.ts.map +1 -1
  13. package/dist/javascript/format/format.js +3 -2
  14. package/dist/javascript/format/format.js.map +1 -1
  15. package/dist/javascript/format/minimum-viable-spacing-visitor.js +3 -3
  16. package/dist/javascript/format/minimum-viable-spacing-visitor.js.map +1 -1
  17. package/dist/javascript/parser.d.ts.map +1 -1
  18. package/dist/javascript/parser.js +11 -17
  19. package/dist/javascript/parser.js.map +1 -1
  20. package/dist/javascript/print.d.ts +4 -0
  21. package/dist/javascript/print.d.ts.map +1 -1
  22. package/dist/javascript/print.js +82 -20
  23. package/dist/javascript/print.js.map +1 -1
  24. package/dist/javascript/rpc.js +2 -0
  25. package/dist/javascript/rpc.js.map +1 -1
  26. package/dist/javascript/scope.d.ts.map +1 -1
  27. package/dist/javascript/scope.js +4 -1
  28. package/dist/javascript/scope.js.map +1 -1
  29. package/dist/javascript/templating/comparator.d.ts +9 -0
  30. package/dist/javascript/templating/comparator.d.ts.map +1 -1
  31. package/dist/javascript/templating/comparator.js +21 -0
  32. package/dist/javascript/templating/comparator.js.map +1 -1
  33. package/dist/javascript/templating/debug.d.ts.map +1 -1
  34. package/dist/javascript/templating/debug.js +2 -0
  35. package/dist/javascript/templating/debug.js.map +1 -1
  36. package/dist/javascript/templating/precedence.d.ts.map +1 -1
  37. package/dist/javascript/templating/precedence.js +36 -39
  38. package/dist/javascript/templating/precedence.js.map +1 -1
  39. package/dist/javascript/templating/types.d.ts +4 -4
  40. package/dist/javascript/tree-debug.d.ts.map +1 -1
  41. package/dist/javascript/tree-debug.js +6 -3
  42. package/dist/javascript/tree-debug.js.map +1 -1
  43. package/dist/javascript/tree.d.ts +4 -1
  44. package/dist/javascript/tree.d.ts.map +1 -1
  45. package/dist/javascript/tree.js +2 -0
  46. package/dist/javascript/tree.js.map +1 -1
  47. package/dist/javascript/type-mapping.d.ts +1 -0
  48. package/dist/javascript/type-mapping.d.ts.map +1 -1
  49. package/dist/javascript/type-mapping.js +12 -1
  50. package/dist/javascript/type-mapping.js.map +1 -1
  51. package/dist/json/edit.d.ts +150 -0
  52. package/dist/json/edit.d.ts.map +1 -0
  53. package/dist/json/edit.js +667 -0
  54. package/dist/json/edit.js.map +1 -0
  55. package/dist/json/index.d.ts +1 -0
  56. package/dist/json/index.d.ts.map +1 -1
  57. package/dist/json/index.js +1 -0
  58. package/dist/json/index.js.map +1 -1
  59. package/dist/parser.d.ts +1 -1
  60. package/dist/parser.d.ts.map +1 -1
  61. package/dist/print.d.ts +16 -0
  62. package/dist/print.d.ts.map +1 -1
  63. package/dist/print.js +33 -0
  64. package/dist/print.js.map +1 -1
  65. package/dist/rewrite-javascript-version.txt +1 -1
  66. package/dist/rpc/request/get-languages.d.ts.map +1 -1
  67. package/dist/rpc/request/get-languages.js +1 -0
  68. package/dist/rpc/request/get-languages.js.map +1 -1
  69. package/dist/rpc/request/parse.d.ts.map +1 -1
  70. package/dist/rpc/request/parse.js +4 -0
  71. package/dist/rpc/request/parse.js.map +1 -1
  72. package/dist/rpc/server.d.ts +1 -0
  73. package/dist/rpc/server.d.ts.map +1 -1
  74. package/dist/rpc/server.js +1 -0
  75. package/dist/rpc/server.js.map +1 -1
  76. package/dist/xml/assertions.d.ts +4 -0
  77. package/dist/xml/assertions.d.ts.map +1 -0
  78. package/dist/xml/assertions.js +31 -0
  79. package/dist/xml/assertions.js.map +1 -0
  80. package/dist/xml/index.d.ts +8 -0
  81. package/dist/xml/index.d.ts.map +1 -0
  82. package/dist/xml/index.js +39 -0
  83. package/dist/xml/index.js.map +1 -0
  84. package/dist/xml/namespaces.d.ts +36 -0
  85. package/dist/xml/namespaces.d.ts.map +1 -0
  86. package/dist/xml/namespaces.js +98 -0
  87. package/dist/xml/namespaces.js.map +1 -0
  88. package/dist/xml/parser.d.ts +15 -0
  89. package/dist/xml/parser.d.ts.map +1 -0
  90. package/dist/xml/parser.js +677 -0
  91. package/dist/xml/parser.js.map +1 -0
  92. package/dist/xml/print.d.ts +2 -0
  93. package/dist/xml/print.d.ts.map +1 -0
  94. package/dist/xml/print.js +209 -0
  95. package/dist/xml/print.js.map +1 -0
  96. package/dist/xml/rpc.d.ts +2 -0
  97. package/dist/xml/rpc.d.ts.map +1 -0
  98. package/dist/xml/rpc.js +313 -0
  99. package/dist/xml/rpc.js.map +1 -0
  100. package/dist/xml/tree.d.ts +244 -0
  101. package/dist/xml/tree.d.ts.map +1 -0
  102. package/dist/xml/tree.js +265 -0
  103. package/dist/xml/tree.js.map +1 -0
  104. package/dist/xml/visitor.d.ts +35 -0
  105. package/dist/xml/visitor.d.ts.map +1 -0
  106. package/dist/xml/visitor.js +203 -0
  107. package/dist/xml/visitor.js.map +1 -0
  108. package/package.json +5 -1
  109. package/src/java/rpc.ts +6 -1
  110. package/src/javascript/add-import.ts +3 -0
  111. package/src/javascript/binding.ts +10 -1
  112. package/src/javascript/comparator.ts +2 -1
  113. package/src/javascript/format/format.ts +3 -2
  114. package/src/javascript/format/minimum-viable-spacing-visitor.ts +3 -3
  115. package/src/javascript/parser.ts +12 -17
  116. package/src/javascript/print.ts +85 -23
  117. package/src/javascript/rpc.ts +2 -0
  118. package/src/javascript/scope.ts +4 -1
  119. package/src/javascript/templating/comparator.ts +23 -0
  120. package/src/javascript/templating/debug.ts +1 -0
  121. package/src/javascript/templating/precedence.ts +17 -20
  122. package/src/javascript/templating/types.ts +4 -4
  123. package/src/javascript/tree-debug.ts +7 -3
  124. package/src/javascript/tree.ts +4 -1
  125. package/src/javascript/type-mapping.ts +15 -1
  126. package/src/json/edit.ts +750 -0
  127. package/src/json/index.ts +1 -0
  128. package/src/parser.ts +1 -1
  129. package/src/print.ts +42 -0
  130. package/src/rpc/request/get-languages.ts +1 -0
  131. package/src/rpc/request/parse.ts +3 -0
  132. package/src/rpc/server.ts +1 -0
  133. package/src/xml/assertions.ts +28 -0
  134. package/src/xml/index.ts +23 -0
  135. package/src/xml/namespaces.ts +109 -0
  136. package/src/xml/parser.ts +692 -0
  137. package/src/xml/print.ts +225 -0
  138. package/src/xml/rpc.ts +370 -0
  139. package/src/xml/tree.ts +455 -0
  140. package/src/xml/visitor.ts +227 -0
@@ -0,0 +1,225 @@
1
+ /*
2
+ * Copyright 2026 the original author or authors.
3
+ * <p>
4
+ * Licensed under the Moderne Source Available License (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ * <p>
8
+ * https://docs.moderne.io/licensing/moderne-source-available-license
9
+ * <p>
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import {PrintOutputCapture, TreePrinters} from "../print";
17
+ import {Cursor} from "../tree";
18
+ import {XmlVisitor} from "./visitor";
19
+ import {Xml} from "./tree";
20
+
21
+ class XmlPrinter extends XmlVisitor<PrintOutputCapture> {
22
+
23
+ protected async visitDocument(document: Xml.Document, p: PrintOutputCapture): Promise<Xml | undefined> {
24
+ this.beforeSyntax(document, p);
25
+ await this.visit(document.prolog, p);
26
+ if (document.root) {
27
+ await this.visit(document.root, p);
28
+ }
29
+ this.afterSyntax(document, p);
30
+ p.append(document.eof);
31
+ return document;
32
+ }
33
+
34
+ protected async visitProlog(prolog: Xml.Prolog, p: PrintOutputCapture): Promise<Xml | undefined> {
35
+ this.beforeSyntax(prolog, p);
36
+ if (prolog.xmlDecl) {
37
+ await this.visit(prolog.xmlDecl, p);
38
+ }
39
+ await this.visitAll(prolog.misc, p);
40
+ await this.visitAll(prolog.jspDirectives, p);
41
+ this.afterSyntax(prolog, p);
42
+ return prolog;
43
+ }
44
+
45
+ protected async visitXmlDecl(xmlDecl: Xml.XmlDecl, p: PrintOutputCapture): Promise<Xml | undefined> {
46
+ this.beforeSyntax(xmlDecl, p);
47
+ p.append("<?").append(xmlDecl.name);
48
+ await this.visitAll(xmlDecl.attributes, p);
49
+ p.append(xmlDecl.beforeTagDelimiterPrefix).append("?>");
50
+ this.afterSyntax(xmlDecl, p);
51
+ return xmlDecl;
52
+ }
53
+
54
+ protected async visitTag(tag: Xml.Tag, p: PrintOutputCapture): Promise<Xml | undefined> {
55
+ this.beforeSyntax(tag, p);
56
+ p.append("<").append(tag.name);
57
+ await this.visitAll(tag.attributes, p);
58
+ p.append(tag.beforeTagDelimiterPrefix);
59
+ if (tag.markers.markers.some(m => m.kind === Xml.MarkersKind.HtmlVoidElement)) {
60
+ p.append(">");
61
+ } else if (!tag.closing) {
62
+ p.append("/>");
63
+ } else {
64
+ p.append(">");
65
+ await this.visitAll(tag.content ?? [], p);
66
+ await this.visit(tag.closing, p);
67
+ }
68
+ this.afterSyntax(tag, p);
69
+ return tag;
70
+ }
71
+
72
+ protected async visitTagClosing(closing: Xml.TagClosing, p: PrintOutputCapture): Promise<Xml | undefined> {
73
+ this.beforeSyntax(closing, p);
74
+ p.append("</").append(closing.name).append(closing.beforeTagDelimiterPrefix).append(">");
75
+ this.afterSyntax(closing, p);
76
+ return closing;
77
+ }
78
+
79
+ protected async visitAttribute(attribute: Xml.Attribute, p: PrintOutputCapture): Promise<Xml | undefined> {
80
+ this.beforeSyntax(attribute, p);
81
+ p.append(attribute.key.prefix)
82
+ .append(attribute.key.name)
83
+ .append(attribute.beforeEquals)
84
+ .append("=");
85
+ await this.visit(attribute.value, p);
86
+ this.afterSyntax(attribute, p);
87
+ return attribute;
88
+ }
89
+
90
+ protected async visitAttributeValue(value: Xml.AttributeValue, p: PrintOutputCapture): Promise<Xml | undefined> {
91
+ this.beforeSyntax(value, p);
92
+ const delimiter = value.quote === "Double" ? '"' : "'";
93
+ p.append(delimiter).append(value.value).append(delimiter);
94
+ this.afterSyntax(value, p);
95
+ return value;
96
+ }
97
+
98
+ protected async visitComment(comment: Xml.Comment, p: PrintOutputCapture): Promise<Xml | undefined> {
99
+ this.beforeSyntax(comment, p);
100
+ p.append("<!--").append(comment.text).append("-->");
101
+ this.afterSyntax(comment, p);
102
+ return comment;
103
+ }
104
+
105
+ protected async visitProcessingInstruction(pi: Xml.ProcessingInstruction, p: PrintOutputCapture): Promise<Xml | undefined> {
106
+ this.beforeSyntax(pi, p);
107
+ p.append("<?").append(pi.name);
108
+ if (pi.processingInstructions) {
109
+ await this.visit(pi.processingInstructions, p);
110
+ }
111
+ p.append(pi.beforeTagDelimiterPrefix).append("?>");
112
+ this.afterSyntax(pi, p);
113
+ return pi;
114
+ }
115
+
116
+ protected async visitCharData(charData: Xml.CharData, p: PrintOutputCapture): Promise<Xml | undefined> {
117
+ this.beforeSyntax(charData, p);
118
+ if (charData.cdata) {
119
+ p.append("<![CDATA[").append(charData.text).append("]]>");
120
+ } else {
121
+ p.append(charData.text);
122
+ }
123
+ p.append(charData.afterText);
124
+ this.afterSyntax(charData, p);
125
+ return charData;
126
+ }
127
+
128
+ protected async visitDocTypeDecl(docTypeDecl: Xml.DocTypeDecl, p: PrintOutputCapture): Promise<Xml | undefined> {
129
+ this.beforeSyntax(docTypeDecl, p);
130
+ p.append("<!").append(docTypeDecl.documentDeclaration);
131
+ await this.visit(docTypeDecl.name, p);
132
+ if (docTypeDecl.externalId) {
133
+ await this.visit(docTypeDecl.externalId, p);
134
+ }
135
+ await this.visitAll(docTypeDecl.internalSubset, p);
136
+ if (docTypeDecl.externalSubsets) {
137
+ await this.visit(docTypeDecl.externalSubsets, p);
138
+ }
139
+ p.append(docTypeDecl.beforeTagDelimiterPrefix).append(">");
140
+ this.afterSyntax(docTypeDecl, p);
141
+ return docTypeDecl;
142
+ }
143
+
144
+ protected async visitDocTypeDeclExternalSubsets(externalSubsets: Xml.DocTypeDeclExternalSubsets, p: PrintOutputCapture): Promise<Xml | undefined> {
145
+ this.beforeSyntax(externalSubsets, p);
146
+ p.append("[");
147
+ await this.visitAll(externalSubsets.elements, p);
148
+ p.append("]");
149
+ this.afterSyntax(externalSubsets, p);
150
+ return externalSubsets;
151
+ }
152
+
153
+ protected async visitElement(element: Xml.Element, p: PrintOutputCapture): Promise<Xml | undefined> {
154
+ this.beforeSyntax(element, p);
155
+ await this.visitAll(element.subset, p);
156
+ p.append(element.beforeTagDelimiterPrefix);
157
+ this.afterSyntax(element, p);
158
+ return element;
159
+ }
160
+
161
+ protected async visitIdent(ident: Xml.Ident, p: PrintOutputCapture): Promise<Xml | undefined> {
162
+ this.beforeSyntax(ident, p);
163
+ p.append(ident.name);
164
+ this.afterSyntax(ident, p);
165
+ return ident;
166
+ }
167
+
168
+ protected async visitJspDirective(jsp: Xml.JspDirective, p: PrintOutputCapture): Promise<Xml | undefined> {
169
+ this.beforeSyntax(jsp, p);
170
+ p.append("<%@").append(jsp.beforeTypePrefix).append(jsp.type);
171
+ await this.visitAll(jsp.attributes, p);
172
+ p.append(jsp.beforeDirectiveEndPrefix).append("%>");
173
+ this.afterSyntax(jsp, p);
174
+ return jsp;
175
+ }
176
+
177
+ protected async visitJspScriptlet(jsp: Xml.JspScriptlet, p: PrintOutputCapture): Promise<Xml | undefined> {
178
+ return this.printDelimited(jsp, "<%", jsp.content, "%>", p);
179
+ }
180
+
181
+ protected async visitJspExpression(jsp: Xml.JspExpression, p: PrintOutputCapture): Promise<Xml | undefined> {
182
+ return this.printDelimited(jsp, "<%=", jsp.content, "%>", p);
183
+ }
184
+
185
+ protected async visitJspDeclaration(jsp: Xml.JspDeclaration, p: PrintOutputCapture): Promise<Xml | undefined> {
186
+ return this.printDelimited(jsp, "<%!", jsp.content, "%>", p);
187
+ }
188
+
189
+ protected async visitJspComment(jsp: Xml.JspComment, p: PrintOutputCapture): Promise<Xml | undefined> {
190
+ return this.printDelimited(jsp, "<%--", jsp.content, "--%>", p);
191
+ }
192
+
193
+ private printDelimited(x: Xml, open: string, content: string, close: string, p: PrintOutputCapture): Xml {
194
+ this.beforeSyntax(x, p);
195
+ p.append(open).append(content).append(close);
196
+ this.afterSyntax(x, p);
197
+ return x;
198
+ }
199
+
200
+ private async visitAll(nodes: Xml[], p: PrintOutputCapture): Promise<void> {
201
+ for (const node of nodes) {
202
+ await this.visit(node, p);
203
+ }
204
+ }
205
+
206
+ private beforeSyntax(x: Xml, p: PrintOutputCapture): void {
207
+ for (const marker of x.markers.markers) {
208
+ p.append(p.markerPrinter.beforePrefix(marker, new Cursor(marker, this.cursor), this.xmlMarkerWrapper));
209
+ }
210
+ p.append(x.prefix);
211
+ for (const marker of x.markers.markers) {
212
+ p.append(p.markerPrinter.beforeSyntax(marker, new Cursor(marker, this.cursor), this.xmlMarkerWrapper));
213
+ }
214
+ }
215
+
216
+ private afterSyntax(x: Xml, p: PrintOutputCapture): void {
217
+ for (const marker of x.markers.markers) {
218
+ p.append(p.markerPrinter.afterSyntax(marker, new Cursor(marker, this.cursor), this.xmlMarkerWrapper));
219
+ }
220
+ }
221
+
222
+ private xmlMarkerWrapper = (out: string): string => `<!--~~${out}${out ? "~~" : ""}>-->`;
223
+ }
224
+
225
+ TreePrinters.register(Xml.Kind.Document, () => new XmlPrinter());
package/src/xml/rpc.ts ADDED
@@ -0,0 +1,370 @@
1
+ /*
2
+ * Copyright 2026 the original author or authors.
3
+ * <p>
4
+ * Licensed under the Moderne Source Available License (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ * <p>
8
+ * https://docs.moderne.io/licensing/moderne-source-available-license
9
+ * <p>
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import {asRef, RpcCodecs, RpcReceiveQueue, RpcSendQueue} from "../rpc";
17
+ import {Xml} from "./tree";
18
+ import {updateIfChanged} from "../util";
19
+
20
+ /**
21
+ * Dispatches an Xml element to the sender's or receiver's method for its kind. The fields of each kind
22
+ * go over the wire in the order `org.openrewrite.xml.internal.rpc.XmlSender` writes them.
23
+ */
24
+ abstract class XmlRpcVisitor<Q> {
25
+ visit<R extends Xml>(tree: Xml | undefined, q: Q): R | undefined {
26
+ if (!tree) {
27
+ return undefined;
28
+ }
29
+ const t = this.preVisit(tree, q);
30
+ return t === undefined ? undefined : this.accept(t, q) as R | undefined;
31
+ }
32
+
33
+ protected abstract preVisit(tree: Xml, q: Q): Xml | undefined;
34
+
35
+ protected accept(t: Xml, q: Q): Xml | undefined {
36
+ switch (t.kind) {
37
+ case Xml.Kind.Document:
38
+ return this.visitDocument(t as Xml.Document, q);
39
+ case Xml.Kind.Prolog:
40
+ return this.visitProlog(t as Xml.Prolog, q);
41
+ case Xml.Kind.XmlDecl:
42
+ return this.visitXmlDecl(t as Xml.XmlDecl, q);
43
+ case Xml.Kind.ProcessingInstruction:
44
+ return this.visitProcessingInstruction(t as Xml.ProcessingInstruction, q);
45
+ case Xml.Kind.Tag:
46
+ return this.visitTag(t as Xml.Tag, q);
47
+ case Xml.Kind.TagClosing:
48
+ return this.visitTagClosing(t as Xml.TagClosing, q);
49
+ case Xml.Kind.Attribute:
50
+ return this.visitAttribute(t as Xml.Attribute, q);
51
+ case Xml.Kind.AttributeValue:
52
+ return this.visitAttributeValue(t as Xml.AttributeValue, q);
53
+ case Xml.Kind.CharData:
54
+ return this.visitCharData(t as Xml.CharData, q);
55
+ case Xml.Kind.Comment:
56
+ return this.visitComment(t as Xml.Comment, q);
57
+ case Xml.Kind.DocTypeDecl:
58
+ return this.visitDocTypeDecl(t as Xml.DocTypeDecl, q);
59
+ case Xml.Kind.DocTypeDeclExternalSubsets:
60
+ return this.visitDocTypeDeclExternalSubsets(t as Xml.DocTypeDeclExternalSubsets, q);
61
+ case Xml.Kind.Element:
62
+ return this.visitElement(t as Xml.Element, q);
63
+ case Xml.Kind.Ident:
64
+ return this.visitIdent(t as Xml.Ident, q);
65
+ case Xml.Kind.JspDirective:
66
+ return this.visitJspDirective(t as Xml.JspDirective, q);
67
+ case Xml.Kind.JspScriptlet:
68
+ case Xml.Kind.JspExpression:
69
+ case Xml.Kind.JspDeclaration:
70
+ case Xml.Kind.JspComment:
71
+ return this.visitJspContent(t as Xml.JspScriptlet | Xml.JspExpression | Xml.JspDeclaration | Xml.JspComment, q);
72
+ default:
73
+ throw new Error(`No RPC codec for kind ${t.kind}`);
74
+ }
75
+ }
76
+
77
+ protected abstract visitDocument(tree: Xml.Document, q: Q): Xml | undefined;
78
+ protected abstract visitProlog(tree: Xml.Prolog, q: Q): Xml | undefined;
79
+ protected abstract visitXmlDecl(tree: Xml.XmlDecl, q: Q): Xml | undefined;
80
+ protected abstract visitProcessingInstruction(tree: Xml.ProcessingInstruction, q: Q): Xml | undefined;
81
+ protected abstract visitTag(tree: Xml.Tag, q: Q): Xml | undefined;
82
+ protected abstract visitTagClosing(tree: Xml.TagClosing, q: Q): Xml | undefined;
83
+ protected abstract visitAttribute(tree: Xml.Attribute, q: Q): Xml | undefined;
84
+ protected abstract visitAttributeValue(tree: Xml.AttributeValue, q: Q): Xml | undefined;
85
+ protected abstract visitCharData(tree: Xml.CharData, q: Q): Xml | undefined;
86
+ protected abstract visitComment(tree: Xml.Comment, q: Q): Xml | undefined;
87
+ protected abstract visitDocTypeDecl(tree: Xml.DocTypeDecl, q: Q): Xml | undefined;
88
+ protected abstract visitDocTypeDeclExternalSubsets(tree: Xml.DocTypeDeclExternalSubsets, q: Q): Xml | undefined;
89
+ protected abstract visitElement(tree: Xml.Element, q: Q): Xml | undefined;
90
+ protected abstract visitIdent(tree: Xml.Ident, q: Q): Xml | undefined;
91
+ protected abstract visitJspDirective(tree: Xml.JspDirective, q: Q): Xml | undefined;
92
+ protected abstract visitJspContent(tree: Xml.JspScriptlet | Xml.JspExpression | Xml.JspDeclaration | Xml.JspComment, q: Q): Xml | undefined;
93
+ }
94
+
95
+ class XmlSender extends XmlRpcVisitor<RpcSendQueue> {
96
+
97
+ protected preVisit(x: Xml, q: RpcSendQueue): Xml | undefined {
98
+ q.getAndSend(x, x2 => x2.id);
99
+ q.getAndSend(x, x2 => x2.prefix);
100
+ q.getAndSend(x, x2 => asRef(x2.markers));
101
+ return x;
102
+ }
103
+
104
+ protected visitDocument(document: Xml.Document, q: RpcSendQueue): Xml | undefined {
105
+ q.getAndSend(document, d => d.sourcePath);
106
+ q.getAndSend(document, d => d.charsetName);
107
+ q.getAndSend(document, d => d.charsetBomMarked);
108
+ q.getAndSend(document, d => d.checksum);
109
+ q.getAndSend(document, d => d.fileAttributes);
110
+ q.getAndSend(document, d => d.prolog, p => this.visit(p, q));
111
+ q.getAndSend(document, d => d.root, t => this.visit(t, q));
112
+ q.getAndSend(document, d => d.eof);
113
+ return document;
114
+ }
115
+
116
+ protected visitProlog(prolog: Xml.Prolog, q: RpcSendQueue): Xml | undefined {
117
+ q.getAndSend(prolog, p => p.xmlDecl, d => this.visit(d, q));
118
+ q.getAndSendList(prolog, p => p.misc, m => m.id, m => this.visit(m, q));
119
+ q.getAndSendList(prolog, p => p.jspDirectives, j => j.id, j => this.visit(j, q));
120
+ return prolog;
121
+ }
122
+
123
+ protected visitXmlDecl(xmlDecl: Xml.XmlDecl, q: RpcSendQueue): Xml | undefined {
124
+ q.getAndSend(xmlDecl, x => x.name);
125
+ q.getAndSendList(xmlDecl, x => x.attributes, a => a.id, a => this.visit(a, q));
126
+ q.getAndSend(xmlDecl, x => x.beforeTagDelimiterPrefix);
127
+ return xmlDecl;
128
+ }
129
+
130
+ protected visitProcessingInstruction(pi: Xml.ProcessingInstruction, q: RpcSendQueue): Xml | undefined {
131
+ q.getAndSend(pi, p => p.name);
132
+ q.getAndSend(pi, p => p.processingInstructions, c => this.visit(c, q));
133
+ q.getAndSend(pi, p => p.beforeTagDelimiterPrefix);
134
+ return pi;
135
+ }
136
+
137
+ protected visitTag(tag: Xml.Tag, q: RpcSendQueue): Xml | undefined {
138
+ q.getAndSend(tag, t => t.name);
139
+ q.getAndSendList(tag, t => t.attributes, a => a.id, a => this.visit(a, q));
140
+ q.getAndSendList(tag, t => t.content, c => c.id, c => this.visit(c, q));
141
+ q.getAndSend(tag, t => t.closing, c => this.visit(c, q));
142
+ q.getAndSend(tag, t => t.beforeTagDelimiterPrefix);
143
+ return tag;
144
+ }
145
+
146
+ protected visitTagClosing(closing: Xml.TagClosing, q: RpcSendQueue): Xml | undefined {
147
+ q.getAndSend(closing, c => c.name);
148
+ q.getAndSend(closing, c => c.beforeTagDelimiterPrefix);
149
+ return closing;
150
+ }
151
+
152
+ protected visitAttribute(attribute: Xml.Attribute, q: RpcSendQueue): Xml | undefined {
153
+ q.getAndSend(attribute, a => a.key, k => this.visit(k, q));
154
+ q.getAndSend(attribute, a => a.beforeEquals);
155
+ q.getAndSend(attribute, a => a.value, v => this.visit(v, q));
156
+ return attribute;
157
+ }
158
+
159
+ protected visitAttributeValue(value: Xml.AttributeValue, q: RpcSendQueue): Xml | undefined {
160
+ q.getAndSend(value, v => v.quote);
161
+ q.getAndSend(value, v => v.value);
162
+ return value;
163
+ }
164
+
165
+ protected visitCharData(charData: Xml.CharData, q: RpcSendQueue): Xml | undefined {
166
+ q.getAndSend(charData, c => c.cdata);
167
+ q.getAndSend(charData, c => c.text);
168
+ q.getAndSend(charData, c => c.afterText);
169
+ return charData;
170
+ }
171
+
172
+ protected visitComment(comment: Xml.Comment, q: RpcSendQueue): Xml | undefined {
173
+ q.getAndSend(comment, c => c.text);
174
+ return comment;
175
+ }
176
+
177
+ protected visitDocTypeDecl(docTypeDecl: Xml.DocTypeDecl, q: RpcSendQueue): Xml | undefined {
178
+ q.getAndSend(docTypeDecl, d => d.name, n => this.visit(n, q));
179
+ q.getAndSend(docTypeDecl, d => d.documentDeclaration);
180
+ q.getAndSend(docTypeDecl, d => d.externalId, e => this.visit(e, q));
181
+ q.getAndSendList(docTypeDecl, d => d.internalSubset, i => i.id, i => this.visit(i, q));
182
+ q.getAndSend(docTypeDecl, d => d.externalSubsets, e => this.visit(e, q));
183
+ q.getAndSend(docTypeDecl, d => d.beforeTagDelimiterPrefix);
184
+ return docTypeDecl;
185
+ }
186
+
187
+ protected visitDocTypeDeclExternalSubsets(externalSubsets: Xml.DocTypeDeclExternalSubsets, q: RpcSendQueue): Xml | undefined {
188
+ q.getAndSendList(externalSubsets, e => e.elements, e => e.id, e => this.visit(e, q));
189
+ return externalSubsets;
190
+ }
191
+
192
+ protected visitElement(element: Xml.Element, q: RpcSendQueue): Xml | undefined {
193
+ q.getAndSendList(element, e => e.subset, i => i.id, i => this.visit(i, q));
194
+ q.getAndSend(element, e => e.beforeTagDelimiterPrefix);
195
+ return element;
196
+ }
197
+
198
+ protected visitIdent(ident: Xml.Ident, q: RpcSendQueue): Xml | undefined {
199
+ q.getAndSend(ident, i => i.name);
200
+ return ident;
201
+ }
202
+
203
+ protected visitJspDirective(jspDirective: Xml.JspDirective, q: RpcSendQueue): Xml | undefined {
204
+ q.getAndSend(jspDirective, j => j.beforeTypePrefix);
205
+ q.getAndSend(jspDirective, j => j.type);
206
+ q.getAndSendList(jspDirective, j => j.attributes, a => a.id, a => this.visit(a, q));
207
+ q.getAndSend(jspDirective, j => j.beforeDirectiveEndPrefix);
208
+ return jspDirective;
209
+ }
210
+
211
+ protected visitJspContent(jsp: Xml.JspScriptlet | Xml.JspExpression | Xml.JspDeclaration | Xml.JspComment, q: RpcSendQueue): Xml | undefined {
212
+ q.getAndSend(jsp, j => j.content);
213
+ return jsp;
214
+ }
215
+ }
216
+
217
+ // noinspection ES6MissingAwait
218
+ class XmlReceiver extends XmlRpcVisitor<RpcReceiveQueue> {
219
+
220
+ protected preVisit(x: Xml, q: RpcReceiveQueue): Xml | undefined {
221
+ return updateIfChanged(x, {
222
+ id: q.receive(x.id),
223
+ prefix: q.receive(x.prefix),
224
+ markers: q.receive(x.markers),
225
+ });
226
+ }
227
+
228
+ protected visitDocument(document: Xml.Document, q: RpcReceiveQueue): Xml | undefined {
229
+ return updateIfChanged(document, {
230
+ sourcePath: q.receive(document.sourcePath),
231
+ charsetName: q.receive(document.charsetName),
232
+ charsetBomMarked: q.receive(document.charsetBomMarked),
233
+ checksum: q.receive(document.checksum),
234
+ fileAttributes: q.receive(document.fileAttributes),
235
+ prolog: q.receive(document.prolog, p => this.visit<Xml.Prolog>(p, q)!),
236
+ root: q.receive(document.root, t => this.visit<Xml.Tag>(t, q)!),
237
+ eof: q.receive(document.eof),
238
+ });
239
+ }
240
+
241
+ protected visitProlog(prolog: Xml.Prolog, q: RpcReceiveQueue): Xml | undefined {
242
+ return updateIfChanged(prolog, {
243
+ xmlDecl: q.receive(prolog.xmlDecl, d => this.visit<Xml.XmlDecl>(d, q)),
244
+ misc: q.receiveListDefined(prolog.misc, m => this.visit<Xml.Misc>(m, q)),
245
+ jspDirectives: q.receiveListDefined(prolog.jspDirectives, j => this.visit<Xml.JspDirective>(j, q)),
246
+ });
247
+ }
248
+
249
+ protected visitXmlDecl(xmlDecl: Xml.XmlDecl, q: RpcReceiveQueue): Xml | undefined {
250
+ return updateIfChanged(xmlDecl, {
251
+ name: q.receive(xmlDecl.name),
252
+ attributes: q.receiveListDefined(xmlDecl.attributes, a => this.visit<Xml.Attribute>(a, q)),
253
+ beforeTagDelimiterPrefix: q.receive(xmlDecl.beforeTagDelimiterPrefix),
254
+ });
255
+ }
256
+
257
+ protected visitProcessingInstruction(pi: Xml.ProcessingInstruction, q: RpcReceiveQueue): Xml | undefined {
258
+ return updateIfChanged(pi, {
259
+ name: q.receive(pi.name),
260
+ processingInstructions: q.receive(pi.processingInstructions, c => this.visit<Xml.CharData>(c, q)),
261
+ beforeTagDelimiterPrefix: q.receive(pi.beforeTagDelimiterPrefix),
262
+ });
263
+ }
264
+
265
+ protected visitTag(tag: Xml.Tag, q: RpcReceiveQueue): Xml | undefined {
266
+ return updateIfChanged(tag, {
267
+ name: q.receive(tag.name),
268
+ attributes: q.receiveListDefined(tag.attributes, a => this.visit<Xml.Attribute>(a, q)),
269
+ content: q.receiveList(tag.content, c => this.visit<Xml.Content>(c, q)),
270
+ closing: q.receive(tag.closing, c => this.visit<Xml.TagClosing>(c, q)),
271
+ beforeTagDelimiterPrefix: q.receive(tag.beforeTagDelimiterPrefix),
272
+ });
273
+ }
274
+
275
+ protected visitTagClosing(closing: Xml.TagClosing, q: RpcReceiveQueue): Xml | undefined {
276
+ return updateIfChanged(closing, {
277
+ name: q.receive(closing.name),
278
+ beforeTagDelimiterPrefix: q.receive(closing.beforeTagDelimiterPrefix),
279
+ });
280
+ }
281
+
282
+ protected visitAttribute(attribute: Xml.Attribute, q: RpcReceiveQueue): Xml | undefined {
283
+ return updateIfChanged(attribute, {
284
+ key: q.receive(attribute.key, k => this.visit<Xml.Ident>(k, q)!),
285
+ beforeEquals: q.receive(attribute.beforeEquals),
286
+ value: q.receive(attribute.value, v => this.visit<Xml.AttributeValue>(v, q)!),
287
+ });
288
+ }
289
+
290
+ protected visitAttributeValue(value: Xml.AttributeValue, q: RpcReceiveQueue): Xml | undefined {
291
+ return updateIfChanged(value, {
292
+ quote: q.receive(value.quote),
293
+ value: q.receive(value.value),
294
+ });
295
+ }
296
+
297
+ protected visitCharData(charData: Xml.CharData, q: RpcReceiveQueue): Xml | undefined {
298
+ return updateIfChanged(charData, {
299
+ cdata: q.receive(charData.cdata),
300
+ text: q.receive(charData.text),
301
+ afterText: q.receive(charData.afterText),
302
+ });
303
+ }
304
+
305
+ protected visitComment(comment: Xml.Comment, q: RpcReceiveQueue): Xml | undefined {
306
+ return updateIfChanged(comment, {
307
+ text: q.receive(comment.text),
308
+ });
309
+ }
310
+
311
+ protected visitDocTypeDecl(docTypeDecl: Xml.DocTypeDecl, q: RpcReceiveQueue): Xml | undefined {
312
+ return updateIfChanged(docTypeDecl, {
313
+ name: q.receive(docTypeDecl.name, n => this.visit<Xml.Ident>(n, q)!),
314
+ documentDeclaration: q.receive(docTypeDecl.documentDeclaration),
315
+ externalId: q.receive(docTypeDecl.externalId, e => this.visit<Xml.Ident>(e, q)),
316
+ internalSubset: q.receiveListDefined(docTypeDecl.internalSubset, i => this.visit<Xml.Ident>(i, q)),
317
+ externalSubsets: q.receive(docTypeDecl.externalSubsets, e => this.visit<Xml.DocTypeDeclExternalSubsets>(e, q)),
318
+ beforeTagDelimiterPrefix: q.receive(docTypeDecl.beforeTagDelimiterPrefix),
319
+ });
320
+ }
321
+
322
+ protected visitDocTypeDeclExternalSubsets(externalSubsets: Xml.DocTypeDeclExternalSubsets, q: RpcReceiveQueue): Xml | undefined {
323
+ return updateIfChanged(externalSubsets, {
324
+ elements: q.receiveListDefined(externalSubsets.elements, e => this.visit<Xml.Element>(e, q)),
325
+ });
326
+ }
327
+
328
+ protected visitElement(element: Xml.Element, q: RpcReceiveQueue): Xml | undefined {
329
+ return updateIfChanged(element, {
330
+ subset: q.receiveListDefined(element.subset, i => this.visit<Xml.Ident>(i, q)),
331
+ beforeTagDelimiterPrefix: q.receive(element.beforeTagDelimiterPrefix),
332
+ });
333
+ }
334
+
335
+ protected visitIdent(ident: Xml.Ident, q: RpcReceiveQueue): Xml | undefined {
336
+ return updateIfChanged(ident, {
337
+ name: q.receive(ident.name),
338
+ });
339
+ }
340
+
341
+ protected visitJspDirective(jspDirective: Xml.JspDirective, q: RpcReceiveQueue): Xml | undefined {
342
+ return updateIfChanged(jspDirective, {
343
+ beforeTypePrefix: q.receive(jspDirective.beforeTypePrefix),
344
+ type: q.receive(jspDirective.type),
345
+ attributes: q.receiveListDefined(jspDirective.attributes, a => this.visit<Xml.Attribute>(a, q)),
346
+ beforeDirectiveEndPrefix: q.receive(jspDirective.beforeDirectiveEndPrefix),
347
+ });
348
+ }
349
+
350
+ protected visitJspContent(jsp: Xml.JspScriptlet | Xml.JspExpression | Xml.JspDeclaration | Xml.JspComment, q: RpcReceiveQueue): Xml | undefined {
351
+ return updateIfChanged(jsp, {
352
+ content: q.receive(jsp.content),
353
+ });
354
+ }
355
+ }
356
+
357
+ const receiver = new XmlReceiver();
358
+ const sender = new XmlSender();
359
+
360
+ for (const kind of Object.values(Xml.Kind)) {
361
+ RpcCodecs.registerCodec(kind, {
362
+ rpcReceive(before: Xml, q: RpcReceiveQueue): Xml {
363
+ return receiver.visit(before, q)!;
364
+ },
365
+
366
+ rpcSend(after: Xml, q: RpcSendQueue): void {
367
+ sender.visit(after, q);
368
+ }
369
+ }, Xml.Kind.Document);
370
+ }