List<ChainedCallChunk> (@NotNull List<? extends ASTNode> nodes) { List<ChainedCallChunk> result = new ArrayList<>(); List<ASTNode> current = new ArrayList<>(); for (ASTNode node : nodes) { if (node.getElementType() == JavaTokenType.DOT || node.getPsi() instanceof PsiComment) { if (!current.isEmpty()) { result.add(new ChainedCallChunk(current)); } current = new ArrayList<>(); } current.add(node); } if (!current.isEmpty()) { result.add(new ChainedCallChunk(current)); } return result; }