Skip to content

Support go to declaration for Mapper#qualifiedByName#119

Merged
filiphr merged 4 commits intomapstruct:mainfrom
thunderhook:go-to-qualified-by-name
Apr 2, 2023
Merged

Support go to declaration for Mapper#qualifiedByName#119
filiphr merged 4 commits intomapstruct:mainfrom
thunderhook:go-to-qualified-by-name

Conversation

@thunderhook
Copy link
Contributor

@thunderhook thunderhook commented Dec 26, 2022

This pull request closes #107.

What it does:

  • Provide code-completion for @Mapping#qualifiedByName
  • Code-complete "local" named methods (from the current mapper class)
  • Code-complete "external" named methods (defined by @Mapper(uses = AnotherMapper.class))
  • Filters out named methods that are used for @BeforeMapping/@AfterMapping: I just provide named methods containing a return type different than PsiType.VOID - maybe this needs to be more precise?

What it does not:

  • Provide code-completion of the @BeanMapping#qualifiedByName: I tried to implement it, but discarded it due to the complexity of nested qualifiers as seen here

@thunderhook thunderhook force-pushed the go-to-qualified-by-name branch 2 times, most recently from 69c303c to 0446f0b Compare December 27, 2022 00:11
provides code completion and resolving of named methods from  local and external (defined with `uses = ...`) mappers
@thunderhook thunderhook force-pushed the go-to-qualified-by-name branch from 0446f0b to ac592b0 Compare December 27, 2022 00:16
@almogtavor
Copy link

almogtavor commented Jan 12, 2023

@thunderhook Looks awesome thanks! Can you tell when approximately this should get merged?

@thunderhook
Copy link
Contributor Author

Since I am not a part of the plugin maintainers, I can't really tell. It depends on the free time of the plugin maintainers (e.g. @filiphr) and if the pull request looks good to them.

If they get time, it usually will be released quickly. 🙂

Copy link
Member

@filiphr filiphr left a comment

Choose a reason for hiding this comment

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

This is really great work @thunderhook. The functionality is great. I've added some comments to clean it up a bit.

Please let us know if you don't have the time to finish it.

Btw. sorry for the late reply, but I've been pretty busy lately and haven't had enough time to look into this.

* @return the classes / interfaces that are defined with the {@code uses} attribute,
* or {@code null} if there isn't anything defined
*/
public static List<PsiClass> resolveUsesConfigClasses(PsiAnnotation mapperAnnotation) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we also look into the Mapper#config class for this? We do something with it in TargetUtils#isBuilderEnabled (as a reference example). Would also be good to add a test case for it as well

Comment on lines +65 to +66
.filter( MapstructUtil::isNamedMethod )
.filter( this::methodHasReturnType )
Copy link
Member

Choose a reason for hiding this comment

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

Let's move these checks in the findAllMethodsFromThisAndReferencedMappers. That one is already partially doing this for the named methods in used mappers.

Comment on lines +99 to +100
.filter( MapstructUtil::isNamedMethod )
.filter( this::methodHasReturnType )
Copy link
Member

Choose a reason for hiding this comment

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

Let's move these checks in the findAllMethodsFromThisAndReferencedMappers. That one is already partially doing this for the named methods in used mappers.

}

@NotNull
private List<PsiMethod> findAllMethodsFromThisAndReferencedMappers(@NotNull PsiMethod mappingMethod) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that it is better if we return a Stream<PsiMethod> here

method,
lookupString,
lookupString,
String.format(
Copy link
Member

Choose a reason for hiding this comment

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

I think that for this it would be good to show the method parameters here as well. e.g. StringMapper#trim(String).

@thunderhook
Copy link
Contributor Author

I added the named method resolving of mappers that are referenced by @MapperConfig.
I also changed a named method in a test to cover the display of multiple parameters.
Please take a look and let me know if there is something else missing. 🙂

If you have any other ideas for this plugin (with that kind of complexity), please let me know, and I'm willing to help out again. 👍

* More resilient
** When mapper config class does not have `@MapperConfig`
** When `@Named` has no value
* Rename methods to match the fact that we are returning methods annotated with `@Named`
* Remove obsolete `@Mapper` on a util class in Mapper#uses
@filiphr
Copy link
Member

filiphr commented Apr 2, 2023

That's a lot for your changes @thunderhook. I pushed one more commit with some small polishing.

If you have any other ideas for this plugin (with that kind of complexity), please let me know, and I'm willing to help out again.

Thanks for offering your help. I think that you can have a look at the open issues to see what is being requested. If you are interested in something let us know. Also if you have some other ideas that you'd like to see let us know, we are more than happy to accept your contributions.

@filiphr filiphr merged commit 3047d18 into mapstruct:main Apr 2, 2023
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.

Support for completion and Go To Definition within Mapping#qualifiedByName

3 participants