mapstruct / mapstruct/mapstruct-idea

Source value mapped more than once inspection for @ValueMapping

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

Nobody has claimed this yet.

feature hack.commit.push
Dominant language
Java
Stars
168
Forks
41
PR merge metrics
No merged PRs in 30d

Description

For value mappings a source value can only be mapped once. For example
```
import org.mapstruct.Mapper;
import org.mapstruct.ValueMapping;

@Mapper
public interface ValueMapper {

enum A {
A,B
}

enum B {
A,B
}

@ValueMapping(source = "A", target = "B")
@ValueMapping(source = "A", target = "A")
A from(B b);
}
```
is invalide as source `A` is mapped twice. MapStruct report this as

> Source value mapping: "A" cannot be mapped more than once.

Currently the plugin does not recognize this as an error. An inspection should be added for this.

For normal mappings there is already an inspection implemented and could be used as an example: https://github.com/mapstruct/mapstruct-idea/blob/main/src/main/java/org/mapstruct/intellij/inspection/TargetPropertyMappedMoreThanOnceInspection.java.

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 with src/main/java/org/mapstruct/intellij/inspection/TargetPropertyMappedMoreThanOnceInspection.java, which provides the existing inspection pattern. Trace how it detects duplicate normal mappings, then apply the same approach to @ValueMapping source values. Done means duplicate source values are recognized and reported with the expected error message.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.