mapstruct / mapstruct-idea

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

support Multi-line Java expression (#82 #98) #158

Closed cofedream closed 7 months ago

cofedream commented 1 year ago

This is related to #82 #98 . I could aslo supported java text blocks, but I don't know if I need to do it. Because test cases always run fail on my computer, I can't use test cases for testing, so I am currently using runIde for test. Maybe someone can help me write the unit tests.

thunderhook commented 11 months ago

Hi @cofedream!

Sorry it took me so long to review this. I have not looked at the code yet, but I checked your branch and tried some examples via runIde. However, my test data (also using java text blocks, but these can be ignored) did not work completely, only the first line, see: grafik

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

import java.math.BigDecimal;
import java.util.List;

@Mapper
interface MultilineMapper {

    @Mapping(target = "someField", expression = "java(" +
            "java.time.LocalDate.MAX" +
            ")")
    B mapDemo1(A order);

    @Mapping(target = "someField", expression = """
            java(
            java.time.LocalDate.from(
            java.time.LocalDate.MAX);
            )
            """)
    B mapDemo2(A order);

    @Mapping(target = "someField", expression = "java(dto.getDetailList().stream()" +
            ".map(ADetail::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add))")
    B mapDemoIssue82(A dto);

    @Mapping(target = "someField",
            expression = "java(EnumClass1.ENUM_VALUE_1 == dto.getEnumValue1()"
                    + " ? someValidCode()"
                    + " : otherValidCode())")
    B mapDemoIssue98(A dto);

}

class A {

    public String someField;
    private List<ADetail> detailList;

    public List<ADetail> getDetailList() {
        return detailList;
    }
}

class ADetail {

    BigDecimal amount;

    public BigDecimal getAmount() {
        return amount;
    }
}

class B {
    public String someField;
}

What examples have you used during implementation?

Because test cases always run fail on my computer, I can't use test cases for testing, so I am currently using runIde for test. Maybe someone can help me write the unit tests.

Sure. What exactly do you mean by "always run fail on my machine"? Can you provide some error logs? Does this only happen in IntelliJ or also in the gradle build?

hduelme commented 11 months ago

Hi @cofedream Your branch is currently behind #153. That's the reason your tests are failing. Try to rebase your branch and then run ./gradlew clean. After this everything should work with ./gradlew build. If you are using windows use gradlew.bat instead of gradlew.

filiphr commented 7 months ago

@hduelme is this obsolete with me merging #188, or do you think that this is addressing a different need?

hduelme commented 7 months ago

@filiphr sadly IntelliJ treats multi-line Java text differently. So this pr is still relevant.

cofedream commented 7 months ago

Now I have time to do this matter, I'm going to reprocess and submit.

filiphr commented 7 months ago

Take all the time you need @cofedream. Feel free to create a new PR or reopen this one if you want us to look into it.

If you don't have time then please let us know so that we can work on this.