mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
StringConcatenationInLoop#isAppended: check whether polyadic expression is actually a concatenation (IDEA-CR-16590)
This commit is contained in:
+5
-2
@@ -215,8 +215,11 @@ public class StringConcatenationInLoopsInspection extends BaseInspection {
|
||||
private static boolean isAppended(PsiVariable variable, PsiExpression expression) {
|
||||
expression = PsiUtil.skipParenthesizedExprDown(expression);
|
||||
if(expression instanceof PsiPolyadicExpression) {
|
||||
for(PsiExpression operand : ((PsiPolyadicExpression)expression).getOperands()) {
|
||||
if(ExpressionUtils.isReferenceTo(operand, variable) || isAppended(variable, operand)) return true;
|
||||
PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
|
||||
if (polyadicExpression.getOperationTokenType().equals(JavaTokenType.PLUS)) {
|
||||
for (PsiExpression operand : polyadicExpression.getOperands()) {
|
||||
if (ExpressionUtils.isReferenceTo(operand, variable) || isAppended(variable, operand)) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
+6
@@ -94,6 +94,12 @@ public class StringConcatenationInLoop
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
s = (s == "") + "...";
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
s = ("xyz" <warning descr="String concatenation '+' in loop">+</warning> (i <warning descr="String concatenation '+' in loop">+</warning> s)) <warning descr="String concatenation '+' in loop">+</warning> "...";
|
||||
}
|
||||
System.out.println(foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user