mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
DeferFinalAssignmentFix should not be available if the previous assignment occurred in another member
E.g. in field initializer or in chained constructor: in this case defer does something strange and doesn't fix the problem GitOrigin-RevId: bb50f7b0ccd847a61b7e00864706a2cb5ce86dcf
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c7557bba96
commit
1c910b0b32
@@ -505,6 +505,7 @@ public class HighlightControlFlowUtil {
|
||||
break;
|
||||
}
|
||||
}
|
||||
boolean canDefer = !inLoop;
|
||||
|
||||
if (!alreadyAssigned) {
|
||||
if (!(variable instanceof PsiField)) return null;
|
||||
@@ -555,6 +556,7 @@ public class HighlightControlFlowUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
canDefer = !alreadyAssigned;
|
||||
}
|
||||
|
||||
if (alreadyAssigned) {
|
||||
@@ -563,7 +565,7 @@ public class HighlightControlFlowUtil {
|
||||
final HighlightInfo highlightInfo =
|
||||
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
|
||||
HighlightFixUtil.registerMakeNotFinalAction(variable, highlightInfo);
|
||||
if (!inLoop) {
|
||||
if (canDefer) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createDeferFinalAssignmentFix(variable, expression));
|
||||
}
|
||||
return highlightInfo;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Defer assignment to 'x' using temp variable" "false"
|
||||
import java.io.*;
|
||||
|
||||
class a {
|
||||
final int x;
|
||||
|
||||
a(int _x) {
|
||||
x = _x;
|
||||
}
|
||||
|
||||
a() {
|
||||
this(0);
|
||||
<caret>x = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user