From 39d3d2c8946384f71e8e6a463282e15547181ec2 Mon Sep 17 00:00:00 2001 From: cremet Date: Mon, 12 Jan 2004 13:10:34 +0000 Subject: - fixed the bug about vals that appeared as defs. --- sources/scala/tools/scaladoc/HTMLGenerator.java | 33 +++++------- sources/scala/tools/scaladoc/ScalaSearch.java | 63 +++++++++++++++------- .../scala/tools/scaladoc/SymbolTablePrinter.java | 15 +++++- 3 files changed, 71 insertions(+), 40 deletions(-) diff --git a/sources/scala/tools/scaladoc/HTMLGenerator.java b/sources/scala/tools/scaladoc/HTMLGenerator.java index cac689e621..c9010160ab 100644 --- a/sources/scala/tools/scaladoc/HTMLGenerator.java +++ b/sources/scala/tools/scaladoc/HTMLGenerator.java @@ -382,6 +382,12 @@ public class HTMLGenerator { Comment comment = (Comment) comments.get(sym); if (comment == null) { String s = (String) global.mapSymbolComment.get(sym); + // comment inheritance +// if (s == null) { +// Symbol overriden = ScalaSearch.overridenBySymbol(sym); +// if (overriden != Symbol.NONE) +// s = "/** (inherited comment)" + getComment(overriden).rawText + "*/"; +// } comment = new Comment(sym, s); comments.put(sym, comment); } @@ -389,8 +395,7 @@ public class HTMLGenerator { } /** - * Generates a HTML page for a class or object definition as well - * as pages for every inner class or object. + * Generates a HTML page for a class or object definition. */ protected void createPages(Symbol sym) { String title = Location.getName(sym); @@ -412,7 +417,8 @@ public class HTMLGenerator { "Trait", "Class", "Package" }; // "Constructor" String[] inherited = new String[]{ "Fields", "Methods", "Objects", "Traits", "Classes", "Packages" }; - Symbol[][] members = ScalaSearch.splitMembers(ScalaSearch.members(sym, isDocumented)); + Symbol[][] members = + ScalaSearch.splitMembers(ScalaSearch.members(sym, isDocumented)); for (int i = 0; i < members.length; i++) { addMemberSummary(members[i], titles[i] + " Summary"); if (i == 1) addInheritedMembers(sym, inherited[i]); @@ -432,15 +438,6 @@ public class HTMLGenerator { closePrinters(); } - /** - * Returns the string representation of the kind of a symbol. - * - * @param sym - */ - protected String kind(Symbol sym) { - return symtab.getSymbolKeyword(sym); - } - /** * Writes the product name and version to the current page. * @@ -550,10 +547,7 @@ public class HTMLGenerator { // kind and name page.printlnOTag("div", ATTRS_ENTITY).indent(); - if (sym.isPackage()) - page.print("package "); - else - page.print(kind(sym) + " "); + page.print(symtab.getSymbolKeywordForDoc(sym) + " "); page.printlnTag("span", ATTRS_ENTITY, sym.nameString()).undent(); page.printlnCTag("div"); page.printlnHLine(); @@ -733,7 +727,7 @@ public class HTMLGenerator { * @param sym */ protected void addInheritedMembers(Symbol sym, String inheritedMembers) { - Symbol[] syms = ScalaSearch.findMembers(sym); + Symbol[] syms = ScalaSearch.collectMembers(sym); Pair grouped = ScalaSearch.groupSymbols(syms); Symbol[] owners = (Symbol[]) grouped.fst; Map/**/ group = (Map) grouped.snd; @@ -783,7 +777,7 @@ public class HTMLGenerator { symtab.print(mods).space(); // kind - String keyword = symtab.getSymbolKeyword(symbol); + String keyword = symtab.getSymbolKeywordForDoc(symbol); if (keyword != null) symtab.print(keyword).space(); String inner = symtab.getSymbolInnerString(symbol); @@ -1207,7 +1201,8 @@ public class HTMLGenerator { */ protected void addIndexEntry(Symbol symbol) { // kind - String keyword = symbol.isPackage() ? "package" : symtab.getSymbolKeyword(symbol); + String keyword = symtab.getSymbolKeywordForDoc(symbol); + if (keyword != null) page.print(keyword).space(); // name symtab.printDefinedSymbolName(symbol, true); diff --git a/sources/scala/tools/scaladoc/ScalaSearch.java b/sources/scala/tools/scaladoc/ScalaSearch.java index cd279b2181..3e8c864b99 100644 --- a/sources/scala/tools/scaladoc/ScalaSearch.java +++ b/sources/scala/tools/scaladoc/ScalaSearch.java @@ -73,7 +73,8 @@ public class ScalaSearch { */ public static boolean isRelevant(Symbol sym) { return !isGenerated(sym) && !isLazy(sym) && !isPrivate(sym) && - !(sym.isPackage() && sym.isClass()); + !(sym.isPackage() && sym.isClass()) && !sym.isConstructor() && + !sym.isCaseFactory(); } //////////////////////// SCOPE ITERATOR ////////////////////////////// @@ -146,7 +147,8 @@ public class ScalaSearch { public static Symbol[] members(Symbol sym) { if (isContainer(sym) && !isLazy(sym)) { List memberList = new LinkedList(); - SymbolIterator i = new UnloadLazyIterator(sym.members().iterator(false)); + SymbolIterator i = + new UnloadLazyIterator(sym.members().iterator(false)); while (i.hasNext()) { Symbol member = i.next(); if (isRelevant(member)) @@ -161,7 +163,8 @@ public class ScalaSearch { /** Apply a given function to all symbols below the given symbol * in the symbol table. */ - public static void foreach(Symbol sym, SymFun fun, SymbolBooleanFunction isDocumented) { + public static void foreach(Symbol sym, SymFun fun, + SymbolBooleanFunction isDocumented) { if (isDocumented.apply(sym) && isRelevant(sym)) { fun.apply(sym); Symbol[] members = members(sym, isDocumented); @@ -172,10 +175,12 @@ public class ScalaSearch { /** Return all members of a container symbol. */ - public static Symbol[] members(Symbol sym, SymbolBooleanFunction isDocumented) { + public static Symbol[] members(Symbol sym, + SymbolBooleanFunction isDocumented) { if (isContainer(sym) && !isLazy(sym)) { List memberList = new LinkedList(); - SymbolIterator i = new UnloadLazyIterator(sym.members().iterator(false)); + SymbolIterator i = + new UnloadLazyIterator(sym.members().iterator(false)); while (i.hasNext()) { Symbol member = i.next(); if (isDocumented.apply(member) && isRelevant(sym)) @@ -371,38 +376,38 @@ public class ScalaSearch { * * @param sym */ - public static Symbol[] findMembers(Symbol sym) { + public static Symbol[] collectMembers(Symbol sym) { Type thistype = sym.thisType(); - Name[] names = potentialMemberNames(thistype); // potentialMembers - List/**/ members = new LinkedList(); // actual members + Name[] names = collectNames(thistype); + List/**/ members = new LinkedList(); for (int i = 0; i < names.length; i++) { Symbol member = thistype.lookup(names[i]); if (member != Symbol.NONE) - if (!member.isConstructor()) - if (!isGenerated(member)) - members.add(member); + members.add(member); } List unloadedMembers = new LinkedList(); Iterator it = members.iterator(); while (it.hasNext()) { Symbol[] alts = ((Symbol) it.next()).alternativeSymbols(); for (int i = 0; i < alts.length; i++) - unloadedMembers.add(alts[i]); + if (isRelevant(alts[i])) + unloadedMembers.add(alts[i]); } return (Symbol[]) unloadedMembers.toArray(new Symbol[unloadedMembers.size()]); } // where - protected static Name[] potentialMemberNames(Type tpe) { + protected static Name[] collectNames(Type tpe) { List names = new LinkedList(); - potentialMemberNames(tpe, names); + collectNames(tpe, names); return (Name[]) names.toArray(new Name[names.size()]); } // where - protected static void potentialMemberNames(Type tpe, List/**/ names) { + protected static void collectNames(Type tpe, List/**/ names) { // local members - Scope.SymbolIterator it = tpe.members().iterator(); + SymbolIterator it = + new UnloadLazyIterator(tpe.members().iterator(false)); while (it.hasNext()) { Name name = ((Symbol) it.next()).name; if (!names.contains(name)) @@ -411,7 +416,7 @@ public class ScalaSearch { // inherited members Type[] parents = tpe.parents(); for (int i = 0; i < parents.length; i++) - potentialMemberNames(parents[i], names); + collectNames(parents[i], names); } /** @@ -430,18 +435,38 @@ public class ScalaSearch { } group.add(syms[i]); } - Symbol[] owners = (Symbol[]) groups.keySet().toArray(new Symbol[groups.keySet().size()]); + Symbol[] owners = + (Symbol[]) groups.keySet().toArray(new Symbol[groups.keySet().size()]); Arrays.sort(owners, symPathOrder); for (int i = 0; i < owners.length; i++) { List groupList = (List) groups.get(owners[i]); - Symbol[] group = (Symbol[]) groupList.toArray(new Symbol[groupList.size()]); + Symbol[] group = + (Symbol[]) groupList.toArray(new Symbol[groupList.size()]); Arrays.sort(group, symAlphaOrder); groups.put(owners[i], group); } return new Pair(owners, groups); } + + //////////////////////////// OVERRIDEN SYMBOL ////////////////////////////// + // Does not work. + public static Symbol overridenBySymbol(Symbol sym) { + if (!sym.isRoot()) { +// System.out.println(sym.owner().moduleClass().thisType()); +// System.out.println(sym.owner().moduleClass().info()); + Type tpe = sym.owner().moduleClass().info(); + Symbol res = tpe.lookup(sym.name); + if (res == Symbol.NONE) return Symbol.NONE; + Symbol[] alts = res.alternativeSymbols(); + for(int i = 0; i < alts.length; i++) + if (sym.overrides(alts[i])) return alts[i]; + } + return Symbol.NONE; + } } +//////////////////////////// DOCUMENTED SYMBOLS ////////////////////////////// + /** Compute documented symbols. */ public class DocSyms { diff --git a/sources/scala/tools/scaladoc/SymbolTablePrinter.java b/sources/scala/tools/scaladoc/SymbolTablePrinter.java index fc2ff51c89..25ea8e8bc7 100644 --- a/sources/scala/tools/scaladoc/SymbolTablePrinter.java +++ b/sources/scala/tools/scaladoc/SymbolTablePrinter.java @@ -171,6 +171,17 @@ public abstract class SymbolTablePrinter extends scalac.symtab.SymbolTablePrinte .printSymbolType(symbol, getSymbolInnerString(symbol)); } + /** The keyword of a symbol from the user side. */ + public String getSymbolKeywordForDoc(Symbol symbol) { + String keyword = getSymbolKeyword(symbol); + // package + if (symbol.isPackage()) keyword = "package"; + // accessor function for a val + if (symbol.isInitializedMethod() && (symbol.flags & Modifiers.STABLE) != 0) + keyword = "val"; + return keyword; + } + /** * Prints the signature of the given symbol. * @@ -178,7 +189,7 @@ public abstract class SymbolTablePrinter extends scalac.symtab.SymbolTablePrinte * @param addLink */ public SymbolTablePrinter printShortSignature(Symbol symbol, boolean addLink) { - String keyword = getSymbolKeyword(symbol); + String keyword = getSymbolKeywordForDoc(symbol); if (keyword != null) print(keyword).space(); printSymbol(symbol, addLink); return printType(symbol.loBound(), ">:"); @@ -193,7 +204,7 @@ public abstract class SymbolTablePrinter extends scalac.symtab.SymbolTablePrinte */ public SymbolTablePrinter printTemplateSignature(Symbol symbol, boolean addLink) { // kind - String keyword = getSymbolKeyword(symbol); + String keyword = getSymbolKeywordForDoc(symbol); if (keyword != null) print(keyword).space(); String inner = getSymbolInnerString(symbol); -- cgit v1.2.3