mapstruct-idea icon indicating copy to clipboard operation
mapstruct-idea copied to clipboard

No language injection for expressions when target is a field

Open Cerber-Ursi opened this issue 3 years ago • 1 comments

Consider the following code:

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

class Target {
  public String value;
}

class Source {
}

@Mapper
abstract class SourceToScratchMapper {
  @Mapping(target = "value", expression = "java(new Source().toString())")
  public abstract Target map(Source source);
}

In this case, code inside expression parameter is treated as a plain string, i.e. no code highlighting and no navigation assistance. However, if we add a setter to the Target class -

class Target {
  public String value;

  public void setValue(String value) {
    this.value = value;
  }
}

...leaving mapper and source the same, the language is injected correctly - code inside java(...) is treated as Java fragment.

Cerber-Ursi avatar Apr 15 '22 09:04 Cerber-Ursi

In fact, the fix seems to be easy, so sent the #96 with patch.

Cerber-Ursi avatar Apr 15 '22 18:04 Cerber-Ursi