All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.org.python.indexer.demos.HtmlOutline Maven / Gradle / Ivy

Go to download

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.

There is a newer version: 2.7.4
Show newest version
/**
 * Copyright 2009, Google Inc.  All rights reserved.
 * Licensed to PSF under a Contributor Agreement.
 */
package org.python.indexer.demos;

import org.python.indexer.Indexer;
import org.python.indexer.Outliner;

import java.util.List;

/**
 * Generates a static-html outline for a file.
 */
class HtmlOutline {

    private Indexer indexer;
    private StringBuilder buffer;

    public HtmlOutline(Indexer idx) {
        this.indexer = idx;
    }

    /**
     * Generates HTML outline for {@code path}.
     * @return the html as an {@code UL} element
     */
    public String generate(String path) throws Exception {
        buffer = new StringBuilder(1024);
        List entries = indexer.generateOutline(path);
        addOutline(entries);
        String html = buffer.toString();
        buffer = null;
        return html;
    }

    private void addOutline(List entries) {
        add("
    \n"); for (Outliner.Entry e : entries) { addEntry(e); } add("
\n"); } private void addEntry(Outliner.Entry e) { add("
  • "); String style = null; switch (e.getKind()) { case FUNCTION: case METHOD: case CONSTRUCTOR: style = "function"; break; case CLASS: style = "type-name"; break; case PARAMETER: style = "parameter"; break; case VARIABLE: case SCOPE: style = "identifier"; break; } add(""); if (style != null) { add(""); } add(e.getName()); if (style != null) { add(""); } add(""); if (e.isBranch()) { addOutline(e.getChildren()); } add("
  • "); } private void add(String text) { buffer.append(text); } }




    © 2015 - 2024 Weber Informatics LLC | Privacy Policy