STGroupStructureViewModel.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:jetbrains-plugin-st4 作者:
/** From editor's cursor, find associated parse tree node so we can highlight
 *  in structure view. It wants the parse tree node not a
 *  StructureViewTreeElement. It will try to find a path from root to
 *  that node and highlight it.
 */
@Nullable
public Object getCurrentEditorElement() {
    if (editor==null) return null;
    final int offset = editor.getCaretModel().getOffset();
    if ( parseTree==null ) return null;
    Tree selectedNode = Trees.findNodeSuchThat(parseTree, new Predicate<Tree>() {
        @Override
        public boolean test(Tree node) {
            if ( !(node instanceof TerminalNode) ) return false;
            Token t = ((TerminalNode) node).getSymbol();
            return offset>=t.getStartIndex() && offset<=t.getStopIndex();
        }
    });
    if ( selectedNode==null ) return null;
    // now walk up looking for template def node
    ParseTree p = (ParseTree)selectedNode;
    while ( p!=null && !(p instanceof STGParser.TemplateContext) ) {
        p = p.getParent();
    }
    if ( p!=null ) {
        return ((STGParser.TemplateContext)p).ID(0);
    }
    return null;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号