Skip to content
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

depluralizeDictionary not working as expected #1485

Open
overfullstack opened this issue Oct 6, 2023 · 3 comments
Open

depluralizeDictionary not working as expected #1485

overfullstack opened this issue Oct 6, 2023 · 3 comments
Labels

Comments

@overfullstack
Copy link

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

@elucash
Copy link
Member

elucash commented Oct 6, 2023

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.

@overfullstack
Copy link
Author

overfullstack commented Oct 7, 2023

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?

@elucash
Copy link
Member

elucash commented Oct 7, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants