Search in sources :

Example 1 with PsiAssertStatement

use of com.intellij.psi.PsiAssertStatement in project intellij-community by JetBrains.

the class AssertionCanBeIfInspection method doFixImpl.

private static void doFixImpl(@NotNull PsiElement element) {
    final PsiAssertStatement assertStatement = (PsiAssertStatement) element;
    @NonNls final StringBuilder newStatement = new StringBuilder();
    final PsiExpression condition = assertStatement.getAssertCondition();
    newStatement.append("if(").append(BoolUtils.getNegatedExpressionText(condition)).append(") throw new java.lang.AssertionError(");
    final PsiExpression description = assertStatement.getAssertDescription();
    if (description != null) {
        newStatement.append(description.getText());
    }
    newStatement.append(");");
    PsiReplacementUtil.replaceStatement(assertStatement, newStatement.toString());
}
Also used : NonNls(org.jetbrains.annotations.NonNls) PsiExpression(com.intellij.psi.PsiExpression) PsiAssertStatement(com.intellij.psi.PsiAssertStatement)

Aggregations

PsiAssertStatement (com.intellij.psi.PsiAssertStatement)1 PsiExpression (com.intellij.psi.PsiExpression)1 NonNls (org.jetbrains.annotations.NonNls)1