boolean (ASTNode node, AlignmentInColumnsConfig config, int blankLinesToBeKeptOnReformat) { ASTNode prev = getPreviousAdjacentNodeOfTargetType(node, config, blankLinesToBeKeptOnReformat); if (prev == null) { return true; } ASTNode curr = deriveNodeOfTargetType(node, TokenSet.create(prev.getElementType())); if (curr == null) { return true; } // The main idea is to avoid alignment like the one below: // private final int i; // double d; // I.e. we want to avoid alignment-implied long indents from the start of line. // Please note that we do allow alignment like below: // private final int i; // private double d; ASTNode prevSubNode = getSubNodeThatStartsNewLine(prev.getFirstChildNode(), config); ASTNode currSubNode = getSubNodeThatStartsNewLine(curr.getFirstChildNode(), config); while (true) { boolean prevNodeIsDefined = prevSubNode != null; boolean currNodeIsDefined = currSubNode != null; // Check if one sub-node starts from new line and another one doesn't start. if (prevNodeIsDefined ^ currNodeIsDefined) { return true; } if (prevSubNode == null) { break; } if (prevSubNode.getElementType() != currSubNode.getElementType() /*|| StringUtil.countNewLines(prevSubNode.getChars()) != StringUtil.countNewLines(currSubNode.getChars())*/) { return true; } prevSubNode = getSubNodeThatStartsNewLine(prevSubNode.getTreeNext(), config); currSubNode = getSubNodeThatStartsNewLine(currSubNode.getTreeNext(), config); } // There is a possible declaration like the one below // int i1 = 1; // int i2, i3 = 2; // Three fields are declared here - 'i1', 'i2' and 'i3'. So, the check if field 'i2' contains assignment should be // performed against 'i3'. ASTNode currentFieldToUse = curr; ASTNode nextNode = curr.getTreeNext(); for (; nextNode != null && nextNode.getTreeParent() == curr.getTreeParent(); nextNode = nextNode.getTreeNext()) { IElementType type = nextNode.getElementType(); if (config.getWhiteSpaceTokenTypes().contains(type)) { ASTNode previous = nextNode.getTreePrev(); if ((previous != null && previous.getElementType() == curr.getElementType()) || StringUtil.countNewLines(nextNode.getChars()) > 1) { break; } continue; } if (config.getCommentTokenTypes().contains(type)) { continue; } if (type == curr.getElementType()) { currentFieldToUse = nextNode; } } List<IElementType> prevTypes = findSubNodeTypes(prev, config.getDistinguishableTypes()); List<IElementType> currTypes = findSubNodeTypes(currentFieldToUse, config.getDistinguishableTypes()); return !prevTypes.equals(currTypes); }