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

Add method getFluentBeanProperties to JavaClassElement #6415

Merged
merged 1 commit into from
Nov 4, 2021

Conversation

ilopmar
Copy link
Contributor

@ilopmar ilopmar commented Oct 25, 2021

See micronaut-projects/micronaut-openapi#593

This PR does two things:

  • Adds the method getFluentBeanProperties to ClassElement to return the bean properties declared in a "fluent" way, like when using Lombok. It only adds implementation for Java because it doesn't make sense for Groovy.
  • Extract some private methods with code used in getBeanProperties that is now used for both getBeanProperties and getFluentBeanProperties method.

Basically in the current micronaut-openapi implementation there is a helper class that duplicates all the code extracted here to private methods. With this PR merged in core (and some changes I've already done in micronaut-openapi) I can remove that class and avoid using core's internal classes.
Without this merged micronaut-openapi won't use now internal classes but as mentioned before we will need to duplicate a lot of code and keep it in sync.

One final thought. I wasn't sure about including this new method in ClassElement instead of in JavaClassElement so I can change it to the child class if necessary. Being in ClassElement simplifies even more micronaut-openapi because there is no need to check if code is Java or Groovy, though.

The method return the bean properties (declared or generated) in a
fluent API. This is a pattern used with Lombok.

See micronaut-projects/micronaut-openapi#593
Comment on lines +80 to +88
* Deprecated. This can be removed in Micronaut 3.2.0
*
* @param classElement The {@link TypeElement}
* @param annotationMetadata The annotation metadata
* @param visitorContext The visitor context
* @param genericsInfo The generic type info
* @param arrayDimensions The number of array dimensions
*/
@Deprecated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this PR is merged I will send a new PR to remove this for Micronaut 3.2.0 when I release a new version of micronaut-openapi

@jameskleeh
Copy link
Contributor

Can you explain why it doesn't make sense for Groovy or Kotlin?
Does the getFluentBeanProperties include only the fluent properties? What is the use case for caring if the property is fluent or not?

@graemerocher
Copy link
Contributor

Personally I think we should instead add support for the element query API and allow:

ClassElement.getEnclosedElements(ElementQuery.of(PropertyElement.class))

Rather than adding yet another method

@ilopmar
Copy link
Contributor Author

ilopmar commented Oct 25, 2021

The JavaClassElementExt class was created sometime ago in micronaut-openapi and currently extends from the @Internal JavaClassElement was introduced originally to support fluent-like getters and setters like the ones created with Lombok. The test I've added to this PR is the same that was introduced in micronaut-openapi (and is the only one that is failing at this moment in my work-in-progress changes).

As far as I know Lombok only works with Java. Maybe is debatable that this pattern can be used with Groovy or Kotlin. From a Groovy point of view I've never used that patter before, I've only used Groovy's @Builder annotation when needed something different. I don't know too much about Kotlin but I think Kotlin users are used to use data classes that don't generate these setters/getters.

@ilopmar
Copy link
Contributor Author

ilopmar commented Oct 25, 2021

I will explore @graemerocher's suggestion as it seems a better approach :)

@ilopmar
Copy link
Contributor Author

ilopmar commented Nov 4, 2021

Sorry, I've merged this by mistake 🤦‍♂️ . Reverting it now in #6477

GavrilovSV pushed a commit to GavrilovSV/micronaut-core that referenced this pull request Nov 6, 2021
…jects#6415)

The method return the bean properties (declared or generated) in a
fluent API. This is a pattern used with Lombok.

See micronaut-projects/micronaut-openapi#593
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants