Java Code Examples for com.intellij.psi.impl.source.tree.TreeUtil#findChildBackward()

The following examples show how to use com.intellij.psi.impl.source.tree.TreeUtil#findChildBackward() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FunctionCaseConverter.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 6 votes vote down vote up
@Override
protected String convert(PsiElement element) {
    if (isLookupFunction(element.getNode()) || isNonStarCount(element.getNode())) {
        return element.getText().toLowerCase();
    }

    if (element.getNode().getElementType() == CypherTypes.FUNCTION_NAME
            && TreeUtil.findChildBackward(element.getNode(), CypherTypes.K_COUNT) == null) {
        String text = element.getText();

        if (text == null || text.isEmpty()) {
            return null;
        }

        if (Strings.isUpperCase(text)) {
            return text.toLowerCase();
        }

        char first = text.charAt(0);
        return Character.toLowerCase(first) + (text.length() > 1 ? text.substring(1) : "");
    }

    return null;
}
 
Example 2
Source File: ANTLRv4FoldingBuilder.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static void addRuleRefFoldingDescriptors(List<FoldingDescriptor> descriptors, PsiElement root) {
    for (RuleSpecNode specNode : PsiTreeUtil.findChildrenOfType(root, RuleSpecNode.class)) {
        GrammarElementRefNode refNode = PsiTreeUtil.findChildOfAnyType(specNode, GrammarElementRefNode.class);
        if (refNode == null) continue;
        PsiElement nextSibling = refNode.getNextSibling();
        if (nextSibling == null) continue;
        int startOffset = nextSibling.getTextOffset();

        ASTNode backward = TreeUtil.findChildBackward(specNode.getNode(), SEMICOLON);
        if (backward == null) continue;
        int endOffset = backward.getTextRange().getEndOffset();
        if (startOffset >= endOffset) continue;

        descriptors.add(new FoldingDescriptor(specNode, new TextRange(startOffset, endOffset)));

    }
}