Completion for java "expression" does't work with DTO as records
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
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.
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();
}
- Dominant language
- Java
- Stars
- 168
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
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.
More from mapstruct/mapstruct-idea
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
mapstruct/mapstruct-idea#274 · 2 comments ·
-
feature hack.commit.push
Difficulty 3/5 1-2 days Newbie friendliness 68/100
mapstruct/mapstruct-idea#267 ·
-
feature hack.commit.push
Difficulty 3/5 1-2 days Newbie friendliness 55/100
mapstruct/mapstruct-idea#266 ·
-
feature hack.commit.push
Difficulty 3/5 1-2 days Newbie friendliness 75/100
mapstruct/mapstruct-idea#265 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
mapstruct/mapstruct-idea#257 · 1 comment ·
All issues in mapstruct/mapstruct-idea
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Two open-case totals on one screen: the Programs tile says 15,858 and the nav badge says 15,868 Openbug frontend maui-pilot
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
objectionary/eo-graphs#74 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100