mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ManualArrayCopyInspection: prevent changing semantics : IDEA-52481
This commit is contained in:
+9
-2
@@ -16,6 +16,7 @@
|
||||
package com.siyeh.ig.performance;
|
||||
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.dataFlow.DfaUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
@@ -84,7 +85,13 @@ public class ManualArrayCopyInspection extends BaseInspection {
|
||||
if (newExpression == null) {
|
||||
return;
|
||||
}
|
||||
PsiReplacementUtil.replaceStatement(forStatement, newExpression, commentTracker);
|
||||
PsiIfStatement ifStatement = (PsiIfStatement)commentTracker.replaceAndRestoreComments(forStatement, newExpression);
|
||||
if (Boolean.TRUE.equals(DfaUtil.evaluateCondition(ifStatement.getCondition()))) {
|
||||
PsiStatement nakedSubListClear = ControlFlowUtils.stripBraces(ifStatement.getThenBranch());
|
||||
assert nakedSubListClear != null;
|
||||
CommentTracker ct = new CommentTracker();
|
||||
ct.replaceAndRestoreComments(ifStatement, ct.markUnchanged(nakedSubListClear));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -161,7 +168,7 @@ public class ManualArrayCopyInspection extends BaseInspection {
|
||||
final String toOffsetText = buildOffsetText(strippedLhsIndexExpression, variable,
|
||||
limitExpression, decrement && (JavaTokenType.LT.equals(tokenType) || JavaTokenType.GT.equals(tokenType)),
|
||||
commentTracker);
|
||||
return "System.arraycopy(" + fromArrayText + ", " + fromOffsetText + ", " + toArrayText + ", " + toOffsetText + ", " + lengthText + ");";
|
||||
return "if(" + lengthText + ">=0)" + "System.arraycopy(" + fromArrayText + ", " + fromOffsetText + ", " + toArrayText + ", " + toOffsetText + ", " + lengthText + ");";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user