summaryrefslogtreecommitdiffstats
path: root/o3d/documentation/jsdoc-toolkit-templates/publish.js
blob: 1040137e3170667640cb5f88a1af39236efbb234 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
/*
 * Copyright 2009, Google Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


/**
 * @fileoverview The jsdoctoolkit loads this file and calls publish()
 */


var g_symbolSet;  // so we can look stuff up below.
var g_filePrefix;
var g_skipRE;
var g_validJSDOCTypes = {
  'number': true,
  'Number': true,
  'object': true,
  'Object': true,
  '*': true,
  '...': true,
  'string': true,
  'String': true,
  'void': true,
  'undefined': true};
var g_unknownTypes = { };
var g_numErrors = 0;
var g_o3djsMode = false;
var g_baseURL;

/**
 * Called automatically by JsDoc Toolkit.
 * @param {SymbolSet} symbolSet Set of all symbols in all files.
 */
function publish(symbolSet) {
  publish.conf = {  // trailing slash expected for dirs
    ext: '.ezt',
    outDir: JSDOC.opt.d,
    templatesDir: JSDOC.opt.t,
    symbolsDir: '',
    prefix: JSDOC.opt.D.prefix,
    o3djs: JSDOC.opt.D.o3djs};
  publish.conf.srcDir = publish.conf.outDir + 'src/';
  publish.conf.htmlDir = JSDOC.opt.D.htmlOutDir;
  g_baseURL = JSDOC.opt.D.baseURL;

  if (publish.conf.o3djs) {
    g_o3djsMode = true;
  }

  // In o3djs mode, don't generate docs for these.
  g_skipRE = new RegExp('^(o3d$|o3d\\.|Vectormath)');

  // is source output is suppressed, just display the links to the source file
  if (JSDOC.opt.s && defined(Link) && Link.prototype._makeSrcLink) {
    Link.prototype._makeSrcLink = function(srcFilePath) {
      return '<' + srcFilePath + '>';
    }
  }

  // create the folders and subfolders to hold the output
  IO.mkPath((publish.conf.outDir).split('/'));
  IO.mkPath((publish.conf.htmlDir).split('/'));

  // used to allow Link to check the details of things being linked to
  Link.symbolSet = symbolSet;
  Link.base = '../';

  // used to allow other parts of this module to access database of symbols
  // and the file prefix.
  g_symbolSet = symbolSet;
  g_filePrefix = publish.conf.prefix;

  // create the required templates
  try {
    var templatesDir = publish.conf.templatesDir;
    var classTemplate = new JSDOC.JsPlate(templatesDir + 'class.tmpl');
    var membersTemplate = new JSDOC.JsPlate(templatesDir + 'members.tmpl');
    var classTreeTemplate = new JSDOC.JsPlate(templatesDir + 'classtree.tmpl');
    var fileListTemplate = new JSDOC.JsPlate(templatesDir + 'filelist.tmpl');
    var annotatedTemplate = new JSDOC.JsPlate(templatesDir + 'annotated.tmpl');
    var namespacesTemplate = new JSDOC.JsPlate(templatesDir +
                                               'namespaces.tmpl');
  } catch(e) {
    generateError('Couldn\'t create the required templates: ' + e);
    System.exit(1);
  }

  // some ustility filters
  function hasNoParent($) {return ($.memberOf == '')}
  function isaFile($) {return ($.is('FILE'))}
  function isaClass($) {return ($.is('CONSTRUCTOR') || $.isNamespace)}

  // get an array version of the symbolset, useful for filtering
  var symbols = symbolSet.toArray();

  // create the hilited source code files
  if (false) {
    var files = JSDOC.opt.srcFiles;
    for (var i = 0, l = files.length; i < l; i++) {
      var file = files[i];
      makeSrcFile(file, publish.conf.srcDir);
    }
  }

  // get a list of all the classes in the symbolset
  var classes = symbols.filter(isaClass).sort(makeSortby('alias'));

  // create each of the class pages
  for (var i = 0, l = classes.length; i < l; i++) {
    var symbol = classes[i];
    g_unknownTypes = { };

    symbol.events = symbol.getEvents();   // 1 order matters
    symbol.methods = symbol.getMethods(); // 2

    if (g_o3djsMode && g_skipRE.test(symbol.alias)) {
      print('Skipping docs for  : ' + symbol.alias);
      continue;
    }

    print('Generating docs for: ' + symbol.alias);
    // Comment these lines in to see what data is available to the templates.
    //print('----------------------------------------------------------------');
    //dumpObject(symbol, 5);

    // <a href='symbol.source'>symbol.filename</a>
    symbol.source = symbol.srcFile;    // This is used as a link to the source
    symbol.filename = symbol.srcFile;  // This is display as the link.

    var output = '';
    output = classTemplate.process(symbol);

    IO.saveFile(publish.conf.outDir,
                (publish.conf.prefix + symbol.alias +
                 '_ref' + publish.conf.ext).toLowerCase(),
                output);
    IO.saveFile(publish.conf.htmlDir,
                (publish.conf.prefix + symbol.alias +
                 '_ref.html').toLowerCase(),
                output);

    var output = '';
    output = membersTemplate.process(symbol);
    IO.saveFile(publish.conf.outDir,
                (publish.conf.prefix + symbol.alias +
                 '_members' + publish.conf.ext).toLowerCase(),
                output);
    IO.saveFile(publish.conf.htmlDir,
                (publish.conf.prefix + symbol.alias +
                 '_members.html').toLowerCase(),
                output);
  }

  var classTree = classTreeTemplate.process(classes);
  IO.saveFile(publish.conf.outDir, 'classtree.html', classTree);
  IO.saveFile(publish.conf.htmlDir, 'classtree.html', classTree);

  var fileList = fileListTemplate.process(symbols);
  IO.saveFile(publish.conf.outDir, 'filelist.html', fileList);
  IO.saveFile(publish.conf.htmlDir, 'filelist.html', fileList);

  var annotated = annotatedTemplate.process(classes);
  IO.saveFile(publish.conf.outDir, 'annotated' + publish.conf.ext, annotated);
  IO.saveFile(publish.conf.htmlDir, 'annotated.html', annotated);

  var namespaces = namespacesTemplate.process(classes);
  IO.saveFile(publish.conf.outDir, 'namespaces' + publish.conf.ext, namespaces);
  IO.saveFile(publish.conf.htmlDir, 'namespaces.html', namespaces);

  if (g_numErrors > 0) {
    print('Num Errors: ' + g_numErrors);
    System.exit(1);
  }
}

/**
 *  Gets just the first sentence (up to a full stop).
 *  Should not break on dotted variable names.
 *  @param {string} desc Description to extract summary from.
 *  @return {string} summary.
 */
function summarize(desc) {
  if (typeof desc != 'undefined')
    return desc.match(/([\w\W]+?\.)[^a-z0-9_$]/i) ? RegExp.$1 : desc;
}

/**
 * Makes a symbol sorter by some attribute.
 * @param {string} attribute to sort by.
 * @return {number} sorter result.
 */
function makeSortby(attribute) {
  return function(a, b) {
    if (a[attribute] != undefined && b[attribute] != undefined) {
      a = a[attribute].toLowerCase();
      b = b[attribute].toLowerCase();
      if (a < b) return -1;
      if (a > b) return 1;
      return 0;
    }
  }
}

/**
 * Pull in the contents of an external file at the given path.
 * @param {string} path Path of file relative to template directory.
 * @return {string} contents of file.
 */
function include(path) {
  var path = publish.conf.templatesDir + path;
  return IO.readFile(path);
}

/**
 * Turns a raw source file into a code-hilited page in the docs.
 * @param {string} path Path to source.
 * @param {string} srcDir path to place to store hilited page.
 * @param {string} opt_name to name output file.
 *
 */
function makeSrcFile(path, srcDir, opt_name) {
  if (JSDOC.opt.s) return;

  if (!opt_name) {
    opt_name = path.replace(/\.\.?[\\\/]/g, '').replace(/[\\\/]/g, '_');
    opt_name = opt_name.replace(/\:/g, '_');
  }

  var src = {path: path, name: opt_name, charset: IO.encoding, hilited: ''};

  if (defined(JSDOC.PluginManager)) {
    JSDOC.PluginManager.run('onPublishSrc', src);
  }

  if (src.hilited) {
    IO.saveFile(srcDir, opt_name + publish.conf.ext, src.hilited);
  }
}

/**
 * Builds output for displaying function parameters.
 * @param {Array} params Array of function params.
 * @return {string} string in format '(param1, param2)'.
 */
function makeSignature(params) {
  if (!params) return '()';
  var signature = '(' +
  params.filter(
    function($) {
      return $.name.indexOf('.') == -1; // don't show config params in signature
    }
  ).map(
    function($) {
      return $.name;
    }
  ).join(', ') + ')';
  return signature;
}

/**
 * Find symbol {@link ...} strings in text and turn into html links.
 * @param {string} str String to modify.
 * @return {string} modifed string.
 */
function resolveLinks(str) {
  str = str.replace(/\{@link ([^} ]+) ?\}/gi,
    function(match, symbolName) {
      return new Link().toSymbol(symbolName);
    }
  );

  return str;
}

/**
 * Makes a link for a symbol.
 *
 * @param {string} symbolName Name of symbol
 * @param {string} extra extra
 * @param {string} opt_bookmark Optional bookmark.
 */
function makeSymbolLink(symbolName, extra, opt_bookmark) {
  var prefix = g_filePrefix;
  if (g_o3djsMode && g_skipRE.test(symbolName)) {
    prefix = '../classo3d_1_1_';
  }
  return (prefix + symbolName + extra +
          '.html').toLowerCase() +
         (opt_bookmark ? '#' + opt_bookmark : '');
}

/**
 * Make link from symbol.
 * @param {Object} symbol Symbol from class database.
 * @param {string} opt_extra extra suffix to add before '.html'.
 * @return {string} url to symbol.
 */
function getLinkToSymbol(symbol, opt_extra) {
  opt_extra = opt_extra || '_ref';
  if (symbol.is('CONSTRUCTOR') || symbol.isNamespace) {
    return makeSymbolLink(symbol.alias, opt_extra);
  } else {
    var parentSymbol = getSymbol(symbol.memberOf);
    return makeSymbolLink(parentSymbol.alias, opt_extra, symbol.name);
  }
}

/**
 * Given a class alias, returns a link to its reference page
 * @param {string} classAlias Fully qualified name of class.
 * @return {string} url to class.
 */
function getLinkToClassByAlias(classAlias) {
  var symbol = getSymbol(classAlias);
  if (!symbol) {
    throw Error('no documentation for "' + classAlias + '"');
  }
  return getLinkToSymbol(symbol);
}

/**
 * Given a class alias, returns a link to its member reference page
 * @param {string} classAlias Fully qualified name of class.
 * @return {string} url to class in members file.
 */
function getLinkToClassMembersByAlias(classAlias) {
  var symbol = getSymbol(classAlias);
  return getLinkToSymbol(symbol, '_members');
}

/**
 * Given a class alias like o3djs.namespace.function returns an HTML string
 * with a link to each part (o3djs, namespace, function)
 * @param {string} classAlias Fully qualified alias of class.
 * @param {string} opt_cssClassId css class Id to put in class="" instead links.
 * @return {string} html with links to each class and parent.
 */
function getHierarchicalLinksToClassByAlias(classAlias, opt_cssClassId) {
  var parts = classAlias.split('.');
  var name = '';
  var html = '';
  var delim = '';
  var classId = '';
  if (opt_cssClassId) {
    classId = ' class="' + opt_cssClassId + '"';
  }
  for (var pp = 0; pp < parts.length; ++pp) {
    var part = parts[pp];
    name = name + delim + part;
    link = getLinkToClassByAlias(name);
    html = html + delim + '<a' + classId +
           ' href="' + link + '">' + part + '</a>';
    delim = '.';
  }
  return html;
}

/**
 * Dumps a javascript object.
 *
 * @param {Object} obj Object to dump.
 * @param {number} depth Depth to dump (0 = forever).
 * @param {string} opt_prefix Prefix to put before each line.
 */
function dumpObject(obj, depth, opt_prefix) {
  opt_prefix = opt_prefix || '';
  --depth;
  for (var prop in obj) {
    if (typeof obj[prop] != 'function') {
      dumpWithPrefix(prop + ' : ' + obj[prop], opt_prefix);
      if (depth != 0) {
        dumpObject(obj[prop], depth, opt_prefix + '    ');
      }
    }
  }
}

/**
 * Dumps a string, putting a prefix before each line
 * @param {string} str String to dump.
 * @param {string} prefix Prefix to put before each line.
 */
function dumpWithPrefix(str, prefix) {
  var parts = str.split('\n');
  for (var pp = 0; pp < parts.length; ++pp) {
    print(prefix + parts[pp]);
  }
}

/**
 * gets the type of a property.
 * @param {!object} property Property object.
 * @return {string} type of property.
 */
function getPropertyType(property) {
  if (property.type.length > 0) {
    return property.type;
  } else {
    var tag = property.comment.getTag('type');
    if (tag.length > 0) {
      return tag[0].type;
    } else {
      return 'undefined';
    }
  }
}

/**
 * Converts [ to [[] for ezt files.
 * Also converts '\n\n' to <br/></br>
 * @param {string} str to sanitize.
 * @return {string} Sanitized string.
 */
function sanitizeForEZT(str) {
  return str.replace(/\[/g, '[[]').replace(/\n\n/g, '<br/><br/>');
}

/**
 * Check if string starts with another string.
 * @param {string} str String to check.
 * @param {string} prefix Prefix to check for.
 * @return {boolean} True if str starts with prefix.
 */
function startsWith(str, prefix) {
  return str.substring(0, prefix.length) === prefix;
}

/**
 * Check if string ends with another string.
 * @param {string} str String to check.
 * @param {string} suffix Suffix to check for.
 * @return {boolean} True if str ends with suffix.
 */
function endsWith(str, suffix) {
  return str.substring(str.length - suffix.length) === suffix;
}

/**
 * Converts a camelCase name to underscore as in TypeOfFruit becomes
 * type_of_fruit.
 * @param {string} str CamelCase string.
 * @return {string} underscorified str.
 */
function camelCaseToUnderscore(str) {
  function toUnderscore(match) {
    return '_' + match.toLowerCase();
  }
  return str[0].toLowerCase() +
      str.substring(1).replace(/[A-Z]/g, toUnderscore);
}

/**
 * Prints a warning about an unknown type only once.
 * @param {string} place Use to print error message if type not found.
 * @param {string} type Type specification.
 */
function reportUnknownType(place, type) {
  if (!g_unknownTypes[type]) {
    g_unknownTypes[type] = true;
    generatePlaceError (place, 'reference to unknown type: "' + type + '"');
  }
}

/**
 * Gets index of closing character.
 * @param {string} str string to search.
 * @param {number} startIndex index to start searching at. Must be an opening
 *      character.
 * @return {number} Index of closing character or (-1) if not found.
 */
function getIndexOfClosingCharacter(str, startIndex) {
  var openCloseMap = {
    '(': ')',
    '<': '>',
    '[': ']',
    '{': '}'};
  var closeMap = {
    ')': true,
    '>': true,
    ']': true,
    '}': true,
  };
  var stack = [];
  if (!openCloseMap[str[startIndex]]) {
    throw 'startIndex does not point to opening character.';
  }
  var endIndex = str.length;
  while (startIndex < endIndex) {
    var c = str[startIndex];
    var closing = openCloseMap[c];
    if (closing) {
      stack.unshift(closing);
    } else {
      closing = closeMap[c];
      if (closing) {
        var expect = stack.shift()
        if (c != expect) {
          return -1;
        }
        if (stack.length == 0) {
          return startIndex;
        }
      }
    }
    ++startIndex;
  }
  return -1;
}

/**
 * Make's a name by concatenating strings.
 * @param {...[string]} strings to concatenate.
 * @return {string} Concatenated string.
 */
function makeName() {
  var str = '';
  for (var ii = 0; ii < arguments.length; ++ii) {
    if (str) {
      str += '.';
    }
    str += arguments[ii];
  }
  return str;
}

/**
 * Generates an error msg.
 * @param {string} msg.
 */
function generateError(msg) {
  ++g_numErrors;
  print('ERROR: ' + msg);
}

/**
 * Generates an error msg.
 * @param {string} place Use to print error message.
 * @param {string} msg.
 */
function generatePlaceError(place, msg) {
  generateError(place + ': ' + msg);
}

/**
 * Converts a reference to a single JSDOC type specification to an html link.
 * @param {string} place Use to print error message if type not found.
 * @param {string} str to linkify.
 * @return {string} linkified string.
 */
function linkifySingleType(place, type) {
  var not = '';
  var equals = '';
  // Remove ! if it exists.
  if (type[0] == '!') {
    not = '!'
    type = type.substring(1);
  }
  if (endsWith(type, '=')) {
    equals = '=';
    type = type.substring(0, type.length - 1);
  }

  var link = type;

  // Check for array wrapper.
  if (startsWith(type, 'Array.<')) {
    var closingAngle = getIndexOfClosingCharacter(type, 6);
    if (closingAngle < 0) {
      generatePlaceError(place, 'Unmatched "<" in Array type : ' + type);
    } else {
      link = 'Array.&lt;' +
        linkifySingleType(place, type.substring(7, closingAngle)) + '>';
    }
  } else if (startsWith(type, 'function(')) {
    var closingParen = getIndexOfClosingCharacter(type, 8);
    if (closingParen < 0) {
      generatePlaceError(place, 'Unmatched "(" in function type : ' + type);
    } else {
      var end = type.substring(closingParen + 1);
      if (!startsWith(end, ': ')) {
        generatePlaceError(place,
            'Malformed return specification on function. Must be' +
            ' "function(args): type" including the space after the colon.');
      } else {
        var output = '';
        var argsStr = type.substring(9, closingParen);
        if (argsStr) {
          var args = argsStr.split(/ *, */);
          for (var ii = 0; ii < args.length; ++ii) {
            if (ii > 0) {
              output += ', ';
            }
            output += linkifyTypeSpec(place, args[ii]);
          }
        }
        link = 'function(' + output + '): ' +
               linkifyTypeSpec(place, end.substring(2));
      }
    }
  } else if (type.indexOf(':') >= 0) { // check for records.
    if (type.indexOf('::') >= 0) { // check for CPP scope
      generatePlaceError(place,
                         'CPP "::" scope operator found for type "' + type +
                         '" must be Javascript "." scope operator.');
    } else {
      var elements = type.split(/\s*,\s*/);
      var output = '{';
      for (var ii = 0; ii < elements.length; ++ii) {
        if (ii > 0) {
          output += ', ';
        }
        var element = elements[ii];
        var colon = element.indexOf(': ');
        if (colon < 0) {
          generatePlaceError(place,
                             'Malformed record specification. Format must be ' +
                             '{id1: type1, id2: type2, ...}.');
          output += element;
        } else {
          var name = element.substring(0, colon);
          var subType = element.substring(colon + 2);
          output += name + ':&nbsp;' + linkifyTypeSpec(place, subType)
        }
      }
      link = output + '}';
    }
  } else {
    var symbol = getSymbol(type);
    if (symbol) {
      link = '<a class="el" href="' + getLinkToSymbol(symbol) + '">' +
          type + '</a>';
    } else {
      // See if the symbol is a property or field.
      var period = type.lastIndexOf('.');
      if (period >= 0 && type != '...') {
        var subType = type.substring(0, period);
        symbol = getSymbol(subType);
        if (symbol) {
          var field = type.substring(period + 1);
          link = '<a class="el" href="' + getLinkToSymbol(symbol) + '#' +
              field + '">' +  type + '</a>';
        } else {
          if (subType[0] == '?') {
            subType = subType.substring(1);
          }
          if (!g_validJSDOCTypes[subType]) {
            reportUnknownType(place, type);
          }
        }
      }
    }
  }

  return not + link + equals;
}

/**
 * Fix function specs.
 * The jsdoctoolkit wrongly converts ',' to | as in 'function(a, b)' to
 * 'function(a|b)' and '{id1: type1, id2: type2}' to '{id1: type1|id2: type2}'
 * so we need to put those back here (or fix jsdoctoolkit, the proper solution).
 * @param {string} str JSDOC type specification string .
 * @return {string} str with '|' converted back to ', ' unless the specification
 *     starts with '(' and ends with ')'. That's not a very good check beacuse
 *     you could 'function((string|number)) and this would fail to do the right
 *     thing.
 *
 */
function fixSpecCommas(str) {
  // TODO: This is really a complete hack and we should fix the
  // jsdoctoolkit.
  if (startsWith(str, '(') && endsWith(str, ')')) {
    return str;
  } else {
    return str.replace(/\|/g, ', ');
  }
}

/**
 * Converts a JSDOC type specification into html links. For example
 * '(!o3djs.math.Vector3|!O3D.math.Vector4)' would change to
 * '(!<a href="??">o3djs.math.Vector3</a>
 * |!<a href="??">o3djs.math.Vector4</a>)'.
 * @param {string} place Use to print error message if type not found.
 * @param {string} str to linkify.
 * @return {string} linkified string.
 */
function linkifyTypeSpec(place, str) {
  var output = '';
  if (str) {
    var fixed = fixSpecCommas(str);
    // TODO: needs to split outside of parens and angle brackets.
    if (startsWith(fixed, '(') && endsWith(fixed, ')')) {
      var types = fixed.substring(1, fixed.length - 1).split('|');
      output += '(';
      for (var tt = 0; tt < types.length; ++tt) {
        if (tt > 0) {
          output += '|';
        }
        output += linkifySingleType(place, types[tt]);
      }
      output += ')';
    } else {
      output += linkifySingleType(place, fixed);
    }
  } else {
    generatePlaceError(place, 'missing type specification (' + str + ')');
  }
  return output;
}

/**
 * Same as linkifyTypeSpec but allows str to be undefined or ''.
 * @param {string} place Use to print error message if type not found.
 * @param {string} str to linkify.
 * @return {string} linkified string.
 */
function linkifyTypeSpecForReturn(place, str) {
  if (str) {
    return linkifyTypeSpec(place, str);
  }
  return '';
}

/**
 * Gets a symbol for a type.
 * This is here mostly for debugging so you can insert a print before or after
 * each call to g_symbolSet.getSymbol.
 * @param {string} type fully qualified type.
 * @return {Symbol} The symbol object for the type or null if not found.
 */
function getSymbol(type) {
  return g_symbolSet.getSymbol(type);
}

/**
 * Gets the source path for a symbol starting from 'o3djs/'
 * @param {!Symbol} symbol The symbol to get the source name for.
 * @return {string} The name of the source file.
 */
function getSourcePath(symbol) {
  var path = symbol.srcFile.replace(/\\/g, '/');
  var index = path.indexOf('/o3djs/');
  return path.substring(index + 1);
}

/**
 * Gets a qualified name. Used for members. For namespaces will return the fully
 * qualified name. For objects will return just ObjectName.method
 * @param {!Symbol} method The method or property to get a qualified name for.
 * @return {string} The qualified name for the method or property.
 */
function getQualifiedName(method) {
  var parent = getSymbol(method.memberOf);
  if (parent.isNamespace) {
    return method.memberOf + "." + method.name
  }
  return parent.name + '.' + method.name;
}

/**
 * Get the base URL for links.
 */
function getBaseURL() {
  return g_baseURL;
}