Skip to content

Commit f6e99fa

Browse files
committed
feat(model-api): added missing IRoleDefinition including subtypes
1 parent d4442fb commit f6e99fa

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

model-api/src/commonMain/kotlin/org/modelix/model/api/IChildLink.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import kotlinx.serialization.Serializable
2121
* Representation of a parent-child relationship between [IConcept]s.
2222
*/
2323
@Deprecated("Use IChildLinkReference or IChildLinkDefinition")
24-
interface IChildLink : ILink {
24+
interface IChildLink : ILink, IChildLinkDefinition {
2525
/**
2626
* Specifies if the parent-child relation ship is 1:n.
2727
*/
28-
val isMultiple: Boolean
28+
override val isMultiple: Boolean
2929

3030
@Deprecated("use .targetConcept")
3131
val childConcept: IConcept
@@ -42,16 +42,22 @@ interface IChildLink : ILink {
4242
* If a child role is not ordered, implementations of [[INode.moveChild]] are allowed to fail
4343
* when instructed to move a node in between existing nodes.
4444
*/
45-
val isOrdered
45+
override val isOrdered
4646
get() = true
4747

4848
override fun toReference(): IChildLinkReference = IChildLinkReference.fromIdAndName(getUID(), getSimpleName())
4949
}
5050

51+
sealed interface IChildLinkDefinition : ILinkDefinition {
52+
val isMultiple: Boolean
53+
val isOrdered: Boolean
54+
override fun toReference(): IChildLinkReference
55+
}
56+
5157
fun IChildLink?.toReference(): IChildLinkReference = this?.toReference() ?: NullChildLinkReference
5258

5359
@Serializable
54-
sealed interface IChildLinkReference : IRoleReference {
60+
sealed interface IChildLinkReference : ILinkReference {
5561

5662
override fun toLegacy(): IChildLink
5763

model-api/src/commonMain/kotlin/org/modelix/model/api/ILink.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@ package org.modelix.model.api
55
* A link belongs to one concept and targets another.
66
* It can be an [IChildLink] or an [IReferenceLink].
77
*/
8-
interface ILink : IRole {
8+
@Deprecated("Use ILinkReference or ILinkDefinition")
9+
interface ILink : IRole, ILinkDefinition {
910
/**
1011
* The concept targeted by this link.
1112
*/
13+
override val targetConcept: IConcept
14+
}
15+
16+
sealed interface ILinkDefinition : IRoleDefinition {
1217
val targetConcept: IConcept
18+
override fun toReference(): ILinkReference
19+
}
20+
21+
sealed interface ILinkReference : IRoleReference {
22+
override fun toLegacy(): ILink
1323
}
1424

1525
abstract class LinkFromName : RoleFromName(), ILink {

model-api/src/commonMain/kotlin/org/modelix/model/api/IProperty.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import kotlinx.serialization.Serializable
2121
* Representation of a property within an [IConcept].
2222
*/
2323
@Deprecated("Use IPropertyReference or IPropertyDefinition")
24-
interface IProperty : IRole {
24+
interface IProperty : IRole, IPropertyDefinition {
2525

2626
override fun toReference(): IPropertyReference = IPropertyReference.fromIdAndName(getUID(), getSimpleName())
2727

@@ -30,6 +30,10 @@ interface IProperty : IRole {
3030
}
3131
}
3232

33+
sealed interface IPropertyDefinition : IRoleDefinition {
34+
override fun toReference(): IPropertyReference
35+
}
36+
3337
@Serializable
3438
sealed interface IPropertyReference : IRoleReference {
3539

model-api/src/commonMain/kotlin/org/modelix/model/api/IReferenceLink.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import kotlinx.serialization.Serializable
2121
* Representation of a non-containment reference link between [IConcept]s.
2222
*/
2323
@Deprecated("Use IReferenceLinkReference or IReferenceLinkDefinition")
24-
interface IReferenceLink : ILink {
24+
interface IReferenceLink : ILink, IReferenceLinkDefinition {
2525

2626
override fun toReference(): IReferenceLinkReference = IReferenceLinkReference.fromIdAndName(getUID(), getSimpleName())
2727

@@ -30,8 +30,12 @@ interface IReferenceLink : ILink {
3030
}
3131
}
3232

33+
sealed interface IReferenceLinkDefinition : ILinkDefinition {
34+
override fun toReference(): IReferenceLinkReference
35+
}
36+
3337
@Serializable
34-
sealed interface IReferenceLinkReference : IRoleReference {
38+
sealed interface IReferenceLinkReference : ILinkReference {
3539

3640
override fun toLegacy(): IReferenceLink
3741

model-api/src/commonMain/kotlin/org/modelix/model/api/IRole.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@ import org.modelix.kotlin.utils.ContextValue
88
* It can either be an [IProperty] or an [ILink].
99
*/
1010
@Deprecated("Use IRoleReference or IRoleDefinition")
11-
interface IRole {
11+
interface IRole : IRoleDefinition {
1212
/**
1313
* Returns the concept this role belongs to.
1414
*
1515
* @return concept
1616
*/
17-
fun getConcept(): IConcept
17+
override fun getConcept(): IConcept
1818

1919
/**
2020
* Returns the uid of this role.
2121
*
2222
* @return uid
2323
*/
24-
fun getUID(): String
24+
override fun getUID(): String
2525

2626
/**
2727
* Returns the unqualified name of this role.
2828
*
2929
* @return simple name
3030
*/
31-
fun getSimpleName(): String
31+
override fun getSimpleName(): String
3232

3333
@Deprecated("Use getSimpleName() when showing it to the user or when accessing the model use the INode functions that accept an IRole or use IRole.key(...)")
3434
val name: String get() = RoleAccessContext.getKey(this)
@@ -38,8 +38,16 @@ interface IRole {
3838
*
3939
* @return true if this role's value is optional, false otherwise
4040
*/
41-
val isOptional: Boolean
41+
override val isOptional: Boolean
4242

43+
override fun toReference(): IRoleReference
44+
}
45+
46+
sealed interface IRoleDefinition {
47+
fun getConcept(): IConcept
48+
fun getUID(): String
49+
fun getSimpleName(): String
50+
val isOptional: Boolean
4351
fun toReference(): IRoleReference
4452
}
4553

0 commit comments

Comments
 (0)