@Nullable private static PsiElement getFirstCompositeElement(@Nullable PsiElement at) { if (at instanceof PsiComment || at instanceof LeafPsiElement && ((LeafPsiElement)at).getElementType() == GoTypes.STRING) return at; PsiElement result = at; while (result != null && (result instanceof PsiWhiteSpace || result.getNode().getChildren(null).length == 0)) { result = result.getParent(); } return result; }
private void highlight(@NotNull final ElixirMapArguments mapArguments, @NotNull AnnotationHolder annotationHolder, @NotNull final TextAttributesKey textAttributesKey) { ASTNode[] braces = mapArguments.getNode().getChildren(BRACES_TOKEN_SET); for (ASTNode brace : braces) { highlight(brace.getTextRange(), annotationHolder, textAttributesKey); } }
public static int codePoint(@NotNull EscapedHexadecimalDigits hexadecimalEscapeSequence) { ASTNode[] validHexadecimalDigitsArray = hexadecimalEscapeSequence .getNode() .getChildren( TokenSet.create(ElixirTypes.VALID_HEXADECIMAL_DIGITS) ); int parsedCodePoint = -1; if (validHexadecimalDigitsArray.length == 1) { ASTNode validHexadecimalDigits = validHexadecimalDigitsArray[0]; String formattedHexadecimalDigits = validHexadecimalDigits.getText(); parsedCodePoint = Integer.parseInt(formattedHexadecimalDigits, 16); } return parsedCodePoint; }
/** * Highlights fragment ASTNodes under `body` that have fragment type from `fragmented.getFragmentType()`. * * @param fragmented supplies fragment type * @param body contains fragments * @param annotationHolder the container which receives annotations created by the plugin. * @param textAttributesKey text attributes to apply to the fragments. */ private void highlightFragments(@NotNull final Fragmented fragmented, @NotNull final Body body, @NotNull AnnotationHolder annotationHolder, @NotNull final TextAttributesKey textAttributesKey) { ASTNode bodyNode = body.getNode(); ASTNode[] fragmentNodes = bodyNode.getChildren( TokenSet.create(fragmented.getFragmentType()) ); for (ASTNode fragmentNode : fragmentNodes) { highlight( fragmentNode.getTextRange(), annotationHolder, textAttributesKey ); } }
@NotNull private WrapType noParenthesesOneArgumentChildrenWrapType(@NotNull ASTNode noParenthesesOneArgument) { WrapType childrenWrapType; ASTNode noParenthesesKeywords = noParenthesesOneArgument.findChildByType(NO_PARENTHESES_KEYWORDS); if (noParenthesesKeywords != null) { ASTNode[] noParenthesesKeywordPairs = noParenthesesKeywords.getChildren(NO_PARENTHESES_KEYWORD_PAIR_TOKEN_SET); childrenWrapType = null; for (ASTNode noParenthesesKeywordPair : noParenthesesKeywordPairs) { if (oneLinerKeywordPair(noParenthesesKeywordPair)) { childrenWrapType = WrapType.CHOP_DOWN_IF_LONG; break; } } if (childrenWrapType == null) { childrenWrapType = noParenthesesOneArgumentWrapType(noParenthesesOneArgument); if (childrenWrapType == WrapType.ALWAYS && !noParenthesesKeywords.textContains('\n')) { childrenWrapType = WrapType.CHOP_DOWN_IF_LONG; } } } else { childrenWrapType = WrapType.CHOP_DOWN_IF_LONG; } return childrenWrapType; }
public static int codePoint(@NotNull ElixirEscapedCharacter escapedCharacter) { ASTNode[] escapedCharacterTokens = escapedCharacter .getNode() .getChildren(TokenSet.create(ElixirTypes.ESCAPED_CHARACTER_TOKEN)); int parsedCodePoint = -1;
private static boolean isStringIndexExpression(@NotNull GoIndexOrSliceExpr expr) { GoExpression expression = expr.getExpression(); if (expression == null || !GoTypeUtil.isString(expression.getGoType(null))) { return false; } Trinity<GoExpression, GoExpression, GoExpression> indices = expr.getIndices(); return indices.getSecond() == null && indices.getThird() == null && expr.getNode().getChildren(TokenSet.create(GoTypes.COLON)).length == 0; } }
private void highlightTypesAndTypeParameterUsages(@NotNull ElixirDecimalFloat decimalFloat, @NotNull AnnotationHolder annotationHolder) { PsiElement parent = decimalFloat.getParent(); String message = null; if (parent instanceof ElixirAccessExpression) { PsiElement grandParent = parent.getParent(); if (grandParent instanceof Two) { Two two = (Two) grandParent; Operator operator = two.operator(); if (operator != null) { ASTNode[] rangeOperators = operator.getNode().getChildren(TokenSet.create(RANGE_OPERATOR)); if (rangeOperators.length > 0) { message = "Floats aren't allowed in Ranges"; } } } } else { cannotHighlightTypes(decimalFloat); } if (message == null) { message = "Float literals are not allowed in types: use float() instead"; } highlightTypeError(decimalFloat, message, annotationHolder); }
if (typeNode != null && innerTypeNode != null) { StringBuilder result = new StringBuilder(); for (ASTNode node : typeNode.getChildren(null)) { if (node.equals(innerTypeNode)) { break;
@NotNull public static Trinity<GoExpression, GoExpression, GoExpression> getIndices(@NotNull GoIndexOrSliceExpr slice) { GoExpression start; GoExpression end = null; GoExpression max = null; ASTNode[] colons = slice.getNode().getChildren(TokenSet.create(GoTypes.COLON)); List<GoExpression> exprList = slice.getExpressionList(); start = ContainerUtil.getFirstItem(getExpressionsInRange(exprList, slice.getLbrack(), colons.length > 0 ? colons[0].getPsi() : null)); if (colons.length == 1) { end = ContainerUtil.getFirstItem(getExpressionsInRange(exprList, colons[0].getPsi(), slice.getRbrack())); } if (colons.length == 2) { end = ContainerUtil.getFirstItem(getExpressionsInRange(exprList, colons[0].getPsi(), colons[1].getPsi())); max = ContainerUtil.getFirstItem(getExpressionsInRange(exprList, colons[1].getPsi(), slice.getRbrack())); } return Trinity.create(start, end, max); }
ASTNode[] colons = slice.getNode().getChildren(TokenSet.create(GoTypes.COLON)); if (colons.length == 2) { PsiElement secondColon = colons[1].getPsi();
private static ASTNode[] getBashChildren(final ASTNode node) { return node.getChildren(null); }
/** * Find all elements for given node that are keywords. */ public static Collection<PsiElement> findKeywords(ASTNode parent) { ASTNode[] keywords = parent.getChildren(ProtoParserDefinition.KEYWORDS); List<PsiElement> result = new ArrayList<>(keywords.length); for (ASTNode keyword : keywords) { result.add((PsiElement) keyword); } return result; }
/** * @return a block for the {@code blockOwner}, omiting lazy-parsable blocks if any */ @Nullable static PsiPerlBlock findBlock(@NotNull PerlBlockOwner blockOwner) { PsiPerlBlock block = blockOwner.getBlock(); if (block != null) { return block; } ASTNode[] children = blockOwner.getNode().getChildren(LAZY_CODE_BLOCKS); PsiElement lazyParsableBlock = children.length == 0 ? null : children[0].getPsi(); if (lazyParsableBlock != null) { PsiElement possibleBlock = lazyParsableBlock.getFirstChild(); return possibleBlock instanceof PsiPerlBlock ? (PsiPerlBlock)possibleBlock : null; } return null; } }
@NotNull @Override public PsiElement[] getAllChildren(@NotNull ASTNode node) { ASTNode[] childNodes = node.getChildren(null); if (childNodes.length == 0) { return PsiElement.EMPTY_ARRAY; } PsiElement[] children = new PsiElement[childNodes.length]; for (int i = 0; i < childNodes.length; i++) { children[i] = childNodes[i].getPsi(); } return children; }
@Override public void tokenize(@NotNull BashHereDoc element, TokenConsumer consumer) { //indexes the heredoc content leaf nodes ASTNode[] contentNodes = element.getNode().getChildren(TokenSet.create(BashTokenTypes.HEREDOC_CONTENT)); for (ASTNode node : contentNodes) { consumer.consumeToken(node.getPsi(), false, TextSplitter.getInstance()); } } }
@Override public void tokenize(@NotNull BashString element, TokenConsumer consumer) { //indexes the string content leaf nodes ASTNode[] contentNodes = element.getNode().getChildren(TokenSet.create(BashTokenTypes.STRING_CONTENT)); for (ASTNode node : contentNodes) { consumer.consumeToken(node.getPsi(), false, TextSplitter.getInstance()); } } }
private static void collectDescriptorsRecursively(@NotNull ASTNode node, @NotNull Document document, @NotNull List<FoldingDescriptor> descriptors) { final IElementType type = node.getElementType(); if (type == token(COMMENT) && spanMultipleLines(node, document)) { descriptors.add(new FoldingDescriptor(node, node.getTextRange())); } if (type == token(LINE_COMMENT)) { final Couple<PsiElement> commentRange = expandLineCommentsRange(node.getPsi()); final int startOffset = commentRange.getFirst().getTextRange().getStartOffset(); final int endOffset = commentRange.getSecond().getTextRange().getEndOffset(); if (document.getLineNumber(startOffset) != document.getLineNumber(endOffset)) { descriptors.add(new FoldingDescriptor(node, new TextRange(startOffset, endOffset))); } } if (PROVIDERS.keySet().contains(type) && spanMultipleLines(node, document)) { descriptors.add(new FoldingDescriptor(node, node.getTextRange())); } for (ASTNode child : node.getChildren(null)) { collectDescriptorsRecursively(child, document, descriptors); } }
ASTNode[] children = getNode().getChildren(null); boolean newIsStatic = false;
@Override public PsiElement findElementAt(int offset) { ASTNode node = root.getNode(); if (offset >= node.getTextLength()) { return null; } boolean foundChild = true; while (foundChild) { foundChild = false; for (ASTNode child : node.getChildren(null)) { int startOffset = child.getStartOffset(); if (offset >= startOffset && offset < startOffset + child.getTextLength()) { node = child; foundChild = true; break; } } } return node.getPsi(); }