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

The following are Jave code examples for showing how to use getTextRange() 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: AppleScript-IDEA   File: AppleScriptTargetReferenceImpl.java   Source Code and License Vote up 4 votes
@Override
public TextRange getRangeInElement() {
  final ASTNode nameElement = myElement.getNameIdentifier() != null ? myElement.getNameIdentifier().getNode() : getNode();
  final TextRange range = nameElement != null ? nameElement.getTextRange() : myElement.getNode().getTextRange();
  return range.shiftRight(-myElement.getNode().getStartOffset());
}