Repository navigation
[Puml Parser] Support free functions in class diagram #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hoe-jo
merged 1 commit into
eclipse-score:main
from
melodyoncode:melody_puml_parse_free_function
Oct 13, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <!-- ---------------------------------------------------------------------------- | ||
| Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
|
|
||
| See the NOTICE file(s) distributed with this work for additional | ||
| information regarding copyright ownership. | ||
|
|
||
| This program and the accompanying materials are made available under the | ||
| terms of the Apache License Version 2.0 which is available at | ||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 | ||
| ----------------------------------------------------------------------------- --> | ||
|
|
||
| # Class Diagram Support Guide | ||
|
|
||
| This guide describes class-diagram syntax that has specific semantic meaning in | ||
| the PlantUML parser and resolver. | ||
|
|
||
| ## Free functions | ||
|
|
||
| Use an `entity` with the `<<function>>` stereotype to group free functions. | ||
| The entity is a syntactic container only and is omitted from the resolved | ||
| class-diagram model. Its methods resolve as free functions in the enclosing | ||
| namespace. | ||
|
|
||
| ```plantuml | ||
| @startuml algorithms | ||
| namespace amp { | ||
| namespace algorithm { | ||
| entity Placeholder <<function>> { | ||
| + clamp(value, min, max) | ||
| + max<T>(a, b) | ||
| } | ||
| } | ||
| } | ||
| @enduml | ||
| ``` | ||
|
|
||
| This resolves to the free functions `amp.algorithm.clamp` and `amp.algorithm.max`. | ||
| Visibility markers such as `+` are accepted for PlantUML compatibility and do not | ||
| affect free-function semantics. | ||
|
|
||
| The parser currently preserves only the entity's name, namespace, package, | ||
| stereotypes, and methods. Entity-level template parameters, `extends` and | ||
| `implements` clauses, attributes, and `using` type aliases are not represented | ||
| in the entity model. The grammar may accept these constructs, but the parser | ||
| silently drops them, so do not rely on them. Use method-level template | ||
| parameters for templated free functions. | ||
|
|
||
| An `entity` without `<<function>>` is not modeled as a class-diagram entity. | ||
| Use the corresponding PlantUML declaration (`class`, `interface`, or `struct`) | ||
| to model those element kinds. The `entity <<function>>` handling is a focused | ||
| extension for grouping free functions, not a general substitute for those | ||
| declarations. |
29 changes: 29 additions & 0 deletions
29
...tuml/parser/integration_test/class_diagram/free_function_entity/free_function_entity.puml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| ' ******************************************************************************* | ||
| ' Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| ' | ||
| ' See the NOTICE file(s) distributed with this work for additional | ||
| ' information regarding copyright ownership. | ||
| ' | ||
| ' This program and the accompanying materials are made available under the | ||
| ' terms of the Apache License Version 2.0 which is available at | ||
| ' https://www.apache.org/licenses/LICENSE-2.0 | ||
| ' | ||
| ' SPDX-License-Identifier: Apache-2.0 | ||
| ' ******************************************************************************* | ||
|
|
||
| @startuml free_function_entity | ||
|
|
||
| namespace amp { | ||
| namespace algorithm { | ||
| entity Placeholder <<function>> { | ||
| + clamp(value, min, max) | ||
| + Submit<CallableType, ArgumentTypes...>(callable, arguments) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| entity amp.algorithm.Qualified <<function>> { | ||
| + qualified() | ||
| } | ||
|
|
||
| @enduml |
81 changes: 81 additions & 0 deletions
81
plantuml/parser/integration_test/class_diagram/free_function_entity/output.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| { | ||
| "free_function_entity.puml": { | ||
| "name": "free_function_entity", | ||
| "entities": [], | ||
| "free_functions": [ | ||
| { | ||
| "name": "clamp", | ||
| "enclosing_namespace_id": "amp.algorithm", | ||
| "return_type": null, | ||
| "parameters": [ | ||
| { | ||
| "name": "value", | ||
| "param_type": null, | ||
| "is_variadic": false | ||
| }, | ||
| { | ||
| "name": "min", | ||
| "param_type": null, | ||
| "is_variadic": false | ||
| }, | ||
| { | ||
| "name": "max", | ||
| "param_type": null, | ||
| "is_variadic": false | ||
| } | ||
| ], | ||
| "template_parameters": null, | ||
| "source_location": { | ||
| "file": "", | ||
| "line": 19 | ||
| } | ||
| }, | ||
| { | ||
| "name": "Submit", | ||
| "enclosing_namespace_id": "amp.algorithm", | ||
| "return_type": null, | ||
| "parameters": [ | ||
| { | ||
| "name": "callable", | ||
| "param_type": null, | ||
| "is_variadic": false | ||
| }, | ||
| { | ||
| "name": "arguments", | ||
| "param_type": null, | ||
| "is_variadic": false | ||
| } | ||
| ], | ||
| "template_parameters": [ | ||
| { | ||
| "Type": { | ||
| "name": "CallableType", | ||
| "is_pack": false | ||
| } | ||
| }, | ||
| { | ||
| "Type": { | ||
| "name": "ArgumentTypes", | ||
| "is_pack": true | ||
| } | ||
| } | ||
| ], | ||
| "source_location": { | ||
| "file": "", | ||
| "line": 20 | ||
| } | ||
| }, | ||
| { | ||
| "name": "qualified", | ||
| "enclosing_namespace_id": "amp.algorithm", | ||
| "return_type": null, | ||
| "parameters": [], | ||
| "template_parameters": null, | ||
| "source_location": { | ||
| "file": "", | ||
| "line": 26 | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template params, extends/implements, attributes and type aliases on an entity are dropped silently. entity E <>andentity E extends Base <> both parse with no diagnostic. Reject or document.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've documented this limitation in the class-diagram support guide. I’m keeping the current behavior unchanged rather than adding rejection logic in this change.
After the abstract of class/interface/struct/..., maybe rejecting these constructs can be handled as a follow-up.