Search in sources :

Example 1 with ASTStructure

use of com.intellij.psi.impl.source.tree.ASTStructure in project intellij-community by JetBrains.

the class PsiBuilderQuickTest method doTest.

private static void doTest(@NonNls final String text, final Parser parser, @NonNls final String expected) {
    final PsiBuilder builder = createBuilder(text);
    final PsiBuilder.Marker rootMarker = builder.mark();
    parser.parse(builder);
    rootMarker.done(ROOT);
    // check light tree composition
    final FlyweightCapableTreeStructure<LighterASTNode> lightTree = builder.getLightTree();
    assertEquals(expected, DebugUtil.lightTreeToString(lightTree, false));
    // verify that light tree can be taken multiple times
    final FlyweightCapableTreeStructure<LighterASTNode> lightTree2 = builder.getLightTree();
    assertEquals(expected, DebugUtil.lightTreeToString(lightTree2, false));
    // check heavy tree composition
    final ASTNode root = builder.getTreeBuilt();
    assertEquals(expected, DebugUtil.nodeTreeToString(root, false));
    // check heavy vs. light tree merging
    final PsiBuilder builder2 = createBuilder(text);
    final PsiBuilder.Marker rootMarker2 = builder2.mark();
    parser.parse(builder2);
    rootMarker2.done(ROOT);
    DiffTree.diff(new ASTStructure(root), builder2.getLightTree(), new ShallowNodeComparator<ASTNode, LighterASTNode>() {

        @NotNull
        @Override
        public ThreeState deepEqual(@NotNull ASTNode oldNode, @NotNull LighterASTNode newNode) {
            return ThreeState.UNSURE;
        }

        @Override
        public boolean typesEqual(@NotNull ASTNode oldNode, @NotNull LighterASTNode newNode) {
            return true;
        }

        @Override
        public boolean hashCodesEqual(@NotNull ASTNode oldNode, @NotNull LighterASTNode newNode) {
            return true;
        }
    }, new DiffTreeChangeBuilder<ASTNode, LighterASTNode>() {

        @Override
        public void nodeReplaced(@NotNull ASTNode oldChild, @NotNull LighterASTNode newChild) {
            fail("replaced(" + oldChild + "," + newChild.getTokenType() + ")");
        }

        @Override
        public void nodeDeleted(@NotNull ASTNode oldParent, @NotNull ASTNode oldNode) {
            fail("deleted(" + oldParent + "," + oldNode + ")");
        }

        @Override
        public void nodeInserted(@NotNull ASTNode oldParent, @NotNull LighterASTNode newNode, int pos) {
            fail("inserted(" + oldParent + "," + newNode.getTokenType() + ")");
        }
    }, root.getText());
}
Also used : ThreeState(com.intellij.util.ThreeState) ASTStructure(com.intellij.psi.impl.source.tree.ASTStructure) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ASTStructure (com.intellij.psi.impl.source.tree.ASTStructure)1 ThreeState (com.intellij.util.ThreeState)1 NotNull (org.jetbrains.annotations.NotNull)1