summaryrefslogtreecommitdiff
path: root/sources/scala/tools/scaladoc/HTMLGenerator.java
diff options
context:
space:
mode:
Diffstat (limited to 'sources/scala/tools/scaladoc/HTMLGenerator.java')
-rw-r--r--sources/scala/tools/scaladoc/HTMLGenerator.java314
1 files changed, 82 insertions, 232 deletions
diff --git a/sources/scala/tools/scaladoc/HTMLGenerator.java b/sources/scala/tools/scaladoc/HTMLGenerator.java
index 350786d21c..04c4cdcaaa 100644
--- a/sources/scala/tools/scaladoc/HTMLGenerator.java
+++ b/sources/scala/tools/scaladoc/HTMLGenerator.java
@@ -57,11 +57,6 @@ import scalac.util.Strings;
*/
public class HTMLGenerator {
- public static final String PRODUCT =
- System.getProperty("scala.product", "scaladoc");
- public static final String VERSION =
- System.getProperty("scala.version", "unknown version");
-
/*
* Names of predefined page names.
*/
@@ -78,12 +73,7 @@ public class HTMLGenerator {
protected final String ROOT_FRAME = "rootFrame";
protected final String PACKAGES_FRAME = "packagesFrame";
protected final String CLASSES_FRAME = "classesFrame";
-
- /*
- * HTML meta information.
- */
- protected final String GENERATOR = PRODUCT + " (" + VERSION + ")";
- protected final SimpleDateFormat df = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
+ protected final String SELF_FRAME = "_self";
/*
* XML attributes.
@@ -112,9 +102,6 @@ public class HTMLGenerator {
protected final XMLAttribute[] ATTRS_MEMBER_TITLE =
new XMLAttribute[]{ new XMLAttribute("class", "member-title") };
- protected final XMLAttribute[] ATTRS_META =
- new XMLAttribute[]{ new XMLAttribute("generator", GENERATOR) };
-
protected final XMLAttribute[] ATTRS_MODIFIERS =
new XMLAttribute[]{
new XMLAttribute("valign", "top"),
@@ -157,6 +144,20 @@ public class HTMLGenerator {
new XMLAttribute("style", "margin-top:5px; text-align:center; font-size:9pt;")
};
+ /** HTML meta information.
+ */
+ public static final String PRODUCT =
+ System.getProperty("scala.product", "scaladoc");
+ public static final String VERSION =
+ System.getProperty("scala.version", "unknown version");
+ protected final String GENERATOR = PRODUCT + " (" + VERSION + ")";
+ protected final SimpleDateFormat df = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
+ protected final XMLAttribute[] ATTRS_META =
+ new XMLAttribute[]{ new XMLAttribute("generator", GENERATOR) };
+ protected String getGenerator() {
+ return "Generated by " + GENERATOR + " on " + df.format(new Date());
+ }
+
/** The unique documented tree.
*/
protected final Tree tree;
@@ -179,7 +180,7 @@ public class HTMLGenerator {
/** The underlying HTML printer.
*/
- public HTMLPrinter page;
+ public Page page;
/** Symbols defined in the syntactic tree.
*/
@@ -214,9 +215,6 @@ public class HTMLGenerator {
*/
protected final Stack stack = new Stack();
- private final Symbol JAVALANG; // !!! remove ?
- private final Type ROOT_TYPE; // !!! remove ?
-
/**
* Navigation context.
*/
@@ -242,10 +240,8 @@ public class HTMLGenerator {
this.global = global;
this.subs = ScalaSearch.subTemplates(tree);
this.treeSymbols = new TreeSymbols(tree);
- try { this.uri = new URI("."); } catch(Exception e) {}
+ this.uri = Location.makeURI(".");
- this.JAVALANG = global.definitions.getClass(Names.java_lang);
- this.ROOT_TYPE = global.definitions.ROOT.thisType();
assert global.args instanceof HTMLGeneratorCommand;
HTMLGeneratorCommand args = (HTMLGeneratorCommand) global.args;
this.representation = new HTMLRepresentation(
@@ -259,78 +255,36 @@ public class HTMLGenerator {
this.validate = args.validate.value;
}
+ /** Relative URL of the definition of the given symbol.
+ */
+ protected String definitionURL(Symbol sym) {
+ return page.rel(Location.get(sym));
+ }
+
/**
* Open a new documentation page and make it the current page.
* @param uri URL of the page
* @param title Title of the page
*/
- protected void openPage(URI uri, String title) {
- try {
- stack.push(page);
- stack.push(symtab);
- stack.push(uri);
-
- this.uri = uri;
- File f = new File(directory, uri.toString());
- f.getParentFile().mkdirs();
-
- BufferedWriter out = new BufferedWriter(new FileWriter(f));
- String stylesheetPath = Location.asSeenFrom(new URI(stylesheet), uri).toString();
- if (representation.isXHTMLType())
- page = new XHTMLPrinter(out, title, representation, stylesheetPath);
- else
- page = new HTMLPrinter(out, title, representation, stylesheetPath);
- symtab = new SymbolTablePrinter(page.getCodePrinter()) {
- public void printSymbol(Symbol sym, boolean addLink) {
- HTMLGenerator.this.printSymbol(sym, addLink);
- }
- public Type getTypeToPrintForPrefix(Type prefix/*, sym*/) {
- while (true) {
- Type result = getTypeToPrintForPrefix0(prefix);
- if (result == prefix || result == null) {
- return
- cleanPrefix(result); // vincent
- // Next lines should replace the previous one in theory.
- // htmlGenerator.isReferenced(sym) ?
- // htmlGenerator.cleanPrefix(result) : // vincent
- // result;
- }
- prefix = result;
- }
- }
- public String getSymbolInnerString(Symbol symbol) {
- if (symbol.kind == Kinds.TYPE)
- return INNER_LT; // HTML encoded "<:" symbol
- else
- return super.getSymbolInnerString(symbol);
- }
- // where
- protected String INNER_LT = "&lt;:";
- public SymbolTablePrinter printType(Type type, String inner) {
- if ((INNER_LT.equals(inner) && type.symbol() == global.definitions.ANY_CLASS) ||
- (">:".equals(inner) && type.symbol() == global.definitions.ALL_CLASS))
- return this;
- else {
- printType0(getTypeToPrintForType(type), inner);
- return this;
- }
- }
- };
- } catch(Exception e) { throw Debug.abort(e); }
+ protected void createPrinters(URI uri, String title, String destinationFrame) {
+ stack.push(page);
+ stack.push(symtab);
+ // Create a new page.
+ page = new Page(directory, uri, destinationFrame,
+ title, representation,
+ stylesheet/*, script*/);
+ // Create a printer to print symbols and types.
+ symtab = SymbolTablePrinterFactory.makeHTML(page, treeSymbols);
+ page.open();
}
/**
* Close the current page.
*/
- protected void closePage() {
- try {
- page.getCodePrinter().getWriter().close();
- uri = (URI) stack.pop();
- symtab = (SymbolTablePrinter) stack.pop();
- page = (HTMLPrinter) stack.pop();
- } catch (IOException exception) {
- throw Debug.abort(exception); // !!! reporting an error would be wiser
- }
+ protected void closePrinters() {
+ page.close();
+ symtab = (SymbolTablePrinter) stack.pop();
+ page = (Page) stack.pop();
}
/**
@@ -356,14 +310,6 @@ public class HTMLGenerator {
}
/**
- * Return the URL of the definition of the given symbol relative
- * to the current page.
- */
- public String definitionURL(Symbol sym) {
- return Location.asSeenFrom(Location.getURI(sym), uri).toString();
- }
-
- /**
* Generates the HTML pages.
*/
protected void apply() {
@@ -461,10 +407,6 @@ public class HTMLGenerator {
};
}
- protected String getGenerator() {
- return "Generated by " + GENERATOR + " on " + df.format(new Date());
- }
-
/**
* Generates a HTML page for a class or object definition as well
* as pages for every inner class or object.
@@ -474,13 +416,10 @@ public class HTMLGenerator {
protected void createPages(Tree tree) {
Symbol sym = tree.symbol();
String title = Location.getName(sym);
- openPage(Location.getURI(sym), title);
-
+ createPrinters(Location.getURI(sym), title, SELF_FRAME);
page.printHeader(ATTRS_META, getGenerator());
- String windowTitle = title + " (" + doctitle.replaceAll("<.*>", " ") + ")";
- page.printOpenBody(new XMLAttribute[]{
- new XMLAttribute("onload", "setWindowTitle('" + windowTitle + "');")
- });
+ page.printOpenBody();
+
if (sym.isRoot())
addNavigationBar(ROOT_NAV_CONTEXT);
else
@@ -510,9 +449,9 @@ public class HTMLGenerator {
addNavigationBar(CONTAINER_NAV_CONTEXT);
if (validate)
addValidationBar();
- page.printFootpage();
- closePage();
+ page.printFootpage();
+ closePrinters();
}
/**
@@ -542,9 +481,9 @@ public class HTMLGenerator {
*/
protected void addNavigationBar(int navigationContext) {
try {
- String overviewLink = Location.asSeenFrom(new URI(ROOT_PAGE), uri).toString();
- String indexLink = Location.asSeenFrom(new URI(INDEX_PAGE), uri).toString();
- String helpLink = Location.asSeenFrom(new URI(HELP_PAGE), uri).toString();
+ String overviewLink = page.rel(ROOT_PAGE);
+ String indexLink = page.rel(INDEX_PAGE);
+ String helpLink = page.rel(HELP_PAGE);
page.printlnOTag("table", ATTRS_NAVIGATION).indent();
page.printlnOTag("tr").indent();
@@ -552,13 +491,12 @@ public class HTMLGenerator {
page.printlnOTag("table").indent();
page.printlnOTag("tr").indent();
-
// overview link
if (navigationContext == ROOT_NAV_CONTEXT)
page.printlnTag("td", ATTRS_NAVIGATION_SELECTED, "Overview");
else {
page.printOTag("td", ATTRS_NAVIGATION_ENABLED);
- page.printAhref(overviewLink, ROOT_FRAME, "Overview");
+ page.printAhref(overviewLink, SELF_FRAME, "Overview");
page.printlnCTag("td");
}
// index link
@@ -566,7 +504,7 @@ public class HTMLGenerator {
page.printlnTag("td", ATTRS_NAVIGATION_SELECTED, "Index");
else {
page.printOTag("td", ATTRS_NAVIGATION_ENABLED);
- page.printAhref(indexLink, ROOT_FRAME, "Index");
+ page.printAhref(indexLink, SELF_FRAME, "Index");
page.printlnCTag("td");
}
// help link
@@ -574,7 +512,7 @@ public class HTMLGenerator {
page.printlnTag("td", ATTRS_NAVIGATION_SELECTED, "Help");
else {
page.printOTag("td", ATTRS_NAVIGATION_ENABLED);
- page.printAhref(helpLink, ROOT_FRAME, "Help");
+ page.printAhref(helpLink, SELF_FRAME, "Help");
page.printlnCTag("td");
}
@@ -606,7 +544,7 @@ public class HTMLGenerator {
page.printlnOTag("div", ATTRS_VALIDATION);
page.indent();
page.printlnAhref(
- "http://validator.w3.org/check/referer", ROOT_FRAME,
+ "http://validator.w3.org/check/referer", SELF_FRAME,
"validate html");
page.undent();
page.printlnCTag("div");
@@ -630,7 +568,7 @@ public class HTMLGenerator {
} else {
// in
page.print("in ");
- printPath(sym.owner());
+ printPath(sym.owner(), SELF_FRAME);
// kind and name
page.printlnOTag("div", ATTRS_ENTITY).indent();
@@ -664,7 +602,7 @@ public class HTMLGenerator {
symtab.defString(sub, true /*addLink*/);
if (sub.owner() != sym.owner()) {
page.print(" in ");
- printPath(sub.owner());
+ printPath(sub.owner(), SELF_FRAME);
}
page.printlnCTag("dd");
}
@@ -799,7 +737,7 @@ public class HTMLGenerator {
protected void addMemberDetail(Symbol sym) {
if (treeSymbols.contains(sym)) {
// title with label
- page.printlnAname(Location.asSeenFrom(Location.getURI(sym), uri).getFragment(), "");
+ page.printlnAname(Page.asSeenFrom(Location.getURI(sym), uri).getFragment(), "");
page.printTag("h3", sym.nameString());
// signature
@@ -834,7 +772,7 @@ public class HTMLGenerator {
page.printlnOTag("td", new XMLAttribute[]{
new XMLAttribute("class", "inherited-owner")}).indent();
page.print(inheritedMembers + " inherited from ");
- printPath(owners[i]);
+ printPath(owners[i], SELF_FRAME);
page.undent();
page.printlnCTag("td").undent();
page.printlnCTag("tr");
@@ -846,7 +784,7 @@ public class HTMLGenerator {
Symbol[] members = (Symbol[]) group.get(owners[i]);
for (int j = 0; j < members.length; j++) {
if (j > 0) page.print(", ");
- printSymbol(members[j], true);
+ symtab.printSymbol(members[j], true);
}
page.undent();
page.printlnCTag("td").undent();
@@ -858,58 +796,6 @@ public class HTMLGenerator {
}
/**
- * Removes the longest prefix of this type which corresponds to a
- * nested of class and object definitions. The idea is that this
- * prefix is redondant and can be recovered directly from the tree
- * itself.
- *
- * @param prefix
- */
- protected Type cleanPrefix(Type prefix) {
- if (prefix == null) return null;
- if (prefix.symbol().kind == Kinds.NONE) return null;
- if (prefix.symbol().isRoot()) return null;
-
- // Next line should be removed in theory.
- if (prefix.symbol().moduleClass() == JAVALANG)
- return null;
-
- switch(prefix) {
- case ThisType(Symbol sym):
- if (sym.isPackage() && treeSymbols.contains(sym.module()))
- return null;
- else if (treeSymbols.contains(sym))
- return null;
- else
- return prefix;
- case TypeRef(Type pre, Symbol sym, Type[] args):
- Type pre1 = cleanPrefix(pre);
- if (pre1 == null && args.length == 0 && treeSymbols.contains(sym))
- return null;
- else {
- pre1 = pre1 == null ? ROOT_TYPE : pre1;
- return Type.typeRef(pre1, sym, args);
- }
- case SingleType(Type pre, Symbol sym):
- Type pre1 = cleanPrefix(pre);
- if (pre1 == null) {
- if (sym.isClass() || sym.isModule())
- if (treeSymbols.contains(sym)) {
- return null;
- }
- else
- return Type.singleType(ROOT_TYPE, sym);
- else
- return Type.singleType(ROOT_TYPE, sym);
- }
- else
- return Type.singleType(pre1, sym);
- default:
- return prefix;
- }
- }
-
- /**
* Prints the signature of a class symbol.
*
* @param symbol
@@ -963,22 +849,15 @@ public class HTMLGenerator {
page.printCTag("dl");
}
-
- protected URI mkURI(String uri) {
- try {
- return new URI(uri);
- } catch(Exception e) { throw Debug.abort(e); }
- }
-
/**
* Creates the page describing the different frames.
*
* @param title The page title
*/
protected void createFramePage() {
- openPage(mkURI(FRAME_PAGE), windowtitle);
-
+ createPrinters(Location.makeURI(FRAME_PAGE), windowtitle, "");
page.printHeader(ATTRS_META, getGenerator());
+
page.printlnOTag("frameset", new XMLAttribute[] {
new XMLAttribute("cols", "25%, 75%")}).indent();
page.printlnOTag("frameset", new XMLAttribute[] {
@@ -1005,7 +884,7 @@ public class HTMLGenerator {
page.printlnCTag("frameset");
page.printlnCTag("html");
- closePage();
+ closePrinters();
}
/**
@@ -1121,12 +1000,12 @@ public class HTMLGenerator {
* @param title
*/
protected void createPackageIndexPage() {
- openPage(mkURI(PACKAGE_LIST_PAGE), "List of packages");
+ createPrinters(Location.makeURI(PACKAGE_LIST_PAGE), "List of packages", CLASSES_FRAME);
+ page.printHeader(ATTRS_META, getGenerator());
+ page.printOpenBody();
Tree[] packages = ScalaSearch.getSortedPackageList(tree);
- page.printHeader(ATTRS_META, getGenerator());
- page.printOpenBody();
addDocumentationTitle(new XMLAttribute[]{
new XMLAttribute("class", "doctitle-larger")});
page.printAhref(PACKAGE_PAGE, CLASSES_FRAME, "All objects, traits and classes");
@@ -1134,9 +1013,9 @@ public class HTMLGenerator {
printPackagesTable(packages, "Packages");
if (validate)
addValidationBar();
- page.printFootpage();
- closePage();
+ page.printFootpage();
+ closePrinters();
}
/**
@@ -1146,23 +1025,19 @@ public class HTMLGenerator {
*/
protected void createContainerIndexPage(Tree tree) {
Symbol sym = tree.symbol();
- openPage(mkURI(packageSummaryPage(sym)), Location.getName(sym));
+ createPrinters(Location.makeURI(packageSummaryPage(sym)), Location.getName(sym), ROOT_FRAME);
page.printHeader(ATTRS_META, getGenerator());
page.printOpenBody();
page.printlnOTag("table", ATTRS_NAVIGATION).indent();
page.printlnOTag("tr").indent();
page.printlnOTag("td", ATTRS_NAVIGATION_LINKS).indent();
-
- printPath(sym);
- // page.printlnAhref(definitionURL(sym), ROOT_FRAME, sym.fullNameString());
-
+ printPath(sym, ROOT_FRAME);
page.printlnCTag("td");
page.printlnCTag("tr");
page.printlnCTag("table");
page.printlnSTag("p");
-
String[] titles = new String[]{ "Objects", "Traits", "Classes" };
if (sym.isRoot()) {
Tree[][] members = ScalaSearch.getSortedPackageMemberList(tree);
@@ -1176,9 +1051,9 @@ public class HTMLGenerator {
if (validate)
addValidationBar();
- page.printFootpage();
- closePage();
+ page.printFootpage();
+ closePrinters();
}
/**
@@ -1188,13 +1063,10 @@ public class HTMLGenerator {
*/
protected void createIndexPage() {
String title = "Scala Library Index";
- openPage(mkURI(INDEX_PAGE), title);
-
+ createPrinters(Location.makeURI(INDEX_PAGE), title, SELF_FRAME);
page.printHeader(ATTRS_META, getGenerator());
- String windowTitle = title + " (" + doctitle.replaceAll("<.*>", " ") + ")";
- page.printOpenBody(new XMLAttribute[]{
- new XMLAttribute("onload", "setWindowTitle('" + windowTitle + "');")
- });
+ page.printOpenBody();
+
addNavigationBar(INDEX_NAV_CONTEXT);
page.printlnHLine();
@@ -1211,7 +1083,7 @@ public class HTMLGenerator {
Character[] chars = (Character[]) index.fst;
Map map = (Map) index.snd;
for (int i = 0; i < chars.length; i++)
- page.printlnAhref("#" + i, ROOT_FRAME, HTMLPrinter.encode(chars[i]));
+ page.printlnAhref("#" + i, SELF_FRAME, HTMLPrinter.encode(chars[i]));
page.printlnHLine();
for (int i = 0; i < chars.length; i++) {
Character car = chars[i];
@@ -1234,9 +1106,9 @@ public class HTMLGenerator {
addNavigationBar(INDEX_NAV_CONTEXT);
if (validate)
addValidationBar();
- page.printFootpage();
- closePage();
+ page.printFootpage();
+ closePrinters();
}
/**
@@ -1246,13 +1118,10 @@ public class HTMLGenerator {
*/
protected void createHelpPage() {
String title = "API Help";
- openPage(mkURI(HELP_PAGE), title);
-
+ createPrinters(Location.makeURI(HELP_PAGE), title, ROOT_PAGE);
page.printHeader(ATTRS_META, getGenerator());
- String windowTitle = title + " (" + doctitle.replaceAll("<.*>", " ") + ")";
- page.printOpenBody(new XMLAttribute[]{
- new XMLAttribute("onload", "setWindowTitle('" + windowTitle + "');")
- });
+ page.printOpenBody();
+
addNavigationBar(HELP_NAV_CONTEXT);
page.printlnHLine();
@@ -1272,7 +1141,7 @@ public class HTMLGenerator {
page.printlnTag("div", h3, "Overview");
page.printlnOTag("blockquote").indent();
page.print("The ");
- page.printAhref(ROOT_PAGE, ROOT_FRAME, "Overview");
+ page.printAhref(ROOT_PAGE, SELF_FRAME, "Overview");
page.println(" page is the front page of this API document and "
+ "provides a list of all top-level packages, classes, traits "
+ "and objects with a summary for each. "
@@ -1325,7 +1194,7 @@ public class HTMLGenerator {
page.printlnTag("div", h3, "Index");
page.printlnOTag("blockquote").indent();
page.print("The ");
- page.printAhref(INDEX_PAGE, ROOT_FRAME, "Index");
+ page.printAhref(INDEX_PAGE, SELF_FRAME, "Index");
page.print(" contains an alphabetic list of all classes, interfaces, "
+ "constructors, methods, and fields.");
page.printlnCTag("blockquote");
@@ -1339,45 +1208,26 @@ public class HTMLGenerator {
addNavigationBar(HELP_NAV_CONTEXT);
if (validate)
addValidationBar();
- page.printFootpage();
- closePage();
+ page.printFootpage();
+ closePrinters();
}
/**
* Adds to the current page an hyperlinked path leading to a given
* symbol (including itself).
*/
- protected void printPath(Symbol sym) {
+ protected void printPath(Symbol sym, String destinationFrame) {
String name = removeHtmlSuffix(Location.getURI(sym).toString());
if (treeSymbols.contains(sym)) {
String target = definitionURL(sym);
- page.printlnAhref(target, ROOT_FRAME, name);
+ page.printlnAhref(target, destinationFrame, name);
}
else
page.println(name);
}
/**
- * Adds to the current page an hyperlink leading to a given
- * symbol.
- */
- protected void printSymbol(Symbol sym, boolean addLink) {
- String name = sym.nameString();
- if (global.debug) name = sym.name.toString();
- if (treeSymbols.contains(sym))
- if (addLink)
- page.printAhref(definitionURL(sym), ROOT_FRAME, name);
- else {
- page.printOTag("em");
- page.print(name);
- page.printCTag("em");
- }
- else
- page.print(name);
- }
-
- /**
* Writes the string representation of a symbol entry in the index.
*
* @param symbol
@@ -1391,7 +1241,7 @@ public class HTMLGenerator {
// owner
if (!symbol.isRoot()) {
page.print(" in ");
- printPath(symbol.owner());
+ printPath(symbol.owner(), SELF_FRAME);
}
}