public static void toBuffer(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StringBuilder buffer, @Nullable TokenSet skipTypes) { if (skipTypes != null && skipTypes.contains(node.getTokenType())) { return; } if (node instanceof LighterASTTokenNode) { buffer.append(((LighterASTTokenNode)node).getText()); return; } if (node instanceof LighterLazyParseableNode) { buffer.append(((LighterLazyParseableNode)node).getText()); return; } List<LighterASTNode> children = tree.getChildren(node); for (int i = 0, size = children.size(); i < size; ++i) { toBuffer(tree, children.get(i), buffer, skipTypes); } tree.disposeChildren(children); }
public static void toBuffer(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StringBuilder buffer, @Nullable TokenSet skipTypes) { if (skipTypes != null && skipTypes.contains(node.getTokenType())) return; if (node instanceof LighterASTTokenNode) { buffer.append(((LighterASTTokenNode)node).getText()); return; } if (node instanceof LighterLazyParseableNode) { buffer.append(((LighterLazyParseableNode)node).getText()); return; } List<LighterASTNode> children = tree.getChildren(node); for (int i = 0, size = children.size(); i < size; ++i) { toBuffer(tree, children.get(i), buffer, skipTypes); } }
public static void toBuffer(@Nonnull LighterAST tree, @Nonnull LighterASTNode node, @Nonnull StringBuilder buffer, @Nullable TokenSet skipTypes) { if (skipTypes != null && skipTypes.contains(node.getTokenType())) { return; } if (node instanceof LighterASTTokenNode) { buffer.append(((LighterASTTokenNode)node).getText()); return; } if (node instanceof LighterLazyParseableNode) { buffer.append(((LighterLazyParseableNode)node).getText()); return; } List<LighterASTNode> children = tree.getChildren(node); for (int i = 0, size = children.size(); i < size; ++i) { toBuffer(tree, children.get(i), buffer, skipTypes); } }
@Override public ThreeState fun(ASTNode oldNode, LighterASTNode newNode, FlyweightCapableTreeStructure<LighterASTNode> structure) { if (oldNode instanceof XmlTag && newNode.getTokenType() == XmlElementType.XML_TAG) { String oldName = ((XmlTag)oldNode).getName(); Ref<LighterASTNode[]> childrenRef = Ref.create(null); int count = structure.getChildren(newNode, childrenRef); if (count < 3) return ThreeState.UNSURE; LighterASTNode[] children = childrenRef.get(); if (children[0].getTokenType() != XmlTokenType.XML_START_TAG_START) return ThreeState.UNSURE; if (children[1].getTokenType() != XmlTokenType.XML_NAME) return ThreeState.UNSURE; if (children[2].getTokenType() != XmlTokenType.XML_TAG_END) return ThreeState.UNSURE; LighterASTTokenNode name = (LighterASTTokenNode)children[1]; CharSequence newName = name.getText(); if (!oldName.equals(newName)) return ThreeState.NO; } return ThreeState.UNSURE; }
protected RecursiveLighterASTNodeWalkingVisitor(@NotNull final LighterAST ast) { this.ast = ast; myWalkingState = new WalkingState<IndexedLighterASTNode>(new LighterASTGuide()) { @Override public void elementFinished(@NotNull IndexedLighterASTNode element) { RecursiveLighterASTNodeWalkingVisitor.this.elementFinished(element.node); if (parentStack.peek() == element) { // getFirstChild returned nothing. otherwise getFirstChild() was not called, i.e. super.visitNode() was not called i.e. just ignore IndexedLighterASTNode[] children = childrenStack.pop(); List<LighterASTNode> list = children.length == 0 ? Collections.<LighterASTNode>emptyList() : ContainerUtil.map(children, new Function<IndexedLighterASTNode, LighterASTNode>() { @Override public LighterASTNode fun(IndexedLighterASTNode node) { return node.node; } }); ast.disposeChildren(list); parentStack.pop(); } } @Override public void visit(@NotNull IndexedLighterASTNode iNode) { LighterASTNode element = iNode.node; RecursiveLighterASTNodeWalkingVisitor visitor = RecursiveLighterASTNodeWalkingVisitor.this; if (element instanceof LighterLazyParseableNode) { visitor.visitLazyParseableNode((LighterLazyParseableNode)element); } else if (element instanceof LighterASTTokenNode) { visitor.visitTokenNode((LighterASTTokenNode)element); } else { visitor.visitNode(element); } } }; }
protected RecursiveLighterASTNodeWalkingVisitor(@Nonnull final LighterAST ast) { this.ast = ast; myWalkingState = new WalkingState<IndexedLighterASTNode>(new LighterASTGuide()) { @Override public void elementFinished(@Nonnull IndexedLighterASTNode element) { RecursiveLighterASTNodeWalkingVisitor.this.elementFinished(element.node); if (parentStack.peek() == element) { // getFirstChild returned nothing. otherwise getFirstChild() was not called, i.e. super.visitNode() was not called i.e. just ignore childrenStack.pop(); parentStack.pop(); } } @Override public void visit(@Nonnull IndexedLighterASTNode iNode) { LighterASTNode element = iNode.node; RecursiveLighterASTNodeWalkingVisitor visitor = RecursiveLighterASTNodeWalkingVisitor.this; if (element instanceof LighterLazyParseableNode) { visitor.visitLazyParseableNode((LighterLazyParseableNode)element); } else if (element instanceof LighterASTTokenNode) { visitor.visitTokenNode((LighterASTTokenNode)element); } else { visitor.visitNode(element); } } }; }
@Nullable @Override public LighterASTNode parent(@NotNull LighterASTNode node) { return node instanceof LighterASTTokenNode ? null : super.parent(node); }
public static void lightTreeToBuffer(@NotNull final FlyweightCapableTreeStructure<LighterASTNode> tree, @NotNull final LighterASTNode node, @NotNull final Appendable buffer, final int indent, final boolean skipWhiteSpaces) { final IElementType tokenType = node.getTokenType(); if (skipWhiteSpaces && tokenType == TokenType.WHITE_SPACE) return; final boolean isLeaf = (node instanceof LighterASTTokenNode); StringUtil.repeatSymbol(buffer, ' ', indent); try { if (tokenType == TokenType.ERROR_ELEMENT) { buffer.append("PsiErrorElement:").append(PsiBuilderImpl.getErrorMessage(node)); } else if (tokenType == TokenType.WHITE_SPACE) { buffer.append("PsiWhiteSpace"); } else { buffer.append(isLeaf ? "PsiElement" : "Element").append('(').append(tokenType.toString()).append(')'); } if (isLeaf) { final String text = ((LighterASTTokenNode)node).getText().toString(); buffer.append("('").append(fixWhiteSpaces(text)).append("')"); } buffer.append('\n'); if (!isLeaf) { final Ref<LighterASTNode[]> kids = new Ref<LighterASTNode[]>(); final int numKids = tree.getChildren(tree.prepareForGetChildren(node), kids); if (numKids == 0) { StringUtil.repeatSymbol(buffer, ' ', indent + 2); buffer.append("<empty list>\n"); } else { for (int i = 0; i < numKids; i++) { lightTreeToBuffer(tree, kids.get()[i], buffer, indent + 2, skipWhiteSpaces); } } } } catch (IOException e) { LOG.error(e); } }
public void visitTokenNode(@NotNull LighterASTTokenNode node) { visitNode(node); }
@Nullable @Override public LighterASTNode parent(@Nonnull LighterASTNode node) { return node instanceof LighterASTTokenNode ? null : super.parent(node); }
public static void lightTreeToBuffer(@Nonnull final FlyweightCapableTreeStructure<LighterASTNode> tree, @Nonnull final LighterASTNode node, @Nonnull final Appendable buffer, final int indent, final boolean skipWhiteSpaces) { final IElementType tokenType = node.getTokenType(); if (skipWhiteSpaces && tokenType == TokenType.WHITE_SPACE) return; final boolean isLeaf = (node instanceof LighterASTTokenNode); StringUtil.repeatSymbol(buffer, ' ', indent); try { if (tokenType == TokenType.ERROR_ELEMENT) { buffer.append("PsiErrorElement:").append(PsiBuilderImpl.getErrorMessage(node)); } else if (tokenType == TokenType.WHITE_SPACE) { buffer.append("PsiWhiteSpace"); } else { buffer.append(isLeaf ? "PsiElement" : "Element").append('(').append(tokenType.toString()).append(')'); } if (isLeaf) { final String text = ((LighterASTTokenNode)node).getText().toString(); buffer.append("('").append(fixWhiteSpaces(text)).append("')"); } buffer.append('\n'); if (!isLeaf) { final Ref<LighterASTNode[]> kids = new Ref<LighterASTNode[]>(); final int numKids = tree.getChildren(tree.prepareForGetChildren(node), kids); if (numKids == 0) { StringUtil.repeatSymbol(buffer, ' ', indent + 2); buffer.append("<empty list>\n"); } else { for (int i = 0; i < numKids; i++) { lightTreeToBuffer(tree, kids.get()[i], buffer, indent + 2, skipWhiteSpaces); } } } } catch (IOException e) { LOG.error(e); } }
public void visitTokenNode(@Nonnull LighterASTTokenNode node) { visitNode(node); }