#7 Fix HTML anchors for class member elements.

closed-fixed
Quinn Taylor
6
2008-01-13
2008-01-08
Quinn Taylor
No

XhtmlPageWriter.memberAnchor(MemberDoc) needs to be updated to create method signatures that are valid HTML id and name attribute values.

The specification is that ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

The method must be modified to handle arrays (since [ and ] are not valid) and parameterized types (since < and > are not valid). Letters, numbers, and underscores may be used in Java symbols, and periods are used in package names, so they can't be used. Hyphens should be used to separate arguments. This leaves the colon (":") for delimiting arrays and type parameters, but how to use them without signature name collisions is TDB.

Further, Java generics may use "?", so a suitable equivalent for that must be found.

Discussion

  • Vincent
    Vincent
    2008-01-12

    Logged In: YES
    user_id=1966132
    Originator: NO

    Here is a quick idea:
    - replace '[' and ']' by ':' (int[] becomes int::)
    - replace '<' and '>' by '::' (List<Integer> becodes List::Integer::)
    - replace '?' by '..'

     
  • Vincent
    Vincent
    2008-01-12

    Logged In: YES
    user_id=1966132
    Originator: NO

    Here is the corresponding (quick and dirty) patch:
    Index: trunk/src/net/sourceforge/xhtmldoclet/AbstractPageWriter.java
    ===================================================================
    --- trunk/src/net/sourceforge/xhtmldoclet/AbstractPageWriter.java (revision 28)
    +++ trunk/src/net/sourceforge/xhtmldoclet/AbstractPageWriter.java (working copy)
    @@ -1583,9 +1583,14 @@
    if (member instanceof ExecutableMemberDoc) {
    Vector<String> params = new Vector<String>();
    for (Parameter p : ((ExecutableMemberDoc) member).parameters()) {
    - params.add(p.type().toString());
    - // TODO Handle type parameters and arrays in method signatures
    - // Corresponds to bug #1867096.
    + String paramAsString = p.type().toString();
    + // Handle the array delimiters
    + paramAsString = paramAsString.replace('[', ':').replace(']', ':');
    + // Handle the parameter types delimiters
    + paramAsString = paramAsString.replaceAll("<|>", "::");
    + paramAsString = paramAsString.replaceAll("\\?", "..");
    + //paramAsString.replaceAll(">", "::");
    + params.add(paramAsString);
    }
    // return target.name() + "-" + getJoinedStrings(params, "-");
    return member.name() + "(" + getJoinedStrings(params, "-") + ")";

     
  • Quinn Taylor
    Quinn Taylor
    2008-01-13

    Logged In: YES
    user_id=1014310
    Originator: YES

    Thanks for the suggestions and code, they provided a good starting point. I ended up choosing the following substitutions:

    "[]" with ":"
    "<" with ".:"
    ">" with ":."
    "?" with "_"
    "? extends X" with "_:X"
    ", " with "-"

    This should help minimize collisions of symbols and make links at least understandable. The HTML anchors and linking now works. The next problem to tackle in this vein is in displaying method signatures that have parameters that include type parameters, generics, and/or varargs. To this end, I added a test(...) method to Doclet to be able to see progress.

    Code is included in revision 29.

     
  • Quinn Taylor
    Quinn Taylor
    2008-01-13

    • status: open --> closed-fixed