private boolean isApplicableToNode(final SNode node, final EditorContext editorContext) {
   return (IntentionUtils.getExpressionFromNode(SLinkOperations.getTarget(node, "ifTrue", true))
           != null)
       && (IntentionUtils.getExpressionFromNode(
               SLinkOperations.getTarget(node, "ifFalseStatement", true))
           != null)
       && ListSequence.fromList(SLinkOperations.getTargets(node, "elsifClauses", true)).isEmpty();
 }
 public void execute(final SNode node, final EditorContext editorContext) {
   SNode ternaryOperator =
       _quotation_createNode_78c6t8_a0a0a(
           SLinkOperations.getTarget(node, "condition", true),
           IntentionUtils.getExpressionFromNode(SLinkOperations.getTarget(node, "ifTrue", true)),
           IntentionUtils.getExpressionFromNode(
               SLinkOperations.getTarget(node, "ifFalseStatement", true)));
   SNodeOperations.replaceWithAnother(node, ternaryOperator);
 }
Exemple #3
0
  public void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
    final GrIfStatement parentStatement = (GrIfStatement) element;
    assert parentStatement != null;
    final GrStatement parentThenBranch = (GrStatement) parentStatement.getThenBranch();
    final GrIfStatement childStatement =
        (GrIfStatement) ConditionalUtils.stripBraces(parentThenBranch);

    final GrExpression childCondition = (GrExpression) childStatement.getCondition();
    final String childConditionText;
    if (ParenthesesUtils.getPrecendence(childCondition) > ParenthesesUtils.AND_PRECEDENCE) {
      childConditionText = '(' + childCondition.getText() + ')';
    } else {
      childConditionText = childCondition.getText();
    }

    final GrExpression parentCondition = (GrExpression) parentStatement.getCondition();
    final String parentConditionText;
    if (ParenthesesUtils.getPrecendence(parentCondition) > ParenthesesUtils.AND_PRECEDENCE) {
      parentConditionText = '(' + parentCondition.getText() + ')';
    } else {
      parentConditionText = parentCondition.getText();
    }

    final GrStatement childThenBranch = (GrStatement) childStatement.getThenBranch();
    @NonNls
    final String statement =
        "if(" + parentConditionText + "&&" + childConditionText + ')' + childThenBranch.getText();
    IntentionUtils.replaceStatement(statement, parentStatement);
  }
 public void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
   final GrLiteral exp = (GrLiteral) element;
   @NonNls String textString = exp.getText();
   final int textLength = textString.length();
   final char lastChar = textString.charAt(textLength - 1);
   final boolean isLong = lastChar == 'l' || lastChar == 'L';
   if (isLong) {
     textString = textString.substring(0, textLength - 1);
   }
   final BigInteger val;
   if (textString.startsWith("0x")) {
     final String rawTextString = textString.substring(2);
     val = new BigInteger(rawTextString, 16);
   } else {
     val = new BigInteger(textString, 10);
   }
   String octString = '0' + val.toString(8);
   if (isLong) {
     octString += 'L';
   }
   IntentionUtils.replaceExpression(octString, exp);
 }