Search in sources :

Example 1 with BlockTreeStructure

use of com.intellij.internal.psiView.formattingblocks.BlockTreeStructure in project intellij-community by JetBrains.

the class PsiViewerDialog method doOKAction.

@Override
protected void doOKAction() {
    if (myBlockTreeBuilder != null) {
        Disposer.dispose(myBlockTreeBuilder);
    }
    final String text = myEditor.getDocument().getText();
    myEditor.getSelectionModel().removeSelection();
    myLastParsedText = text;
    myLastParsedTextHashCode = text.hashCode();
    myNewDocumentHashCode = myLastParsedTextHashCode;
    PsiElement rootElement = parseText(text);
    focusTree();
    ViewerTreeStructure structure = getTreeStructure();
    structure.setRootPsiElement(rootElement);
    myPsiTreeBuilder.queueUpdate();
    myPsiTree.setRootVisible(true);
    myPsiTree.expandRow(0);
    myPsiTree.setRootVisible(false);
    if (!myShowBlocksCheckBox.isSelected()) {
        return;
    }
    Block rootBlock = rootElement == null ? null : buildBlocks(rootElement);
    if (rootBlock == null) {
        myBlockTreeBuilder = null;
        myBlockTree.setRootVisible(false);
        myBlockTree.setVisible(false);
        return;
    }
    myBlockTree.setVisible(true);
    BlockTreeStructure blockTreeStructure = new BlockTreeStructure();
    BlockTreeNode rootNode = new BlockTreeNode(rootBlock, null);
    blockTreeStructure.setRoot(rootNode);
    myBlockTreeBuilder = new BlockTreeBuilder(myBlockTree, blockTreeStructure);
    myPsiToBlockMap = new HashMap<>();
    final PsiElement psiFile = (getTreeStructure()).getRootPsiElement();
    initMap(rootNode, psiFile);
    PsiElement rootPsi = rootNode.getBlock() instanceof ASTBlock ? ((ASTBlock) rootNode.getBlock()).getNode().getPsi() : rootElement;
    BlockTreeNode blockNode = myPsiToBlockMap.get(rootPsi);
    if (blockNode == null) {
        LOG.error(LogMessageEx.createEvent("PsiViewer: rootNode not found", "Current language: " + rootElement.getContainingFile().getLanguage(), AttachmentFactory.createAttachment(rootElement.getContainingFile().getOriginalFile().getVirtualFile())));
        blockNode = findBlockNode(rootPsi);
    }
    blockTreeStructure.setRoot(blockNode);
    myBlockTree.addTreeSelectionListener(new MyBlockTreeSelectionListener());
    myBlockTree.setRootVisible(true);
    myBlockTree.expandRow(0);
    myBlockTreeBuilder.queueUpdate();
}
Also used : BlockTreeBuilder(com.intellij.internal.psiView.formattingblocks.BlockTreeBuilder) BlockTreeNode(com.intellij.internal.psiView.formattingblocks.BlockTreeNode) ASTBlock(com.intellij.formatting.ASTBlock) BlockTreeStructure(com.intellij.internal.psiView.formattingblocks.BlockTreeStructure) Block(com.intellij.formatting.Block) ASTBlock(com.intellij.formatting.ASTBlock)

Aggregations

ASTBlock (com.intellij.formatting.ASTBlock)1 Block (com.intellij.formatting.Block)1 BlockTreeBuilder (com.intellij.internal.psiView.formattingblocks.BlockTreeBuilder)1 BlockTreeNode (com.intellij.internal.psiView.formattingblocks.BlockTreeNode)1 BlockTreeStructure (com.intellij.internal.psiView.formattingblocks.BlockTreeStructure)1