public static PsiStatement[] getChildStatements(CompositeElement psiCodeBlock) { ApplicationManager.getApplication().assertReadAccessAllowed(); // no lock is needed because all chameleons are expanded already int count = 0; for (ASTNode child1 = psiCodeBlock.getFirstChildNode(); child1 != null; child1 = child1.getTreeNext()) { if (child1.getPsi() instanceof PsiStatement) { count++; } } PsiStatement[] result = PsiStatement.ARRAY_FACTORY.create(count); if (count == 0) return result; int idx = 0; for (ASTNode child = psiCodeBlock.getFirstChildNode(); child != null && idx < count; child = child.getTreeNext()) { PsiElement element = child.getPsi(); if (element instanceof PsiStatement) { result[idx++] = (PsiStatement) element; } } return result; }
@Nullable public static ASTNode findDocComment(@NotNull CompositeElement element) { TreeElement node = element.getFirstChildNode(); while (node != null && (isWhitespaceOrComment(node) && !(node.getPsi() instanceof PsiDocComment))) { node = node.getTreeNext(); } if (node != null && node.getElementType() == JavaDocElementType.DOC_COMMENT) { return node; } else { return null; } }
private static void deQualifyImpl(@NotNull CompositeElement reference) { ASTNode qualifier = reference.findChildByRole(ChildRole.QUALIFIER); if (qualifier != null) { ASTNode firstChildNode = qualifier.getFirstChildNode(); boolean markToReformatBefore = firstChildNode instanceof TreeElement && CodeEditUtil.isMarkedToReformatBefore((TreeElement) firstChildNode); reference.deleteChildInternal(qualifier); if (markToReformatBefore) { firstChildNode = reference.getFirstChildNode(); if (firstChildNode != null) { CodeEditUtil.markToReformatBefore(firstChildNode, true); } } } }
// remove nodes from this[including] to end[excluding] from the parent protected final void rawRemoveUpToWithoutNotifications(TreeElement end, boolean invalidate) { if (this == end) return; final CompositeElement parent = getTreeParent(); final TreeElement startPrev = getTreePrev(); final TreeElement endPrev = end != null ? end.getTreePrev() : null; assert end == null || end.getTreeParent() == parent : "Trying to remove non-child"; if (end != null) { TreeElement element; for (element = this; element != end && element != null; element = element.getTreeNext()) ; assert element == end : end + " is not successor of " + this + " in the .getTreeNext() chain"; } if (parent != null) { if (this == parent.getFirstChildNode()) { parent.setFirstChildNode(end); } if (end == null) { parent.setLastChildNode(startPrev); } } if (startPrev != null) { startPrev.setTreeNext(end); } if (end != null) { end.setTreePrev(startPrev); } setTreePrev(null); if (endPrev != null) { endPrev.setTreeNext(null); } if (parent != null) { for (TreeElement element = this; element != null; element = element.getTreeNext()) { element.setTreeParent(null); if (invalidate) { element.onInvalidated(); } } } DebugUtil.checkTreeStructure(parent); DebugUtil.checkTreeStructure(this); }