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

Kotlin support for target / source in @Mapping and @ValueMapping #20

Closed
aRusenov opened this issue Nov 8, 2017 · 6 comments
Closed
Labels
Milestone

Comments

@aRusenov
Copy link

aRusenov commented Nov 8, 2017

Currently the plugin only works in .java @Mapper classes (though it offers completions for source and target when referencing Kotlin classes as well!). It seems as if the plugin is simply not triggered in .kt mappers, but it works otherwise fine with Kotlin.

Kotlin Mapper interface:
Kotlin

Java Mapper interface:
Java

In both cases the DTO and model are Kotlin classes.

Versions used:

  • Kotlin 1.1.51
  • mapstruct 1.2.0.final
  • IntelliJ Community Edition 2017.2.3
@filiphr
Copy link
Member

filiphr commented Jun 9, 2018

The plugin uses the default way of accessing the annotations in elements. I have to dig in to understand how it works within kotlin. If someone has some idea or knows what exactly needs to be done I am looking forward to your help 😄

@lppedd
Copy link

lppedd commented Aug 30, 2018

@filiphr I can have a look at it, I want to keep using Kotlin and completion is always helpful. Could you maybe point to a starting class?

@filiphr
Copy link
Member

filiphr commented Aug 31, 2018

One starting point would be Handling code from the IntelliJ SDK documentation.

As for the plugin some starting classes that you would need to look are:

<psi.referenceContributor language="JAVA" implementation="org.mapstruct.intellij.codeinsight.references.MapstructReferenceContributor" />
<methodReferencesSearch implementation="org.mapstruct.intellij.search.MappingMethodUsagesSearcher" />
<renameHandler implementation="org.mapstruct.intellij.rename.MapstructSourceTargetParameterRenameHandler"/>

The way the completion works is by providing references through a reference contributor. The MapstructReferenceContributor is the one that registers the contributors. I think that you can actually use the same implementation, but you would need to provide different MapstructElementUtils that would be able to get the PsiElement from the kotlin plugin.

The MappingMethodUsagesSearcher is something I needed to add for find usages to work. Maybe it would work ootb with Kotlin, as I don't see anything specific to Java in there.

The MapstructSourceTargetParameterRenameHandler is something I needed to add for renaming to work properly, I think that we can reuse that as well, but we would need to find a neat way to pass MAPPING_SOURCE_OR_TARGET as the Kotlin plugin dependency should be optional.

There are some tests, that might guide you and that you might be able to utilise for debugging

@greenarr0w
Copy link

Are there any news on this issue? It would be very nice to have kotlin support.

@filiphr
Copy link
Member

filiphr commented Dec 11, 2019

@greenarr0w I haven't had a lot of time to look into this. If someone from the community would like to step up and help with this it would be much appreciated.

ifrankwang added a commit to ifrankwang/mapstruct-idea that referenced this issue Aug 14, 2020
filiphr added a commit that referenced this issue Oct 17, 2020
Make sure that plugin works with a disabled Kotlin plugin
filiphr added a commit that referenced this issue Oct 17, 2020
Make sure that plugin works with a disabled Kotlin plugin
@filiphr filiphr added this to the 1.2.3 milestone Oct 17, 2020
@filiphr
Copy link
Member

filiphr commented Oct 17, 2020

Done in 41dd190 and 1119db7

thanks @ifrankwang for your work on this.

@filiphr filiphr closed this as completed Oct 17, 2020
@filiphr filiphr changed the title Kotlin support Kotlin support for target / source in @Mapping and @ValueMapping Oct 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants