mapstruct / mapstruct-idea

An IntelliJ IDEA plugin for working with MapStruct
Other
142 stars 38 forks source link

#129 improve support of mapping composition #134

Closed thunderhook closed 1 year ago

thunderhook commented 1 year ago

This PR is about #129.

Mapping composition (or meta annotations) were already tacklet with the following commit (target version 1.2.1): https://github.com/mapstruct/mapstruct-idea/commit/35f171224af8267163f33edcedb92b01d14a3bbc

However, the used utility method com.intellij.codeInsight.MetaAnnotationUtil#findMetaAnnotations returns only a single (more precise: the first) @Mapping annotation. Therefore this did not work as expected (but already worked with the simple test named UnmappedTargetPropertiesWithMetaAnnotationInspectionTest.

I implemented an own recursive method to find @Mapping annotations and provided a test case with an infinitve chained meta-annotation. I also added a test with combined @Mapping and meta-annotation on the same mapping method. The current implementation did not merge them together but worked against each other.


Sidenote: The intellij utility method MetaAnnotationUtil#findMetaAnnotations used an internal cache. I chose against using one, because it felt like a premature optimization which made the code less readable. Let me know what you think, especially because of the TODO comments to use a cache in line 300 😆

If we/you really want this, we should do this in a separate issue/PR with a clean cache solution outsourced in a separate class to keep the code clean.

I can also improve this with the current PR. Let me know what you think.

filiphr commented 1 year ago

Thanks @thunderhook