Comments (8)
Hey 👋, great thanks for suggestion!
I agree that such feature would be quite useful, but I would hesitate to enable it by default - virtually every feature that we ever added and had it turned on by default ended up with a bug report from someone who expected the code to fail/require manual intervention. I don't think that all such cases make sense (if one ends up with more configs than code they are helping to replace, it kind of misses the point), but this one feels like something that could be opt-in.
I recently started developing a feature allowing to customize how fields and subtypes are compared. It would address quite similar request for fields (#89) but also add an ability to customize comparison of subtypes/enum values.
If it was merged then adding enum support could be done e.g.
import io.scalaland.chimney.dsl.*
import io.scalaland.chimney.protobufs.*
implicit val config = TransformerConfiguration.default
.enableCustomSubtypeNameComparison(PbEnumAwareNameComparison)
(alternatively, there could be several conventions prepared inside TransformedNamesComparison
, one of them supporting UPPERCASE_WITH_UNDERSCORES
).
Would such solution work for you?
I am not sure when I finish working on it. I started that mainly to take a break from some more mundane tickets that has to be implemented before 1.0.0-RC1, but I also have less time on mu hand AT.
from chimney.
Hey Mateusz, thanks for your reply!
I totally missed #89. #478 looks great. I think it would solve our problem. Do you think I could help somehow getting it merged?
from chimney.
I think right now, it's mostly grind:
- replace all usages of "global" methods with something that uses
ctx
- there might be some tricky places like this one, where probably I could hardcode setter aware comparison and this one where I might need to hardcode strict equality check - but without running it against tests it's hard to tell if it won't break something
- write tests, they should make sure that top-level object/objects nested only on other objects work fine, and that disabling of the feature works as well
- documentation - it should explain the limitation of this approach really well
- to make code available to macro (we cannot rely on
reify
) it has to be available on the classpath - it also has to be instantiable with no dependencies
- so the only sane choice are
object
s defined in module current module depends on - only then we can safely load object to memory and call it
- it's basically unholy hack, but it seems to work
- to make code available to macro (we cannot rely on
It isn't necessarily trivial, low-hanging fruit, but for the kind of work that happens in this project it's relatively simple - if you want to try, you can create a branch off #478 and see how it goes. :)
from chimney.
I continued in https://github.com/saeltz/chimney/tree/custom-name-comparator-saeltz.
All usages have been replaced with TransformerContext
. Tests and documentation still missing.
from chimney.
Thank you! I've created a PR out of your changes.
from chimney.
Added in 1.0.0-M3
from chimney.
This is not really solved by #478. I opened #489.
from chimney.
I think it might be useful to have something OOTB in Chimney for some very common cases like Protobufs and Java integrations, however I need to point out that
This is not really solved by #478.
the whole point of #489 the PR is that everyone can add a custom comparator in their own codebase. The code in macros is as tricky as you see because we are not relying on pattern-matching on a sealed trait
to obtain the comparator, but we are reading singleton value from the class-path by its type, so that every project is able to create and employ its own comparators without being blocked whether Chimney supports a particular convention OOTB.
from chimney.
Related Issues (20)
- Silent invalid behavior of `withFieldConst` when field name starts with "set" HOT 6
- [PartialTransformer] Field Option[Field].None to Proto3.Fields.Default
- ClassCastException thrown on Scala 3 when transforming sealed traits to Protobuf GeneratedEnum HOT 12
- Can't transform coproduct - Java Enum to Sealed trait HOT 24
- Cannot transform Scala class to Java class HOT 5
- Chimney stabilization into 1.0.0
- Exclude macro generated code from WartRemover checks HOT 16
- Fix Overrides for Subtypes matching
- Support seamless transformation of protobuf oneof types HOT 4
- Compiler bugs: known, relevant and unresolved/undocumented
- Support transformation to and from Java primitives
- Test more Scala CLI snippets for output (printed results)
- Support runtime-defined enums
- Rewrite Patchers as a special case of multiple case classes mapping
- Refactor internals to NOT rely on RuntimeDataStore
- Chimney >= 0.8.0 can't transform case class with annotated parameter HOT 7
- Total transformation for Cats' `NonEmptyX[A] -> NonEmptyX[B]` HOT 3
- Possible documentation improvements
- Macro is ignoring overrides in collections when From =:= Target
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chimney.