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 protected boolean skipChildProcessingWhenBuildingStubs(@NotNull LighterAST tree, @NotNull LighterASTNode parent, @NotNull LighterASTNode node) { IElementType parentType = parent.getTokenType(); IElementType nodeType = node.getTokenType(); if (checkByTypes(parentType, nodeType)) return true; if (nodeType == JavaElementType.CODE_BLOCK) { CodeBlockVisitor visitor = new CodeBlockVisitor(); ((LighterLazyParseableNode)node).accept(visitor); return visitor.result; } return false; }
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); } } }; }
public MasqueradingPsiBuilderAdapter(@NotNull final Project project, @NotNull final ParserDefinition parserDefinition, @NotNull final MasqueradingLexer lexer, @NotNull final LighterLazyParseableNode chameleon, @NotNull final CharSequence text) { this(new PsiBuilderImpl(project, parserDefinition, lexer, chameleon, text)); }
@Override protected boolean skipChildProcessingWhenBuildingStubs(@NotNull LighterAST tree, @NotNull LighterASTNode parent, @NotNull LighterASTNode node) { IElementType parentType = parent.getTokenType(); IElementType nodeType = node.getTokenType(); if (checkByTypes(parentType, nodeType)) return true; if (nodeType == JavaElementType.CODE_BLOCK && node instanceof LighterLazyParseableNode) { CodeBlockVisitor visitor = new CodeBlockVisitor(); ((LighterLazyParseableNode)node).accept(visitor); return visitor.result; } return false; }
public HaxePsiBuilder(@NotNull Project project, @NotNull ParserDefinition parserDefinition, @NotNull Lexer lexer, @NotNull LighterLazyParseableNode chameleon, @NotNull CharSequence text) { super(project, parserDefinition, lexer, chameleon, text); psiFile = chameleon.getContainingFile(); setupDebugTraces(); }
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); } } }; }
@NotNull public static PsiBuilder createBuilder(final LighterLazyParseableNode chameleon) { final PsiElement psi = chameleon.getContainingFile(); assert psi != null : chameleon; final Project project = psi.getProject(); final PsiBuilderFactory factory = PsiBuilderFactory.getInstance(); final LanguageLevel level = PsiUtil.getLanguageLevel(psi); final Lexer lexer = new JavaLexer(level); final PsiBuilder builder = factory.createBuilder(project, chameleon, lexer, chameleon.getTokenType().getLanguage(), level.toLangVersion(), chameleon.getText()); setLanguageLevel(builder, level); return builder; }
@Override public FlyweightCapableTreeStructure<LighterASTNode> parseContents(final LighterLazyParseableNode chameleon) { final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon); JavaParser.INSTANCE.getStatementParser().parseCodeBlockDeep(builder, true); return builder.getLightTree(); }
public static boolean isCodeBlockWithoutStubs(@NotNull LighterASTNode node) { if(node.getTokenType() == JavaElementType.CODE_BLOCK && node instanceof LighterLazyParseableNode) { CodeBlockVisitor visitor = new CodeBlockVisitor(); ((LighterLazyParseableNode) node).accept(visitor); return visitor.result; } return false; }
public void visitLazyParseableNode(@NotNull LighterLazyParseableNode node) { visitNode(node); }
public void visitLazyParseableNode(@Nonnull LighterLazyParseableNode node) { visitNode(node); }
/** * Parses the contents of the specified chameleon node and returns the lightweight tree * representing parsed contents. * * @param chameleon the node to parse. * @return the parsed contents of the node. */ FlyweightCapableTreeStructure<LighterASTNode> parseContents(final LighterLazyParseableNode chameleon);