GoDeclarationsScanner.java 文件源码

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

项目:goworks 作者:
@Override
@RuleDependencies({
    @RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_constSpec, version=0),
    @RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_identifierList, version=0),
})
public void enterConstSpec(ConstSpecContext ctx) {
    if (!isTopLevel(ctx)) {
        return;
    }

    IdentifierListContext idListContext = ctx.identifierList();
    List<? extends TerminalNode> identifiers = idListContext.IDENTIFIER();
    String type = ctx.type() != null ? String.format(" : <font color='808080'>%s</font>", HtmlSignatureVisitor.UNCOLORED.visit(ctx.type())) : "";
    for (TerminalNode identifier : identifiers) {
        Interval sourceInterval = new Interval(identifier.getSymbol().getStartIndex(), ParseTrees.getStopSymbol(ctx).getStopIndex());
        String name = identifier.getSymbol().getText();
        String signature = name + type;

        GoNode.DeclarationDescription description = new GoNode.DeclarationDescription(name, DeclarationKind.CONSTANT);
        description.setOffset(snapshot, getCurrentParent().getFileObject(), sourceInterval.a);
        description.setHtmlHeader(signature);
        getCurrentParent().getChildren().add(description);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号