@NotNull public static Resolvable resolvable(@NotNull ElixirAtom atom) { ElixirCharListLine charListLine = atom.getCharListLine(); Resolvable resolvable; if (charListLine != null) { resolvable = resolvable(charListLine); } else { ElixirStringLine stringLine = atom.getStringLine(); if (stringLine != null) { resolvable = resolvable(stringLine); } else { ASTNode atomNode = atom.getNode(); ASTNode atomFragmentNode = atomNode.getLastChildNode(); assert atomFragmentNode.getElementType() == ElixirTypes.ATOM_FRAGMENT; resolvable = new Exact(":" + atomFragmentNode.getText()); } } return resolvable; }
@Override public String createEquallyWrappedString(String newContent) { ASTNode node = getNode(); ASTNode firstChild = node.getFirstChildNode(); ASTNode lastChild = node.getLastChildNode(); StringBuilder result = new StringBuilder(firstChild.getTextLength() + newContent.length() + lastChild.getTextLength()); return result.append(firstChild.getText()).append(newContent).append(lastChild.getText()).toString(); }
@Nullable @Override public PsiElement getLastChild(@NotNull ASTNode node) { ASTNode child = node.getLastChildNode(); return child == null ? null : child.getPsi(); }
@Override public boolean isIncomplete() { ASTNode lastChild = myNode.getLastChildNode(); while (lastChild != null && lastChild.getElementType() == TokenType.WHITE_SPACE) { lastChild = lastChild.getTreePrev(); } if (lastChild == null) return false; if (lastChild.getElementType() == TokenType.ERROR_ELEMENT) return true; return FormatterUtil.isIncomplete(lastChild); }
/** * Returns the deepest nested ast node which still covers the same part of the file as the parent node. Happens if a single leaf node is * contained in several composite parent nodes of the same range, e.g. a var in a combined word. * * @param parent The element to use as the startin point * @return The deepest node inside of parent which covers the same range or (if none exists) the input element */ @NotNull public static ASTNode getDeepestEquivalent(ASTNode parent) { ASTNode element = parent; while (element.getFirstChildNode() != null && element.getFirstChildNode() == element.getLastChildNode() && element.getTextRange().equals(parent.getTextRange())) { element = element.getFirstChildNode(); } return element; }
@NotNull public TextRange getTextContentRange() { if (!isWrapped()) { return TextRange.from(0, getTextLength()); } ASTNode node = getNode(); String first = node.getFirstChildNode().getText(); String last = node.getLastChildNode().getText(); int textLength = getTextLength(); if (first.startsWith("$'") && last.endsWith("'")) { return TextRange.from(2, textLength - 3); } return TextRange.from(1, textLength - 2); }
@Nullable public Boolean isIncomplete(@NotNull PerlAstBlock block) { IElementType elementType = block.getElementType(); if (elementType == COMMA_SEQUENCE_EXPR) { IElementType lastNodeType = PsiUtilCore.getElementType(block.getNode().getLastChildNode()); if (lastNodeType == COMMA || lastNodeType == FAT_COMMA) { return true; } } else if (STATEMENTS.contains(elementType)) { PsiElement lastLeaf = PsiTreeUtil.getDeepestLast(block.getNode().getPsi()); return PsiUtilCore.getElementType(lastLeaf) != SEMICOLON; } return null; }
/** * @param node Tree node * @return true if node is incomplete */ public boolean isIncomplete(@NotNull final ASTNode node) { if (node.getElementType() instanceof ILazyParseableElementType) { return false; } ASTNode lastChild = node.getLastChildNode(); while (lastChild != null && !(lastChild.getElementType() instanceof ILazyParseableElementType) && (lastChild.getPsi() instanceof PsiWhiteSpace || lastChild.getPsi() instanceof PsiComment)) { lastChild = lastChild.getTreePrev(); } return lastChild != null && (lastChild.getPsi() instanceof PsiErrorElement || isIncomplete(lastChild)); }
@Override public boolean isWrapped() { if (isWrapped == null) { synchronized (stateLock) { if (isWrapped == null) { boolean newIsWrapped = false; if (getTextLength() >= 2) { ASTNode node = getNode(); IElementType firstType = node.getFirstChildNode().getElementType(); IElementType lastType = node.getLastChildNode().getElementType(); newIsWrapped = firstType == BashTokenTypes.STRING_BEGIN && lastType == BashTokenTypes.STRING_END; } isWrapped = newIsWrapped; } } } return isWrapped; }
ASTNode closingBrace = TreeUtil.findSiblingBackward(parent.getNode().getLastChildNode(), BnfTypes.BNF_RIGHT_BRACE); attrCompletion = closingBrace == null || position.getTextOffset() <= closingBrace.getStartOffset(); if (attrCompletion) {
ASTNode run = child1Node; while (run instanceof CompositeElement) { run = run.getLastChildNode(); IElementType leftSignType = PsiUtilCore.getElementType(child1Node.getLastChildNode()); if (OPERATOR_COLLISIONS_MAP.get(child2Type).contains(leftSignType)) { return Spacing.createSpacing(1, 1, 0, true, 1);
if (leftNode != null && leftNode.getLastChildNode() != null && leftNode.getLastChildNode().getElementType() == HEREDOC_END_ELEMENT) { return Spacing.getReadOnlySpacing();