@@ -14,7 +14,7 @@ import {
14
14
} from "./transpilation-package" ;
15
15
import { TRANSPILATION_EPACKAGE_V1 } from "./transpilation-package-v1" ;
16
16
import { ensureEcoreContainsAllDataTypes } from "./ecore-patching" ;
17
- import { NodeAdapter , ParserNode , TraceNode } from "../trace/trace-node" ;
17
+ import { NodeAdapter , TraceNode } from "../trace/trace-node" ;
18
18
19
19
export function saveForStrumentaPlayground < R extends Node > (
20
20
result : ParsingResult < R > , name : string ,
@@ -52,15 +52,15 @@ export class ParserTrace {
52
52
}
53
53
}
54
54
55
- get rootNode ( ) : ParserNode {
55
+ get rootNode ( ) : TraceNode {
56
56
let root ;
57
57
const ast = this . node . get ( "ast" ) ;
58
58
if ( ast ?. nodeDefinition ?. name == "Result" ) {
59
59
root = ast . get ( "root" ) ;
60
60
} else {
61
61
root = ast ;
62
62
}
63
- return new ParserNode ( root ) ;
63
+ return new TraceNode ( root ) ;
64
64
}
65
65
66
66
get issues ( ) : Issue [ ] {
@@ -247,15 +247,17 @@ export class TargetWorkspaceFile extends AbstractWorkspaceFile<TargetNode> {
247
247
}
248
248
249
249
export class SourceNode extends TraceNode {
250
- parent ?: SourceNode ;
250
+
251
+ parent ?: SourceNode = undefined ;
251
252
protected _destinations ?: TargetNode [ ] ;
252
253
253
254
constructor ( wrappedNode : NodeAdapter , protected trace : AbstractTranspilationTrace ,
254
255
public readonly file ?: SourceWorkspaceFile ) {
255
256
super ( wrappedNode ) ;
256
- if ( wrappedNode . parent ) {
257
- this . parent = new SourceNode ( wrappedNode . parent , this . trace , file ) ;
258
- }
257
+ }
258
+
259
+ protected make ( node : NodeAdapter ) : SourceNode {
260
+ return new SourceNode ( node , this . trace , this . file ) ;
259
261
}
260
262
261
263
getDestinationNodes ( ) : TargetNode [ ] {
@@ -265,23 +267,21 @@ export class SourceNode extends TraceNode {
265
267
return this . _destinations ;
266
268
}
267
269
268
- getChildren ( role ?: string ) : SourceNode [ ] {
269
- return this . nodeAdapter . getChildren ( role ) . map ( ( c ) => new SourceNode ( c , this . trace , this . file ) . withParent ( this ) ) ;
270
- }
271
-
272
- get children ( ) : Node [ ] {
273
- return this . getChildren ( ) ;
270
+ getChildren ( role ?: string | symbol ) : SourceNode [ ] {
271
+ return super . getChildren ( role ) as SourceNode [ ] ;
274
272
}
275
273
}
276
274
277
275
export class TargetNode extends TraceNode {
278
- parent ?: TargetNode ;
276
+
277
+ parent ?: TargetNode = undefined ;
279
278
280
279
constructor ( wrapped : NodeAdapter , protected trace : AbstractTranspilationTrace , public file ?: TargetWorkspaceFile ) {
281
280
super ( wrapped ) ;
282
- if ( wrapped . parent ) {
283
- this . parent = new TargetNode ( wrapped . parent , this . trace , this . file ) ;
284
- }
281
+ }
282
+
283
+ protected make ( node : NodeAdapter ) : TargetNode {
284
+ return new TargetNode ( node , this . trace , this . file ) ;
285
285
}
286
286
287
287
getPosition ( ) : Position | undefined {
@@ -317,18 +317,23 @@ export class TargetNode extends TraceNode {
317
317
parent = parent . eContainer ;
318
318
}
319
319
}
320
- this . origin = new SourceNode ( new ECoreNode ( rawOrigin ) , this . trace , file ) ;
320
+ const eCoreNode = new ECoreNode ( rawOrigin ) ;
321
+ this . origin = this . makeSourceNode ( eCoreNode , file ) ;
321
322
}
322
323
}
323
324
return this . origin as SourceNode ;
324
325
}
325
326
326
- getChildren ( role ?: string ) : TargetNode [ ] {
327
- return this . nodeAdapter . getChildren ( role ) . map ( ( c ) => new TargetNode ( c , this . trace , this . file ) ) ;
327
+ protected makeSourceNode ( eCoreNode : ECoreNode , file : SourceWorkspaceFile | undefined ) {
328
+ const sourceNode = new SourceNode ( eCoreNode , this . trace , file ) ;
329
+ if ( eCoreNode . parent ) {
330
+ sourceNode . withParent ( this . makeSourceNode ( eCoreNode . parent , file ) ) ;
331
+ }
332
+ return sourceNode ;
328
333
}
329
334
330
- get children ( ) : Node [ ] {
331
- return this . getChildren ( ) ;
335
+ getChildren ( role ?: string | symbol ) : TargetNode [ ] {
336
+ return super . getChildren ( role ) as TargetNode [ ] ;
332
337
}
333
338
}
334
339
0 commit comments