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); } } } }