Skip to content

[fix] Preserve SysML syntax and comments during round-trip serialization - #2686

Open
cbrun wants to merge 16 commits into
mainfrom
cbr/serializer-validation-cases
Open

cbrun wants to merge 16 commits into
mainfrom
cbr/serializer-validation-cases

Conversation

@cbrun

@cbrun cbrun commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Summary

SysML validation cases exposed declarations and comments that could change or disappear when a model was parsed and serialized again.

  • Preserve connector and succession ends, their explicit multiplicities, and the prefixes and specializations of cross features.
  • Keep transition and expression body members, declared satisfaction subjects, and metadata field redefinitions in their original roles.
  • Preserve explicit snapshot and timeslice syntax and keep comments with the elements they describe.

Verification

Added 23 SysML regression fixtures to the text and model round-trip suites. Ran 6,670 parser tests and 9,784 serializer tests with no failures, including 2,771 text round trips and 3,419 model round trips after removing the parser text adapters.

mvn -o test -Dtest="org.eclipse.syson.sysml.serializer.**,org.eclipse.syson.sysml.parser.**" -Dsurefire.failIfNoSpecifiedTests=false

Auto review

  • Have you reviewed this PR? Please do a first quick review, It is very useful to detect typos and missing copyrights, check comments, check your code... The reviewer will thank you for that :)

Project management

  • Has the pull request been added to the relevant milestone?
  • Have the queue: and review-window: labels been added to the pull request? (In case of doubt, start with the labels queue: triage and review-window: unscheduled)
  • Have the relevant issues been added to the pull request?
  • Have the relevant labels been added to the issues? (package:, type:)
  • Have the relevant issues been added to the same project milestone as the pull request?

Changelog and release notes

  • Has the CHANGELOG.adoc + doc/content/modules/user-manual/pages/release-notes/YYYY.MM.0.adoc been updated to reference the relevant issues?
  • Have the relevant API breaks been described in the CHANGELOG.adoc?
  • Are the new / upgraded dependencies mentioned in the relevant section of the CHANGELOG.adoc?
  • In case of a change with a visual impact, are there any screenshots in the doc/content/modules/user-manual/pages/release-notes/YYYY.MM.0.adoc?
  • In case of a key change, has the change been added to Key highlights section in doc/content/modules/user-manual/pages/release-notes/YYYY.MM.0.adoc?

Documentation

  • Have you included an update of the documentation in your pull request? Please ask yourself if an update (installation manual, user manual, developer manual...) is needed and add one accordingly.

Tests

  • Is the code properly tested? Any pull request (fix, enhancement or new feature) should come with a test (or several). It could be unit tests, integration tests or cypress tests depending on the context. Only doc and releng pull request do not need for tests.

@cbrun cbrun added this to the 2026.12.0 milestone Nov 27, 2026
@cbrun cbrun added queue: triage A reviewer needs to evaluate the capacity to review this PR review-window: unscheduled The PR is not scheduled for review labels Nov 27, 2026
@cbrun
cbrun force-pushed the cbr/serializer-validation-cases branch 3 times, most recently from 89d3c9f to e94363a Compare November 27, 2026 12:39
@cbrun cbrun self-assigned this Nov 27, 2026
cbrun added 16 commits November 27, 2026 16:58
The serializer wrote the direction and the derived/abstract/constant
modifiers of an end feature before end (in end left : Vehicle), which
the parser rejects: defaultReferenceUsage only accepts refPrefix after
end. They are now written right after end, as in the source text.

Covered by connections/end-feature-prefixes.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
…dy field

A metadata body field that redefines two features (:>> level :>> limit;)
was written as :>> level, limit;, which the parser rejects:
metadataBodyUsage takes a single ownedRedefinition before its
featureSpecializationPart. Only the first redefinition is now written
as the field name, the others as their own clauses.

Normalized output used the generic usage declaration for these fields,
which groups the redefinitions the same way; it now uses the field form
too. Every serializer and parser fixture keeps its round trip.

Covered by metadata/metadata-body-feature-with-two-redefinitions.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
…ce usages

snapshot occurrence captured; and timeslice occurrence phase; were
written as snapshot captured; and timeslice phase;: the serializer
always used the compact portionUsage form for plain occurrence usages,
so round-trip output lost the occurrence keyword of the source.

The parser now marks a portion kind followed by a usage keyword with
PORTION_KIND_BEFORE_USAGE_KEYWORD, and the serializer keeps occurrence
when the marker is present. Models without text adapters keep the
compact form. The text-adapter goldens of the parser fixtures that
write timeslice occurrence gain the new marker.

Covered by declarations/portion-usage-occurrence-keyword.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
succession first prepare then [1] dispatch; lost its [1]: the
serializer treated [1] as the implicit multiplicity of a succession end
and wrote it only for a source whose target had another multiplicity.
The parser creates the cross multiplicity of a connector end only from
text, so leaving it out dropped it from the model. Every multiplicity of
a succession or transition end is now written.

Covered by actions/succession-end-multiplicities.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
binding equality bind left = right { end ref ::> extra; } and the same
body after connect left to right lost their body: the body content test
of connectors ignored every unnamed element as a generated helper, so
the extra end, which only references extra, made no body. It now counts
unnamed reference usages that designate something as user-written, as
variant memberships already did.

Covered by connections/binding-connector-body-end.sysml and
connections/connection-usage-body-end.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
transition change first waiting then running { attribute trace; } lost
its attribute: transitions ended with the restricted statement body
(comments and metadata only), while every transition rule ends with a
full actionBody. The members after the transition succession, which
closes the declaration, are now written in the body; trigger, guard and
effect memberships stay in the declaration wherever they are.

Covered by states/transition-usage-body.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
…quirement

satisfy requirement explicit : Required { subject participant redefines
Required::participant; } was written as satisfy requirement explicit :
Required by Required::participant {}: any untyped subject whose
redefinition gave an endpoint path was taken for the by clause. Only a
subject with the shape of satisfactionParameter (unidentified, untyped,
valued by the satisfying feature) is now written after by; other
subjects stay in the body.

Covered by requirements/satisfy-requirement-body-subject.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
end crossPart : Member [0..1] :> allMembers item left : Member; lost the
typing and the subsetting of its cross feature: the end prefix only
wrote the cross feature name, its multiplicity and nonunique, while
ownedCrossFeature declares it like any usage. The cross feature is now
written with the specialization writer, which keeps its clauses, its
multiplicity and its modifiers in source order.

Covered by connections/owned-cross-feature.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
port def Plug; // note was serialized without its note: the empty rule
portConjugation, which builds the implicit conjugated port definition,
starts on the next token of the input, so it took the notes written
before that token as its leading comments, and the serializer never
writes that generated subtree. An end action now leaves those notes
when its rule consumed no token; the next element takes them. The same
happened to a note after a join node followed by a shorthand
succession.

Covered by comments/note-after-port-definition.sysml,
comments/own-line-note-after-port-definition.sysml and
comments/note-after-join-node.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
state mode { // note followed by entry action prepare; lost its note:
the parser attaches it to the StateSubactionMembership as a leading
note, and the state subaction writer, unlike the other membership
writers, wrote neither the leading nor the trailing notes of its
membership. It now writes them around the subaction.

Covered by comments/note-after-state-usage-opening-brace.sysml and
comments/note-after-state-definition-opening-brace.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
…xed members

variant part option; // note lost its note: the parser attaches it to
the VariantMembership as a trailing note, and the writer of
keyword-prefixed memberships (variant, verify, require...) wrote only
the leading notes of the membership. It now writes the trailing notes
after the owned declaration.

Covered by comments/note-after-variant-usage.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
…references a feature

connection link { // note followed by end ::> origin; lost its note: the
parser attaches it to the unnamed reference usage, which the membership
writer renders through the forced declaration, and that path skips the
notes that element dispatch writes. They are now written before it.

Covered by comments/note-after-connection-usage-opening-brace.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
calc def Compute { // note followed by the result expression 2 wrote the
note twice: the parser attaches it to the literal, element dispatch
writes the leading notes of every element, and the expression text of a
standalone expression added them again. A standalone expression is now
rendered without the notes its dispatch already wrote.

Covered by comments/note-before-result-expression.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
connection link connect entrance // note followed by to exitPort; lost
its note at parse time: no rule starts or ends around the note, so no
element took it. The parser now attaches the notes that follow a
connector end to that end, as it does for accept actions, and the
binary and n-ary connector end writers write them right after the end,
terminating a line note so that it cannot swallow the next end.

Covered by comments/note-between-connection-ends.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
(1, 2).{ in operand : T; attribute bias : T; operand + bias } lost the
attribute keyword, return parameters lost return, binding connectors
were dropped and a body without result expression became .{}: body
expressions are rendered as a string that only knows named parameters
and the result expression. When a body has other members, or no result
expression, its members are now rendered with the element renderers
into a separate text (SysMLTextRenderer#relationshipsText), which the
expression text embeds; other bodies keep the compact form.

Covered by expressions/body-expression-without-result.sysml,
expressions/body-expression-return-parameter.sysml,
expressions/body-expression-attribute-usage.sysml and
expressions/body-expression-binding-connector.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
…sion

(1, 2).{ // note followed by in operand : T; operand + operand lost its
note: the parser attaches it to the operand parameter, and the compact
text of a body expression wrote the parameters without their leading
notes. They are now written before each parameter, a line note being
terminated so that it cannot swallow the declaration.

Covered by expressions/body-expression-note.sysml.

Signed-off-by: cbrun <cedric.brun@obeo.fr>
@cbrun
cbrun force-pushed the cbr/serializer-validation-cases branch from e94363a to be46624 Compare November 27, 2026 15:59
@cbrun
cbrun marked this pull request as ready for review November 27, 2026 16:04

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

queue: triage A reviewer needs to evaluate the capacity to review this PR review-window: unscheduled The PR is not scheduled for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant