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

Remove out modifiers from the generic parameters of codegen-runtime interfaces #53

Merged
merged 3 commits into from
Oct 12, 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 @@ -26,6 +26,7 @@

package io.spine.chords.codegen.plugins

import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.asClassName
Expand Down Expand Up @@ -151,5 +152,27 @@ internal val TypeName.simpleClassName: String
"",
".$simpleName"
)
else
simpleName
else simpleName

/**
* Builds `@Suppress` annotation with `UNCHECKED_CAST` and
* `RemoveRedundantQualifierName` arguments.
*/
internal fun suppressUncheckedCastAndRedundantQualifier() =
buildSuppressAnnotation(
"UNCHECKED_CAST",
"RemoveRedundantQualifierName"
)

/**
* Builds `@Suppress` annotation with given [warnings].
*/
@Suppress("SameParameterValue")
private fun buildSuppressAnnotation(vararg warnings: String) =
AnnotationSpec.builder(Suppress::class.asClassName())
.also { builder ->
warnings.forEach { warning ->
builder.addMember("%S", warning)
}
}
.build()
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.KModifier.OVERRIDE
import com.squareup.kotlinpoet.KModifier.PUBLIC
import com.squareup.kotlinpoet.ParameterizedTypeName
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.WildcardTypeName
import com.squareup.kotlinpoet.asClassName
import io.spine.chords.runtime.MessageDef
import io.spine.chords.runtime.MessageField
Expand Down Expand Up @@ -85,8 +85,11 @@ internal class MessageDefObjectGenerator(
*
* public val `value`: IpAddressValueOneof = IpAddressValueOneof
*
* public override val fields: Collection<MessageField<IpAddress, out Any>>
* = listOf(ipv4, ipv6)
* public override val fields: Collection<MessageField<IpAddress, Any>>
* = listOf(
* ipv4 as MessageField<IpAddress, Any>,
* ipv6 as MessageField<IpAddress, Any>
* )
*
* public override val oneofs: Collection<MessageOneof<IpAddress>>
* = listOf(value)
Expand Down Expand Up @@ -132,14 +135,18 @@ internal class MessageDefObjectGenerator(
* Builds the `fields` property of [MessageDef] implementation.
*/
private fun buildFieldsProperty(): PropertySpec {
val messageDefClassName = messageFieldClassName.parameterizedBy(
messageTypeName.fullClassName(typeSystem),
messageFieldValueTypeAlias
)
val propType = Collection::class.asClassName().parameterizedBy(
messageFieldClassName.parameterizedBy(
messageTypeName.fullClassName(typeSystem),
WildcardTypeName.producerOf(messageFieldValueTypeAlias)
)
messageDefClassName
)
return PropertySpec.builder("fields", propType, PUBLIC, OVERRIDE)
.initializer(fieldListInitializer(fieldNames))
.addAnnotation(
suppressUncheckedCastAndRedundantQualifier()
)
.initializer(fieldListInitializer(fieldNames, messageDefClassName))
.build()
}

Expand Down Expand Up @@ -186,6 +193,31 @@ internal class MessageDefObjectGenerator(
* The generated code looks like the following:
* ```
* listOf(
* ipv4 as MessageField<IpAddress, Any>,
* ipv6 as MessageField<IpAddress, Any>
* )
* ```
*/
private fun fieldListInitializer(
fieldNames: Iterable<String>,
messageField: ParameterizedTypeName
): String {
return fieldNames.joinToString(
",${lineSeparator()}",
"listOf(${lineSeparator()}",
")"
) {
"${it.propertyName} as $messageField"
}
}

/**
* Generates initialization code for the `oneofs` property
* of the [MessageDef] implementation.
*
* The generated code looks like the following:
* ```
* listOf(
* ipv4,
* ipv6
* )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier.OVERRIDE
import com.squareup.kotlinpoet.KModifier.PRIVATE
import com.squareup.kotlinpoet.KModifier.PUBLIC
import com.squareup.kotlinpoet.ParameterizedTypeName
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.WildcardTypeName
import com.squareup.kotlinpoet.asClassName
import io.spine.chords.runtime.MessageOneof
import io.spine.protodata.Field
Expand Down Expand Up @@ -87,10 +87,10 @@ internal class MessageOneofObjectGenerator(
* The generated code for some `oneof` filed looks like the following:
* ```
* public object IpAddressValueOneof : MessageOneof<IpAddress> {
* private val fieldMap: Map<Int, MessageField<IpAddress, *>> =
* private val fieldMap: Map<Int, MessageField<IpAddress, Any>> =
* mapOf(
* 1 to IpAddressDef.ipv4,
* 2 to IpAddressDef.ipv6
* 1 to IpAddressDef.ipv4 as MessageField<IpAddress, Any>,
* 2 to IpAddressDef.ipv6 as MessageField<IpAddress, Any>
* )
*
* public override val name: String = "value"
Expand All @@ -109,7 +109,7 @@ internal class MessageOneofObjectGenerator(
): TypeSpec {
val messageFieldType = messageFieldClassName.parameterizedBy(
messageFullClassName,
WildcardTypeName.producerOf(messageFieldValueTypeAlias)
messageFieldValueTypeAlias
)
val fieldMapType = Map::class.asClassName().parameterizedBy(
Int::class.asClassName(),
Expand All @@ -129,10 +129,14 @@ internal class MessageOneofObjectGenerator(
.addProperty(
PropertySpec
.builder("fieldMap", fieldMapType, PRIVATE)
.addAnnotation(
suppressUncheckedCastAndRedundantQualifier()
)
.initializer(
fieldMapInitializer(
oneofFields,
messageTypeName.messageDefClassName()
messageTypeName.messageDefClassName(),
messageFieldType
)
)
.build()
Expand Down Expand Up @@ -168,20 +172,21 @@ internal class MessageOneofObjectGenerator(
* The generated code looks like the following:
* ```
* mapOf(
* 1 to IpAddressDef.ipv4,
* 2 to IpAddressDef.ipv6
* 1 to IpAddressDef.ipv4 as MessageField<IpAddressDef, Any>,
* 2 to IpAddressDef.ipv6 as MessageField<IpAddressDef, Any>
* )
* ```
*/
private fun fieldMapInitializer(
fields: Iterable<Field>,
generatedClassName: String
messageDefClassName: String,
messageField: ParameterizedTypeName
): String {
return fields.joinToString(
",${lineSeparator()}",
"mapOf(${lineSeparator()}",
")"
) {
"${it.number} to $generatedClassName.${it.name.javaCase()}"
"${it.number} to $messageDefClassName.${it.name.javaCase()} as $messageField"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface MessageDef<T : Message> {
/**
* Returns collection of [MessageField]s generated for the fields of [T] Proto message.
*/
public val fields: Collection<MessageField<T, out MessageFieldValue>>
public val fields: Collection<MessageField<T, MessageFieldValue>>

/**
* Returns collection of [MessageOneof]s generated for the oneofs of [T] Proto message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public interface MessageOneof<T : Message> {
/**
* Returns collection of [MessageField]s declared by this `oneof`.
*/
public val fields: Collection<MessageField<T, out MessageFieldValue>>
public val fields: Collection<MessageField<T, MessageFieldValue>>

/**
* Returns [MessageField] that is currently set in this oneof.
*/
public fun selectedField(message: T): MessageField<T, out MessageFieldValue>?
public fun selectedField(message: T): MessageField<T, MessageFieldValue>?
}
28 changes: 14 additions & 14 deletions dependencies.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


# Dependencies of `io.spine.chords:spine-chords-client:2.0.0-SNAPSHOT.28`
# Dependencies of `io.spine.chords:spine-chords-client:2.0.0-SNAPSHOT.29`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -1066,12 +1066,12 @@

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Thu Oct 10 16:32:16 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Fri Oct 11 18:13:15 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.chords:spine-chords-codegen-tests:2.0.0-SNAPSHOT.28`
# Dependencies of `io.spine.chords:spine-chords-codegen-tests:2.0.0-SNAPSHOT.29`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -1925,12 +1925,12 @@ This report was generated on **Thu Oct 10 16:32:16 EEST 2024** using [Gradle-Lic

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Thu Oct 10 16:32:18 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Fri Oct 11 18:13:17 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.chords:spine-chords-core:2.0.0-SNAPSHOT.28`
# Dependencies of `io.spine.chords:spine-chords-core:2.0.0-SNAPSHOT.29`

## Runtime
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
Expand Down Expand Up @@ -2912,12 +2912,12 @@ This report was generated on **Thu Oct 10 16:32:18 EEST 2024** using [Gradle-Lic

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Thu Oct 10 16:32:20 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Fri Oct 11 18:13:18 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.chords:spine-chords-gradle-plugin:1.9.6`
# Dependencies of `io.spine.chords:spine-chords-gradle-plugin:1.9.7`

## Runtime
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
Expand Down Expand Up @@ -3668,12 +3668,12 @@ This report was generated on **Thu Oct 10 16:32:20 EEST 2024** using [Gradle-Lic

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Thu Oct 10 16:32:21 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Fri Oct 11 18:13:19 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.chords:spine-chords-proto:2.0.0-SNAPSHOT.28`
# Dependencies of `io.spine.chords:spine-chords-proto:2.0.0-SNAPSHOT.29`

## Runtime
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
Expand Down Expand Up @@ -4672,12 +4672,12 @@ This report was generated on **Thu Oct 10 16:32:21 EEST 2024** using [Gradle-Lic

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Thu Oct 10 16:32:23 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Fri Oct 11 18:13:20 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.chords:spine-chords-proto-values:2.0.0-SNAPSHOT.28`
# Dependencies of `io.spine.chords:spine-chords-proto-values:2.0.0-SNAPSHOT.29`

## Runtime
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
Expand Down Expand Up @@ -5471,12 +5471,12 @@ This report was generated on **Thu Oct 10 16:32:23 EEST 2024** using [Gradle-Lic

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Thu Oct 10 16:32:24 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Fri Oct 11 18:13:20 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.chords:spine-chords-runtime:2.0.0-SNAPSHOT.28`
# Dependencies of `io.spine.chords:spine-chords-runtime:2.0.0-SNAPSHOT.29`

## Runtime
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
Expand Down Expand Up @@ -6240,4 +6240,4 @@ This report was generated on **Thu Oct 10 16:32:24 EEST 2024** using [Gradle-Lic

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Thu Oct 10 16:32:25 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Fri Oct 11 18:13:21 EEST 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject.
-->
<groupId>io.spine.chords</groupId>
<artifactId>Chords</artifactId>
<version>2.0.0-SNAPSHOT.28</version>
<version>2.0.0-SNAPSHOT.29</version>

<inceptionYear>2015</inceptionYear>

Expand Down
4 changes: 2 additions & 2 deletions version.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* The version of all Chords libraries.
*/
val chordsVersion: String by extra("2.0.0-SNAPSHOT.28")
val chordsVersion: String by extra("2.0.0-SNAPSHOT.29")


/**
Expand All @@ -41,4 +41,4 @@ val chordsVersion: String by extra("2.0.0-SNAPSHOT.28")
*
* Update this version if the `chordsVersion` is updated.
*/
val gradlePluginVersion: String by extra("1.9.6")
val gradlePluginVersion: String by extra("1.9.7")
Loading