Skip to content

ST6RI-982 (alternate) Move transition structure preparation out of semantic getters - #831

Draft
seidewitz wants to merge 2 commits into
masterfrom
ST6RI-982-1
Draft

seidewitz wants to merge 2 commits into
masterfrom
ST6RI-982-1

Conversation

@seidewitz

@seidewitz seidewitz commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

This PR continues the line of changes in previous PRs #814 (ST6RI-947), #818 (ST6RI-979) and #822 (ST6RI-981) to separate model preparation from model queries. It can also be considered a proactive prototype for expanding the resolution of the following issue on the succession shorthand to also cover transitions.

  • SYSML21-171 Semantic constraints missing for shorthand succession notation

Background

Previously, the various textual notations for transitions were all parsed into a TransitionUsage without a required transitionLink feature. This was physically inserted into the abstract syntax tree (AST) later by overriding the method addAdditionalMembers in class TransitionUsageAdapter. Further, the shorthand transition notation in which the source is determined lexically (e.g, of the form "then...") was parsed into a TransitionUsage without the initial owned membership that usually determines the transition source. The source was determined later, also as part of the addAdditionalMembers functionality.

Normally, addAdditionalMembers is called from Namespace::doTransform as part of the semantic transformation of a model. However, it was also possible to call TransactionUsage.getSource() before a full transformation was done, in which case the implementation called TransitionUsageAdapter.addAdditionalMembers on-demand. This coupled model queries with structural model mutations and adapter initialization. Such couplings are being systematically removed from the implementation.

For example, consider following model, with a transition that explicitly declares both the source and target states:

state def S {
    state s1;
    transition s1_s2 first s1 accept T then s2;
    state s2;
}

A transition declaration in this form was parsed as referencing it's source state using an alias membership and containing a succession whose target feature was the transition target. Transforming the transition then resulted in an implied reference subsetting from the source end of the contained succession to the alias member, establishing that member as the succession source feature. The method TransitionUsage.getSource returned the alias member reference to the transition source state.

Now consider a version of this model that uses the implied-source shorthand notaion. In this shorthand, the source state is not explicitly denoted in the transaction, but is determined as the lexically nearest previous state before the transition.

state def S {
    state s1;
    then s2;
    state s2;
}

This was parsed similarly to the previous version of the model, but without an alias membership for the source state. The correct source state was computed during transformation and an alias membership referencing this state was physically added to the TransitionUsage. At this point, the TransitionUsage in the AST has the same form as when parsed from the full notation.

So, during semantic transformation of the model, calling TransitionUsageAdapter.transform included an initial call to TransitionUsageAdapter.addAdditionalMembers. The method TransitionUsageAdapter.addAdditionalMembers did two things:

  1. Called computeSource, which added a source alias membership to the TransitionUsage if it had been missing.
  2. Called computeTransitionLinkConnectors, which (among other things) added a transitionLinkFeature to the TransitionUsage as necessary.

The property getter getSource on the TransitionUsage was also implemented to call addAdditionalMembers on the TransitionUsage before actually getting the source element. This ensured that a TransitionUsage parsed from the shorthand notation actually had its source added to the parse tree, so it could be returned by the getter, in the case that the getter was called before transform. However, in this case, the getSource query could result in the physical mutations to the parsed model as described above.

Changes

  1. Parse post-processing.
    • Added TransitionUsageParsePostProcessor, which adds an owned transitionLink feature to a just-parsed TransitionUsage. This is similar to the approach taken in the other PRs mentioned earlier, in which functionality is moved from the adapter for a syntactic element to the post-processor for the element.
  2. Transformation.
    • Removed the method computeSource completely from the TransitionUsageAdapter.
    • Removed adding the transitionLinkFeature from the method computeTransitionLinkConnectors, but left other processing.
    • Moved the call of computeTransitionLinkConnections from addAdditionalMembers to doTransform, and removed addAdditionalMembers.
    • Removed the flag guarding against recursion, since it is no longer necessary.
  3. Query.
    • Updated UsageUtil.getSourceFeatureOf(Transition) to remove the call to TransitionUsageAdapter.addAdditionalMembers, which no longer exists. Revised the functionality of this method so that, if there is not source alias membership, it determines the proper source element and returns that. No alias membership is added to the TransitionUsage.
    • Updated the derivation computation for TransitionUsage.getSource so that it returns the source feature of the succession of a TransitionUsage. If the succession has no source feature, then the proper source is obtained by calling getSourceFeatureOf and attached to the succession source end using an implicit ReferenceSubsetting specialization.

Tests

Added org.omg.sysml.interactive.tests.TransitionUsageTest:

  1. testTransitionSource – Tests that the source (and target) of a longhand transition declaration are computed correctly.
  2. testTransitionSourceWithFeatureChain - Tests that the source feature and source of a transition usage are computed correctly when the source is a feature chain.
  3. testTransitionShorthandNotation – Tests:
    • A TransitionUsage parsed from the shorthand notation has its source set correctly.
    • Once the source is set for a TransitionUsage parsed from the shorthand notation, that TransitionUsage can change position in the abstract syntax tree for a model, and it's source feature won't change.
    • Moving the shorthand transition declaration in the model text and re-parsing can result in a different transition source.
  4. testSuccessionInTransitionUsage – Tests that the source of a transition is set properly, whether or not the TransitionUsage has been transformed.

Test methods
- testTransitionShorthandNotation, checks that, when a transition is
parsed from the shorthand notation, and then moved programmatically in
the model, it retains its already computed source and target values.
(Test passes with implementationf from master.)

- Tests for longhand transitions with and without a feature chain
as source. (Test with source feature chain fails.)
- Adopted an approach for the "source" property shorthand using implied
reference subsetting, analogously to what is done for the plain
succession shorthand. Changed the derivation of the "source" to get the
source of the succession contained in the transition usage.

- Added a TransitionUsageParsePostProcessor to add a transitionLink
feature at the end of a transition usage.

- Removed adding the source and transitionLink features as additional
members in the TransitionUsageAdapter.
@seidewitz seidewitz added this to the 2026-11 milestone Nov 26, 2026
@seidewitz
seidewitz requested a review from adaussy November 26, 2026 00:22
@seidewitz seidewitz self-assigned this Nov 26, 2026
@seidewitz
seidewitz marked this pull request as draft November 26, 2026 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant