Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Completion for java "expression" does't work with DTO as records

Open
#245 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
devtools

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mapstruct/mapstruct-idea

All issues in mapstruct/mapstruct-idea

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.