Add Record and Data classes#2232
Conversation
|
Thanks, this sounds like a good idea. However, I would have used "dataclass" instead of "data class" (for consistency with other type) Which means change the regex Does it make sense ? |
|
I may be wrong, but shouldn't we have |
|
Many thanks for your contribution! If possible, could you also add some basic examples to https://github.com/plantuml/pdiff ? This tool is used to manage non-regression tests. If you're unsure how to do this, feel free to share your examples here in the thread, we'll be happy to add them to PS: |
|
Yeah without a reference I have no idea how to add my references there, however I can show some examples here for These are the java classes: The java code for the record public record Key(String namespace, String key) {
public static final Pattern NAMESPACED_KEY_PATTERN = Pattern.compile("^[a-z0-9._-]+:[a-z0-9._-]+$");
public Key(String namespace, String key) {
this.namespace = namespace.toLowerCase(Locale.ROOT);
this.key = key.toLowerCase(Locale.ROOT);
if (!NAMESPACED_KEY_PATTERN.matcher(this.full()).matches()) {
throw new IllegalArgumentException("Invalid NS key: " + this.full());
}
}
public String full() {
return namespace + ":" + key;
}
@Override
public String toString() {
return "Key[" +
"namespace=" + namespace + ", " +
"key=" + key + ']';
}
}To PlantUML @startuml
record Key {
- namespace : String
- key : String
+ {static} NAMESPACED_KEY_PATTERN : Pattern
+ Key(namespace : String, key : String)
+ full() : String
+ toString() : String
}
@endumlA java POJO (dataclass example) // lombok data annotation generates setters and getters
@Data public class AngleData {
private double horizontalAngle;
private double verticalAngle;
private double additionalHorizontalAngle;
private double additionalVerticalAngle;
}To PlantUML dataclass AngleData <<lombok>> {
- aimingPitch : double
- aimingYaw : double
- aimingFinished : boolean
- lastAimed : long
- timestampAimingMode : long
} |
|
For the record, done here plantuml/pdiff@f2d71d2 |
|
To anticipate new request...
Hints:
Ref.: Regards, |
I think the module keyword might be useful in the future for adding another layer of abstraction over packages Also worth considering are sealed classes, though they’d require special handling to define permitted subclasses |
|
[Just for the record] I found (also) this request: Regards, |
…ywords] (#2336) * 🐛 add `floating note` on Language Descriptor Fix /issues/2334 * ✨ add Network Diagram keywords on Language Descriptor * ⚗️ add minimum Timing Diagram keywords on Language Descriptor * 🐛 fix Activity Diagram keywords on Language Descriptor * 🔥 suppress duplicate `bold` on Language Descriptor * ✨ add `dataclass` and `record` on Language Descriptor Ref.: - #2232 * 🐛 fix JSON/YAML keywords on Language Descriptor * 🚧 add Preproc keywords on Language Descriptor To be conform to: - https://github.com/plantuml/plantuml/blob/7d3a9ce1abdba648497c2bb7e73c8b40d415631a/src/main/java/net/sourceforge/plantuml/text/TLineType.java
I used #1028 and #1056 as a base, Data classes are a mutable set of data, whereas record are immutable set of data, many programming language implemented the latter (Java, C#, etc.), the former is less used but still present (POJOs and kotlin's data classes).
Let me know if there are any needed change, or I missed something