Skip to content

Source value mapped more than once inspection for @ValueMapping #265

@hduelme

Description

@hduelme

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.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions