mapstruct / mapstruct-idea

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

Report Non-existing target/source properties as errors #177

Open CodeSimcoe opened 7 months ago

CodeSimcoe commented 7 months ago

Goal is to add a new inspection that reports non-existing target properties

image

CodeSimcoe commented 7 months ago

I found an issue when using dotted . notation, will attempt to fix it

filiphr commented 7 months ago

Thanks for your work on this @CodeSimcoe. Is it possible to report the error on the actual property in the Mapping#target directly? This way it would be immediately clear where the issue is.

CodeSimcoe commented 7 months ago

That would be better indeed. Also, this reporting could be extended to source attribute as well.

And as stated above, I still need to figure out some issues about attributes with dotted . notations like target="field1.field2. I see this is managed for completion but I need to handle this as well here. Any help could be useful... is there a way to easily recursively get all attributes ? I'll work on this when i get some time anyway. Ty

filiphr commented 7 months ago

I've been investigating this a bit and also exploring how IntelliJ is implementing some things like this. e.g. for JUnit's @MethodSource (https://github.com/JetBrains/intellij-community/blob/dff1750f6269d0a51ed4df6b3bc8ef0e9f931e61/plugins/junit/src/com/intellij/execution/junit/codeInspection/JUnitMalformedDeclarationInspection.kt#L539). Seems like we can do resolving here. Perhaps we need to rely on that. Maybe even look into using PsiPolyVariantReference for our source and target references.

CodeSimcoe commented 7 months ago

For a starter, we could only check base target. That is not exhaustive, but that's still better than nothing, most error cases would be raised (this often happens to me during refactors and I only get the error when compiling...). I also moved the error to the attribute itself

image