Skip to content
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
@@ -1,5 +1,5 @@
/*
* Copyright 2025, TeamDev. All rights reserved.
* Copyright 2026, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -80,6 +80,12 @@ public val FieldType.isMap: Boolean
public val FieldType.isSingular: Boolean
get() = isMessage || isEnum || isPrimitive

/**
* Tells if this [FieldType] represents a `repeated` of messages.
*/
public val FieldType.isRepeatedMessage: Boolean
get() = isList && list.isMessage
Comment thread
alexander-yevsyukov marked this conversation as resolved.

/**
* Obtains a cardinality of this field type.
*
Expand Down
109 changes: 83 additions & 26 deletions api/src/test/kotlin/io/spine/tools/compiler/ast/FieldTypeSpec.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025, TeamDev. All rights reserved.
* Copyright 2026, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -58,30 +58,42 @@ internal class FieldTypeSpec {
`provide type name for diagnostics` : TypeTest() {

/** Obtains a type name of the field with the given name. */
private fun nameOf(fieldName: String) = typeOf(fieldName).name
private fun nameOf(fieldName: String): String = typeOf(fieldName).name

@Test
fun `when primitive`() = nameOf("count") shouldBe "int32"
fun `when primitive`() {
nameOf("count") shouldBe "int32"
}

@Test
fun `when message`() = nameOf("email") shouldBe "given.type.Email"
fun `when message`() {
nameOf("email") shouldBe "given.type.Email"
}

@Test
fun `when enum`() = nameOf("assumed") shouldBe "given.type.Priority"
fun `when enum`() {
nameOf("assumed") shouldBe "given.type.Priority"
}

@Test
fun `when repeated primitive`() = nameOf("counts") shouldBe "repeated uint64"
fun `when repeated primitive`() {
nameOf("counts") shouldBe "repeated uint64"
}

@Test
fun `when repeated message`() = nameOf("emails") shouldBe "repeated given.type.Email"
fun `when repeated message`() {
nameOf("emails") shouldBe "repeated given.type.Email"
}

@Test
fun `when map with primitive values`() =
fun `when map with primitive values`() {
nameOf("histogram") shouldBe "map<string, sint64>"
}

@Test
fun `when map with message values`() =
fun `when map with message values`() {
nameOf("sorted") shouldBe "map<int32, given.type.Email>"
}

@Test
fun `returning the name of 'kindCase' otherwise`() {
Expand Down Expand Up @@ -127,19 +139,38 @@ internal class FieldTypeSpec {
FieldType.getDefaultInstance().isSingular shouldBe false
}

@Test
fun `tell if it is repeated message`() {
val messageType = FieldSamples.getDescriptor().toMessageType()
fun isRepeatedMessage(fieldName: String) =
messageType.field(fieldName).type.isRepeatedMessage

isRepeatedMessage("email") shouldBe false
isRepeatedMessage("counts") shouldBe false
isRepeatedMessage("sorted") shouldBe false
isRepeatedMessage("count") shouldBe false
isRepeatedMessage("emails") shouldBe true
}

@Nested inner class
`obtain cardinality of` : TypeTest() {

private fun cardinalityOf(fieldName: String): Cardinality = typeOf(fieldName).cardinality

@Test
fun `single fields`() = cardinalityOf("count") shouldBe CARDINALITY_SINGLE
fun `single fields`() {
cardinalityOf("count") shouldBe CARDINALITY_SINGLE
}

@Test
fun `list fields`() = cardinalityOf("counts") shouldBe CARDINALITY_LIST
fun `list fields`() {
cardinalityOf("counts") shouldBe CARDINALITY_LIST
}

@Test
fun `map fields`() = cardinalityOf("histogram") shouldBe CARDINALITY_MAP
fun `map fields`() {
cardinalityOf("histogram") shouldBe CARDINALITY_MAP
}

@Test
fun `throwing when no type information available`() {
Expand All @@ -161,12 +192,14 @@ internal class FieldTypeSpec {
}

@Test
fun `when message`() =
fun `when message`() {
toType("email") shouldBe type { message = Email.getDescriptor().name() }
}

@Test
fun `when enum`() =
fun `when enum`() {
toType("assumed") shouldBe type { enumeration = Priority.getDescriptor().name() }
}

@Test
fun `rejecting when list`() {
Expand Down Expand Up @@ -197,13 +230,19 @@ internal class FieldTypeSpec {
private val expected = Email.getDescriptor().toMessageType()

@Test
fun `when message`() = messageTypeFrom("email") shouldBe expected
fun `when message`() {
messageTypeFrom("email") shouldBe expected
}

@Test
fun `when list`() = messageTypeFrom("emails") shouldBe expected
fun `when list`() {
messageTypeFrom("emails") shouldBe expected
}

@Test
fun `when map`() = messageTypeFrom("sorted") shouldBe expected
fun `when map`() {
messageTypeFrom("sorted") shouldBe expected
}

@Test
fun `returning 'null' for other types`() {
Expand Down Expand Up @@ -251,13 +290,19 @@ internal class FieldTypeSpec {
typeOf(fieldName).extractPrimitiveType()

@Test
fun `from singular`() = extractFrom("count") shouldBe TYPE_INT32
fun `from singular`() {
extractFrom("count") shouldBe TYPE_INT32
}

@Test
fun `from list`() = extractFrom("counts") shouldBe TYPE_UINT64
fun `from list`() {
extractFrom("counts") shouldBe TYPE_UINT64
}

@Test
fun `from map`() = extractFrom("histogram") shouldBe TYPE_SINT64
fun `from map`() {
extractFrom("histogram") shouldBe TYPE_SINT64
}

@Test
fun `returning 'null' if does not refer to a primitive type`() {
Expand All @@ -277,22 +322,34 @@ internal class FieldTypeSpec {
private val expectedMessageType = Email.getDescriptor().toType()

@Test
fun `when primitive`() = extractFrom("count") shouldBe TYPE_INT32.toType()
fun `when primitive`() {
extractFrom("count") shouldBe TYPE_INT32.toType()
}

@Test
fun `when list of primitives`() = extractFrom("counts") shouldBe TYPE_UINT64.toType()
fun `when list of primitives`() {
extractFrom("counts") shouldBe TYPE_UINT64.toType()
}

@Test
fun `when message`() = extractFrom("email") shouldBe expectedMessageType
fun `when message`() {
extractFrom("email") shouldBe expectedMessageType
}

@Test
fun `when message list`() = extractFrom("emails") shouldBe expectedMessageType
fun `when message list`() {
extractFrom("emails") shouldBe expectedMessageType
}

@Test
fun `when a map with messages`() = extractFrom("sorted") shouldBe expectedMessageType
fun `when a map with messages`() {
extractFrom("sorted") shouldBe expectedMessageType
}

@Test
fun `when a map with primitives`() = extractFrom("histogram") shouldBe TYPE_SINT64.toType()
fun `when a map with primitives`() {
extractFrom("histogram") shouldBe TYPE_SINT64.toType()
}

@Test
fun `throwing when type info is not available`() {
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ buildscript {
configurations.all {
resolutionStrategy {
force(
io.spine.dependency.lib.JetBrainsAnnotations.lib,
io.spine.dependency.lib.Protobuf.javaLib,
io.spine.dependency.local.Logging.grpcContext,
io.spine.dependency.local.ToolBase.intellijPlatform,
Expand Down
7 changes: 2 additions & 5 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ plugins {
java
groovy
`kotlin-dsl`
Comment thread
alexander-yevsyukov marked this conversation as resolved.

// https://github.com/jk1/Gradle-License-Report/releases
id("com.github.jk1.dependency-license-report").version("2.9")
}

repositories {
Expand Down Expand Up @@ -118,7 +115,7 @@ val protobufPluginVersion = "0.9.6"
* @see <a href="https://github.com/Kotlin/dokka/releases">
* Dokka Releases</a>
*/
val dokkaVersion = "2.1.0"
val dokkaVersion = "2.2.0"

/**
* The version of Detekt Gradle Plugin.
Expand All @@ -144,7 +141,7 @@ val koverVersion = "0.9.1"
*
* @see <a href="https://github.com/GradleUp/shadow">Shadow Plugin releases</a>
*/
val shadowVersion = "9.2.2"
val shadowVersion = "9.4.1"

/**
* The version of JUnit used to test the build scripts.
Expand Down
5 changes: 4 additions & 1 deletion buildSrc/src/main/kotlin/io/spine/dependency/build/Dokka.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

package io.spine.dependency.build

import io.spine.dependency.build.Dokka.GradlePlugin.id
import io.spine.dependency.local.Spine

// https://github.com/Kotlin/dokka
@Suppress("unused", "ConstPropertyName")
object Dokka {
Expand Down Expand Up @@ -76,7 +79,7 @@ object Dokka {
* Custom Dokka Plugins</a>
*/
object SpineExtensions {
private const val group = "io.spine.tools"
private const val group = Spine.toolsGroup

const val version = "2.0.0-SNAPSHOT.7"
const val lib = "$group:spine-dokka-extensions:$version"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2026, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package io.spine.dependency.lib

/**
* Annotations library from JetBrains.
*
* https://github.com/JetBrains/java-annotations
*/
object JetBrainsAnnotations {
/**
* The version of the library transitively used.
*/
const val version = "23.0.0"
const val groupId = "org.jetbrains"
const val artifactId = "annotations"
const val lib = "$groupId:$artifactId:$version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import io.spine.dependency.Dependency
)
object Compiler : Dependency() {
const val pluginGroup = Spine.group
override val group = "io.spine.tools"
override val group = Spine.toolsGroup
const val pluginId = "io.spine.compiler"

/**
Expand All @@ -72,7 +72,7 @@ object Compiler : Dependency() {
* The version of the Compiler dependencies.
*/
override val version: String
private const val fallbackVersion = "2.0.0-SNAPSHOT.041"
private const val fallbackVersion = "2.0.0-SNAPSHOT.043"

/**
* The distinct version of the Compiler used by other build tools.
Expand All @@ -81,7 +81,7 @@ object Compiler : Dependency() {
* transitive dependencies, this is the version used to build the project itself.
*/
val dogfoodingVersion: String
private const val fallbackDfVersion = "2.0.0-SNAPSHOT.041"
private const val fallbackDfVersion = "2.0.0-SNAPSHOT.043"

/**
* The artifact for the Compiler Gradle plugin.
Expand Down
12 changes: 6 additions & 6 deletions buildSrc/src/main/kotlin/io/spine/dependency/local/CoreJvm.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025, TeamDev. All rights reserved.
* Copyright 2026, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,7 +39,7 @@ typealias CoreJava = CoreJvm
@Suppress("ConstPropertyName", "unused")
object CoreJvm {
const val group = Spine.group
const val version = "2.0.0-SNAPSHOT.372"
const val version = "2.0.0-SNAPSHOT.373"

const val coreArtifact = "spine-core"
const val clientArtifact = "spine-client"
Expand All @@ -50,9 +50,9 @@ object CoreJvm {
const val server = "$group:$serverArtifact:$version"

@Deprecated("Use `serverTestLib` instead.", ReplaceWith("serverTestLib"))
const val testUtilServer = "${Spine.toolsGroup}:spine-server-testlib:$version"
const val testUtilServer = "${Spine.toolsGroup}:server-testlib:$version"

const val coreTestLib = "${Spine.toolsGroup}:spine-core-testlib:$version"
const val clientTestLib = "${Spine.toolsGroup}:spine-client-testlib:$version"
const val serverTestLib = "${Spine.toolsGroup}:spine-server-testlib:$version"
const val coreTestLib = "${Spine.toolsGroup}:core-testlib:$version"
const val clientTestLib = "${Spine.toolsGroup}:client-testlib:$version"
const val serverTestLib = "${Spine.toolsGroup}:server-testlib:$version"
}
Loading
Loading