ASTNode (ASTNode baseNode, AlignmentInColumnsConfig config, final double blankLinesToBeKeptOnReformat) { ASTNode nodeOfTargetType = deriveNodeOfTargetType(baseNode, config.getTargetDeclarationTypes()); if (nodeOfTargetType == null) { return null; } final ASTNode[] prev = new ASTNode[1]; findPreviousNode(config, baseNode, new NodeProcessor() { @Override public boolean targetTypeFound(ASTNode node) { prev[0] = node; return true; } @Override public boolean whitespaceFound(ASTNode node) { return blankLinesToBeKeptOnReformat > 0 && StringUtil.countChars(node.getText(), '\n') > 1; } }); if (prev[0] == null) return null; // ensure there are no non-whitespace, non-comment elements on the top level between baseNode and the found one Couple<ASTNode> siblingParents = TreeUtil.findTopmostSiblingParents(prev[0], baseNode); if (siblingParents.first != null && siblingParents.second != null) { for (ASTNode each = siblingParents.second.getTreePrev(); each != null && each != siblingParents.first; each = each.getTreePrev()) { IElementType eachType = each.getElementType(); if (!config.getCommentTokenTypes().contains(eachType) && !config.getWhiteSpaceTokenTypes().contains(eachType)) return null; } } return deriveNodeOfTargetType(prev[0], TokenSet.create(nodeOfTargetType.getElementType())); }