-
Notifications
You must be signed in to change notification settings - Fork 2
Handle compare_by option
#154
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
Merged
Merged
Changes from all commits
Commits
Show all changes
188 commits
Select commit
Hold shift + click to select a range
440c1c8
Add proto messages with `compare_by` option
079cc5a
Implement a test that checks the message implements `Comparable`
408bf36
Implement `ComparableMessageDiscovery`
35fab00
Register a new module in Gradle
2ba1be1
Implement `ComparableMessageView`
25383bc
Implement `ComparableActionRenderer`
741ce71
Implement `ImplementComparable`
586c59e
Append a primitive implementation of `compareTo()` for comparable mes…
c99629f
Fix long lines
4e3b4b8
Fix the message package
fe93de9
Bump the version → `2.0.0-SNAPSHOT.218`
edc39a6
Put missing Spine annotations
d96a7d1
Store `file` along with type name
79c37e7
Propagate .proto changes to entities
dba9a22
Roll back to `TypeDiscovered` event
77a8cd1
Implement a renderer from scratch
26c58cd
Bump `gradle-doctor` to `0.10.0`
50294d3
Implement `ComparableSettings`
91524dd
Make comparable settings configurable from `codegen`
a132596
Propagate setting to the plugin model
5c2d3e1
Write `comparables` settings to a file
ef7f672
Use `TypeRenderer` for rendering
6c0c6dc
Test `ComparableSettings`
6549ba7
Test generation of implementing `Comparable`
d0514b8
Make the used regex expression stricter
8e7427e
Assert the generic parameter as well
3ce3e0a
Remove an empty line
35ce744
Enhance docs
d80ff09
Pick up a better name for the view
fba226b
Move actions to their own package
330683b
Extend settings with `default_comparator` map
409380e
Store `default_comparator` map in the view
01f653d
Merge remote-tracking branch 'refs/remotes/origin/master' into handle…
26324d0
Use `protodata.Actions` to declare actions in Proto definitions
07313a9
Propagate Proto changes to model
7db3445
Drop `ImplementComparable` action in favor of parametrized `Implement…
af133f1
Use a typed option
39c3280
Pass an empty parameter
51ff8c3
Restore `ImplementComparable` action
90367f1
Implement the first approximation of `AddComparator` action
b6ee64f
Test the most basic scenario
f26a586
Test nested field and other comparables
9652f9b
Implement `OptionValidator`
47856b2
Implement `ComparatorBuilder`
6ebfe70
Add more nested fields in the test data
ca0e634
Implement negative tests
5a11320
Leave a TODO for the double validation
94277dc
Wrap nested spec classes
62e65d1
Implement tests for well-known types
9151d92
Implement tests for nested well-known types
82d5aef
Bypass well-known messages during validation
29875d5
Implement `OptionFieldLocator`
8d27fb5
Move validation responsibility to `AppComparator` action
9f9117d
Use already created `PsiJavaFile` instance
0cd2f4c
Don't even try to insert an import
e9e52e2
Fix tests
8f8c084
Add an alias to enum
9186f67
Update docs to Proto messages
eddda97
Use better names for codegen content entities
5521958
Document codegen analysis entities
5e29dda
Document actions
c4c6fa1
Extract `MessagesLookup`
f6954dd
Extract an object for storing of the supported well-known types
0bc6677
Refactor `AddComparator` option
8b20542
Use FQNs
3d30b79
Leave a comment about `cls.addFirst()`
b6bea66
Remove `required` option from test fixtures
80bdbf1
Remove a superfluous intermediate check
8cbe86d
Take into account the reversed ordering
aa45d96
Test `AddCompareTo` action
540cf7b
Simplify instantiation of `ComparablePluginTestSetup`
911fb3d
Don't run the pipeline for each test case
05a9ae6
Refactor `ImplementComparableSpec`
f8d3935
Refactor `AddCompareToSpec`
522fe0f
Refactor `AddComparatorSpec`
7402e16
Avoid code duplication in negative test cases
38920ac
Bump version --> `2.0.0-SNAPSHOT.221`
e4d557c
Implement an integration test for `mc-java-comparable`
a806b02
Update reports
4dfccff
Fix `ComparableSettings` spec
5a94b01
Remove a `todo`
2325aa1
Remove docs repeating
fbd9bfe
Remove no longer used method
e71f5dc
Move cases with nested fields to a nested class
a5c6ad5
Commit IDEA metadata
1f9aee3
Suppress a Detekt warning
c867317
Actualize test case name
2838496
Fix formatting
0ba06c2
Proofread docs
12b2774
Remove a superfluous field from `Debtor`
d0c1058
Proofread docs
74c882e
Proofread docs
76460c9
Suppress `MaxLineLength` for `AddComparatorSpec`
e93967f
Proofread docs
2d3c672
Remove unused (and misplaced) import
081340d
Update test case name
e407261
Document test messages used in the integration test
e78184c
Document a public `reversed()` method
c2db03b
Shorten the parameter name
9c75921
Fix the proto file name
b332a29
Add an integration test for nested fields
a8c9a95
Pass the default `Any` instead of packing an `Empty`
c45f0d7
Extract the standard comparators to constants
c067937
Rename `isComparable()` to `isCompareBy()`
60bf3fd
Remove `String.upperCased` extension
f58c08a
Inline a single usage of `String.lowerCased` extension
d05320f
Use `lowerCamelCase()` method
0e347c5
Avoid the unrelated docs details when one class speaks for another
ffeb17c
Avoid string literals where `KClass` can be used
db232b9
Employ a recently-added extension from ProtoData
8caeebc
Bump `spine-base` to the latest version
cb2b7bc
Adapt validation and comparator builder to `ComparatorRegistry`
8636608
Implement an integration test for custom comparators
9feb007
Fix a typo in the import
390f720
Remove no longer used `Cases.kt`
7a22af9
Bump `spine-tool-base` to the latest version
eea8f84
Fix KDoc tag
99413d9
Merge remote-tracking branch 'refs/remotes/origin/master' into handle…
112598a
Remove weird import
e6427bf
Fix broken imports
b6940e2
Bump `spine-base` -> `2.0.0-SNAPSHOT.212`
0947b2e
Bump the version → `2.0.0-SNAPSHOT.242`
08fc5c6
Bump `base` -> `2.0.0-SNAPSHOT.212`
d023116
Rollback `base` version
367d9ce
Fix a test
9fc1944
Fix too long line
e80e3fe
Implement tests for dynamically-registered comparators
d45c437
Throw when the message is comparable and has a comparator simultaneously
486c13f
Mute logging
9297f6d
Merge branch 'refs/heads/master' into handle-comparable-option
9155e2d
Do not cover cyclic comparators in tests
14969a1
Bump the version -> `2.0.0-SNAPSHOT.244`
750d0e2
Merge validation and building into a single method
0a24ecd
Ignore the swallowed exception
4060ee2
Rename `SpecifiedField` to `FieldPath`
c132814
Introduce `ComparisonField`
ec8a86b
Make the builder accept ordering on the constructor
9ea9ae9
Refactor `AddComparator`
e2f6594
Extract common assertions from test cases to a function
af55e3b
Simplify build scripts
3dacc36
Proofread docs
cd5556d
Merge branch 'master' into handle-comparable-option
7748bf2
Adapt to the latest changes in `master`
5556b7f
Bump the version -> `2.0.0-SNAPSHOT.245`
3d5c17f
Update reports
0393f47
Fix logging
9add007
Use message descriptors instead of classes
c40319c
Bump ProtoData -> `0.61.6`
eb5c055
Add an empty line
5f740bd
Clarify the exception message
859f4bd
Bump `spine-core` to `2.0.0-SNAPSHOT.177` and address deprecations
19e4a36
Fix enum item's name
2c05183
Use assertions from Truth
35ef28d
Make error message more user-friendly
05a79d6
Rename `ProtoValueMessages` to `ProtobufWrapperTypes`
949681d
Employ a shortcut
8a0e320
Fix grammar
0a8021d
Explicitly call `runPipeline` in each spec
bea47dd
Use a hard `FieldPath` instead of typealias
a6cdbd3
Rename `ProtobufWrapperTypes` to `WellKnownComparables`
5171273
Move unspecific classes out of `comparable` plugin
55e411b
Update packaging for integration tests
f567ca3
Address Detekt warning
9427154
Update dependencies
abdfbb7
Move Proto field related classes to `base` package
608dcf8
Replace `MessageLookup` in favor of `TypeSystem`
61359b3
Set visual guides
db14147
Use `TypeSystem` in `FieldLookup`
f99651d
Remove `ClassLookup` in favor of an extension
2901dc1
Make `ComparisonField` a sealed class
3855ba6
Substitute `FieldLookup` with an extension function
9fc8b71
Actualize docs
457a34b
Enhance docs to `resolve()`
5b732f5
Proofread docs
5cf0fd8
Make `hasCompareByOption` a private extension
3ae4f9c
Rename `descending` to `reversed`
0f19bad
Update docs to `ComparatorBuilder.reversed`
44321f5
Add more checks to `TypeSystem.resolve()`
546f58e
Use either `proto` or `Protobuf`
8d19afb
Use `reference` extension
1118d91
Mention that the used `LocalDateTime` is not Spine-provided
ff787c2
Bump ProtoData -> `0.61.7`
b616520
Remove unnecessary non-null assertions
1d57415
Remove local implementation of `MessageType.javaClass()`
c6184c6
Extract `unsupportedFieldType()` method with enhanced diagnostic message
81e9f7a
Add negative test cases for `oneof` fields
ef9f94f
Put braces around the option name
c2afd1f
Update reports
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
mc-java-base/src/main/kotlin/io/spine/tools/mc/java/OverrideAnnotation.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * 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 | ||
| * | ||
| * 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.tools.mc.java | ||
|
|
||
| import com.intellij.psi.PsiAnnotation | ||
| import io.spine.tools.java.reference | ||
| import io.spine.tools.mc.java.OverrideAnnotation.create | ||
| import io.spine.tools.psi.java.Environment.elementFactory | ||
|
|
||
| /** | ||
| * Creates a [PsiAnnotation] for marking overridden methods. | ||
| * | ||
| * ## Implementation note | ||
| * We do not cache the created instance of [PsiAnnotation] because PSI elements are mutable. | ||
| * We want to avoid unwanted propagation of modifications made by one renderer to others. | ||
| * | ||
| * @see create | ||
| */ | ||
| public object OverrideAnnotation { | ||
|
|
||
| /** | ||
| * Creates a new [PsiAnnotation] with [Override]. | ||
| */ | ||
| public fun create(): PsiAnnotation { | ||
| val reference = Override::class.java.reference | ||
| val annotation = elementFactory.createAnnotationFromText("@$reference", null) | ||
| return annotation | ||
| } | ||
| } |
93 changes: 93 additions & 0 deletions
93
mc-java-base/src/main/kotlin/io/spine/tools/mc/java/base/FieldPathExts.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * 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 | ||
| * | ||
| * 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.tools.mc.java.base | ||
|
|
||
| import io.spine.base.FieldPath | ||
| import io.spine.base.fieldPath | ||
| import io.spine.protodata.ast.Field | ||
| import io.spine.protodata.ast.MessageType | ||
| import io.spine.protodata.ast.field | ||
| import io.spine.protodata.ast.isMessage | ||
| import io.spine.protodata.type.TypeSystem | ||
|
|
||
| /** | ||
| * Tells if this [FieldPath] doesn't denote a nested field. | ||
| */ | ||
| public val FieldPath.isNotNested: Boolean | ||
| get() = fieldNameList.size == 1 | ||
|
|
||
| /** | ||
| * Returns this [FieldPath] as a single [String], where the field names | ||
| * are separated with a dot. | ||
| * | ||
| * For example, `citizen.passport.firstName`. | ||
| */ | ||
| public val FieldPath.joined: String | ||
| get() = fieldNameList.joinToString(".") | ||
|
|
||
| /** | ||
| * Returns the root field's name of this [FieldPath]. | ||
| * | ||
| * @throws [NoSuchElementException] if the path is empty. | ||
| */ | ||
| public val FieldPath.root: String | ||
| get() = fieldNameList.first() | ||
|
|
||
| /** | ||
| * Resolves the given [FieldPath] against the given [MessageType] within | ||
| * this [TypeSystem]. | ||
| * | ||
| * This method navigates through the nested messages and fields as specified by | ||
| * the [fieldPath], returning the final [Field] that the path points to. | ||
| * | ||
| * @param fieldPath The field path to resolve. | ||
| * @param message The message where the root of the [fieldPath] is declared. | ||
| */ | ||
| public fun TypeSystem.resolve(fieldPath: FieldPath, message: MessageType): Field { | ||
| val currentField = message.field(fieldPath.root) | ||
| if (fieldPath.isNotNested) { | ||
| return currentField | ||
| } | ||
|
|
||
| check(currentField.type.isMessage) { | ||
| "Can't resolve the field path `$fieldPath` because `${currentField.name}` segment " + | ||
| "doesn't denote a message. The type of this field is `${currentField.type}`. " + | ||
| "Only messages can have nested field." | ||
| } | ||
|
|
||
| val currentFieldMessage = currentField.type.message | ||
| val remainingFields = fieldPath.fieldNameList.drop(1) | ||
| val remainingPath = fieldPath { fieldName.addAll(remainingFields) } | ||
| val nextMessageInfo = findMessage(currentFieldMessage) | ||
|
|
||
| check(nextMessageInfo != null) { | ||
| "`$currentFieldMessage` was not found in the passed Proto files or their dependencies." | ||
| } | ||
|
|
||
| val nextMessage = nextMessageInfo.first | ||
| return resolve(remainingPath, nextMessage) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
mc-java-base/src/main/kotlin/io/spine/tools/mc/java/gradle/settings/ComparableSettings.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * 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 | ||
| * | ||
| * 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.tools.mc.java.gradle.settings | ||
|
|
||
| import io.spine.tools.mc.java.settings.Comparables | ||
| import io.spine.tools.mc.java.settings.comparables | ||
| import io.spine.tools.mc.java.settings.noParameter | ||
| import org.gradle.api.Project | ||
|
|
||
| /** | ||
| * Code generation settings for messages that have `compare_by` option. | ||
| */ | ||
| public class ComparableSettings(project: Project) : | ||
| SettingsWithActions<Comparables>(project, DEFAULT_ACTIONS) { | ||
|
|
||
| override fun toProto(): Comparables = comparables { | ||
| actions = actions() | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The actions applied by default to comparable messages. | ||
| */ | ||
| private val DEFAULT_ACTIONS = mapOf( | ||
| "io.spine.tools.mc.java.comparable.action.AddComparator" to noParameter, | ||
| "io.spine.tools.mc.java.comparable.action.AddCompareTo" to noParameter, | ||
| "io.spine.tools.mc.java.comparable.action.ImplementComparable" to noParameter, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.