コード例 #1
0
 /**
  * Generates blocks for binary expressions
  *
  * @param node
  * @return
  */
 private static List<Block> generateForBinaryExpr(
     final ASTNode node, Wrap myWrap, CodeStyleSettings mySettings) {
   final ArrayList<Block> subBlocks = new ArrayList<Block>();
   Alignment alignment =
       mySettings.ALIGN_MULTILINE_BINARY_OPERATION ? Alignment.createAlignment() : null;
   MoonBinaryExpression myExpr = (MoonBinaryExpression) node.getPsi();
   ASTNode[] children = node.getChildren(null);
   if (myExpr.getLeftExpression() instanceof MoonBinaryExpression) {
     addBinaryChildrenRecursively(
         myExpr.getLeftExpression(),
         subBlocks,
         Indent.getContinuationWithoutFirstIndent(),
         alignment,
         myWrap,
         mySettings);
   }
   for (ASTNode childNode : children) {
     if (canBeCorrectBlock(childNode) && !(childNode.getPsi() instanceof MoonBinaryExpression)) {
       subBlocks.add(
           new MoonFormattingBlock(
               childNode,
               alignment,
               Indent.getContinuationWithoutFirstIndent(),
               myWrap,
               mySettings));
     }
   }
   if (myExpr.getRightExpression() instanceof MoonBinaryExpression) {
     addBinaryChildrenRecursively(
         myExpr.getRightExpression(),
         subBlocks,
         Indent.getContinuationWithoutFirstIndent(),
         alignment,
         myWrap,
         mySettings);
   }
   return subBlocks;
 }
コード例 #2
0
 /**
  * Adds all children of specified element to given list
  *
  * @param elem
  * @param list
  * @param indent
  * @param alignment
  */
 private static void addBinaryChildrenRecursively(
     PsiElement elem,
     List<Block> list,
     Indent indent,
     Alignment alignment,
     Wrap myWrap,
     CodeStyleSettings mySettings) {
   if (elem == null) return;
   ASTNode[] children = elem.getNode().getChildren(null);
   // For binary expressions
   if ((elem instanceof MoonBinaryExpression)) {
     MoonBinaryExpression myExpr = ((MoonBinaryExpression) elem);
     if (myExpr.getLeftExpression() instanceof MoonBinaryExpression) {
       addBinaryChildrenRecursively(
           myExpr.getLeftExpression(),
           list,
           Indent.getContinuationWithoutFirstIndent(),
           alignment,
           myWrap,
           mySettings);
     }
     for (ASTNode childNode : children) {
       if (canBeCorrectBlock(childNode) && !(childNode.getPsi() instanceof MoonBinaryExpression)) {
         list.add(new MoonFormattingBlock(childNode, alignment, indent, myWrap, mySettings));
       }
     }
     if (myExpr.getRightExpression() instanceof MoonBinaryExpression) {
       addBinaryChildrenRecursively(
           myExpr.getRightExpression(),
           list,
           Indent.getContinuationWithoutFirstIndent(),
           alignment,
           myWrap,
           mySettings);
     }
   }
 }