mapstruct / mapstruct/mapstruct-idea
Completion for java "expression" does't work with DTO as records
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 168
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
Description
Example mapper:
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
public interface OrderMapper {
OrderGetAllDto toOrderDto(Order order);
default <T, R> R mapFromAggregateReference(AggregateReference<T, R> aggregateReference) {
if (aggregateReference == null) {
return null;
}
return aggregateReference.getId();
}
@Mapping(target = "orderPaymentRefPayments", expression = "java(orderPaymentRefsToOrderPaymentRefPayments())")
OrderDto toOrderGetOneDto(Order order);
default Set<Long> orderPaymentRefsToOrderPaymentRefPayments(Set<OrderPaymentRef> orderPaymentRefs) {
return orderPaymentRefs.stream()
.map(OrderPaymentRef::getPayment)
.map(AggregateReference::getId)
.collect(Collectors.toSet());
}
}
DTO as JAVA record:
public record OrderDto(Long id, String number, Integer owner, Set<Long> orderPaymentRefPayments,
List<OrderItemDto> orderItems, BigDecimal totalCost, LocalDateTime createdDate,
LocalDateTime lastModifiedDate) {
/**
* DTO for {@link OrderItem}
*/
public record OrderItemDto(Long id, Long service, Integer quantity, String serviceName, BigDecimal price,
BigDecimal cost) {
}
}
When writing an JAVA expression for
@Mapping(target = "orderPaymentRefPayments", expression = "java()")
completion hints are not displayed.
Because OrderDto is a record and it's not possible to resolve target type in sources org.mapstruct.intellij.expression.JavaExpressionInjector, see
PsiElement resolved = references[0].resolve();
if ( resolved instanceof PsiMethod resolvedPsiMethod ) {
PsiParameter[] psiParameters =
resolvedPsiMethod.getParameterList().getParameters();
if ( psiParameters.length > 0) {
targetType = psiParameters[0].getType();
}
}
else if ( resolved instanceof PsiParameter resolvedPsiParameter ) {
targetType = resolvedPsiParameter.getType();
}
else if ( resolved instanceof PsiField resolvedPsiField ) {
targetType = resolvedPsiField.getType();
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in org.mapstruct.intellij.expression.JavaExpressionInjector and inspect how the resolved target is converted to a type for Java expressions. Reproduce the completion request with the OrderDto record and check that completion hints appear for orderPaymentRefPayments; done means the record component's target type is resolved without regressing existing field, method, or parameter handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100