Search in sources :

Example 1 with Tag

use of org.opensolaris.opengrok.analysis.Definitions.Tag in project OpenGrok by OpenGrok.

the class JFlexXref method writeSymbolTable.

/**
     * Write a JavaScript function that returns an array with the definitions to
     * list in the navigation panel. Each element of the array is itself an
     * array containing the name of the definition type, the CSS class name for
     * the type, and an array of (symbol, line) pairs for the definitions of
     * that type.
     */
private void writeSymbolTable() throws IOException {
    if (defs == null) {
        // No definitions, no symbol table to write
        return;
    }
    // We want the symbol table to be sorted
    Comparator<Tag> cmp = new Comparator<Tag>() {

        @Override
        public int compare(Tag tag1, Tag tag2) {
            // Order by symbol name, and then by line number if multiple
            // definitions use the same symbol name
            int ret = tag1.symbol.compareTo(tag2.symbol);
            if (ret == 0) {
                ret = tag1.line - tag2.line;
            }
            return ret;
        }
    };
    Map<String, SortedSet<Tag>> symbols = new HashMap<>();
    for (Tag tag : defs.getTags()) {
        Style style = getStyle(tag.type);
        if (style != null && style.title != null) {
            SortedSet<Tag> tags = symbols.get(style.name);
            if (tags == null) {
                tags = new TreeSet<>(cmp);
                symbols.put(style.name, tags);
            }
            tags.add(tag);
        }
    }
    //TODO try to get rid of included js scripts generated from here (all js should ideally be in util)
    out.append("<script type=\"text/javascript\">/* <![CDATA[ */\n");
    out.append("function get_sym_list(){return [");
    boolean first = true;
    for (Style style : DEFINITION_STYLES) {
        SortedSet<Tag> tags = symbols.get(style.name);
        if (tags != null) {
            if (!first) {
                out.append(',');
            }
            out.append("[\"");
            out.append(style.title);
            out.append("\",\"");
            out.append(style.ssClass);
            out.append("\",[");
            boolean firstTag = true;
            for (Tag tag : tags) {
                if (!firstTag) {
                    out.append(',');
                }
                out.append('[');
                out.append(Util.jsStringLiteral(tag.symbol));
                out.append(',');
                out.append(Integer.toString(tag.line));
                out.append(']');
                firstTag = false;
            }
            out.append("]]");
            first = false;
        }
    }
    /* no LF intentionally - xml is whitespace aware ... */
    out.append("];} /* ]]> */</script>");
}
Also used : HashMap(java.util.HashMap) Tag(org.opensolaris.opengrok.analysis.Definitions.Tag) SortedSet(java.util.SortedSet) Comparator(java.util.Comparator)

Example 2 with Tag

use of org.opensolaris.opengrok.analysis.Definitions.Tag in project OpenGrok by OpenGrok.

the class JFlexXref method startScope.

protected void startScope() {
    if (scopesEnabled && scope == null) {
        int line = getLineNumber();
        List<Tag> tags = defs.getTags(line);
        if (tags != null) {
            for (Tag tag : tags) {
                if (tag.type.startsWith("function") || tag.type.startsWith("method")) {
                    scope = new Scope(tag.line, tag.line, tag.symbol, tag.namespace, tag.signature);
                    scopeLevel = 0;
                    break;
                }
            }
        }
    }
}
Also used : Scope(org.opensolaris.opengrok.analysis.Scopes.Scope) Tag(org.opensolaris.opengrok.analysis.Definitions.Tag)

Aggregations

Tag (org.opensolaris.opengrok.analysis.Definitions.Tag)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 SortedSet (java.util.SortedSet)1 Scope (org.opensolaris.opengrok.analysis.Scopes.Scope)1