Skip to content
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

MODELIX-969 conceptAlias does not seem to work #878

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.modelix.metamodel.typed
import org.modelix.metamodel.untyped
import org.modelix.model.ModelFacade
import org.modelix.model.api.INode
import org.modelix.model.api.conceptAlias
import org.modelix.model.api.getRootNode
import org.modelix.model.data.ConceptData
import org.modelix.model.data.ModelData
Expand Down Expand Up @@ -84,6 +85,11 @@ class GeneratedApiTest {
assertEquals("class", alias)
}

@Test
fun `alias can be retrieved via conceptAlias`() {
assertEquals(C_ClassConcept.alias, C_ClassConcept.untyped().conceptAlias())
}

private fun KAnnotatedElement.hasDeprecationWithMessage() =
findAnnotation<Deprecated>()?.message?.isNotEmpty() ?: false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ internal class ConceptObjectGenerator(
addSuperclassConstructorParameter(concept.abstract.toString())
addInstanceClassGetter()
addTypedFun()
addConceptPropertiesGetter()
addLanguageProperty()
addWrapFun()
if (concept.uid != null) {
Expand Down Expand Up @@ -99,6 +100,25 @@ internal class ConceptObjectGenerator(
addProperty(propertySpec)
}

private fun TypeSpec.Builder.addConceptPropertiesGetter() {
if (concept.metaProperties.isEmpty()) return

val getConceptPropertyFun = FunSpec.builder(GeneratedConcept<*, *>::getConceptProperty.name).runBuild {
val paramName = GeneratedConcept<*, *>::getConceptProperty.parameters.first().name ?: "name"
returns(String::class.asTypeName().copy(nullable = true))
addParameter(paramName, String::class)
addModifiers(KModifier.OVERRIDE)
beginControlFlow("return when (%N)", paramName)
for ((key, _) in concept.metaProperties) {
addStatement("""%S -> %T.%N""", key, concept.conceptWrapperInterfaceClass(), key)
}
addStatement("else -> null")
endControlFlow()
}

addFunction(getConceptPropertyFun)
}

private fun TypeSpec.Builder.addConceptObjectChildLink(childLink: ProcessedChildLink) {
val methodName = if (childLink.multiple) {
"newChildListLink"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ internal class ConceptWrapperInterfaceGenerator(
private fun TypeSpec.Builder.addConceptMetaPropertiesIfNecessary() {
if (conceptPropertiesInterfaceName == null) return

// TODO use IConcept.getConceptProperty(name: String)
concept.metaProperties.forEach { (key, value) ->
for ((key, value) in concept.metaProperties) {
val propertySpec = PropertySpec.builder(key, String::class.asTypeName()).runBuild {
addModifiers(KModifier.OVERRIDE)
initializer("%S", value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ import org.modelix.modelql.untyped.property
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.time.Duration.Companion.seconds
import kotlin.time.ExperimentalTime

class HtmlBuilderTest {
@OptIn(ExperimentalTime::class)
private fun runTest(block: suspend (HttpClient) -> Unit) = testApplication {
withTimeout(10.seconds) {
withTimeout(20.seconds) {
application {
val tree = CLTree(ObjectStoreCache(MapBaseStore()))
val branch = PBranch(tree, IdGenerator.getInstance(1))
Expand Down
Loading