mapstruct / mapstruct-idea

An IntelliJ IDEA plugin for working with MapStruct
Other
136 stars 38 forks source link

Fix RemoveMappersFix by using SafeDeleteFix #179

Closed hduelme closed 6 months ago

hduelme commented 6 months ago

@filiphr I found a working solution for #155 I used the SafeDeleteFix to delete the instance unlike my solution in #176 it checks for usage.

hduelme commented 6 months ago

@filiphr the null return of createRemoveMappersFix could still happen. For example:

@Mapper(componentModel = "spring")
abstract class WrongComponentModelMapper {

    static {
        Mappers.getMapper(WrongComponentModelMapper.class);
    }

    Target map(Target source);
}

or

@Mapper(config = MyConfig.class, componentModel = "spring")
interface WrongComponentModelMapper {

    WrongComponentModelMapper INSTANCE = () -> {
        return Mappers.getMapper(WrongComponentModelMapper.class);
    };

    Target map(Target source);
}

No variable to delete but the inspection still shows up. Or while typing. This would cause a plugin crash if we don't check.

Alternatively we could change the behavior to always return the delete Option.

filiphr commented 6 months ago

OK gotcha, I believe that this would have been a problem with the current version already. I don't think that we took such use cases into consideration.

I think that we can do this step by step.

  1. Make sure that the inspection and quick fix work on 2023.3 and later
  2. Add support for the 2 additional examples that you provided

What do you think @hduelme?

hduelme commented 6 months ago

@filiphr Yes, we should solve it step by step. There should be no possible crashes in this version. So I would leaf it as it is for now. Would you open a issue for step 2?

filiphr commented 6 months ago

Would you open a issue for step 2?

Yup, I've opened #183 for this.

I'll proceed with merging this one