antlr4 获取给定父节点和规则 class 的规则节点
antlr4 get rule node given a parent and rule class
ParserRuleContext 的这个方法有什么意义
<T extends ParserRuleContext> List<T>
T getRuleContext(Class<? extends T> ctxType)
当我尝试使用此方法获取父项的子上下文时,它总是 return 为空。
例如
parentRuleContext.getRuleContext(ChildOneContext.class,MyParser.Rule_ChildOne)
我认为这应该 return 所有 ChildOneContexts 但总是 returning null。
我是不是用错了这个方法,它的目的有什么不同吗?由于没有关于此的文档,因此不清楚使用。
getRuleContext
应该 return 第 i 个 child(来自带有 i 参数的变体)或给定 class 的所有 children类型。如果您返回 null,我会说您没有给定类型的 child。您可以通过检查 children
成员并查看 ChildOneContext
child 是否存在来轻松检查这一点。
ParserRuleContext 的这个方法有什么意义
<T extends ParserRuleContext> List<T>
T getRuleContext(Class<? extends T> ctxType)
当我尝试使用此方法获取父项的子上下文时,它总是 return 为空。 例如
parentRuleContext.getRuleContext(ChildOneContext.class,MyParser.Rule_ChildOne)
我认为这应该 return 所有 ChildOneContexts 但总是 returning null。
我是不是用错了这个方法,它的目的有什么不同吗?由于没有关于此的文档,因此不清楚使用。
getRuleContext
应该 return 第 i 个 child(来自带有 i 参数的变体)或给定 class 的所有 children类型。如果您返回 null,我会说您没有给定类型的 child。您可以通过检查 children
成员并查看 ChildOneContext
child 是否存在来轻松检查这一点。