@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.
- package/dist/java/index.d.ts +1 -0
- package/dist/java/index.d.ts.map +1 -1
- package/dist/java/index.js +1 -0
- package/dist/java/index.js.map +1 -1
- package/dist/java/rpc.d.ts +2 -0
- package/dist/java/rpc.d.ts.map +1 -1
- package/dist/java/rpc.js +749 -410
- package/dist/java/rpc.js.map +1 -1
- package/dist/java/tree.d.ts +1 -1
- package/dist/java/tree.d.ts.map +1 -1
- package/dist/java/type-visitor.d.ts +48 -0
- package/dist/java/type-visitor.d.ts.map +1 -0
- package/dist/java/type-visitor.js +260 -0
- package/dist/java/type-visitor.js.map +1 -0
- package/dist/java/type.d.ts +2 -0
- package/dist/java/type.d.ts.map +1 -1
- package/dist/java/type.js +0 -317
- package/dist/java/type.js.map +1 -1
- package/dist/java/visitor.d.ts.map +1 -1
- package/dist/java/visitor.js +579 -363
- package/dist/java/visitor.js.map +1 -1
- package/dist/javascript/preconditions.d.ts +1 -1
- package/dist/javascript/preconditions.d.ts.map +1 -1
- package/dist/javascript/preconditions.js +7 -6
- package/dist/javascript/preconditions.js.map +1 -1
- package/dist/javascript/rpc.js +430 -350
- package/dist/javascript/rpc.js.map +1 -1
- package/dist/javascript/tree.d.ts +1 -1
- package/dist/javascript/tree.d.ts.map +1 -1
- package/dist/javascript/type-mapping.d.ts.map +1 -1
- package/dist/javascript/type-mapping.js +7 -0
- package/dist/javascript/type-mapping.js.map +1 -1
- package/dist/javascript/visitor.d.ts.map +1 -1
- package/dist/javascript/visitor.js +504 -309
- package/dist/javascript/visitor.js.map +1 -1
- package/dist/json/visitor.d.ts.map +1 -1
- package/dist/json/visitor.js +46 -21
- package/dist/json/visitor.js.map +1 -1
- package/dist/rpc/queue.d.ts +7 -4
- package/dist/rpc/queue.d.ts.map +1 -1
- package/dist/rpc/queue.js +22 -32
- package/dist/rpc/queue.js.map +1 -1
- package/dist/rpc/request/generate.d.ts.map +1 -1
- package/dist/rpc/request/generate.js +2 -3
- package/dist/rpc/request/generate.js.map +1 -1
- package/dist/rpc/request/get-languages.d.ts.map +1 -1
- package/dist/rpc/request/get-languages.js +4 -3
- package/dist/rpc/request/get-languages.js.map +1 -1
- package/dist/rpc/request/get-object.d.ts +1 -1
- package/dist/rpc/request/get-object.d.ts.map +1 -1
- package/dist/rpc/request/get-object.js +8 -7
- package/dist/rpc/request/get-object.js.map +1 -1
- package/dist/rpc/request/get-recipes.d.ts.map +1 -1
- package/dist/rpc/request/get-recipes.js +2 -2
- package/dist/rpc/request/get-recipes.js.map +1 -1
- package/dist/rpc/request/index.d.ts +1 -0
- package/dist/rpc/request/index.d.ts.map +1 -1
- package/dist/rpc/request/index.js +1 -0
- package/dist/rpc/request/index.js.map +1 -1
- package/dist/rpc/request/install-recipes.d.ts.map +1 -1
- package/dist/rpc/request/install-recipes.js +30 -21
- package/dist/rpc/request/install-recipes.js.map +1 -1
- package/dist/rpc/request/metrics.d.ts +10 -10
- package/dist/rpc/request/metrics.d.ts.map +1 -1
- package/dist/rpc/request/metrics.js +38 -31
- package/dist/rpc/request/metrics.js.map +1 -1
- package/dist/rpc/request/parse.d.ts.map +1 -1
- package/dist/rpc/request/parse.js +10 -12
- package/dist/rpc/request/parse.js.map +1 -1
- package/dist/rpc/request/prepare-recipe.d.ts.map +1 -1
- package/dist/rpc/request/prepare-recipe.js +4 -4
- package/dist/rpc/request/prepare-recipe.js.map +1 -1
- package/dist/rpc/request/print.d.ts +1 -1
- package/dist/rpc/request/print.d.ts.map +1 -1
- package/dist/rpc/request/print.js +10 -6
- package/dist/rpc/request/print.js.map +1 -1
- package/dist/rpc/request/trace-get-object.d.ts +5 -0
- package/dist/rpc/request/trace-get-object.d.ts.map +1 -0
- package/dist/rpc/request/trace-get-object.js +3 -0
- package/dist/rpc/request/trace-get-object.js.map +1 -0
- package/dist/rpc/request/visit.d.ts.map +1 -1
- package/dist/rpc/request/visit.js +2 -3
- package/dist/rpc/request/visit.js.map +1 -1
- package/dist/rpc/rewrite-rpc.d.ts +2 -3
- package/dist/rpc/rewrite-rpc.d.ts.map +1 -1
- package/dist/rpc/rewrite-rpc.js +14 -5
- package/dist/rpc/rewrite-rpc.js.map +1 -1
- package/dist/rpc/server.d.ts.map +1 -1
- package/dist/rpc/server.js +15 -44
- package/dist/rpc/server.js.map +1 -1
- package/dist/rpc/trace.d.ts +1 -1
- package/dist/rpc/trace.d.ts.map +1 -1
- package/dist/rpc/trace.js +3 -3
- package/dist/rpc/trace.js.map +1 -1
- package/dist/util.d.ts +6 -0
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +14 -0
- package/dist/util.js.map +1 -1
- package/dist/version.txt +1 -1
- package/package.json +1 -1
- package/src/java/index.ts +1 -0
- package/src/java/rpc.ts +726 -537
- package/src/java/tree.ts +1 -1
- package/src/java/type-visitor.ts +241 -0
- package/src/java/type.ts +13 -277
- package/src/java/visitor.ts +581 -378
- package/src/javascript/preconditions.ts +7 -6
- package/src/javascript/rpc.ts +431 -360
- package/src/javascript/tree.ts +1 -1
- package/src/javascript/type-mapping.ts +7 -0
- package/src/javascript/visitor.ts +505 -310
- package/src/json/visitor.ts +47 -22
- package/src/rpc/queue.ts +20 -17
- package/src/rpc/request/generate.ts +31 -25
- package/src/rpc/request/get-languages.ts +18 -10
- package/src/rpc/request/get-object.ts +42 -34
- package/src/rpc/request/get-recipes.ts +15 -8
- package/src/rpc/request/index.ts +1 -0
- package/src/rpc/request/install-recipes.ts +96 -79
- package/src/rpc/request/metrics.ts +54 -48
- package/src/rpc/request/parse.ts +31 -25
- package/src/rpc/request/prepare-recipe.ts +31 -23
- package/src/rpc/request/print.ts +28 -14
- package/src/rpc/request/trace-get-object.ts +4 -0
- package/src/rpc/request/visit.ts +22 -16
- package/src/rpc/rewrite-rpc.ts +23 -10
- package/src/rpc/server.ts +17 -52
- package/src/rpc/trace.ts +3 -3
- package/src/util.ts +14 -0
- package/dist/rpc/chrome-profiler.d.ts +0 -25
- package/dist/rpc/chrome-profiler.d.ts.map +0 -1
- package/dist/rpc/chrome-profiler.js +0 -405
- package/dist/rpc/chrome-profiler.js.map +0 -1
- package/src/rpc/chrome-profiler.ts +0 -373
package/src/java/tree.ts
CHANGED
|
@@ -591,7 +591,7 @@ export namespace J {
|
|
|
591
591
|
|
|
592
592
|
export interface Primitive extends J, TypeTree, Expression {
|
|
593
593
|
readonly kind: typeof Kind.Primitive;
|
|
594
|
-
|
|
594
|
+
type: Type.Primitive;
|
|
595
595
|
}
|
|
596
596
|
|
|
597
597
|
export interface Return extends J, Statement {
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 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 {Cursor, rootCursor} from "../tree";
|
|
17
|
+
import {mapAsync} from "../util";
|
|
18
|
+
import {Type} from "./type";
|
|
19
|
+
import {createDraft, Draft, finishDraft} from "immer";
|
|
20
|
+
import {produceAsync, ValidImmerRecipeReturnType} from "../visitor";
|
|
21
|
+
|
|
22
|
+
export class TypeVisitor<P> {
|
|
23
|
+
protected cursor: Cursor = rootCursor();
|
|
24
|
+
|
|
25
|
+
async visitList<T extends Type>(types: T[] | undefined, p: P): Promise<T[] | undefined> {
|
|
26
|
+
if (!types) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return mapAsync(types, t => this.visit(t, p) as Promise<T>);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async preVisit(type: Type, p: P): Promise<Type | undefined> {
|
|
33
|
+
return type;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async postVisit(type: Type, p: P): Promise<Type | undefined> {
|
|
37
|
+
return type;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* By calling this method, you are asserting that you know that the outcome will be non-null
|
|
42
|
+
* when the compiler couldn't otherwise prove this to be the case. This method is a shortcut
|
|
43
|
+
* for having to assert the non-nullability of the returned type.
|
|
44
|
+
*
|
|
45
|
+
* @param type A non-null type.
|
|
46
|
+
* @param p A state object that passes through the visitor.
|
|
47
|
+
* @return A non-null type.
|
|
48
|
+
*/
|
|
49
|
+
async visitNonNull(type: Type, p: P): Promise<Type> {
|
|
50
|
+
const t = await this.visit(type, p);
|
|
51
|
+
if (!t) {
|
|
52
|
+
throw new Error("Expected non-null type");
|
|
53
|
+
}
|
|
54
|
+
return t;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async visit<T extends Type>(type: T | undefined, p: P): Promise<T | undefined> {
|
|
58
|
+
if (!type) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this.cursor = new Cursor(type, this.cursor);
|
|
63
|
+
|
|
64
|
+
let result = await this.preVisit(type, p);
|
|
65
|
+
if (!result) {
|
|
66
|
+
this.cursor = this.cursor.parent!;
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
switch (result.kind) {
|
|
71
|
+
case Type.Kind.Array:
|
|
72
|
+
result = await this.visitArray(result as Type.Array, p);
|
|
73
|
+
break;
|
|
74
|
+
case Type.Kind.Annotation:
|
|
75
|
+
result = await this.visitAnnotation(result as Type.Annotation, p);
|
|
76
|
+
break;
|
|
77
|
+
case Type.Kind.Class:
|
|
78
|
+
result = await this.visitClass(result as Type.Class, p);
|
|
79
|
+
break;
|
|
80
|
+
case Type.Kind.GenericTypeVariable:
|
|
81
|
+
result = await this.visitGenericTypeVariable(result as Type.GenericTypeVariable, p);
|
|
82
|
+
break;
|
|
83
|
+
case Type.Kind.Intersection:
|
|
84
|
+
result = await this.visitIntersection(result as Type.Intersection, p);
|
|
85
|
+
break;
|
|
86
|
+
case Type.Kind.Union:
|
|
87
|
+
result = await this.visitUnion(result as Type.Union, p);
|
|
88
|
+
break;
|
|
89
|
+
case Type.Kind.Parameterized:
|
|
90
|
+
result = await this.visitParameterized(result as Type.Parameterized, p);
|
|
91
|
+
break;
|
|
92
|
+
case Type.Kind.Primitive:
|
|
93
|
+
result = await this.visitPrimitive(result as Type.Primitive, p);
|
|
94
|
+
break;
|
|
95
|
+
case Type.Kind.Method:
|
|
96
|
+
result = await this.visitMethod(result as Type.Method, p);
|
|
97
|
+
break;
|
|
98
|
+
case Type.Kind.Variable:
|
|
99
|
+
result = await this.visitVariable(result as Type.Variable, p);
|
|
100
|
+
break;
|
|
101
|
+
case Type.Kind.ShallowClass:
|
|
102
|
+
result = await this.visitClass(result as Type.ShallowClass, p);
|
|
103
|
+
break;
|
|
104
|
+
case Type.Kind.Unknown:
|
|
105
|
+
result = await this.visitUnknown(result, p);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (result) {
|
|
110
|
+
result = await this.postVisit(result, p);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
this.cursor = this.cursor.parent!;
|
|
114
|
+
return result as T;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
protected async visitUnion(union: Type.Union, p: P): Promise<Type | undefined> {
|
|
118
|
+
return this.produceType<Type.Union>(union, p, async draft => {
|
|
119
|
+
draft.bounds = await mapAsync(union.bounds || [], b => this.visit(b, p)) as Type[];
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
protected async visitAnnotation(annotation: Type.Annotation, p: P): Promise<Type | undefined> {
|
|
124
|
+
return this.produceType<Type.Annotation>(annotation, p, async draft => {
|
|
125
|
+
draft.type = await this.visit(annotation.type, p) as Type.FullyQualified;
|
|
126
|
+
// Note: values contain element values which themselves contain Type references
|
|
127
|
+
draft.values = await mapAsync(annotation.values || [], async v => {
|
|
128
|
+
const draftValue = createDraft(v);
|
|
129
|
+
draftValue.element = await this.visit(v.element, p) as Type;
|
|
130
|
+
if (v.kind === Type.Kind.SingleElementValue) {
|
|
131
|
+
const single = v as Type.Annotation.SingleElementValue;
|
|
132
|
+
if (single.referenceValue) {
|
|
133
|
+
(draftValue as Draft<Type.Annotation.SingleElementValue>).referenceValue = await this.visit(single.referenceValue, p);
|
|
134
|
+
}
|
|
135
|
+
} else if (v.kind === Type.Kind.ArrayElementValue) {
|
|
136
|
+
const array = v as Type.Annotation.ArrayElementValue;
|
|
137
|
+
if (array.referenceValues) {
|
|
138
|
+
(draftValue as Draft<Type.Annotation.ArrayElementValue>).referenceValues = await mapAsync(
|
|
139
|
+
array.referenceValues,
|
|
140
|
+
rv => this.visit(rv, p)
|
|
141
|
+
) as Type[];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return finishDraft(draftValue);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
protected async visitArray(array: Type.Array, p: P): Promise<Type | undefined> {
|
|
150
|
+
return this.produceType<Type.Array>(array, p, async draft => {
|
|
151
|
+
draft.elemType = await this.visit(array.elemType, p) as Type;
|
|
152
|
+
draft.annotations = await this.visitList(array.annotations, p) as Type.Annotation[] || [];
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
protected async visitClass(aClass: Type.Class, p: P): Promise<Type | undefined> {
|
|
157
|
+
return this.produceType<Type.Class>(aClass, p, async draft => {
|
|
158
|
+
draft.supertype = await this.visit(aClass.supertype, p) as Type.Class | undefined;
|
|
159
|
+
draft.owningClass = await this.visit(aClass.owningClass, p) as Type.Class | undefined;
|
|
160
|
+
draft.annotations = await mapAsync(aClass.annotations || [], a => this.visit(a, p) as Promise<Type.Annotation>);
|
|
161
|
+
draft.interfaces = await mapAsync(aClass.interfaces || [], i => this.visit(i, p) as Promise<Type.Class>);
|
|
162
|
+
draft.members = await mapAsync(aClass.members || [], m => this.visit(m, p) as Promise<Type.Variable>);
|
|
163
|
+
draft.methods = await mapAsync(aClass.methods || [], m => this.visit(m, p) as Promise<Type.Method>);
|
|
164
|
+
draft.typeParameters = await this.visitList(aClass.typeParameters, p) as Type[] || [];
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
protected async visitGenericTypeVariable(generic: Type.GenericTypeVariable, p: P): Promise<Type | undefined> {
|
|
169
|
+
return this.produceType<Type.GenericTypeVariable>(generic, p, async draft => {
|
|
170
|
+
draft.bounds = await mapAsync(generic.bounds || [], b => this.visit(b, p)) as Type[];
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
protected async visitIntersection(intersection: Type.Intersection, p: P): Promise<Type | undefined> {
|
|
175
|
+
return this.produceType<Type.Intersection>(intersection, p, async draft => {
|
|
176
|
+
draft.bounds = await mapAsync(intersection.bounds || [], b => this.visit(b, p)) as Type[];
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* This does not visit the declaring type to avoid a visitor cycle.
|
|
182
|
+
*
|
|
183
|
+
* @param method The method to visit
|
|
184
|
+
* @param p Visit context
|
|
185
|
+
* @return A method
|
|
186
|
+
*/
|
|
187
|
+
protected async visitMethod(method: Type.Method, p: P): Promise<Type | undefined> {
|
|
188
|
+
return this.produceType<Type.Method>(method, p, async draft => {
|
|
189
|
+
draft.declaringType = await this.visit(method.declaringType, p) as Type.FullyQualified;
|
|
190
|
+
draft.returnType = await this.visit(method.returnType, p) as Type;
|
|
191
|
+
draft.parameterTypes = await mapAsync(method.parameterTypes || [], pt => this.visit(pt, p)) as Type[];
|
|
192
|
+
draft.thrownExceptions = await mapAsync(method.thrownExceptions || [], t => this.visit(t, p)) as Type[];
|
|
193
|
+
draft.annotations = await mapAsync(method.annotations || [], a => this.visit(a, p) as Promise<Type.Annotation>);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
protected async visitParameterized(parameterized: Type.Parameterized, p: P): Promise<Type | undefined> {
|
|
198
|
+
return this.produceType<Type.Parameterized>(parameterized, p, async draft => {
|
|
199
|
+
draft.type = await this.visit(parameterized.type, p) as Type.FullyQualified;
|
|
200
|
+
draft.typeParameters = await mapAsync(parameterized.typeParameters || [], t => this.visit(t, p)) as Type[];
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
protected async visitPrimitive(primitive: Type.Primitive, p: P): Promise<Type | undefined> {
|
|
205
|
+
// Primitives are immutable singletons, just return as-is
|
|
206
|
+
return primitive;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* This does not visit the owner to avoid a visitor cycle.
|
|
211
|
+
*
|
|
212
|
+
* @param variable The variable to visit
|
|
213
|
+
* @param p Visit context
|
|
214
|
+
* @return A variable
|
|
215
|
+
*/
|
|
216
|
+
protected async visitVariable(variable: Type.Variable, p: P): Promise<Type | undefined> {
|
|
217
|
+
return this.produceType<Type.Variable>(variable, p, async draft => {
|
|
218
|
+
draft.owner = await this.visit(variable.owner, p);
|
|
219
|
+
draft.type = await this.visit(variable.type, p) as Type;
|
|
220
|
+
draft.annotations = await mapAsync(variable.annotations || [], a => this.visit(a, p) as Promise<Type.Annotation>);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
protected async visitUnknown(unknown: Type, p: P): Promise<Type | undefined> {
|
|
225
|
+
// Unknown types have no properties to visit
|
|
226
|
+
return unknown;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
protected async produceType<T extends Type>(
|
|
230
|
+
before: T,
|
|
231
|
+
p: P,
|
|
232
|
+
recipe?: (draft: Draft<T>) =>
|
|
233
|
+
ValidImmerRecipeReturnType<Draft<T>> |
|
|
234
|
+
PromiseLike<ValidImmerRecipeReturnType<Draft<T>>>
|
|
235
|
+
): Promise<T> {
|
|
236
|
+
if (recipe) {
|
|
237
|
+
return produceAsync<T>(before, recipe);
|
|
238
|
+
}
|
|
239
|
+
return before;
|
|
240
|
+
}
|
|
241
|
+
}
|
package/src/java/type.ts
CHANGED
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {asRef
|
|
17
|
-
import {immerable} from "immer";
|
|
16
|
+
import {asRef} from "../rpc";
|
|
18
17
|
|
|
19
18
|
export interface Type {
|
|
20
19
|
readonly kind: string;
|
|
@@ -41,6 +40,7 @@ export namespace Type {
|
|
|
41
40
|
|
|
42
41
|
export interface Class extends Type, FullyQualified {
|
|
43
42
|
readonly kind: typeof Kind.Class,
|
|
43
|
+
flags: number;
|
|
44
44
|
classKind: Class.Kind;
|
|
45
45
|
fullyQualifiedName: string;
|
|
46
46
|
typeParameters: Type[];
|
|
@@ -91,6 +91,7 @@ export namespace Type {
|
|
|
91
91
|
|
|
92
92
|
export interface Method extends Type {
|
|
93
93
|
readonly kind: typeof Kind.Method;
|
|
94
|
+
flags: number;
|
|
94
95
|
declaringType: Type.FullyQualified;
|
|
95
96
|
name: string;
|
|
96
97
|
returnType: Type;
|
|
@@ -301,37 +302,37 @@ export namespace Type {
|
|
|
301
302
|
case Type.Kind.GenericTypeVariable: {
|
|
302
303
|
const generic = type as Type.GenericTypeVariable;
|
|
303
304
|
let result = "Generic{" + generic.name;
|
|
304
|
-
|
|
305
|
+
|
|
305
306
|
// Initialize stack if needed
|
|
306
307
|
if (typeVariableNameStack === null) {
|
|
307
308
|
typeVariableNameStack = new Set<string>();
|
|
308
309
|
}
|
|
309
|
-
|
|
310
|
+
|
|
310
311
|
// Check for recursion in type variable names
|
|
311
312
|
if (generic.name !== "?" && typeVariableNameStack.has(generic.name)) {
|
|
312
313
|
return result + "}";
|
|
313
314
|
}
|
|
314
|
-
|
|
315
|
+
|
|
315
316
|
// Add to stack to track
|
|
316
317
|
if (generic.name !== "?") {
|
|
317
318
|
typeVariableNameStack.add(generic.name);
|
|
318
319
|
}
|
|
319
|
-
|
|
320
|
+
|
|
320
321
|
try {
|
|
321
322
|
if (!generic.bounds || generic.bounds.length === 0) {
|
|
322
323
|
return result + "}";
|
|
323
324
|
}
|
|
324
|
-
|
|
325
|
+
|
|
325
326
|
// Filter out bounds that would cause cycles through parameterized types
|
|
326
327
|
const safeBounds = generic.bounds.filter(b => {
|
|
327
328
|
return !parameterizedStack || !parameterizedStack.has(b);
|
|
328
329
|
});
|
|
329
|
-
|
|
330
|
+
|
|
330
331
|
if (safeBounds.length > 0) {
|
|
331
332
|
const bounds = safeBounds.map(b => signature(b)).join(" & ");
|
|
332
333
|
result += " extends " + bounds;
|
|
333
334
|
}
|
|
334
|
-
|
|
335
|
+
|
|
335
336
|
return result + "}";
|
|
336
337
|
} finally {
|
|
337
338
|
// Remove from stack when done
|
|
@@ -352,15 +353,15 @@ export namespace Type {
|
|
|
352
353
|
}
|
|
353
354
|
case Type.Kind.Parameterized: {
|
|
354
355
|
const parameterized = type as Type.Parameterized;
|
|
355
|
-
|
|
356
|
+
|
|
356
357
|
// Initialize stack if needed
|
|
357
358
|
if (parameterizedStack === null) {
|
|
358
359
|
parameterizedStack = new Set<Type>();
|
|
359
360
|
}
|
|
360
|
-
|
|
361
|
+
|
|
361
362
|
// Add to stack to track cycles
|
|
362
363
|
parameterizedStack.add(parameterized);
|
|
363
|
-
|
|
364
|
+
|
|
364
365
|
try {
|
|
365
366
|
const baseType = signature(parameterized.type);
|
|
366
367
|
if (!parameterized.typeParameters || parameterized.typeParameters.length === 0) {
|
|
@@ -399,268 +400,3 @@ export namespace Type {
|
|
|
399
400
|
}
|
|
400
401
|
}
|
|
401
402
|
}
|
|
402
|
-
|
|
403
|
-
RpcCodecs.registerCodec(Type.Kind.Primitive, {
|
|
404
|
-
async rpcSend(after: Type.Primitive, q: RpcSendQueue): Promise<void> {
|
|
405
|
-
await q.getAndSend(after, p => p.keyword);
|
|
406
|
-
},
|
|
407
|
-
async rpcReceive(before: Type.Primitive, q: RpcReceiveQueue): Promise<Type.Primitive> {
|
|
408
|
-
const keyword: string = await q.receive(before.keyword);
|
|
409
|
-
return Type.Primitive.fromKeyword(keyword)!;
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
RpcCodecs.registerCodec(Type.Kind.Class, {
|
|
414
|
-
async rpcSend(after: Type.Class, q: RpcSendQueue): Promise<void> {
|
|
415
|
-
await q.getAndSend(after, c => c.classKind);
|
|
416
|
-
await q.getAndSend(after, c => c.fullyQualifiedName);
|
|
417
|
-
await q.getAndSendList(after, c => (c.typeParameters || []).map(t => asRef(t)), t => Type.signature(t));
|
|
418
|
-
await q.getAndSend(after, c => asRef(c.supertype));
|
|
419
|
-
await q.getAndSend(after, c => asRef(c.owningClass));
|
|
420
|
-
await q.getAndSendList(after, c => (c.annotations || []).map(a => asRef(a)), t => Type.signature(t));
|
|
421
|
-
await q.getAndSendList(after, c => (c.interfaces || []).map(i => asRef(i)), t => Type.signature(t));
|
|
422
|
-
await q.getAndSendList(after, c => (c.members || []).map(m => asRef(m)), t => Type.signature(t));
|
|
423
|
-
await q.getAndSendList(after, c => (c.methods || []).map(m => asRef(m)), t => Type.signature(t));
|
|
424
|
-
},
|
|
425
|
-
async rpcReceive(before: Type.Class, q: RpcReceiveQueue): Promise<Type.Class> {
|
|
426
|
-
// Mutate the before object in place to preserve reference identity
|
|
427
|
-
before.classKind = await q.receive(before.classKind);
|
|
428
|
-
before.fullyQualifiedName = await q.receive(before.fullyQualifiedName);
|
|
429
|
-
before.typeParameters = await q.receiveList(before.typeParameters) || [];
|
|
430
|
-
before.supertype = await q.receive(before.supertype);
|
|
431
|
-
before.owningClass = await q.receive(before.owningClass);
|
|
432
|
-
before.annotations = await q.receiveList(before.annotations) || [];
|
|
433
|
-
before.interfaces = await q.receiveList(before.interfaces) || [];
|
|
434
|
-
before.members = await q.receiveList(before.members) || [];
|
|
435
|
-
before.methods = await q.receiveList(before.methods) || [];
|
|
436
|
-
(before as any).toJSON = function () {
|
|
437
|
-
return Type.signature(this);
|
|
438
|
-
};
|
|
439
|
-
// Mark as non-draftable to prevent immer from processing circular references
|
|
440
|
-
(before as any)[immerable] = false;
|
|
441
|
-
|
|
442
|
-
return before;
|
|
443
|
-
}
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
RpcCodecs.registerCodec(Type.Kind.Variable, {
|
|
447
|
-
async rpcSend(after: Type.Variable, q: RpcSendQueue): Promise<void> {
|
|
448
|
-
await q.getAndSend(after, v => v.name);
|
|
449
|
-
await q.getAndSend(after, v => v.owner ? asRef(v.owner) : undefined);
|
|
450
|
-
await q.getAndSend(after, v => asRef(v.type));
|
|
451
|
-
await q.getAndSendList(after, v => (v.annotations || []).map(v2 => asRef(v2)), t => Type.signature(t));
|
|
452
|
-
},
|
|
453
|
-
async rpcReceive(before: Type.Variable, q: RpcReceiveQueue): Promise<Type.Variable> {
|
|
454
|
-
// Mutate the before object in place to preserve reference identity
|
|
455
|
-
before.name = await q.receive(before.name);
|
|
456
|
-
before.owner = await q.receive(before.owner);
|
|
457
|
-
before.type = await q.receive(before.type);
|
|
458
|
-
before.annotations = await q.receiveList(before.annotations) || [];
|
|
459
|
-
return before;
|
|
460
|
-
}
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
RpcCodecs.registerCodec(Type.Kind.Annotation, {
|
|
464
|
-
async rpcSend(after: Type.Annotation, q: RpcSendQueue): Promise<void> {
|
|
465
|
-
await q.getAndSend(after, a => asRef(a.type));
|
|
466
|
-
await q.getAndSendList(after, a => (a.values || []).map(v => asRef(v)), v => {
|
|
467
|
-
let value: any;
|
|
468
|
-
if (v.kind === Type.Kind.SingleElementValue) {
|
|
469
|
-
const single = v as Type.Annotation.SingleElementValue;
|
|
470
|
-
value = single.constantValue !== undefined ? single.constantValue : single.referenceValue;
|
|
471
|
-
} else {
|
|
472
|
-
const array = v as Type.Annotation.ArrayElementValue;
|
|
473
|
-
value = array.constantValues || array.referenceValues;
|
|
474
|
-
}
|
|
475
|
-
return `${Type.signature(v.element)}:${value == null ? "null" : value.toString()}`;
|
|
476
|
-
});
|
|
477
|
-
},
|
|
478
|
-
async rpcReceive(before: Type.Annotation, q: RpcReceiveQueue): Promise<Type.Annotation> {
|
|
479
|
-
// Mutate the before object in place to preserve reference identity
|
|
480
|
-
before.type = await q.receive(before.type);
|
|
481
|
-
before.values = await q.receiveList(before.values) || [];
|
|
482
|
-
return before;
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
RpcCodecs.registerCodec(Type.Kind.SingleElementValue, {
|
|
487
|
-
async rpcSend(after: Type.Annotation.SingleElementValue, q: RpcSendQueue): Promise<void> {
|
|
488
|
-
await q.getAndSend(after, e => asRef(e.element));
|
|
489
|
-
await q.getAndSend(after, e => e.constantValue);
|
|
490
|
-
await q.getAndSend(after, e => asRef(e.referenceValue));
|
|
491
|
-
},
|
|
492
|
-
async rpcReceive(before: Type.Annotation.SingleElementValue | undefined, q: RpcReceiveQueue): Promise<Type.Annotation.SingleElementValue> {
|
|
493
|
-
if (!before) {
|
|
494
|
-
return {
|
|
495
|
-
kind: Type.Kind.SingleElementValue,
|
|
496
|
-
element: (await q.receive(undefined) as unknown) as Type,
|
|
497
|
-
constantValue: await q.receive(undefined),
|
|
498
|
-
referenceValue: await q.receive(undefined)
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
// Mutate the before object in place to preserve reference identity
|
|
502
|
-
before.element = await q.receive(before.element);
|
|
503
|
-
before.constantValue = await q.receive(before.constantValue);
|
|
504
|
-
before.referenceValue = await q.receive(before.referenceValue);
|
|
505
|
-
return before;
|
|
506
|
-
}
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
RpcCodecs.registerCodec(Type.Kind.ArrayElementValue, {
|
|
510
|
-
async rpcSend(after: Type.Annotation.ArrayElementValue, q: RpcSendQueue): Promise<void> {
|
|
511
|
-
await q.getAndSend(after, e => asRef(e.element));
|
|
512
|
-
await q.getAndSendList(after, e => e.constantValues || [], v => v == null ? "null" : v.toString());
|
|
513
|
-
await q.getAndSendList(after, e => (e.referenceValues || []).map(r => asRef(r)), t => Type.signature(t));
|
|
514
|
-
},
|
|
515
|
-
async rpcReceive(before: Type.Annotation.ArrayElementValue | undefined, q: RpcReceiveQueue): Promise<Type.Annotation.ArrayElementValue> {
|
|
516
|
-
if (!before) {
|
|
517
|
-
return {
|
|
518
|
-
kind: Type.Kind.ArrayElementValue,
|
|
519
|
-
element: (await q.receive(undefined) as unknown) as Type,
|
|
520
|
-
constantValues: await q.receiveList(undefined),
|
|
521
|
-
referenceValues: await q.receiveList(undefined)
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
// Mutate the before object in place to preserve reference identity
|
|
525
|
-
before.element = await q.receive(before.element);
|
|
526
|
-
before.constantValues = await q.receiveList(before.constantValues);
|
|
527
|
-
before.referenceValues = await q.receiveList(before.referenceValues);
|
|
528
|
-
return before;
|
|
529
|
-
}
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
RpcCodecs.registerCodec(Type.Kind.Method, {
|
|
533
|
-
async rpcSend(after: Type.Method, q: RpcSendQueue): Promise<void> {
|
|
534
|
-
await q.getAndSend(after, m => asRef(m.declaringType));
|
|
535
|
-
await q.getAndSend(after, m => m.name);
|
|
536
|
-
await q.getAndSend(after, m => asRef(m.returnType));
|
|
537
|
-
await q.getAndSendList(after, m => m.parameterNames || [], v => v);
|
|
538
|
-
await q.getAndSendList(after, m => (m.parameterTypes || []).map(t => asRef(t)), t => Type.signature(t));
|
|
539
|
-
await q.getAndSendList(after, m => (m.thrownExceptions || []).map(t => asRef(t)), t => Type.signature(t));
|
|
540
|
-
await q.getAndSendList(after, m => (m.annotations || []).map(a => asRef(a)), t => Type.signature(t));
|
|
541
|
-
await q.getAndSendList(after, m => m.defaultValue || undefined, v => v);
|
|
542
|
-
await q.getAndSendList(after, m => m.declaredFormalTypeNames || [], v => v);
|
|
543
|
-
},
|
|
544
|
-
async rpcReceive(before: Type.Method, q: RpcReceiveQueue): Promise<Type.Method> {
|
|
545
|
-
// Mutate the before object in place to preserve reference identity
|
|
546
|
-
before.declaringType = await q.receive(before.declaringType);
|
|
547
|
-
before.name = await q.receive(before.name);
|
|
548
|
-
before.returnType = await q.receive(before.returnType);
|
|
549
|
-
before.parameterNames = await q.receiveList(before.parameterNames) || [];
|
|
550
|
-
before.parameterTypes = await q.receiveList(before.parameterTypes) || [];
|
|
551
|
-
before.thrownExceptions = await q.receiveList(before.thrownExceptions) || [];
|
|
552
|
-
before.annotations = await q.receiveList(before.annotations) || [];
|
|
553
|
-
before.defaultValue = await q.receiveList(before.defaultValue);
|
|
554
|
-
before.declaredFormalTypeNames = await q.receiveList(before.declaredFormalTypeNames) || [];
|
|
555
|
-
return before;
|
|
556
|
-
}
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
RpcCodecs.registerCodec(Type.Kind.Array, {
|
|
560
|
-
async rpcSend(after: Type.Array, q: RpcSendQueue): Promise<void> {
|
|
561
|
-
await q.getAndSend(after, a => asRef(a.elemType));
|
|
562
|
-
await q.getAndSendList(after, a => (a.annotations || []).map(ann => asRef(ann)), t => Type.signature(t));
|
|
563
|
-
},
|
|
564
|
-
async rpcReceive(before: Type.Array, q: RpcReceiveQueue): Promise<Type.Array> {
|
|
565
|
-
// Mutate the before object in place to preserve reference identity
|
|
566
|
-
before.elemType = await q.receive(before.elemType);
|
|
567
|
-
before.annotations = await q.receiveList(before.annotations) || [];
|
|
568
|
-
return before;
|
|
569
|
-
}
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
RpcCodecs.registerCodec(Type.Kind.Parameterized, {
|
|
573
|
-
async rpcSend(after: Type.Parameterized, q: RpcSendQueue): Promise<void> {
|
|
574
|
-
await q.getAndSend(after, p => asRef(p.type));
|
|
575
|
-
await q.getAndSendList(after, p => (p.typeParameters || []).map(t => asRef(t)), t => Type.signature(t));
|
|
576
|
-
},
|
|
577
|
-
async rpcReceive(before: Type.Parameterized, q: RpcReceiveQueue): Promise<Type.Parameterized> {
|
|
578
|
-
// Mutate the before object in place to preserve reference identity
|
|
579
|
-
before.type = await q.receive(before.type);
|
|
580
|
-
before.typeParameters = await q.receiveList(before.typeParameters) || [];
|
|
581
|
-
return before;
|
|
582
|
-
}
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
RpcCodecs.registerCodec(Type.Kind.GenericTypeVariable, {
|
|
586
|
-
async rpcSend(after: Type.GenericTypeVariable, q: RpcSendQueue): Promise<void> {
|
|
587
|
-
await q.getAndSend(after, g => g.name);
|
|
588
|
-
// Convert TypeScript enum to Java enum string
|
|
589
|
-
await q.getAndSend(after, g => {
|
|
590
|
-
switch (g.variance) {
|
|
591
|
-
case Type.GenericTypeVariable.Variance.Covariant:
|
|
592
|
-
return 'COVARIANT';
|
|
593
|
-
case Type.GenericTypeVariable.Variance.Contravariant:
|
|
594
|
-
return 'CONTRAVARIANT';
|
|
595
|
-
case Type.GenericTypeVariable.Variance.Invariant:
|
|
596
|
-
default:
|
|
597
|
-
return 'INVARIANT';
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
await q.getAndSendList(after, g => (g.bounds || []).map(b => asRef(b)), t => Type.signature(t));
|
|
601
|
-
},
|
|
602
|
-
async rpcReceive(before: Type.GenericTypeVariable, q: RpcReceiveQueue): Promise<Type.GenericTypeVariable> {
|
|
603
|
-
// Mutate the before object in place to preserve reference identity
|
|
604
|
-
before.name = await q.receive(before.name);
|
|
605
|
-
const varianceStr = await q.receive(before.variance) as any as string;
|
|
606
|
-
// Convert Java enum string to TypeScript enum
|
|
607
|
-
switch (varianceStr) {
|
|
608
|
-
case 'COVARIANT':
|
|
609
|
-
before.variance = Type.GenericTypeVariable.Variance.Covariant;
|
|
610
|
-
break;
|
|
611
|
-
case 'CONTRAVARIANT':
|
|
612
|
-
before.variance = Type.GenericTypeVariable.Variance.Contravariant;
|
|
613
|
-
break;
|
|
614
|
-
case 'INVARIANT':
|
|
615
|
-
default:
|
|
616
|
-
before.variance = Type.GenericTypeVariable.Variance.Invariant;
|
|
617
|
-
break;
|
|
618
|
-
}
|
|
619
|
-
before.bounds = await q.receiveList(before.bounds) || [];
|
|
620
|
-
return before;
|
|
621
|
-
}
|
|
622
|
-
});
|
|
623
|
-
|
|
624
|
-
RpcCodecs.registerCodec(Type.Kind.Union, {
|
|
625
|
-
async rpcSend(after: Type.Union, q: RpcSendQueue): Promise<void> {
|
|
626
|
-
await q.getAndSendList(after, u => (u.bounds || []).map(b => asRef(b)), t => Type.signature(t));
|
|
627
|
-
},
|
|
628
|
-
async rpcReceive(before: Type.Union, q: RpcReceiveQueue): Promise<Type.Union> {
|
|
629
|
-
// Mutate the before object in place to preserve reference identity
|
|
630
|
-
before.bounds = await q.receiveList(before.bounds) || [];
|
|
631
|
-
return before;
|
|
632
|
-
}
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
RpcCodecs.registerCodec(Type.Kind.Intersection, {
|
|
636
|
-
async rpcSend(after: Type.Intersection, q: RpcSendQueue): Promise<void> {
|
|
637
|
-
await q.getAndSendList(after, i => (i.bounds || []).map(b => asRef(b)), t => Type.signature(t));
|
|
638
|
-
},
|
|
639
|
-
async rpcReceive(before: Type.Intersection, q: RpcReceiveQueue): Promise<Type.Intersection> {
|
|
640
|
-
// Mutate the before object in place to preserve reference identity
|
|
641
|
-
before.bounds = await q.receiveList(before.bounds) || [];
|
|
642
|
-
return before;
|
|
643
|
-
}
|
|
644
|
-
});
|
|
645
|
-
|
|
646
|
-
RpcCodecs.registerCodec(Type.Kind.ShallowClass, {
|
|
647
|
-
async rpcSend(after: Type.ShallowClass, q: RpcSendQueue): Promise<void> {
|
|
648
|
-
await q.getAndSend(after, c => c.fullyQualifiedName);
|
|
649
|
-
await q.getAndSend(after, c => asRef(c.owningClass));
|
|
650
|
-
},
|
|
651
|
-
async rpcReceive(before: Type.ShallowClass, q: RpcReceiveQueue): Promise<Type.ShallowClass> {
|
|
652
|
-
before.classKind = Type.Class.Kind.Class;
|
|
653
|
-
before.fullyQualifiedName = await q.receive(before.fullyQualifiedName);
|
|
654
|
-
before.owningClass = await q.receive(before.owningClass);
|
|
655
|
-
return before;
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
|
|
659
|
-
RpcCodecs.registerCodec(Type.Kind.Unknown, {
|
|
660
|
-
async rpcSend(_after: Type, _q: RpcSendQueue): Promise<void> {
|
|
661
|
-
// Unknown type has no additional data
|
|
662
|
-
},
|
|
663
|
-
async rpcReceive(_before: Type, _q: RpcReceiveQueue): Promise<Type> {
|
|
664
|
-
return Type.unknownType;
|
|
665
|
-
}
|
|
666
|
-
});
|