Exemplo n.º 1
0
  public void processIntention(PsiElement element) throws IncorrectOperationException {
    final PsiAssertStatement assertStatement = (PsiAssertStatement) element;
    assert assertStatement != null;
    final PsiExpression condition = assertStatement.getAssertCondition();
    final PsiExpression description = assertStatement.getAssertDescription();

    final String negatedConditionString = BoolUtils.getNegatedExpressionText(condition);
    @NonNls final String newStatement;
    if (description == null) {
      newStatement = "if(" + negatedConditionString + "){ throw new IllegalArgumentException();}";
    } else {
      newStatement =
          "if("
              + negatedConditionString
              + "){ throw new IllegalArgumentException("
              + description.getText()
              + ");}";
    }
    replaceStatement(newStatement, assertStatement);
  }