/** Return first node satisfying the pred * * @since 4.5.1 */ public static Tree findNodeSuchThat(Tree t, Predicate<Tree> pred) { if ( pred.test(t) ) return t; if ( t==null ) return null; int n = t.getChildCount(); for (int i = 0 ; i < n ; i++){ Tree u = findNodeSuchThat(t.getChild(i), pred); if ( u!=null ) return u; } return null; }
/** Same as loadGrammar(fileName) except import vocab from existing lexer */ // public static Grammar loadGrammar(Tool tool, String fileName, LexerGrammar lexerGrammar) { // GrammarRootAST grammarRootAST = parseGrammar(fileName); // if ( grammarRootAST==null ) return null; // final Grammar g = tool.createGrammar(grammarRootAST); // g.fileName = fileName; // if ( lexerGrammar!=null ) { // g.importVocab(lexerGrammar); // } // tool.process(g, false); // return g; // } public static Tree findOverriddenDecisionRoot(Tree ctx) { return Trees.findNodeSuchThat(ctx, new Predicate<Tree>() { @Override public boolean test(Tree t) { return t instanceof PreviewInterpreterRuleContext ? ((PreviewInterpreterRuleContext) t).isDecisionOverrideRoot() : false; } }); }
/** Return first node satisfying the pred * * @since 4.5.1 */ public static Tree findNodeSuchThat(Tree t, Predicate<Tree> pred) { if ( pred.test(t) ) return t; int n = t.getChildCount(); for (int i = 0 ; i < n ; i++){ Tree u = findNodeSuchThat(t.getChild(i), pred); if ( u!=null ) return u; } return null; }
/** Return first node satisfying the pred * * @since 4.5.1 */ public static Tree findNodeSuchThat(Tree t, Predicate<Tree> pred) { if ( pred.eval(t) ) return t; if ( t==null ) return null; int n = t.getChildCount(); for (int i = 0 ; i < n ; i++){ Tree u = findNodeSuchThat(t.getChild(i), pred); if ( u!=null ) return u; } return null; }
/** Return first node satisfying the pred * * @since 4.5.1 */ public static Tree findNodeSuchThat(Tree t, Predicate<Tree> pred) { if ( pred.test(t) ) return t; if ( t==null ) return null; int n = t.getChildCount(); for (int i = 0 ; i < n ; i++){ Tree u = findNodeSuchThat(t.getChild(i), pred); if ( u!=null ) return u; } return null; }