use of com.intellij.formatting.Block 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();
}
use of com.intellij.formatting.Block in project intellij-community by JetBrains.
the class ExtendsListBlock method buildChildren.
@Override
protected List<Block> buildChildren() {
final ArrayList<Block> result = new ArrayList<>();
ArrayList<Block> elementsExceptKeyword = new ArrayList<>();
myChildAlignment = createChildAlignment();
myChildIndent = Indent.getContinuationIndent(myIndentSettings.USE_RELATIVE_INDENTS);
myUseChildAttributes = true;
Wrap childWrap = createChildWrap();
ASTNode child = myNode.getFirstChildNode();
Alignment alignment = alignList() ? Alignment.createAlignment() : null;
while (child != null) {
if (!FormatterUtil.containsWhiteSpacesOnly(child) && child.getTextLength() > 0) {
IElementType elementType = child.getElementType();
if (ElementType.KEYWORD_BIT_SET.contains(elementType)) {
if (!elementsExceptKeyword.isEmpty()) {
result.add(new SyntheticCodeBlock(elementsExceptKeyword, null, mySettings, myJavaSettings, Indent.getNoneIndent(), null));
elementsExceptKeyword = new ArrayList<>();
}
Indent indent = mySettings.ALIGN_THROWS_KEYWORD && elementType == JavaTokenType.THROWS_KEYWORD ? Indent.getNoneIndent() : myChildIndent;
result.add(createJavaBlock(child, mySettings, myJavaSettings, indent, arrangeChildWrap(child, childWrap), alignment));
} else {
Alignment candidate = myAlignmentStrategy.getAlignment(elementType);
if (candidate != null) {
alignment = myChildAlignment = candidate;
}
processChild(elementsExceptKeyword, child, myChildAlignment, childWrap, myChildIndent);
}
}
child = child.getTreeNext();
}
if (!elementsExceptKeyword.isEmpty()) {
result.add(new SyntheticCodeBlock(elementsExceptKeyword, alignment, mySettings, myJavaSettings, Indent.getNoneIndent(), null));
}
return result;
}
use of com.intellij.formatting.Block in project intellij-community by JetBrains.
the class CallChunkBlockBuilder method createJavaBlocks.
@NotNull
private List<Block> createJavaBlocks(@NotNull final List<ASTNode> subNodes) {
final ArrayList<Block> result = new ArrayList<>();
for (ASTNode node : subNodes) {
Indent indent = Indent.getContinuationWithoutFirstIndent(myIndentSettings.USE_RELATIVE_INDENTS);
result.add(newJavaBlock(node, mySettings, myJavaSettings, indent, null, AlignmentStrategy.getNullStrategy()));
}
return result;
}
use of com.intellij.formatting.Block in project intellij-community by JetBrains.
the class CallChunkBlockBuilder method create.
@NotNull
public Block create(@NotNull final List<ASTNode> subNodes, final Wrap wrap, @Nullable final Alignment alignment) {
final ArrayList<Block> subBlocks = new ArrayList<>();
final ASTNode firstNode = subNodes.get(0);
if (firstNode.getElementType() == JavaTokenType.DOT) {
AlignmentStrategy strategy = AlignmentStrategy.getNullStrategy();
Block block = newJavaBlock(firstNode, mySettings, myJavaSettings, Indent.getNoneIndent(), null, strategy);
subBlocks.add(block);
subNodes.remove(0);
if (!subNodes.isEmpty()) {
subBlocks.add(create(subNodes, wrap, null));
}
return new SyntheticCodeBlock(subBlocks, alignment, mySettings, myJavaSettings, Indent.getContinuationIndent(myIndentSettings.USE_RELATIVE_INDENTS), wrap);
}
return new SyntheticCodeBlock(createJavaBlocks(subNodes), alignment, mySettings, myJavaSettings, Indent.getContinuationWithoutFirstIndent(myIndentSettings.USE_RELATIVE_INDENTS), null);
}
use of com.intellij.formatting.Block in project intellij-community by JetBrains.
the class ChainedCallChunk method buildBlocksFrom.
private List<Block> buildBlocksFrom(List<ASTNode> nodes) {
List<ChainedCallChunk> methodCall = splitMethodCallOnChunksByDots(nodes);
Wrap wrap = null;
Alignment chainedCallsAlignment = null;
List<Block> blocks = new ArrayList<>();
for (int i = 0; i < methodCall.size(); i++) {
ChainedCallChunk currentCallChunk = methodCall.get(i);
if (isMethodCall(currentCallChunk) || isComment(currentCallChunk)) {
if (wrap == null) {
wrap = createCallChunkWrap(i, methodCall);
}
if (chainedCallsAlignment == null) {
chainedCallsAlignment = createCallChunkAlignment(i, methodCall);
}
} else {
wrap = null;
chainedCallsAlignment = null;
}
CallChunkBlockBuilder builder = new CallChunkBlockBuilder(mySettings, myJavaSettings);
blocks.add(builder.create(currentCallChunk.nodes, wrap, chainedCallsAlignment));
}
return blocks;
}
Aggregations