mapstruct / mapstruct/mapstruct

WriteAccessors prefers 'later' candidates to earlier ones?

Đang mở
#3,258 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Java
Star
7.7k
Fork
1.1k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

On this line, why does it prefer to overwrite the existing candidate if it has found one? It seems somewhat arbitrary.

https://github.com/mapstruct/mapstruct/blob/1ab5db6a2774a58a6c41b5e4c2bfb23b2fa1bab7/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java#L806

I guess the particular reason I'm asking is that when it is mapping to Immutable.Builders, it finds both the 'normal' setter and the one that accepts an Optional, and it prefers the Optional because it comes later in the candidate list, even though the 'normal' setter would be marginally more efficient - and wouldn't require me to define loads of

Optional<? extends MyClass> toOptional(MyClass x)

methods. The Builders have no readAccessors unfortunately, so it can only really match on the propertyName and is unable to determine the 'preferredType'. This is when a custom SPI is in use btw (the protobuf one), so it isn't using ImmutablesAccessorNamingStrategy though from a brief look that wouldn't make a difference anyway.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu tại dòng 806 của processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java và theo dõi cách các ứng viên WriteAccessors được thay thế. Tái hiện ánh xạ Immutable.Builder bằng protobuf custom SPI, đồng thời so sánh các setter thông thường với các setter Optional. Khi hoàn tất, việc chọn ứng viên phải có chủ đích thay vì phụ thuộc vào thứ tự danh sách, kèm theo coverage cho trường hợp này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.