summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcremet <cremet@epfl.ch>2003-11-13 10:29:29 +0000
committercremet <cremet@epfl.ch>2003-11-13 10:29:29 +0000
commitcebcce6b168cba58a270a9cc00a4848391133bb0 (patch)
tree7987a02bcba482f1b2937f9feea88673fbf667f3
parent70ed6bea272a118d34b6cc7f4b87f83d3935e911 (diff)
downloadscala-cebcce6b168cba58a270a9cc00a4848391133bb0.tar.gz
scala-cebcce6b168cba58a270a9cc00a4848391133bb0.tar.bz2
scala-cebcce6b168cba58a270a9cc00a4848391133bb0.zip
- No new features, just redesigning.
-rw-r--r--config/list/scaladoc.lst2
-rw-r--r--sources/scala/tools/scaladoc/HTMLGenerator.java314
-rw-r--r--sources/scala/tools/scaladoc/Location.java40
-rw-r--r--sources/scala/tools/scaladoc/Page.java126
-rw-r--r--sources/scala/tools/scaladoc/StandardDocModule.java1
-rw-r--r--sources/scala/tools/scaladoc/SymbolTablePrinter.java2
-rw-r--r--sources/scala/tools/scaladoc/SymbolTablePrinterFactory.java137
7 files changed, 356 insertions, 266 deletions
diff --git a/config/list/scaladoc.lst b/config/list/scaladoc.lst
index 62e5e2b979..80e53b0a78 100644
--- a/config/list/scaladoc.lst
+++ b/config/list/scaladoc.lst
@@ -17,5 +17,7 @@ SymbolTablePrinter.java
Tag.java
Location.java
TreeSymbols.java
+Page.java
+SymbolTablePrinterFactory.java
##############################################################################
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);
}
}
diff --git a/sources/scala/tools/scaladoc/Location.java b/sources/scala/tools/scaladoc/Location.java
index 327dd70422..35f7e12cd4 100644
--- a/sources/scala/tools/scaladoc/Location.java
+++ b/sources/scala/tools/scaladoc/Location.java
@@ -26,40 +26,11 @@ public class Location {
static public final String HTML_SUFFIX = ".html";
static public final String CLASS_SUFFIX = "-class";
- /////////////////// AS SEEN FROM //////////////////////
-
- /**
- * Returns a representation of the URL u1 relative to u2.
- * Examples:
- * "A/B/C" as seen from "A" is "A/B/C"
- * "A" as seen from "A/B/C" is "../../A"
- * "A/B#R" as seen from "A" is "A/B#R"
- */
- static public URI asSeenFrom(URI u, URI v) {
- File f_u = new File(u.getPath());
- File f_v = new File(v.getPath());
- try {
- return
- new URI(asSeenFrom(f_u, f_v).getPath()
- + (u.getFragment() != null ? "#" + u.getFragment() : ""))
- .normalize();
- } catch(Exception e) { return null; }
- }
- // where
- static private File asSeenFrom(File f1, File f2) {
- return new File(pathToRoot(f2), f1.getPath());
- }
- // where
- static private File pathToRoot(File f) {
- File parent = f.getParentFile();
- if (parent == null)
- return new File(".");
- else
- return new File(pathToRoot(parent), "..");
- }
-
/////////////////// UNIQUE URL //////////////////////
+ static public String get(Symbol sym) {
+ return getURI(sym).toString();
+ }
/** Returns the URI of a given symbol. */
static private final Map/*<Symbol, URI>*/ uris = new HashMap();
static public URI getURI(Symbol sym) {
@@ -106,4 +77,9 @@ public class Location {
return i;
}
+ static protected URI makeURI(String uri) {
+ try {
+ return new URI(uri);
+ } catch(Exception e) { throw Debug.abort(e); }
+ }
}
diff --git a/sources/scala/tools/scaladoc/Page.java b/sources/scala/tools/scaladoc/Page.java
new file mode 100644
index 0000000000..da388374e5
--- /dev/null
+++ b/sources/scala/tools/scaladoc/Page.java
@@ -0,0 +1,126 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scala.tools.scaladoc;
+
+import java.io.File;
+import java.net.URI;
+import java.io.Writer;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import ch.epfl.lamp.util.XMLAttribute;
+import ch.epfl.lamp.util.HTMLPrinter;
+import ch.epfl.lamp.util.HTMLRepresentation;
+import scalac.util.Debug;
+
+/**
+ * This class represents a web page. The user of this class has to
+ * call the method <code>open</code>, then fill the page and finally
+ * call the method <code>close</code>.
+ */
+class Page extends HTMLPrinter {
+
+ /** Root directory.
+ */
+ protected File rootDirectory;
+
+ /** Page URL relative to the root directory.
+ */
+ protected URI uri;
+
+ /** Frame where to print the contents of links that appear on the
+ * page.
+ */
+ public String destinationFrame;
+
+ /** Build a page.
+ */
+ public Page(File rootDirectory, URI uri, String destinationFrame,
+ String title, HTMLRepresentation representation,
+ String stylesheet/*, String script*/) {
+ super(getWriter(rootDirectory, uri), title, representation,
+ asSeenFrom(mkURI(stylesheet), uri).toString()/*, script*/);
+ this.rootDirectory = rootDirectory;
+ this.uri = uri;
+ this.destinationFrame = destinationFrame;
+ }
+
+ /** Get a writer to the page.
+ */
+ protected static Writer getWriter(File rootDirectory, URI uri) {
+ try {
+ File f = new File(rootDirectory, uri.toString());
+ f.getParentFile().mkdirs();
+ return new BufferedWriter(new FileWriter(f));
+ } catch(IOException e) {
+ throw Debug.abort(e);
+ }
+ }
+
+ /** Open the page.
+ */
+ public void open() {}
+
+ /** Close the page.
+ */
+ public void close() {
+ try {
+ getCodePrinter().getWriter().close();
+ } catch (IOException e) {
+ throw Debug.abort(e);
+ }
+ }
+
+ /** Compute a relative link.
+ */
+ public String rel(String url) {
+ return asSeenFrom(mkURI(url), uri).toString();
+ }
+
+ /////////////////// AS SEEN FROM //////////////////////
+
+ /**
+ * Returns a representation of the URL u1 relative to u2.
+ * Examples:
+ * "A/B/C" as seen from "A" is "A/B/C"
+ * "A" as seen from "A/B/C" is "../../A"
+ * "A/B#R" as seen from "A" is "A/B#R"
+ */
+ static public URI asSeenFrom(URI u, URI v) {
+ File f_u = new File(u.getPath());
+ File f_v = new File(v.getPath());
+ try {
+ return
+ new URI(asSeenFrom(f_u, f_v).getPath()
+ + (u.getFragment() != null ? "#" + u.getFragment() : ""))
+ .normalize();
+ } catch(Exception e) { return null; }
+ }
+ // where
+ static private File asSeenFrom(File f1, File f2) {
+ return new File(pathToRoot(f2), f1.getPath());
+ }
+ // where
+ static private File pathToRoot(File f) {
+ File parent = f.getParentFile();
+ if (parent == null)
+ return new File(".");
+ else
+ return new File(pathToRoot(parent), "..");
+ }
+
+ static protected URI mkURI(String uri) {
+ try {
+ return new URI(uri);
+ } catch(Exception e) { throw Debug.abort(e); }
+ }
+
+}
diff --git a/sources/scala/tools/scaladoc/StandardDocModule.java b/sources/scala/tools/scaladoc/StandardDocModule.java
index ebc3579f44..fa99ff8847 100644
--- a/sources/scala/tools/scaladoc/StandardDocModule.java
+++ b/sources/scala/tools/scaladoc/StandardDocModule.java
@@ -40,7 +40,6 @@ public class StandardDocModule {
* ..
*/
public void apply() {
- //Query.startLoop(global);
Tree tree = OneTree.apply(global);
HTMLGenerator.apply(tree, global);
}
diff --git a/sources/scala/tools/scaladoc/SymbolTablePrinter.java b/sources/scala/tools/scaladoc/SymbolTablePrinter.java
index 404365918b..293ee42689 100644
--- a/sources/scala/tools/scaladoc/SymbolTablePrinter.java
+++ b/sources/scala/tools/scaladoc/SymbolTablePrinter.java
@@ -32,7 +32,7 @@ public abstract class SymbolTablePrinter extends scalac.symtab.SymbolTablePrinte
// Private Fields
/** The global environment */
- private final Global global;
+ protected final Global global;
//########################################################################
// Public Constructors
diff --git a/sources/scala/tools/scaladoc/SymbolTablePrinterFactory.java b/sources/scala/tools/scaladoc/SymbolTablePrinterFactory.java
new file mode 100644
index 0000000000..0f29789547
--- /dev/null
+++ b/sources/scala/tools/scaladoc/SymbolTablePrinterFactory.java
@@ -0,0 +1,137 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scala.tools.scaladoc;
+
+import scalac.Global;
+import scalac.ast.Tree;
+import scalac.ast.Tree.AbsTypeDef;
+import scalac.ast.Tree.Template;
+import scalac.ast.Tree.ValDef;
+import scalac.symtab.Kinds;
+import scalac.symtab.Modifiers;
+import scalac.symtab.NoSymbol;
+import scalac.symtab.Scope;
+import scalac.symtab.Scope.SymbolIterator;
+import scalac.symtab.Symbol;
+import scalac.symtab.Type;
+import scalac.symtab.Type.*;
+import scalac.util.Debug;
+import scalac.util.Name;
+import scalac.util.Names;
+import scalac.util.Strings;
+
+class SymbolTablePrinterFactory {
+
+ public static SymbolTablePrinter makeHTML(final Page page, final TreeSymbols treeSymbols) {
+
+ return new SymbolTablePrinter(page.getCodePrinter()) {
+
+ public 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(page.rel(Location.get(sym)),
+ page.destinationFrame, name);
+ else {
+ page.printOTag("em");
+ page.print(name);
+ page.printCTag("em");
+ }
+ else
+ page.print(name);
+ }
+
+ public Type getTypeToPrintForPrefix(Type prefix/*, sym*/) {
+ while (true) {
+ Type result = getTypeToPrintForPrefix0(prefix);
+ if (result == prefix || result == null) {
+ return
+ cleanPrefix(result, treeSymbols, global);
+ }
+ prefix = result;
+ }
+ }
+
+ protected String INNER_LT = "&lt;:";
+
+ public String getSymbolInnerString(Symbol symbol) {
+ if (symbol.kind == Kinds.TYPE)
+ return INNER_LT; // HTML encoded "<:" symbol
+ else
+ return super.getSymbolInnerString(symbol);
+ }
+
+ 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;
+ }
+ }
+ };
+ }
+
+ /**
+ * 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
+ */
+ static protected Type cleanPrefix(Type prefix, TreeSymbols treeSymbols, Global global) {
+ 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() ==
+ global.definitions.getClass(Names.java_lang))
+ 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, treeSymbols, global);
+ if (pre1 == null && args.length == 0 && treeSymbols.contains(sym))
+ return null;
+ else {
+ pre1 = pre1 == null ? global.definitions.ROOT.thisType() : pre1;
+ return Type.typeRef(pre1, sym, args);
+ }
+ case SingleType(Type pre, Symbol sym):
+ Type pre1 = cleanPrefix(pre, treeSymbols, global);
+ if (pre1 == null) {
+ if (sym.isClass() || sym.isModule())
+ if (treeSymbols.contains(sym)) {
+ return null;
+ }
+ else
+ return Type.singleType(global.definitions.ROOT.thisType(), sym);
+ else
+ return Type.singleType(global.definitions.ROOT.thisType(), sym);
+ }
+ else
+ return Type.singleType(pre1, sym);
+ default:
+ return prefix;
+ }
+ }
+
+
+}