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

Support for completion and Go To Definition within Mapping#qualifiedByName - for shared configurations #136

Closed
philipp-paland opened this issue May 5, 2023 · 5 comments · Fixed by #137
Milestone

Comments

@philipp-paland
Copy link

I love the feature described in #107 - it is extremely helpful. I would like it very much if it also worked in shared configuration classes as described here:

https://mapstruct.org/documentation/stable/reference/html/#shared-configurations

@thunderhook
Copy link
Contributor

thunderhook commented May 5, 2023

This is already supported and covered with the following test (unwrapOptional is referenced in a used mapper from a shared configuration):
https://github.com/thunderhook/mapstruct-idea/blob/b55c1e12fad45b90abb88fa3b0740b3c3a75b4ba/src/test/java/org/mapstruct/intellij/completion/MappingQualifiedByNameCompletionTestCase.java#L54-L54

If it doesn't work for you, would you mind making a minimal reproducible example?

Oh... I see - we identify named methods from methods of referenced mappers (uses = ...) of a shared configuration. But we ignore the methods inside the shared configuration itself, like:

@MapperConfig(uses = OptionalMapper.class)
public class MapperConfigUsingOptionalMapper {

    @Named("thisIsCurrentlyNotCovered")
    public int doSomething(long value) {
        return 0;
    }

}

I will take care of it, thanks for pointing this out.
If your use case is something else, feel free to provide your code.

@philipp-paland
Copy link
Author

philipp-paland commented May 5, 2023

In my case it looks like this:

@Mapper
public interface MyOptionalMapper {

  @Named("stringLength")
  default int stringLength(String str) {
    return str.length();
  }
}
@MapperConfig(uses = MyOptionalMapper.class)
public interface MyMapperConfig {

  @Mapping(target = "targetInt", source = "sourceString", qualifiedByName = "stringLength")
  TargetBean doSomething(SourceBean value);
}
@Mapper(config = MyMapperConfig.class)
public interface MyMapperUsingConfig {

  @InheritConfiguration
  TargetBean doSomething(SourceBean value);
}

I can't navigate to "qualifiedByName = "stringLength"" in the IDE.

I have mapstruct 1.5.4, Intellij 2023.1, MapStruct Support 1.5.0

@thunderhook
Copy link
Contributor

thunderhook commented May 5, 2023

Thank you for the reproducal. The PR #137 handles references inside a @MapperConfig now.

Oh... I see - we identify named methods from methods of referenced mappers (uses = ...) of a shared configuration. But we ignore the methods inside the shared configuration itself, like:

@MapperConfig(uses = OptionalMapper.class)
public class MapperConfigUsingOptionalMapper {

    @Named("thisIsCurrentlyNotCovered")
    public int doSomething(long value) {
        return 0;
    }

}

@Named methods inside a shared configuration itself are not supported by MapStruct itself, therefore I did not handle this case. I don't know if this is by design or a not-yet implemented feature (or bug).

thunderhook added a commit to thunderhook/mapstruct-idea that referenced this issue May 5, 2023
@filiphr
Copy link
Member

filiphr commented May 7, 2023

Thanks for working on this @thunderhook.

@Named methods inside a shared configuration itself are not supported by MapStruct itself, therefore I did not handle this case. I don't know if this is by design or a not-yet implemented feature (or bug).

This is by design. Methods in a @MapperConfig are only template methods, we are not using them to invoke any code.

@filiphr filiphr added this to the 1.6.0 milestone May 7, 2023
filiphr pushed a commit that referenced this issue May 7, 2023
@philipp-paland
Copy link
Author

It works, thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants