Support for Ternary Operator assignments in var context
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu với công việc tái cấu trúc var hiện có được tham chiếu trong #217 và sử dụng các ví dụ ternary cùng các điều kiện tiên quyết được liệt kê làm đặc tả hành vi. Công việc được xem là hoàn tất khi recipe chỉ áp dụng var cho các phép gán ternary đủ điều kiện, bỏ qua các trường hợp loại trừ đã nêu và kiểm tra kết quả trước và sau.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What problem are you trying to solve?
While developing #217 I discovered that handling, especially detecting ternary operator assignments, is hard.
With this issue, Rewrite become able to apply ´var´ to ternary operator assignments.
What precondition(s) should be checked before applying this recipe?
var should not be applied to variable declarations where:
- the type of the ternary operator and the left-hand side don't match
- the type is byte or short
- only null is assigned
- the declaration is outside a method declaration
Describe the situation before applying the recipe
class A {
void foo(String bar) {
int i1 = bar != null ? 3 : 5;
Integer i2 = bar != null ? 3 : null;
Integer i3 = bar == null ? null : bar.lenght();
Integer i4 = bar != null ? throw new IlligalArgumentExcpetion() : -1;
int i5 = bar != null ? bar.lenght() : 0;
float f1 = bar != null ? 3f : 3.5;
}
}
Describe the situation after applying the recipe
class A {
void foo(String bar) {
var i1 = bar != null ? 3 : 5;
var i2 = bar != null ? 3 : null;
var i3 = bar == null ? null : bar.lenght();
var i4 = bar != null ? throw new IlligalArgumentExcpetion() : -1;
var i5 = bar != null ? bar.lenght() : 0;
var f1 = bar != null ? 3f : 3.5;
}
}
Have you considered any alternatives or workarounds?
An alternative would be to skip every ternary operator, this would lead to no 100% local variable type inference for rewrite.
Any additional context
It would be nice to write a separate recipe for this and integrate them later on as global var refactoring.
Are you interested in contributing this recipe to OpenRewrite?
not now.
- Ngôn ngữ chính
- Java
- Star
- 156
- Fork
- 129
- Merge trung bình
- 7 giờ 21 phút
- Pull request đã merge (30 ngày)
- 42
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của openrewrite/rewrite-migrate-java
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
openrewrite/rewrite-migrate-java#1289 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 68/100
openrewrite/rewrite-migrate-java#1246 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 32/100
openrewrite/rewrite-migrate-java#1227 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
OptionalNotPresentToIsEmpty rewrites `!isPresent()` on a non-`java.util.Optional` type, producing uncompilable `isEmpty()`Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 70/100
openrewrite/rewrite-migrate-java#1146 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 50/100
openrewrite/rewrite-migrate-java#1119 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của openrewrite/rewrite-migrate-java
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
apache/rocketmq-dashboard#6610 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Citationcount column sorts alphabetically instead of numericallyCó thể đã có người làm @kpunia306 đã nhận hôm nay. Đang mởstatus: needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
JabRef/jabref#17459 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`RedisList.reversed()` view returns an empty `range` and `trim` removes all elementsCó thể đã có người làm @CCCLL đã nhận hôm nay. Đang mởstatus: waiting-for-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
spring-projects/spring-data-redis#3461 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
javapathfinder/jpf-core#649 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
devops-thiago/ThrillhouseBot#1093 ·
Maintainer thường phản hồi trong vòng 1 ngày