@@ -134,17 +134,20 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
134134 fb .flows = append (fb .flows , flow )
135135 } else {
136136 var flow * microflows.SequenceFlow
137- if pendingThenCase != "" {
137+ originAnchor := prevThenAnchor
138+ destAnchor := thisAnchor
139+ if pendingThenCase != "" || pendingThenAnchor != nil {
140+ originAnchor , destAnchor = pendingFlowAnchors (prevThenAnchor , pendingThenAnchor , thisAnchor )
138141 flow = newHorizontalFlowWithCase (lastThenID , actID , pendingThenCase )
139- if pendingThenAnchor != nil {
140- prevThenAnchor = pendingThenAnchor
142+ if pendingThenCase == "" {
143+ flow = newHorizontalFlow ( lastThenID , actID )
141144 }
142145 pendingThenCase = ""
143146 pendingThenAnchor = nil
144147 } else {
145148 flow = newHorizontalFlow (lastThenID , actID )
146149 }
147- applyUserAnchors (flow , prevThenAnchor , thisAnchor )
150+ applyUserAnchors (flow , originAnchor , destAnchor )
148151 fb .flows = append (fb .flows , flow )
149152 }
150153 prevThenAnchor = thisAnchor
@@ -168,15 +171,18 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
168171 if ! thenReturns && needMerge {
169172 if lastThenID != "" {
170173 var flow * microflows.SequenceFlow
171- if pendingThenCase != "" {
174+ originAnchor := prevThenAnchor
175+ destAnchor := (* ast .FlowAnchors )(nil )
176+ if pendingThenCase != "" || pendingThenAnchor != nil {
177+ originAnchor , destAnchor = pendingFlowAnchors (prevThenAnchor , pendingThenAnchor , nil )
172178 flow = newHorizontalFlowWithCase (lastThenID , mergeID , pendingThenCase )
173- if pendingThenAnchor != nil {
174- prevThenAnchor = pendingThenAnchor
179+ if pendingThenCase == "" {
180+ flow = newHorizontalFlow ( lastThenID , mergeID )
175181 }
176182 } else {
177183 flow = newHorizontalFlow (lastThenID , mergeID )
178184 }
179- applyUserAnchors (flow , prevThenAnchor , nil )
185+ applyUserAnchors (flow , originAnchor , destAnchor )
180186 fb .flows = append (fb .flows , flow )
181187 } else {
182188 // Empty THEN body - connect split directly to merge with true case.
@@ -210,17 +216,20 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
210216 fb .flows = append (fb .flows , flow )
211217 } else {
212218 var flow * microflows.SequenceFlow
213- if pendingElseCase != "" {
219+ originAnchor := prevElseAnchor
220+ destAnchor := thisAnchor
221+ if pendingElseCase != "" || pendingElseAnchor != nil {
222+ originAnchor , destAnchor = pendingFlowAnchors (prevElseAnchor , pendingElseAnchor , thisAnchor )
214223 flow = newHorizontalFlowWithCase (lastElseID , actID , pendingElseCase )
215- if pendingElseAnchor != nil {
216- prevElseAnchor = pendingElseAnchor
224+ if pendingElseCase == "" {
225+ flow = newHorizontalFlow ( lastElseID , actID )
217226 }
218227 pendingElseCase = ""
219228 pendingElseAnchor = nil
220229 } else {
221230 flow = newHorizontalFlow (lastElseID , actID )
222231 }
223- applyUserAnchors (flow , prevElseAnchor , thisAnchor )
232+ applyUserAnchors (flow , originAnchor , destAnchor )
224233 fb .flows = append (fb .flows , flow )
225234 }
226235 prevElseAnchor = thisAnchor
@@ -244,16 +253,18 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
244253 if ! elseReturns && needMerge {
245254 if lastElseID != "" {
246255 flow := newUpwardFlow (lastElseID , mergeID )
247- if pendingElseCase != "" {
248- flow .CaseValue = microflows.EnumerationCase {
249- BaseElement : model.BaseElement {ID : model .ID (types .GenerateID ())},
250- Value : pendingElseCase ,
251- }
252- if pendingElseAnchor != nil {
253- prevElseAnchor = pendingElseAnchor
256+ originAnchor := prevElseAnchor
257+ destAnchor := (* ast .FlowAnchors )(nil )
258+ if pendingElseCase != "" || pendingElseAnchor != nil {
259+ originAnchor , destAnchor = pendingFlowAnchors (prevElseAnchor , pendingElseAnchor , nil )
260+ if pendingElseCase != "" {
261+ flow .CaseValue = microflows.EnumerationCase {
262+ BaseElement : model.BaseElement {ID : model .ID (types .GenerateID ())},
263+ Value : pendingElseCase ,
264+ }
254265 }
255266 }
256- applyUserAnchors (flow , prevElseAnchor , nil )
267+ applyUserAnchors (flow , originAnchor , destAnchor )
257268 fb .flows = append (fb .flows , flow )
258269 }
259270 }
@@ -324,17 +335,20 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
324335 fb .flows = append (fb .flows , flow )
325336 } else {
326337 var flow * microflows.SequenceFlow
327- if pendingThenCase != "" {
338+ originAnchor := prevThenAnchor
339+ destAnchor := thisAnchor
340+ if pendingThenCase != "" || pendingThenAnchor != nil {
341+ originAnchor , destAnchor = pendingFlowAnchors (prevThenAnchor , pendingThenAnchor , thisAnchor )
328342 flow = newHorizontalFlowWithCase (lastThenID , actID , pendingThenCase )
329- if pendingThenAnchor != nil {
330- prevThenAnchor = pendingThenAnchor
343+ if pendingThenCase == "" {
344+ flow = newHorizontalFlow ( lastThenID , actID )
331345 }
332346 pendingThenCase = ""
333347 pendingThenAnchor = nil
334348 } else {
335349 flow = newHorizontalFlow (lastThenID , actID )
336350 }
337- applyUserAnchors (flow , prevThenAnchor , thisAnchor )
351+ applyUserAnchors (flow , originAnchor , destAnchor )
338352 fb .flows = append (fb .flows , flow )
339353 }
340354 prevThenAnchor = thisAnchor
@@ -358,16 +372,18 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
358372 if ! thenReturns && needMerge {
359373 if lastThenID != "" {
360374 flow := newUpwardFlow (lastThenID , mergeID )
361- if pendingThenCase != "" {
362- flow .CaseValue = microflows.EnumerationCase {
363- BaseElement : model.BaseElement {ID : model .ID (types .GenerateID ())},
364- Value : pendingThenCase ,
365- }
366- if pendingThenAnchor != nil {
367- prevThenAnchor = pendingThenAnchor
375+ originAnchor := prevThenAnchor
376+ destAnchor := (* ast .FlowAnchors )(nil )
377+ if pendingThenCase != "" || pendingThenAnchor != nil {
378+ originAnchor , destAnchor = pendingFlowAnchors (prevThenAnchor , pendingThenAnchor , nil )
379+ if pendingThenCase != "" {
380+ flow .CaseValue = microflows.EnumerationCase {
381+ BaseElement : model.BaseElement {ID : model .ID (types .GenerateID ())},
382+ Value : pendingThenCase ,
383+ }
368384 }
369385 }
370- applyUserAnchors (flow , prevThenAnchor , nil )
386+ applyUserAnchors (flow , originAnchor , destAnchor )
371387 fb .flows = append (fb .flows , flow )
372388 } else {
373389 // Empty THEN body - connect split directly to merge going down and back up.
0 commit comments