private JavaConstantExpressionEvaluator(Set<PsiVariable> visitedVars, final boolean throwExceptionOnOverflow, final Project project, final PsiConstantEvaluationHelper.AuxEvaluator auxEvaluator) { myMapFactory = auxEvaluator != null ? new Factory<ConcurrentMap<PsiElement, Object>>() { @Override public ConcurrentMap<PsiElement, Object> create() { return auxEvaluator.getCacheMap(throwExceptionOnOverflow); } } : new Factory<ConcurrentMap<PsiElement, Object>>() { @Override public ConcurrentMap<PsiElement, Object> create() { final Key<CachedValue<ConcurrentMap<PsiElement, Object>>> key = throwExceptionOnOverflow ? CONSTANT_VALUE_WITH_OVERFLOW_MAP_KEY : CONSTANT_VALUE_WO_OVERFLOW_MAP_KEY; return CachedValuesManager.getManager(myProject).getCachedValue(myProject, key, PROVIDER, false); } }; myProject = project; myConstantExpressionVisitor = new ConstantExpressionVisitor(visitedVars, throwExceptionOnOverflow, auxEvaluator); }
public static Object computeConstantExpression(PsiExpression expression, @Nullable Set<PsiVariable> visitedVars, boolean throwExceptionOnOverflow, final PsiConstantEvaluationHelper.AuxEvaluator auxEvaluator) { if (expression == null) return null; JavaConstantExpressionEvaluator evaluator = new JavaConstantExpressionEvaluator(visitedVars, throwExceptionOnOverflow, expression.getProject(), auxEvaluator); if (expression instanceof PsiCompiledElement) { // in case of compiled elements we are not allowed to use PSI walking // but really in Cls there are only so many cases to handle if (expression instanceof PsiPrefixExpression) { PsiElement operand = ((PsiPrefixExpression)expression).getOperand(); if (operand == null) return null; Object value = evaluator.myConstantExpressionVisitor.handle(operand); ConstantExpressionVisitor.store(operand, value); } return evaluator.myConstantExpressionVisitor.handle(expression); } expression.accept(evaluator); Object cached = evaluator.getCached(expression); return cached == NO_VALUE ? null : cached; }
@Override @Nullable public Object computeExpression(PsiElement expression, boolean throwExceptionOnOverflow, @Nullable PsiConstantEvaluationHelper.AuxEvaluator auxEvaluator) { if (!(expression instanceof GrExpression)) return null; return evaluate((GrExpression)expression); }
@Nullable public Object computeExpression(PsiElement expression, boolean throwExceptionOnOverflow, @Nullable PsiConstantEvaluationHelper.AuxEvaluator auxEvaluator) { if (!(expression instanceof GrExpression)) return null; return evaluate((GrExpression)expression); }
@Override public Object computeExpression(PsiElement expression, boolean throwExceptionOnOverflow, @Nullable PsiConstantEvaluationHelper.AuxEvaluator auxEvaluator) { return expression instanceof PsiExpression ? JavaConstantExpressionEvaluator.computeConstantExpression((PsiExpression)expression, null, throwExceptionOnOverflow, auxEvaluator) : null; }
Object computeExpression(PsiElement expression, boolean throwExceptionOnOverflow, @Nullable PsiConstantEvaluationHelper.AuxEvaluator auxEvaluator);