You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
classA {
voidfoo(Stringbar) {
inti1 = bar != null ? 3 : 5;
Integeri2 = bar != null ? 3 : null;
Integeri3 = bar == null ? null : bar.lenght();
Integeri4 = bar != null ? thrownewIlligalArgumentExcpetion() : -1;
inti5 = bar != null ? bar.lenght() : 0;
floatf1 = bar != null ? 3f : 3.5;
}
}
Describe the situation after applying the recipe
classA {
voidfoo(Stringbar) {
vari1 = bar != null ? 3 : 5;
vari2 = bar != null ? 3 : null;
vari3 = bar == null ? null : bar.lenght();
vari4 = bar != null ? thrownewIlligalArgumentExcpetion() : -1;
vari5 = bar != null ? bar.lenght() : 0;
varf1 = 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.
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:Describe the situation before applying the recipe
Describe the situation after applying the recipe
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.
The text was updated successfully, but these errors were encountered: