7
7
Token ,
8
8
WordCompletion ,
9
9
} from "../constraintMenu/AutoCompletion" ;
10
- import { SModelElementImpl , SModelRootImpl , SParentElementImpl , SPortImpl } from "sprotty" ;
10
+ import { SModelElementImpl , SParentElementImpl , SPortImpl } from "sprotty" ;
11
11
import { LabelTypeRegistry } from "../labels/labelTypeRegistry" ;
12
12
import { DfdNodeImpl } from "./nodes" ;
13
13
@@ -148,14 +148,14 @@ export class ReplaceAutoCompleteTree extends AutoCompleteTree {
148
148
149
149
export namespace TreeBuilder {
150
150
export function buildTree (
151
- model : SModelRootImpl ,
152
151
labelTypeRegistry : LabelTypeRegistry ,
152
+ port ?: SPortImpl ,
153
153
) : AutoCompleteNode < WordOrReplacableWord > [ ] {
154
154
return [
155
155
buildSetOrUnsetStatement ( labelTypeRegistry , "set" ) ,
156
156
buildSetOrUnsetStatement ( labelTypeRegistry , "unset" ) ,
157
- buildForwardStatement ( model ) ,
158
- buildAssignStatement ( labelTypeRegistry , model ) ,
157
+ buildForwardStatement ( port ) ,
158
+ buildAssignStatement ( labelTypeRegistry , port ) ,
159
159
] ;
160
160
}
161
161
@@ -173,9 +173,9 @@ export namespace TreeBuilder {
173
173
} ;
174
174
}
175
175
176
- function buildForwardStatement ( model : SModelRootImpl ) {
176
+ function buildForwardStatement ( port ?: SPortImpl ) {
177
177
const inputNode : AutoCompleteNode = {
178
- word : new InputListWord ( model ) ,
178
+ word : new InputListWord ( port ) ,
179
179
children : [ ] ,
180
180
} ;
181
181
return {
@@ -186,20 +186,20 @@ export namespace TreeBuilder {
186
186
187
187
function buildAssignStatement (
188
188
labelTypeRegistry : LabelTypeRegistry ,
189
- model : SModelRootImpl ,
189
+ port ?: SPortImpl ,
190
190
) : AutoCompleteNode < WordOrReplacableWord > {
191
191
const fromNode : AutoCompleteNode = {
192
192
word : new ConstantWord ( "from" ) ,
193
193
children : [
194
194
{
195
- word : new InputListWord ( model ) ,
195
+ word : new InputListWord ( port ) ,
196
196
children : [ ] ,
197
197
} ,
198
198
] ,
199
199
} ;
200
200
const ifNode : AutoCompleteNode = {
201
201
word : new ConstantWord ( "if" ) ,
202
- children : buildCondition ( model , labelTypeRegistry , fromNode ) ,
202
+ children : buildCondition ( labelTypeRegistry , fromNode , port ) ,
203
203
} ;
204
204
return {
205
205
word : new ConstantWord ( "assign" ) ,
@@ -212,7 +212,7 @@ export namespace TreeBuilder {
212
212
} ;
213
213
}
214
214
215
- function buildCondition ( model : SModelRootImpl , labelTypeRegistry : LabelTypeRegistry , nextNode : AutoCompleteNode ) {
215
+ function buildCondition ( labelTypeRegistry : LabelTypeRegistry , nextNode : AutoCompleteNode , port ?: SPortImpl ) {
216
216
const connectors : AutoCompleteNode [ ] = [ "&&" , "||" ] . map ( ( o ) => ( {
217
217
word : new ConstantWord ( o ) ,
218
218
children : [ ] ,
@@ -221,7 +221,7 @@ export namespace TreeBuilder {
221
221
const expressors : AutoCompleteNode [ ] = [
222
222
new ConstantWord ( "TRUE" ) ,
223
223
new ConstantWord ( "FALSE" ) ,
224
- new InputLabelWord ( model , labelTypeRegistry ) ,
224
+ new InputLabelWord ( labelTypeRegistry , port ) ,
225
225
] . map ( ( e ) => ( {
226
226
word : e ,
227
227
children : [ ...connectors , nextNode ] ,
@@ -236,20 +236,14 @@ export namespace TreeBuilder {
236
236
}
237
237
238
238
abstract class InputAwareWord {
239
- constructor ( private model : SModelRootImpl ) { }
239
+ constructor ( private port ?: SPortImpl ) { }
240
240
241
241
protected getAvailableInputs ( ) : string [ ] {
242
- const selectedPorts = this . getSelectedPorts ( this . model ) ;
243
- if ( selectedPorts . length === 0 ) {
244
- return [ ] ;
245
- }
246
- return selectedPorts . flatMap ( ( port ) => {
247
- const parent = port . parent ;
248
- if ( ! ( parent instanceof DfdNodeImpl ) ) {
249
- return [ ] ;
250
- }
242
+ const parent = this . port ?. parent ;
243
+ if ( parent && parent instanceof DfdNodeImpl ) {
251
244
return parent . getAvailableInputs ( ) . filter ( ( input ) => input !== undefined ) as string [ ] ;
252
- } ) ;
245
+ }
246
+ return [ ] ;
253
247
}
254
248
255
249
private getSelectedPorts ( node : SModelElementImpl ) : SPortImpl [ ] {
@@ -386,8 +380,8 @@ class InputWord extends InputAwareWord implements ReplaceableAbstractWord {
386
380
387
381
class InputListWord implements ReplaceableAbstractWord {
388
382
private inputWord : InputWord ;
389
- constructor ( model : SModelRootImpl ) {
390
- this . inputWord = new InputWord ( model ) ;
383
+ constructor ( port ?: SPortImpl ) {
384
+ this . inputWord = new InputWord ( port ) ;
391
385
}
392
386
393
387
completionOptions ( word : string ) : WordCompletion [ ] {
@@ -426,8 +420,8 @@ class InputLabelWord implements ReplaceableAbstractWord {
426
420
private inputWord : InputWord ;
427
421
private labelWord : LabelWord ;
428
422
429
- constructor ( model : SModelRootImpl , labelTypeRegistry : LabelTypeRegistry ) {
430
- this . inputWord = new InputWord ( model ) ;
423
+ constructor ( labelTypeRegistry : LabelTypeRegistry , port ?: SPortImpl ) {
424
+ this . inputWord = new InputWord ( port ) ;
431
425
this . labelWord = new LabelWord ( labelTypeRegistry ) ;
432
426
}
433
427
0 commit comments