mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-186381 bad code green: variable might already have been assigned
Fixed parentheses handling on the left-side of assignment and in unary operations Fixed error message priority
This commit is contained in:
+6
-6
@@ -1249,12 +1249,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
|
||||
PsiElement resolved = result.getElement();
|
||||
if (resolved instanceof PsiVariable && resolved.getContainingFile() == expression.getContainingFile()) {
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
try {
|
||||
myHolder.add(HighlightControlFlowUtil.checkVariableInitializedBeforeUsage(expression, (PsiVariable)resolved, myUninitializedVarProblems,myFile));
|
||||
}
|
||||
catch (IndexNotReadyException ignored) { }
|
||||
}
|
||||
PsiVariable variable = (PsiVariable)resolved;
|
||||
boolean isFinal = variable.hasModifierProperty(PsiModifier.FINAL);
|
||||
if (isFinal && !variable.hasInitializer()) {
|
||||
@@ -1263,6 +1257,12 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
}
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightControlFlowUtil.checkFinalVariableInitializedInLoop(expression, resolved));
|
||||
}
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
try {
|
||||
myHolder.add(HighlightControlFlowUtil.checkVariableInitializedBeforeUsage(expression, (PsiVariable)resolved, myUninitializedVarProblems,myFile));
|
||||
}
|
||||
catch (IndexNotReadyException ignored) { }
|
||||
}
|
||||
}
|
||||
|
||||
PsiElement parent = expression.getParent();
|
||||
|
||||
@@ -1949,11 +1949,13 @@ public class ControlFlowUtil {
|
||||
|
||||
@Nullable
|
||||
private static PsiElement getExpression(@NotNull PsiElement element) {
|
||||
if (element instanceof PsiAssignmentExpression && ((PsiAssignmentExpression)element).getLExpression() instanceof PsiReferenceExpression) {
|
||||
return ((PsiAssignmentExpression)element).getLExpression();
|
||||
if (element instanceof PsiAssignmentExpression) {
|
||||
PsiExpression target = PsiUtil.skipParenthesizedExprDown(((PsiAssignmentExpression)element).getLExpression());
|
||||
return ObjectUtils.tryCast(target, PsiReferenceExpression.class);
|
||||
}
|
||||
else if (element instanceof PsiUnaryExpression) {
|
||||
return ((PsiUnaryExpression)element).getOperand();
|
||||
PsiExpression target = PsiUtil.skipParenthesizedExprDown(((PsiUnaryExpression)element).getOperand());
|
||||
return ObjectUtils.tryCast(target, PsiReferenceExpression.class);
|
||||
}
|
||||
else if (element instanceof PsiDeclarationStatement) {
|
||||
//should not happen
|
||||
|
||||
+13
-1
@@ -130,4 +130,16 @@ class T29a {
|
||||
if (j > 0) break;
|
||||
} while (b == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
class TX {
|
||||
private final int i;
|
||||
private final int j;
|
||||
private final int k;
|
||||
TX() {
|
||||
(i) = 1;
|
||||
(<error descr="Variable 'i' might already have been assigned to">i</error>) = 1;
|
||||
(j) = 1;
|
||||
(<error descr="Variable 'j' might already have been assigned to">j</error>)++;
|
||||
(<error descr="Variable 'k' might not have been initialized">k</error>)++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user