mapstruct-idea icon indicating copy to clipboard operation
mapstruct-idea copied to clipboard

Report Non-existing target/source properties as errors

Open CodeSimcoe opened this issue 1 year ago • 5 comments

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

image

CodeSimcoe avatar Mar 10 '24 18:03 CodeSimcoe

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

CodeSimcoe avatar Mar 11 '24 09:03 CodeSimcoe

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.

filiphr avatar Mar 14 '24 06:03 filiphr

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

CodeSimcoe avatar Mar 14 '24 07:03 CodeSimcoe

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.

filiphr avatar Mar 16 '24 12:03 filiphr

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

CodeSimcoe avatar Mar 16 '24 15:03 CodeSimcoe