From aa812cce53190f75a0ec618d1700ee090d264be7 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 21 Jul 2016 13:25:51 +0200 Subject: [PATCH] add some helper methods to LighterAST --- .../src/com/intellij/lang/LighterAST.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/platform/core-api/src/com/intellij/lang/LighterAST.java b/platform/core-api/src/com/intellij/lang/LighterAST.java index 7d60edca0591..d69e20462e4a 100644 --- a/platform/core-api/src/com/intellij/lang/LighterAST.java +++ b/platform/core-api/src/com/intellij/lang/LighterAST.java @@ -15,7 +15,11 @@ */ package com.intellij.lang; +import com.intellij.openapi.util.Condition; +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.tree.TokenSet; import com.intellij.util.CharTable; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -46,4 +50,25 @@ public abstract class LighterAST { public abstract List getChildren(@NotNull final LighterASTNode parent); public abstract void disposeChildren(@NotNull List children); + + @Nullable + public LighterASTNode findChildByType(@Nullable LighterASTNode node, @NotNull final IElementType type) { + if (node == null) return null; + return ContainerUtil.find(getChildren(node), new Condition() { + @Override + public boolean value(LighterASTNode node) { + return node.getTokenType() == type; + } + }); + } + + @NotNull + public List findChildrenByType(@NotNull LighterASTNode node, @NotNull final TokenSet types) { + return ContainerUtil.filter(getChildren(node), new Condition() { + @Override + public boolean value(LighterASTNode node) { + return types.contains(node.getTokenType()); + } + }); + } } \ No newline at end of file