Support for Ternary Operator assignments in var context
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
#217で参照されている既存のvarリファクタリング作業から始め、列挙されている三項演算子の例と前提条件を動作仕様として使用します。レシピが対象となる三項代入にのみvarを適用し、記載された除外ケースをスキップし、変更前後の結果を検証すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Java
- スター
- 156
- フォーク
- 129
- 平均マージ
- 7時間 12分
- マージ済み PR(30日)
- 43
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
openrewrite/rewrite-migrate-java のほかの issue
-
bug
難易度 3/5 半日 初心者へのやさしさ 40/100
openrewrite/rewrite-migrate-java#1292 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
openrewrite/rewrite-migrate-java#1289 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
openrewrite/rewrite-migrate-java#1246 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 32/100
openrewrite/rewrite-migrate-java#1227 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
OptionalNotPresentToIsEmpty rewrites `!isPresent()` on a non-`java.util.Optional` type, producing uncompilable `isEmpty()`再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 70/100
openrewrite/rewrite-migrate-java#1146 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
openrewrite/rewrite-migrate-java の issue をすべて見る
似ている issue
-
RRateLimiter acquire methods accept negative permits and raise available permits above the rate.オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 4 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
krahets/hello-algo#1993 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
NationalSecurityAgency/ghidra#9884 ·
メンテナーはふだん 2 日以内に返信
-
Status: Pending Review Type: Feature Request
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
OpenRefine/OpenRefine#8019 ·
メンテナーはふだん 1 日以内に返信
-
[TEMP] pin maven version to 3.9.x対応中かも @petrenyi-mark が今日担当しました。 オープン
難易度 2/5 1時間未満 初心者へのやさしさ 62/100