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; }
public ReplaceStaticVariableIncrementDecrement(PsiExpression reference, String originalClassName) { super(reference); this.originalClassName = originalClassName; final PsiPrefixExpression prefixExpr = PsiTreeUtil.getParentOfType(reference, PsiPrefixExpression.class); if (prefixExpr != null) { this.reference = prefixExpr; } else { this.reference = PsiTreeUtil.getParentOfType(reference, PsiPostfixExpression.class); } }
@Override public String getTextForElement(PsiElement element) { final PsiJavaToken sign; if (element instanceof PsiPostfixExpression) { sign = ((PsiPostfixExpression)element).getOperationSign(); } else { sign = ((PsiPrefixExpression)element).getOperationSign(); } final String operator = sign.getText(); return IntentionPowerPackBundle.message( "extract.increment.intention.name", operator); }
@Override public void visitPrefixExpression( PsiPrefixExpression prefixExpression) { super.visitPrefixExpression(prefixExpression); final PsiJavaToken token = prefixExpression.getOperationSign(); final IElementType tokenType = token.getTokenType(); if (!tokenType.equals(JavaTokenType.PLUS)) { return; } registerError(token); }
@Override public void visitPrefixExpression(PsiPrefixExpression expression) { mVisitor.report("PsiPrefixExpression", expression.getText(), expression); super.visitExpression(expression); }