immutables
immutables copied to clipboard
`depluralizeDictionary` not working as expected
Here is my Style:
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
@Value.Style(
typeImmutable = "*",
typeAbstract = ["*Def"],
builder = "configure",
build = "off",
put = "*",
add = "*",
depluralize = true,
depluralizeDictionary = ["templatePath:templatePathsInOrder"],
visibility = PUBLIC
)
annotation class Config
Here is my attribute @SkipNulls fun templatePathsInOrder(): List<String>
Expected: It should generate a templatePath()
method
But it doesn't get generated.
Here is a sample project to demostrate: ImmutablesTest.java
I've tried it and it works as documented
/**
* Dictionary of exceptions — array of "singular:plural" pairs as alternative to mechanical "*s"
* depluralization. Suppress trimming of trailing "s" for certain words by using exceptions of
* form {@code "words:words"} or simply {@code "words"}. Important to note is that words will be
* converted to lowercase and identifier in question consists of couple of words joined using
* camel case — only a last segment will be considered for depluralization when matching
* dictionary. Uninterpretable pairs will be ignored. By default no dictionary is supplied and
* depluralization performed only by mechanical "*s" trimming.
* <p>
* This attribute is semi-deprecated in favor of using {@link Depluralize#dictionary()}
* annotation which may be placed on a package, type or as meta-annotation. And dictionary will
* be merged across all applicable definitions.
* @see #depluralize()
* @see Depluralize#dictionary()
* @return array of "singular:plural" pairs.
*/
String[] depluralizeDictionary() default {};
Your example tries to use depluralization as renaming and this is not an intended use. Only last word segment is considered for depluralization.
Ah! I see, thanks for answering and sorry for not going deep into the documentation. May I ask if you have anything in the backlog for the requirement I have, where I wish singular and plural builders to have different names?
Encodings can customize builders to a great degree, but those are based on the attribute type (overriding List<T>
). https://immutables.github.io/encoding.html
Another option is to just have very special style with convention.
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
@Value.Style(
typeImmutable = "*",
typeAbstract = ["*Def"],
builder = "configure",
build = "off",
put = "*",
add = "*",
get = ["*InOrder"], // <--- See this thing here, it would accept templatePathsInOrder accessor as "templatePaths"
depluralize = true,
visibility = PUBLIC
)
annotation class Config