mapstruct / mapstruct/mapstruct-idea

Plugin won't recognize @Named class

Open
#247 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
168
Forks
41
PR merge metrics
No merged PRs in 30d

Description

I was trying to implement this pattern from documentation:

Image

As for mapper itself, it is working fine and dandy. The plugin, however, seems to have problem with finding the annotated class which contains annotated mapping method. Error description is provided:

"Unknown @ Named reference 'TranslationMapper' ".

Reference for "TranslationsToString" is found properly.

@Mapper(uses = TranslationMapper.class)
public interface PrimaryClassMapper {
    @Mapping(source = "primary.id", target = "id")
    @Mapping(
            source = "primary.translatedNames",
            target = "name",
            qualifiedByName = {"TranslationMapper", "TranslationsToString"})
    SecondaryClass toSecondaryClass(PrimaryClass primary, @Context Language targetLanguage);
}
@Named("TranslationMapper")
public class TranslationMapper {
    @Named("TranslationsToString")
    public String resolveTranslatedText(
            List<TranslationDto> translations, @Context Language targetLanguage) {
        //some fancy logic
    }
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the warning with the PrimaryClassMapper and TranslationMapper examples in the issue, focusing on the class-level and method-level @Named annotations and the qualifiedByName reference. Done means the plugin recognizes the class-level "TranslationMapper" reference without reporting it as unknown while still resolving "TranslationsToString".

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.