mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
computeValue moved to CommonDataflow
GitOrigin-RevId: d0b0c9f10eda163f6fd3e7328d942422b6261895
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2001b7bfb3
commit
62c68622f1
@@ -11,6 +11,7 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.JavaPsiConstructorUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import one.util.streamex.StreamEx;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
@@ -267,6 +268,25 @@ public class CommonDataflow {
|
||||
return dfType instanceof DfIntegralType ? ((DfIntegralType)dfType).getRange() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of given expression calculated via dataflow; or null if value is null or unknown.
|
||||
*
|
||||
* @param expression expression to analyze
|
||||
* @return expression value if known
|
||||
*/
|
||||
@Contract("null -> null")
|
||||
public static Object computeValue(@Nullable PsiExpression expression) {
|
||||
PsiExpression expressionToAnalyze = PsiUtil.skipParenthesizedExprDown(expression);
|
||||
if (expressionToAnalyze == null) return null;
|
||||
Object computed = ExpressionUtils.computeConstantExpression(expressionToAnalyze);
|
||||
if (computed != null) return computed;
|
||||
DataflowResult dataflowResult = getDataflowResult(expressionToAnalyze);
|
||||
if (dataflowResult != null) {
|
||||
return ContainerUtil.getOnlyItem(dataflowResult.getExpressionValues(expressionToAnalyze));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class CommonDataflowVisitor extends StandardInstructionVisitor {
|
||||
private DataflowResult myResult = new DataflowResult(RunnerResult.OK);
|
||||
private final List<DfaMemoryState> myEndOfInitializerStates = new ArrayList<>();
|
||||
|
||||
@@ -322,25 +322,6 @@ public class DfaUtil {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of given expression calculated via dataflow; or null if value is null or unknown.
|
||||
* The expression context is not taken into account; only expression itself.
|
||||
*
|
||||
* @param expression expression to analyze
|
||||
* @return expression value if known
|
||||
*/
|
||||
public static Object computeValue(PsiExpression expression) {
|
||||
PsiExpression expressionToAnalyze = PsiUtil.skipParenthesizedExprDown(expression);
|
||||
if (expressionToAnalyze == null) return null;
|
||||
Object computed = ExpressionUtils.computeConstantExpression(expressionToAnalyze);
|
||||
if (computed != null) return computed;
|
||||
CommonDataflow.DataflowResult dataflowResult = CommonDataflow.getDataflowResult(expressionToAnalyze);
|
||||
if (dataflowResult != null) {
|
||||
return ContainerUtil.getOnlyItem(dataflowResult.getExpressionValues(expressionToAnalyze));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<? extends MethodContract> addRangeContracts(@Nullable PsiMethod method,
|
||||
@NotNull List<? extends MethodContract> contracts) {
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ public class ConditionCoveredByFurtherConditionInspection extends AbstractBaseJa
|
||||
private static int[] getRedundantOperandIndices(PsiPolyadicExpression context, List<PsiExpression> operands, boolean and) {
|
||||
assert !operands.isEmpty();
|
||||
if (operands.size() == 1) {
|
||||
Object value = DfaUtil.computeValue(operands.get(0));
|
||||
Object value = CommonDataflow.computeValue(operands.get(0));
|
||||
return Boolean.valueOf(and).equals(value) ? new int[]{0} : ArrayUtilRt.EMPTY_INT_ARRAY;
|
||||
}
|
||||
String text = StreamEx.ofReversed(operands)
|
||||
|
||||
Reference in New Issue
Block a user