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

The following are Jave code examples for showing how to use getTreeNext() 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: AppleScript-IDEA   File: AppleScriptHandlerSelectorPartImpl.java   Source Code and License Vote up 6 votes
@NotNull
@Override
public String getSelectorPart() {
  StringBuilder builder = new StringBuilder();
  ASTNode child = getNode().getFirstChildNode();
  if (child != null) {
    builder.append(child.getText());
    child = child.getTreeNext();
  }

  while (child != null && AppleScriptTokenTypesSets.COMMENT_OR_WHITE_SPACE.contains(child.getElementType()))
    child = child.getTreeNext();

  if (child != null && child.getElementType() == AppleScriptTypes.COLON) {
    builder.append(child.getText());
  }

  return builder.toString();
}
 
Example 2
Project: greycat-idea-plugin   File: GCMBlock.java   Source Code and License Vote up 6 votes
@Override
protected List<Block> buildChildren() {
    List<Block> blocks = new ArrayList<Block>();
    Alignment innerBodyAlignment = Alignment.createAlignment();
    ASTNode child = getNode().getFirstChildNode();
    while (child != null) {
        if (child.getElementType() != TokenType.WHITE_SPACE) {
            if (child.getElementType() == GCMTypes.PROP) {
                blocks.add(new GCMBlock(child, innerBodyAlignment, getWrap()));
            } else {
                blocks.add(new GCMBlock(child, getAlignment(), getWrap()));
            }
        }
        child = child.getTreeNext();
    }
    return blocks;
}
 
Example 3
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 4
Project: hybris-integration-intellij-idea-plugin   File: FlexibleSearchBlock.java   Source Code and License Vote up 6 votes
@Override
protected List<Block> buildChildren() {
    List<Block> blocks = new ArrayList<>();
    ASTNode child = myNode.getFirstChildNode();
    while (child != null) {
        if (child.getElementType() != TokenType.WHITE_SPACE) {

            Block block = new FlexibleSearchBlock(
                child,
                Wrap.createWrap(WrapType.NONE, false),
                null,
                spacingBuilder
            );

            blocks.add(block);
        }
        child = child.getTreeNext();
    }
    return blocks;
}
 
Example 5
Project: hybris-integration-intellij-idea-plugin   File: CommonPsiUtils.java   Source Code and License Vote up 6 votes
@NotNull
@Contract(pure = true)
public static List<PsiElement> findChildrenByIElementType(
    @NotNull final PsiElement element,
    @NotNull final IElementType elementType
) {
    Validate.notNull(element);
    Validate.notNull(elementType);

    List<PsiElement> result = Collections.emptyList();
    ASTNode child = element.getNode().getFirstChildNode();

    while (child != null) {
        if (elementType == child.getElementType()) {
            if (result.isEmpty()) {
                result = new ArrayList<PsiElement>();
            }
            result.add(child.getPsi());
        }
        child = child.getTreeNext();
    }

    return result;
}
 
Example 6
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 7
Project: AppleScript-IDEA   File: AppleScriptPsiImplUtil.java   Source Code and License Vote up 5 votes
public static String getSelectorName(AppleScriptArgumentSelector argumentSelector) {
  final StringBuilder result = new StringBuilder();
  ASTNode child = argumentSelector.getNode().getFirstChildNode();
  while (child != null) {
    final IElementType tt = child.getElementType();
    if (tt == AppleScriptTypes.IDENTIFIER || tt == AppleScriptTypes.COLON) {
      result.append(child.getText());
    }
    child = child.getTreeNext();
  }
  return result.toString();
}
 
Example 8
Project: intellij-postfix-templates   File: CptBlock.java   Source Code and License Vote up 5 votes
@Override
protected List<Block> buildChildren() {
	List<Block> blocks = new ArrayList<>();
	ASTNode child = myNode.getFirstChildNode();
	while (child != null) {
		final IElementType elementType = child.getElementType();

		final Indent indent = elementType == CptTypes.MAPPINGS
			? Indent.getNormalIndent()
			: Indent.getNoneIndent();

		final Indent childIndent = _Set(CptTypes.TEMPLATE,CptTypes.MAPPINGS, CptTypes.MAPPING, CptTypes.REPLACEMENT,
			CptTypes.TEMPLATE_ESCAPE, CptTypes.TEMPLATE_CODE, CptTypes.TEMPLATE_VARIABLE).contains(elementType)
			? Indent.getNormalIndent()
			: Indent.getNoneIndent();

		if (elementType != TokenType.WHITE_SPACE) {
			Alignment alignment = null; //Alignment.createAlignment();

			/*
			if (elementType == CptTypes.MAP) {
				alignment = mapAlignment;
			}
			*/

			Block block = new CptBlock(child, Wrap.createWrap(WrapType.NONE, false), indent, childIndent, alignment, spacingBuilder);
			blocks.add(block);
		}

		child = child.getTreeNext();
	}
	return blocks;
}
 
Example 9
Project: intellij-csv-validator   File: CsvBlockField.java   Source Code and License Vote up 5 votes
@Override
protected List<Block> buildChildren() {
    ASTNode node = this.getNode().getFirstChildNode();
    List<Block> blocks = new ArrayList<>();
    while (node != null) {
        if (node.getElementType() != TokenType.WHITE_SPACE) {
            CsvBlockElement block = new CsvBlockElement(node, formattingInfo, this);
            blocks.add(block);
        }
        node = node.getTreeNext();
    }
    return blocks;
}
 
Example 10
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;
}
 
Example 11
Project: hybris-integration-intellij-idea-plugin   File: ImpexBlock.java   Source Code and License Vote up 4 votes
private boolean isEndOfValueLine(final ASTNode currentNode) {
    return null == currentNode.getTreeNext() && ImpexTypes.VALUE_LINE == currentNode.getTreeParent()
                                                                                    .getElementType();
}