Skip to content

add inspection for @Mapping annotation#153

Merged
thunderhook merged 13 commits intomapstruct:mainfrom
hduelme:add_mapping_annotation_inspection
Oct 20, 2023
Merged

add inspection for @Mapping annotation#153
thunderhook merged 13 commits intomapstruct:mainfrom
hduelme:add_mapping_annotation_inspection

Conversation

@hduelme
Copy link
Contributor

@hduelme hduelme commented Oct 9, 2023

I added three inspections for @Mapping annotation.

  1. No source property defined
  2. More than one source property defined
  3. More than one default source property defined

For the second inspection I added two possible fixes.

  • remove one source property
  • use one source property as default value/expression (Only available if no default property is already defined.

For the third inspection I added one possible fix. Remove one default source property.

Copy link
Contributor

@thunderhook thunderhook left a comment

Choose a reason for hiding this comment

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

Hi! Thanks alot for the additional inspections.

I stumbled across some mini formatting issues and a case where expression and defaultExpression are also invalid. This should also be handled correctly, so that the quick-fix doesn't produce an invalid code.

Thanks in advance! 💪

@filiphr any ideas about the errors in the pipeline/action?

@hduelme
Copy link
Contributor Author

hduelme commented Oct 12, 2023

As @thunderhook suggested, now move to default value is only available if the source property is present.

I also fixed the pipeline. JetBrains removed the mock-Jdk Files from their main branch. As a fix I switched to the 212.5712 branch, where the files still exist. I don't think this should be a permanent solution, but for now it works :)

@thunderhook
Copy link
Contributor

I also fixed the pipeline. JetBrains removed the mock-Jdk Files from their main branch. As a fix I switched to the 212.5712 branch, where the files still exist. I don't think this should be a permanent solution, but for now it works :)

Interesting, only the Mock-JDK11 directory was removed with this commit - 1.4, 1.7, 1.8 and 1.9 are still there. Maybe that commit can help to find a solution. 🤞

But I have no idea why the build.gradle needs this anyways. Maybe @filiphr knows why.

The latest EAP failed however. Could you please take a look at that error? Thanks in advance! 💪

@hduelme
Copy link
Contributor Author

hduelme commented Oct 17, 2023

As discussed previously, I added an inspection for default properties used with source or expression source property.
For this I added the possible fixes to remove the default source properties.

I also limited the More than one default source property defined, to only apply if the source property is present.

@thunderhook
Copy link
Contributor

I opened separate issues about the EAP build and the annotations.jar problem. Feel free to tackle them. 💪

I just played around with the branch and stumbled accross this. The following code shows No source property defined, which is obviously valid:

    @Mapping(target = "testName", constant = "My name")
    Target map(Source source);

Would you please be so kind and add a test for that and fix it? Thank you!

Copy link
Contributor

@thunderhook thunderhook left a comment

Choose a reason for hiding this comment

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

Still need to get used to this review tool in GitHub 😅 need to add a comment here, see:
#153 (comment)

I tried a few more mappers from the mapstruct-examples project and apart from the one problem, I couldn't find anything else. 💪

When this is fixed, we can merge.

@hduelme
Copy link
Contributor Author

hduelme commented Oct 18, 2023

I opened separate issues about the EAP build and the annotations.jar problem. Feel free to tackle them. 💪

I just played around with the branch and stumbled accross this. The following code shows No source property defined, which is obviously valid:

    @Mapping(target = "testName", constant = "My name")
    Target map(Source source);

Would you please be so kind and add a test for that and fix it? Thank you!

@thunderhook I added an test where the inspection should not show any error. Although I fixed the bug.

Thanks for your feedback

@hduelme
Copy link
Contributor Author

hduelme commented Oct 18, 2023

Damn, I think this checks are too strict.

There are additional cases, where only a target is allowed, see:

* https://github.com/mapstruct/mapstruct/blob/c0d88f86bf4d3de7f2f13a1c8e013d4473039142/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2102IgnoreAllButMapper.java#L20

* https://github.com/mapstruct/mapstruct/blob/53a5c34ed62739feb786a6840b5fe885296f10da/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Mapper.java#L23

* https://github.com/mapstruct/mapstruct/blob/e0eb0f6bb85970e534ebc4a5ea99c85c23bcf8be/processor/src/test/java/org/mapstruct/ap/test/bugs/_2164/Issue2164Mapper.java#L20

* https://github.com/mapstruct/mapstruct/blob/c1fa9bd0bd1e29b01c2c7f951543788b60a4f356/processor/src/test/java/org/mapstruct/ap/test/bugs/_2537/UnmappedSourcePolicyWithImplicitSourceMapper.java#L19

* https://github.com/mapstruct/mapstruct/blob/b35126e60948a69b82c37266d58c752cbeb1fcf7/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderDemoMapper.java#L18

Using your branch on the Mappers in the mapstruct repository is a good way to test the inspections.

Good catch. I will try to fix this too.

@hduelme
Copy link
Contributor Author

hduelme commented Oct 18, 2023

@hduelme
Copy link
Contributor Author

hduelme commented Oct 18, 2023

@hduelme
Copy link
Contributor Author

hduelme commented Oct 18, 2023

@hduelme
Copy link
Contributor Author

hduelme commented Oct 18, 2023

@thunderhook I tested all of your cases myself and looks like I fixed it. Could you confirm?

@thunderhook thunderhook merged commit 14393d1 into mapstruct:main Oct 20, 2023
@thunderhook
Copy link
Contributor

Thanks alot for the contribution (and your patience with the review ping-pong 😄)

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.

3 participants