Skip to content

Commit

Permalink
feat(model-api): replaced usages of the deprecated IConceptReference …
Browse files Browse the repository at this point in the history
…with ConceptReference

BREAKING CHANGE: Remaining usages can also simply be replaced with ConceptReference.
  • Loading branch information
slisson committed Feb 28, 2025
1 parent a8b6fcc commit 120a9b7
Show file tree
Hide file tree
Showing 62 changed files with 626 additions and 266 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.modelix.model.sync.bulk

import org.modelix.model.ModelFacade
import org.modelix.model.api.IConceptReference
import org.modelix.model.api.ConceptReference
import org.modelix.model.api.ITree
import org.modelix.model.api.TreePointer
import org.modelix.model.api.getAncestors
Expand Down Expand Up @@ -79,16 +79,16 @@ class InvalidationTreeTest {

private fun getTestTreeData(): ITree {
var tree = ModelFacade.newLocalTree()
tree = tree.addNewChild(ITree.ROOT_ID, null, -1, 2L, null as IConceptReference?)
tree = tree.addNewChild(ITree.ROOT_ID, null, -1, 3L, null as IConceptReference?)
tree = tree.addNewChild(ITree.ROOT_ID, null, -1, 4L, null as IConceptReference?)
tree = tree.addNewChild(ITree.ROOT_ID, null, -1, 2L, null as ConceptReference?)
tree = tree.addNewChild(ITree.ROOT_ID, null, -1, 3L, null as ConceptReference?)
tree = tree.addNewChild(ITree.ROOT_ID, null, -1, 4L, null as ConceptReference?)

tree = tree.addNewChild(3L, null, -1, 31L, null as IConceptReference?)
tree = tree.addNewChild(3L, null, -1, 32L, null as IConceptReference?)
tree = tree.addNewChild(3L, null, -1, 33L, null as IConceptReference?)
tree = tree.addNewChild(3L, null, -1, 31L, null as ConceptReference?)
tree = tree.addNewChild(3L, null, -1, 32L, null as ConceptReference?)
tree = tree.addNewChild(3L, null, -1, 33L, null as ConceptReference?)

tree = tree.addNewChild(31L, null, -1, 311L, null as IConceptReference?)
tree = tree.addNewChild(311L, null, -1, 3111L, null as IConceptReference?)
tree = tree.addNewChild(31L, null, -1, 311L, null as ConceptReference?)
tree = tree.addNewChild(311L, null, -1, 3111L, null as ConceptReference?)

return tree
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.modelix.model.api.ConceptReference
import org.modelix.model.api.IChildLink
import org.modelix.model.api.IChildLinkReference
import org.modelix.model.api.IConcept
import org.modelix.model.api.IConceptReference
import org.modelix.model.api.INode
import org.modelix.model.api.IProperty
import org.modelix.model.api.IPropertyReference
Expand Down Expand Up @@ -126,7 +125,7 @@ abstract class GeneratedConcept<NodeT : ITypedNode, ConceptT : ITypedConcept>(
?: throw IllegalArgumentException("Concept ${getLongName()} doesn't contain reference link $roleKey")
}

override fun getReference(): IConceptReference {
override fun getReference(): ConceptReference {
return ConceptReference(getUID())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package org.modelix.metamodel

import org.modelix.model.api.ConceptReference
import org.modelix.model.api.IChildLink
import org.modelix.model.api.IConcept
import org.modelix.model.api.IConceptReference
import org.modelix.model.api.ILanguage
import org.modelix.model.api.INode
import org.modelix.model.api.IReferenceLink
import org.modelix.model.api.meta.EmptyConcept
import org.modelix.model.api.meta.NullConcept
import org.modelix.model.api.upcast
import kotlin.reflect.KClass

data class UnknownConcept(private val ref: IConceptReference) : EmptyConcept() {
override fun getReference(): IConceptReference {
return ref
data class UnknownConcept(private val ref: ConceptReference) : EmptyConcept() {
override fun getReference(): ConceptReference {
return ref.upcast()
}

override val language: ILanguage?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ data class ConceptReference(val uid: String) : IConceptReference {
return uid
}

@Deprecated("use getUID()", ReplaceWith("getUID()"))
override fun serialize(): String {
return uid
}

override fun toString(): String {
return uid
}

companion object {
fun deserialize(serialized: String?): ConceptReference? = IConceptReference.deserialize(serialized)
}
}

class ConceptReferenceKSerializer : KSerializer<ConceptReference> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface IConcept {
*
* @return concept reference
*/
fun getReference(): IConceptReference
fun getReference(): ConceptReference

/**
* The language this concept is part of.
Expand Down Expand Up @@ -177,7 +177,7 @@ fun IConcept?.getReference(): ConceptReference = this?.getReference().upcast()
* @param superConceptReference a reference to the potential super-concept
* @return true if this concept (or any of its ancestors) has the same UID as the [superConceptReference]
*/
fun IConcept.isSubConceptOf(superConceptReference: IConceptReference): Boolean {
fun IConcept.isSubConceptOf(superConceptReference: ConceptReference): Boolean {
if (this.getUID() == superConceptReference.getUID()) {
return true
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import org.modelix.model.area.IArea
/**
* Reference to an [IConcept].
*/
@Deprecated("use ConceptReference")
@Deprecated("use ConceptReference", replaceWith = ReplaceWith("org.modelix.model.api.ConceptReference"))
interface IConceptReference {
companion object {
private var deserializers: Map<Any, ((String) -> IConceptReference?)> = LinkedHashMap()
private var deserializers: Map<Any, ((String) -> ConceptReference?)> = LinkedHashMap()

@Deprecated("use ConceptReference()")
fun deserialize(serialized: String?): ConceptReference? {
Expand All @@ -23,7 +23,7 @@ interface IConceptReference {
}

@Deprecated("use ILanguageRepository.register")
fun registerDeserializer(key: Any, deserializer: ((String) -> IConceptReference?)) {
fun registerDeserializer(key: Any, deserializer: ((String) -> ConceptReference?)) {
deserializers = deserializers + (key to deserializer)
}

Expand All @@ -43,7 +43,6 @@ interface IConceptReference {
@Deprecated("use ILanguageRepository.resolveConcept")
fun resolve(area: IArea?): IConcept?

@Deprecated("use getUID()")
fun serialize(): String
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface ILanguageRepository {
* @throws RuntimeException if the concept could not be found
* or multiple concepts were found for the given reference
*/
fun resolveConcept(ref: IConceptReference): IConcept {
fun resolveConcept(ref: ConceptReference): IConcept {
return tryResolveConcept(ref) ?: throw RuntimeException("Concept not found: $ref")
}

Expand All @@ -31,7 +31,7 @@ interface ILanguageRepository {
* @return resolved concept or null, if the concept could not be found
* @throws RuntimeException if multiple concepts were found for the given reference
*/
fun tryResolveConcept(ref: IConceptReference): IConcept? {
fun tryResolveConcept(ref: ConceptReference): IConcept? {
val concepts = repositories.map { it to it.resolveConcept(ref.getUID()) }.filterSecondNotNull()
return when (concepts.size) {
0 -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ data class ModelAsArea(val model: IMutableModel) : IArea, IAreaReference {

override fun getRoot(): INode = model.getRootNode().asLegacyNode()

override fun resolveConcept(ref: IConceptReference): IConcept? = ILanguageRepository.resolveConcept(ref)
override fun resolveConcept(ref: ConceptReference): IConcept? = ILanguageRepository.resolveConcept(ref)

override fun resolveNode(ref: INodeReference): INode? = model.resolveNode(ref)?.asLegacyNode()

Expand Down
22 changes: 11 additions & 11 deletions model-api/src/commonMain/kotlin/org/modelix/model/api/INode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ interface INode {
*
* @return concept reference or null if this node is not instance of any concept.
*/
fun getConceptReference(): IConceptReference?
fun getConceptReference(): ConceptReference?

/**
* Returns children of this node for the given role.
Expand Down Expand Up @@ -104,15 +104,15 @@ interface INode {
* @return new child node
*/
@Deprecated("use IChildLink instead of String")
fun addNewChild(role: String?, index: Int, concept: IConceptReference?): INode {
fun addNewChild(role: String?, index: Int, concept: ConceptReference?): INode {
return addNewChild(role, index, concept?.resolve())
}

fun addNewChildren(role: String?, index: Int, concepts: List<IConceptReference?>): List<INode> {
fun addNewChildren(role: String?, index: Int, concepts: List<ConceptReference?>): List<INode> {
return concepts.mapIndexed { i, it -> addNewChild(role, if (index >= 0) index + i else index, it) }
}

fun addNewChildren(link: IChildLink, index: Int, concepts: List<IConceptReference?>): List<INode> {
fun addNewChildren(link: IChildLink, index: Int, concepts: List<ConceptReference?>): List<INode> {
return concepts.mapIndexed { i, it -> addNewChild(link, if (index >= 0) index + i else index, it) }
}

Expand Down Expand Up @@ -213,7 +213,7 @@ interface INode {
fun getChildren(link: IChildLink): Iterable<INode> = getChildren(link.key(this))
fun moveChild(role: IChildLink, index: Int, child: INode) = moveChild(role.key(this), index, child)
fun addNewChild(role: IChildLink, index: Int, concept: IConcept?): INode = addNewChild(role.key(this), index, concept)
fun addNewChild(role: IChildLink, index: Int, concept: IConceptReference?): INode = addNewChild(role.key(this), index, concept)
fun addNewChild(role: IChildLink, index: Int, concept: ConceptReference?): INode = addNewChild(role.key(this), index, concept)
fun getReferenceTarget(link: IReferenceLink): INode? = getReferenceTarget(link.key(this))
fun setReferenceTarget(link: IReferenceLink, target: INode?) = setReferenceTarget(link.key(this), target)
fun setReferenceTarget(role: IReferenceLink, target: INodeReference?) = setReferenceTarget(role.key(this), target)
Expand Down Expand Up @@ -275,7 +275,7 @@ interface IDeprecatedNodeDefaults : INode {
override fun getChildren(role: String?): Iterable<INode> = getChildren(resolveChildLinkOrFallback(role))
override fun moveChild(role: String?, index: Int, child: INode) = moveChild(resolveChildLinkOrFallback(role), index, child)
override fun addNewChild(role: String?, index: Int, concept: IConcept?): INode = addNewChild(resolveChildLinkOrFallback(role), index, concept)
override fun addNewChild(role: String?, index: Int, concept: IConceptReference?): INode = addNewChild(resolveChildLinkOrFallback(role), index, concept)
override fun addNewChild(role: String?, index: Int, concept: ConceptReference?): INode = addNewChild(resolveChildLinkOrFallback(role), index, concept)
override fun getReferenceTarget(role: String): INode? = getReferenceTarget(resolveReferenceLinkOrFallback(role))
override fun getReferenceTargetRef(role: String): INodeReference? = getReferenceTargetRef(resolveReferenceLinkOrFallback(role))
override fun setReferenceTarget(role: String, target: INode?) = setReferenceTarget(resolveReferenceLinkOrFallback(role), target)
Expand All @@ -290,7 +290,7 @@ interface IDeprecatedNodeDefaults : INode {
override fun getChildren(link: IChildLink): Iterable<INode>
override fun moveChild(role: IChildLink, index: Int, child: INode)
override fun addNewChild(role: IChildLink, index: Int, concept: IConcept?): INode
override fun addNewChild(role: IChildLink, index: Int, concept: IConceptReference?): INode
override fun addNewChild(role: IChildLink, index: Int, concept: ConceptReference?): INode
override fun getReferenceTarget(link: IReferenceLink): INode?
override fun setReferenceTarget(link: IReferenceLink, target: INode?)
override fun setReferenceTarget(role: IReferenceLink, target: INodeReference?)
Expand Down Expand Up @@ -340,9 +340,9 @@ fun INode.getConcept(): IConcept? = getConceptReference()?.resolve()
fun INode.getResolvedReferenceTarget(role: String): INode? = getReferenceTargetRef(role)?.resolveIn(getArea()!!)
fun INode.getResolvedConcept(): IConcept? = getConceptReference()?.resolve()

fun INode.addNewChild(role: String?, index: Int): INode = addNewChild(role, index, null as IConceptReference?)
fun INode.addNewChild(role: String?): INode = addNewChild(role, -1, null as IConceptReference?)
fun INode.addNewChild(role: String?, concept: IConceptReference?): INode = addNewChild(role, -1, concept)
fun INode.addNewChild(role: String?, index: Int): INode = addNewChild(role, index, null as ConceptReference?)
fun INode.addNewChild(role: String?): INode = addNewChild(role, -1, null as ConceptReference?)
fun INode.addNewChild(role: String?, concept: ConceptReference?): INode = addNewChild(role, -1, concept)
fun INode.addNewChild(role: String?, concept: IConcept?): INode = addNewChild(role, -1, concept)

fun INode.resolveChildLink(role: String): IChildLink {
Expand Down Expand Up @@ -453,4 +453,4 @@ fun INode.getRoot(): INode = parent?.getRoot() ?: this
fun INode.isInstanceOf(superConcept: IConcept?): Boolean = concept.let { it != null && it.isSubConceptOf(superConcept) }
fun INode.isInstanceOfSafe(superConcept: IConcept): Boolean = tryGetConcept()?.isSubConceptOf(superConcept) ?: false

fun INode.addNewChild(role: IChildLink, index: Int) = addNewChild(role, index, null as IConceptReference?)
fun INode.addNewChild(role: IChildLink, index: Int) = addNewChild(role, index, null as ConceptReference?)
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface ITransaction {
* @param nodeId id of the desired node
* @return reference to the concept of the node or null, if the concept could not be found
*/
fun getConceptReference(nodeId: Long): IConceptReference?
fun getConceptReference(nodeId: Long): ConceptReference?

/**
* Returns the id of the parent node of the given node in the tree of this transaction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ interface ITree {
* @param nodeId id of the desired node
* @return reference to the concept of the node or null, if the concept could not be found
*/
fun getConceptReference(nodeId: Long): IConceptReference?
fun getConceptReference(nodeId: Long): ConceptReference?

/**
* Returns the id of the parent node of the given node in this.
Expand Down Expand Up @@ -198,7 +198,7 @@ interface ITree {
* @param concept concept reference to the concept of the new node
* @return tree with changes
*/
fun addNewChild(parentId: Long, role: String?, index: Int, childId: Long, concept: IConceptReference?): ITree
fun addNewChild(parentId: Long, role: String?, index: Int, childId: Long, concept: ConceptReference?): ITree

/**
* Creates and adds multiple new children of the given concepts to this tree.
Expand Down Expand Up @@ -226,7 +226,7 @@ interface ITree {
*
* @throws [RuntimeException] if the childId already exists
*/
fun addNewChildren(parentId: Long, role: String?, index: Int, newIds: LongArray, concepts: Array<IConceptReference?>): ITree
fun addNewChildren(parentId: Long, role: String?, index: Int, newIds: LongArray, concepts: Array<ConceptReference?>): ITree

/**
* Deletes the given node.
Expand All @@ -246,7 +246,7 @@ interface ITree {
* @param nodeId id of the node
* @param concept the concept ref of the new concept for the node, or null to remove the concept
*/
fun setConcept(nodeId: Long, concept: IConceptReference?): ITree
fun setConcept(nodeId: Long, concept: ConceptReference?): ITree

fun getAllChildrenAsFlow(parentId: Long): Flow<Long> = getAllChildren(parentId).asFlow()
fun getDescendantsAsFlow(nodeId: Long, includeSelf: Boolean = false): Flow<Long> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interface IWriteTransaction : ITransaction {
*
* @return id of the newly created node
*/
fun addNewChild(parentId: Long, role: String?, index: Int, concept: IConceptReference?): Long
fun addNewChild(parentId: Long, role: String?, index: Int, concept: ConceptReference?): Long

/**
* Creates and adds a new child of the given concept to the tree of this transaction.
Expand All @@ -85,18 +85,18 @@ interface IWriteTransaction : ITransaction {
*
* @throws [RuntimeException] if the childId already exists
*/
fun addNewChild(parentId: Long, role: String?, index: Int, childId: Long, concept: IConceptReference?)
fun addNewChild(parentId: Long, role: String?, index: Int, childId: Long, concept: ConceptReference?)

fun addNewChildren(parentId: Long, role: String?, index: Int, concepts: Array<IConceptReference?>): LongArray
fun addNewChildren(parentId: Long, role: String?, index: Int, childIds: LongArray, concepts: Array<IConceptReference?>)
fun addNewChildren(parentId: Long, role: String?, index: Int, concepts: Array<ConceptReference?>): LongArray
fun addNewChildren(parentId: Long, role: String?, index: Int, childIds: LongArray, concepts: Array<ConceptReference?>)

/**
* Sets the concept of the node identified by the given id.
*
* @param nodeId id of the node
* @param concept the new concept, or null to remove the concept
*/
fun setConcept(nodeId: Long, concept: IConceptReference?)
fun setConcept(nodeId: Long, concept: ConceptReference?)

/**
* Deletes the given node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ open class PNodeAdapter(val nodeId: Long, val branch: IBranch) :
return createAdapter(branch.writeTransaction.addNewChild(nodeId, role, index, concept))
}

override fun addNewChild(role: String?, index: Int, concept: IConceptReference?): INode {
override fun addNewChild(role: String?, index: Int, concept: ConceptReference?): INode {
return createAdapter(branch.writeTransaction.addNewChild(nodeId, role, index, concept))
}

override fun addNewChildren(role: String?, index: Int, concepts: List<IConceptReference?>): List<INode> {
override fun addNewChildren(role: String?, index: Int, concepts: List<ConceptReference?>): List<INode> {
return branch.writeTransaction.addNewChildren(nodeId, role, index, concepts.toTypedArray()).map {
createAdapter(it)
}
Expand All @@ -74,7 +74,7 @@ open class PNodeAdapter(val nodeId: Long, val branch: IBranch) :
override fun addNewChildren(
link: IChildLink,
index: Int,
concepts: List<IConceptReference?>,
concepts: List<ConceptReference?>,
): List<INode> {
return branch.writeTransaction.addNewChildren(nodeId, link.key(this), index, concepts.toTypedArray()).map {
createAdapter(it)
Expand All @@ -85,7 +85,7 @@ open class PNodeAdapter(val nodeId: Long, val branch: IBranch) :
return createAdapter(branch.writeTransaction.addNewChild(nodeId, role.key(this), index, concept))
}

override fun addNewChild(role: IChildLink, index: Int, concept: IConceptReference?): INode {
override fun addNewChild(role: IChildLink, index: Int, concept: ConceptReference?): INode {
return createAdapter(branch.writeTransaction.addNewChild(nodeId, role.key(this), index, concept))
}

Expand Down Expand Up @@ -115,7 +115,7 @@ open class PNodeAdapter(val nodeId: Long, val branch: IBranch) :
}
}

override fun getConceptReference(): IConceptReference? {
override fun getConceptReference(): ConceptReference? {
try {
notifyAccess()
return branch.computeRead { branch.transaction.getConceptReference(nodeId) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ open class SimpleConcept(

override fun getUID(): String = uid ?: getLongName()

override fun getReference(): IConceptReference {
override fun getReference(): ConceptReference {
return ConceptReference(getUID())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class Transaction(override val branch: IBranch) : ITransaction {

override fun containsNode(nodeId: Long): Boolean = tree.containsNode(nodeId)
override fun getConcept(nodeId: Long): IConcept? = tree.getConcept(nodeId)
override fun getConceptReference(nodeId: Long): IConceptReference? = tree.getConceptReference(nodeId)
override fun getConceptReference(nodeId: Long): ConceptReference? = tree.getConceptReference(nodeId)
override fun getParent(nodeId: Long): Long = tree.getParent(nodeId)
override fun getRole(nodeId: Long): String? = tree.getRole(nodeId)
override fun getProperty(nodeId: Long, role: String): String? = tree.getProperty(nodeId, role)
Expand Down
Loading

0 comments on commit 120a9b7

Please sign in to comment.