void (BlockTreeNode rootBlockNode, PsiElement psiEl) { myPsiToBlockMap = new HashMap<>(); JBTreeTraverser<BlockTreeNode> traverser = JBTreeTraverser.of(BlockTreeNode::getChildren); for (BlockTreeNode block : traverser.withRoot(rootBlockNode)) { PsiElement currentElem = null; if (block.getBlock() instanceof ASTBlock) { ASTNode node = ((ASTBlock)block.getBlock()).getNode(); if (node != null) { currentElem = node.getPsi(); } } if (currentElem == null) { currentElem = InjectedLanguageUtil .findElementAtNoCommit(psiEl.getContainingFile(), block.getBlock().getTextRange().getStartOffset()); } myPsiToBlockMap.put(currentElem, block); //nested PSI elements with same ranges will be mapped to one blockNode // assert currentElem != null; //for Scala-language plugin etc it can be null, because formatterBlocks is not instance of ASTBlock TextRange curTextRange = currentElem.getTextRange(); PsiElement parentElem = currentElem.getParent(); while (parentElem != null && parentElem.getTextRange().equals(curTextRange)) { myPsiToBlockMap.put(parentElem, block); parentElem = parentElem.getParent(); } } }