-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more useful error when multiple mappers are resolved
- Loading branch information
1 parent
3052199
commit bdb58e6
Showing
11 changed files
with
151 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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
41 changes: 41 additions & 0 deletions
41
...plugin/src/main/kotlin/tech/mappie/validation/problems/MultipleTransformationsProblems.kt
This file contains 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,41 @@ | ||
package tech.mappie.validation.problems | ||
|
||
import tech.mappie.resolving.ConstructorCallMapping | ||
import tech.mappie.resolving.classes.* | ||
import tech.mappie.resolving.classes.targets.MappieTarget | ||
import tech.mappie.validation.Problem | ||
|
||
class MultipleTransformationsProblems(private val mappings: Map<MappieTarget, List<ObjectMappingSource>>) { | ||
fun all(): List<Problem> = | ||
mappings.map { (_, sources) -> | ||
val source = sources.single() | ||
when (source) { | ||
is ResolvedSource -> source.transformation | ||
is PropertySource -> source.transformation | ||
else -> null | ||
} | ||
} | ||
.filterNotNull() | ||
.map { transformations -> | ||
val names = transformations.map { it as MappieViaResolved }.joinToString { it.definition.clazz.name.asString() } | ||
Problem.error( | ||
"Multiple mappers resolved to be used in an implicit via", | ||
suggestions = listOf( | ||
"Explicitly call one of $names explicitly.", | ||
"Delete all except one of $names." | ||
), | ||
) | ||
} | ||
|
||
companion object { | ||
fun of(mapping: ConstructorCallMapping): MultipleTransformationsProblems = | ||
MultipleTransformationsProblems( | ||
mapping.mappings | ||
.filter { it.value.size == 1 } | ||
.filter { | ||
(it.value.single().let { it is ResolvedSource && it.transformation.size > 1 }) || | ||
(it.value.single().let { it is PropertySource && it.transformation.size > 1 }) | ||
} | ||
) | ||
} | ||
} |
This file contains 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 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