ASTNode (@Nullable ASTNode startNode, AlignmentInColumnsConfig config) { if (startNode == null) { return null; } ASTNode parent = startNode.getTreeParent(); if (parent == null) { // Never expect to be here. return null; } // Check if previous node to the start node is white space that contains line feeds. final boolean[] returnFirstNonEmptySubNode = {false}; findPreviousNode(config, startNode, new NodeProcessor() { @Override public boolean targetTypeFound(ASTNode node) { return true; } @Override public boolean whitespaceFound(ASTNode node) { return returnFirstNonEmptySubNode[0] = StringUtil.countNewLines(node.getChars()) > 0; } }); boolean stop = false; for (ASTNode result = startNode; result != null && result.getTreeParent() == parent; result = result.getTreeNext()) { if (config.getStopMultilineCheckElementTypes().contains(result.getElementType())) { return null; } if (result.getTextLength() <= 0) { continue; } if (config.getCommentTokenTypes().contains(result.getElementType())) { continue; } if (config.getWhiteSpaceTokenTypes().contains(result.getElementType()) && StringUtil.countNewLines(result.getChars()) > 0) { stop = true; continue; } if (returnFirstNonEmptySubNode[0]) { return result; } if (stop) { return result; } } return null; }