Skip to content

Commit

Permalink
Merge pull request #131 from SpineEventEngine/update-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-yevsyukov authored Aug 16, 2024
2 parents b3e6bc9 + 265c507 commit b9da2b2
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object ProtoData {
* The version of ProtoData dependencies.
*/
val version: String
private const val fallbackVersion = "0.51.0"
private const val fallbackVersion = "0.54.2"

/**
* The distinct version of ProtoData used by other build tools.
Expand All @@ -74,7 +74,7 @@ object ProtoData {
* transitional dependencies, this is the version used to build the project itself.
*/
val dogfoodingVersion: String
private const val fallbackDfVersion = "0.51.0"
private const val fallbackDfVersion = "0.54.2"

/**
* The artifact for the ProtoData Gradle plugin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object Spine {
*
* @see <a href="https://github.com/SpineEventEngine/base">spine-base</a>
*/
const val base = "2.0.0-SNAPSHOT.203"
const val base = "2.0.0-SNAPSHOT.205"

/**
* The version of [Spine.reflect].
Expand Down Expand Up @@ -89,7 +89,7 @@ object Spine {
*
* @see <a href="https://github.com/SpineEventEngine/mc-java">spine-mc-java</a>
*/
const val mcJava = "2.0.0-SNAPSHOT.213"
const val mcJava = "2.0.0-SNAPSHOT.217"

/**
* The version of [Spine.baseTypes].
Expand Down Expand Up @@ -124,7 +124,7 @@ object Spine {
*
* @see <a href="https://github.com/SpineEventEngine/tool-base">spine-tool-base</a>
*/
const val toolBase = "2.0.0-SNAPSHOT.218"
const val toolBase = "2.0.0-SNAPSHOT.223"

/**
* The version of [Spine.javadocTools].
Expand Down
68 changes: 34 additions & 34 deletions dependencies.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2023, TeamDev. All rights reserved.
* Copyright 2024, 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
*
* http://www.apache.org/licenses/LICENSE-2.0
* 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
Expand All @@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableList
import com.google.common.reflect.TypeToken
import com.squareup.javapoet.CodeBlock
import io.spine.protodata.Field
import io.spine.protodata.messageOrEnumName
import io.spine.protodata.backend.SecureRandomString
import io.spine.protodata.java.ClassOrEnumName
import io.spine.protodata.java.Expression
Expand All @@ -51,12 +52,12 @@ import kotlin.io.encoding.ExperimentalEncodingApi
* A code generator that distributes the associated simple validation rule to elements of
* a repeated field.
*
* A rule applied to a repeated fields, i.e., a list or a map, may be applied to the fields as
* A rule applied to repeated fields, i.e., a list or a map, may be applied to the fields as
* a whole, or to individual elements of the field.
*
* In the first case, no extra modifications to code generation are required.
*
* In the second case, this generator creates code that iterated over
* In the second case, this generator creates the code that iterates over
* the elements and applies the validation rule to them.
*/
internal class DistributingGenerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ private fun PsiJavaFile.locateBuilderClass(messageClass: ClassName): PsiClass {
*/
private fun PsiClass.implementValidatingBuilder(messageClass: ClassName) {
val superInterface = elementFactory.createClassReference(
this,
ValidatingBuilder::class.java.reference,
messageClass.simpleName
messageClass.simpleName,
context = this,
)
implement(superInterface)
}
44 changes: 0 additions & 44 deletions java/src/main/kotlin/io/spine/validation/java/TypeExts.kt

This file was deleted.

25 changes: 3 additions & 22 deletions java/src/main/kotlin/io/spine/validation/java/ValidateGenerator.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2023, TeamDev. All rights reserved.
* Copyright 2024, 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
*
* http://www.apache.org/licenses/LICENSE-2.0
* 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
Expand All @@ -28,7 +28,7 @@ package io.spine.validation.java

import com.squareup.javapoet.CodeBlock
import io.spine.protodata.Field
import io.spine.protodata.Type
import io.spine.protodata.isAny
import io.spine.protodata.java.Expression
import io.spine.protodata.java.Literal
import io.spine.protodata.java.MessageReference
Expand Down Expand Up @@ -166,22 +166,3 @@ internal class ValidateGenerator(ctx: GenerationContext) : SimpleRuleGenerator(c
return error().createParentViolation(ctx, violations)
}
}

/**
* Tells if this type is `google.protobuf.Any`.
*
* TODO: Migrate to the similar property from ProtoData.
*/
private val Type.isAny: Boolean
get() = (hasMessage()
&& message.packageName.equals("google.protobuf"))
&& message.simpleName.equals("Any")


/**
* Obtains the name of the field which includes a qualified name of the type which declares it.
*
* TODO: Migrate to an extension `val` from ProtoData.
*/
private val Field.qualifiedName: String
get() = "${declaringType.qualifiedName}.${name.value}"
5 changes: 3 additions & 2 deletions java/src/main/proto/spine/validation/java/type.proto
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2023, TeamDev. All rights reserved.
* Copyright 2024, 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
*
* http://www.apache.org/licenses/LICENSE-2.0
* 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
Expand Down Expand Up @@ -37,6 +37,7 @@ option java_multiple_files = true;
option (internal_all) = true;

import "spine/protodata/ast.proto";
import "spine/protodata/source.proto";

// A tuple of a message type and the header of the file where it is declared.
message MessageWithFile {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* 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
Expand Down Expand Up @@ -66,6 +66,7 @@ public abstract class ValidationPolicy<E extends EventMessage>
* </pre>
*/
protected final EitherOf2<RuleAdded, Nothing> noReaction() {
//TODO:2024-08-11:alexander.yevsyukov: Use EventProducer.noReaction() extension from `core-java`.
return EitherOf2.withB(nothing());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* 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
Expand All @@ -23,10 +23,12 @@
* (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.validation

import io.spine.core.External
import io.spine.protodata.MessageType
import io.spine.protodata.firstField
import io.spine.protodata.event.TypeDiscovered
import io.spine.server.event.React
import io.spine.server.model.NoReaction
Expand Down Expand Up @@ -61,7 +63,7 @@ internal class RequiredIdOptionPolicy : RequiredIdPolicy() {
if (!type.isEntityState()) {
return noReaction()
}
val field = type.firstField()
val field = type.firstField
return withField(field)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* 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
Expand All @@ -23,12 +23,14 @@
* (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.validation

import io.spine.core.External
import io.spine.protodata.File
import io.spine.protodata.FilePattern
import io.spine.protodata.event.TypeDiscovered
import io.spine.protodata.firstField
import io.spine.protodata.matches
import io.spine.server.event.React
import io.spine.server.model.NoReaction
Expand Down Expand Up @@ -64,7 +66,7 @@ internal class RequiredIdPatternPolicy : RequiredIdPolicy() {
return noReaction()
}
val type = event.type
val field = type.firstField()
val field = type.firstField
return withField(field)
}

Expand Down
19 changes: 2 additions & 17 deletions model/src/main/kotlin/io/spine/validation/RequiredIdPolicy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* 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
Expand All @@ -26,9 +26,7 @@
package io.spine.validation

import io.spine.protodata.Field
import io.spine.protodata.MessageType
import io.spine.protodata.event.TypeDiscovered
import io.spine.protodata.qualifiedName
import io.spine.protodata.settings.loadSettings
import io.spine.server.model.NoReaction
import io.spine.server.tuple.EitherOf2
Expand Down Expand Up @@ -61,8 +59,7 @@ internal abstract class RequiredIdPolicy : ValidationPolicy<TypeDiscovered>() {
*
* If the field is marked with `(required) = false`, no rule is generated.
*
* @param field
* the ID field.
* @param field ID field.
* @return a required rule event or `NoReaction`, if the ID field is not required.
*/
@Suppress("ReturnCount") // prefer sooner exit and precise conditions.
Expand All @@ -77,16 +74,4 @@ internal abstract class RequiredIdPolicy : ValidationPolicy<TypeDiscovered>() {
}
return EitherOf2.withA(rule.get().toEvent(field.declaringType))
}

/**
* Obtains the first field declared in the type.
*
* The index of the field is not taken into account.
*/
protected fun MessageType.firstField(): Field {
check(fieldCount != 0) {
"The type `${name.qualifiedName}` must have at least one field."
}
return getField(0)
}
}
Loading

0 comments on commit b9da2b2

Please sign in to comment.