Java Code Examples for com.intellij.lang.ASTNode.getFirstChildNode()

The following are Jave code examples for showing how to use getFirstChildNode() of the com.intellij.lang.ASTNode class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: greycat-idea-plugin   File: GCMFoldingBuilder.java   Source Code and License Vote up 6 votes
private void appendDescriptors(final ASTNode node, final Document document, final List<FoldingDescriptor> descriptors) {
    if (node.getElementType() == GCMTypes.CLASS_DECLARATION || node.getElementType() == GCMTypes.CUSTOM_TYPE_DECLARATION) {
        TextRange fullRange = node.getTextRange();
        if (fullRange.getEndOffset() - fullRange.getStartOffset() > 0) {

            try {
                int startOffset = fullRange.getStartOffset() + document.getText(fullRange).indexOf("{") + 1;
                int endOffset = fullRange.getEndOffset() - 1;
                if (startOffset < endOffset) {
                    TextRange shortRange = new TextRange(startOffset, fullRange.getEndOffset() - 1);
                    if (shortRange.getEndOffset() - shortRange.getStartOffset() > 1) {
                        descriptors.add(new FoldingDescriptor(node, shortRange));
                    }
                }
            } catch (Throwable e) {

            }
        }
    }
    ASTNode child = node.getFirstChildNode();
    while (child != null) {
        appendDescriptors(child, document, descriptors);
        child = child.getTreeNext();
    }
}
 
Example 2
Project: intellij-csv-validator   File: CsvFormatHelper.java   Source Code and License Vote up 6 votes
public static Map<Integer, CsvColumnInfo<ASTNode>> createColumnInfoMap(ASTNode root, CodeStyleSettings settings) {
    Map<Integer, CsvColumnInfo<ASTNode>> columnInfoMap = new HashMap<>();
    ASTNode child = root.getFirstChildNode();
    while (child != null) {
        if (child.getElementType() == CsvTypes.RECORD) {
            Integer column = 0;
            ASTNode subChild = child.getFirstChildNode();
            while (subChild != null) {
                if (subChild.getElementType() == CsvTypes.FIELD) {
                    int length = getTextLength(subChild, settings);
                    if (!columnInfoMap.containsKey(column)) {
                        columnInfoMap.put(column, new CsvColumnInfo(column, length));
                    } else if (columnInfoMap.get(column).getMaxLength() < length) {
                        columnInfoMap.get(column).setMaxLength(length);
                    }
                    columnInfoMap.get(column).addElement(subChild);
                    ++column;
                }
                subChild = subChild.getTreeNext();
            }
        }
        child = child.getTreeNext();
    }
    return columnInfoMap;
}
 
Example 3
Project: TS-IJ   File: TSPsiImplUtil.java   Source Code and License Vote up 5 votes
public static String getName(TSVarExpr variable) {
    ASTNode node = variable.getNode();
    if (node == null) {
        return null;
    }
    node = node.getFirstChildNode();
    if (node == null) {
        return null;
    }
    return node.getText().substring(1);
}
 
Example 4
Project: TS-IJ   File: TSPsiImplUtil.java   Source Code and License Vote up 5 votes
public static boolean isLocal(TSVarExpr variable) {
    ASTNode node = variable.getNode();
    if (node == null) {
        return false;
    }
    node = node.getFirstChildNode();
    if (node == null) {
        return false;
    }
    return (node.getElementType().equals(TSTypes.LOCALVAR));
}
 
Example 5
Project: hybris-integration-intellij-idea-plugin   File: ImpexBlock.java   Source Code and License Vote up 4 votes
@Override
protected List<Block> buildChildren() {
    final List<Block> blocks = new ArrayList<Block>();

    final AlignmentStrategy alignmentStrategy = getAlignmentStrategy();
    alignmentStrategy.processNode(myNode);

    ASTNode currentNode = myNode.getFirstChildNode();

    while (null != currentNode) {

        // Unpack 'Value Line' as columns will not be aligned if they do not share the same parent
        if (ImpexTypes.VALUE_LINE == currentNode.getElementType()) {
            currentNode = currentNode.getFirstChildNode();
        }

        alignmentStrategy.processNode(currentNode);

        if (isNotWhitespaceOrNewLine(currentNode)
            && !isCurrentNodeHasParentValue(currentNode)) {

            final Block block = new ImpexBlock(
                currentNode,
                null,
                alignmentStrategy.getAlignment(currentNode),
                spacingBuilder
            );

            blocks.add(block);
        }

        // Unpack Value Line
        if (isEndOfValueLine(currentNode)) {
            currentNode = currentNode.getTreeParent().getTreeNext();
        } else {
            currentNode = currentNode.getTreeNext();
        }
    }

    return blocks;
}