Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: pkg/docgen/lib/docgen.dart

Issue 103423002: Update references for exported variables and methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// **docgen** is a tool for creating machine readable representations of Dart 5 /// **docgen** is a tool for creating machine readable representations of Dart
6 /// code metadata, including: classes, members, comments and annotations. 6 /// code metadata, including: classes, members, comments and annotations.
7 /// 7 ///
8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files.
9 /// 9 ///
10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR]
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 }); 756 });
757 757
758 var linkResolver = (name) => fixReferenceWithScope(name, itemToDocument); 758 var linkResolver = (name) => fixReferenceWithScope(name, itemToDocument);
759 commentText = commentText == null ? '' : 759 commentText = commentText == null ? '' :
760 markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver, 760 markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver,
761 inlineSyntaxes: markdownSyntaxes); 761 inlineSyntaxes: markdownSyntaxes);
762 return commentText; 762 return commentText;
763 } 763 }
764 764
765 /// Returns a map of [Variable] objects constructed from [mirrorMap]. 765 /// Returns a map of [Variable] objects constructed from [mirrorMap].
766 /// The optional parameter [containingLibrary] is contains data for variables
767 /// defined at the top level of a library (potentially for exporting
768 /// purposes).
766 Map<String, Variable> _createVariables(Map<String, 769 Map<String, Variable> _createVariables(Map<String,
767 VariableMirror> mirrorMap) { 770 VariableMirror> mirrorMap, [Library containingLibrary]) {
768 var data = {}; 771 var data = {};
769 // TODO(janicejl): When map to map feature is created, replace the below 772 // TODO(janicejl): When map to map feature is created, replace the below
770 // with a filter. Issue(#9590). 773 // with a filter. Issue(#9590).
771 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { 774 mirrorMap.forEach((String mirrorName, VariableMirror mirror) {
772 if (_includePrivate || !_isHidden(mirror)) { 775 if (_includePrivate || !_isHidden(mirror)) {
773 entityMap[docName(mirror)] = new Variable(mirrorName, mirror); 776 if (containingLibrary != null && mirror.owner.qualifiedName !=
777 containingLibrary.mirror.qualifiedName) {
778 entityMap[docName(mirror)] = new ExportedVariable(mirrorName, mirror,
779 containingLibrary);
780 } else {
781 entityMap[docName(mirror)] = new Variable(mirrorName, mirror);
782 }
774 data[mirrorName] = entityMap[docName(mirror)]; 783 data[mirrorName] = entityMap[docName(mirror)];
775 } 784 }
776 }); 785 });
777 return data; 786 return data;
778 } 787 }
779 788
780 /// Returns a map of [Method] objects constructed from [mirrorMap]. 789 /// Returns a map of [Method] objects constructed from [mirrorMap].
781 MethodGroup _createMethods(Map<String, MethodMirror> mirrorMap) { 790 /// The optional parameter [containingLibrary] is contains data for variables
791 /// defined at the top level of a library (potentially for exporting
792 /// purposes).
793 MethodGroup _createMethods(Map<String, MethodMirror> mirrorMap,
794 [Library containingLibrary]) {
782 var group = new MethodGroup(); 795 var group = new MethodGroup();
783 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { 796 mirrorMap.forEach((String mirrorName, MethodMirror mirror) {
784 if (_includePrivate || !mirror.isPrivate) { 797 if (_includePrivate || !mirror.isPrivate) {
785 group.addMethod(mirror); 798 group.addMethod(mirror, containingLibrary);
786 } 799 }
787 }); 800 });
788 return group; 801 return group;
789 } 802 }
790 803
791 /// Returns a map of [Parameter] objects constructed from [mirrorList]. 804 /// Returns a map of [Parameter] objects constructed from [mirrorList].
792 Map<String, Parameter> _createParameters(List<ParameterMirror> mirrorList) { 805 Map<String, Parameter> _createParameters(List<ParameterMirror> mirrorList) {
793 var data = {}; 806 var data = {};
794 mirrorList.forEach((ParameterMirror mirror) { 807 mirrorList.forEach((ParameterMirror mirror) {
795 data[mirror.simpleName] = new Parameter(mirror.simpleName, 808 data[mirror.simpleName] = new Parameter(mirror.simpleName,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 String packageName = ''; 879 String packageName = '';
867 bool hasBeenCheckedForPackage = false; 880 bool hasBeenCheckedForPackage = false;
868 String packageIntro; 881 String packageIntro;
869 882
870 Map<String, Exported> _exportedMembers; 883 Map<String, Exported> _exportedMembers;
871 884
872 Library(LibraryMirror libraryMirror) : super(libraryMirror) { 885 Library(LibraryMirror libraryMirror) : super(libraryMirror) {
873 var exported = _calcExportedItems(libraryMirror); 886 var exported = _calcExportedItems(libraryMirror);
874 _createClasses(exported['classes']..addAll(libraryMirror.classes)); 887 _createClasses(exported['classes']..addAll(libraryMirror.classes));
875 this.functions = _createMethods( 888 this.functions = _createMethods(
876 exported['methods']..addAll(libraryMirror.functions)); 889 exported['methods']..addAll(libraryMirror.functions), this);
877 this.variables = _createVariables( 890 this.variables = _createVariables(
878 exported['variables']..addAll(libraryMirror.variables)); 891 exported['variables']..addAll(libraryMirror.variables), this);
879 892
880 var exportedVariables = {}; 893 var exportedVariables = {};
881 variables.forEach((key, value) { 894 variables.forEach((key, value) {
882 if (value is ExportedVariable) { 895 if (value is ExportedVariable) {
883 exportedVariables[key] = value; 896 exportedVariables[key] = value;
884 } 897 }
885 }); 898 });
886 _exportedMembers = new Map.from(this.classes.exported) 899 _exportedMembers = new Map.from(this.classes.exported)
887 ..addAll(this.functions.exported) 900 ..addAll(this.functions.exported)
888 ..addAll(exportedVariables); 901 ..addAll(exportedVariables);
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 return super.comment; 1366 return super.comment;
1354 } 1367 }
1355 } 1368 }
1356 1369
1357 class ExportedVariable extends Variable implements Exported { 1370 class ExportedVariable extends Variable implements Exported {
1358 Library _exportingLibrary; 1371 Library _exportingLibrary;
1359 1372
1360 ExportedVariable(String variableName, VariableMirror originalVariable, 1373 ExportedVariable(String variableName, VariableMirror originalVariable,
1361 Library this._exportingLibrary) : super(variableName, originalVariable); 1374 Library this._exportingLibrary) : super(variableName, originalVariable);
1362 1375
1363 String get fileName => '${_exportingLibrary.packageName}/' + 1376 String get fileName => path.join(_exportingLibrary.packageName,
1364 super.fileName.substring(packagePrefix.length); 1377 _exportingLibrary.mirror.qualifiedName + '.' + super.name);
1365 1378
1366 void updateExports(Map<String, Indexable> libraryExports) { 1379 void updateExports(Map<String, Indexable> libraryExports) {
1367 // TODO(efortuna): if this class points to another exported class or type 1380 // TODO(efortuna): if this class points to another exported class or type
1368 // of some sort, then that reference needs to be updated here. 1381 // of some sort, then that reference needs to be updated here.
1369 /* these need to be updated: 1382 /* these need to be updated:
1370 'comment': comment, 1383 'comment': comment,
1371 'type': new List.filled(1, type.toMap()), 1384 'type': new List.filled(1, type.toMap()),
1372 'annotations': annotations.map((a) => a.toMap()).toList() 1385 'annotations': annotations.map((a) => a.toMap()).toList()
1373 */ 1386 */
1374 } 1387 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 return super.comment; 1456 return super.comment;
1444 } 1457 }
1445 } 1458 }
1446 1459
1447 class ExportedMethod extends Method implements Exported { 1460 class ExportedMethod extends Method implements Exported {
1448 Library _exportingLibrary; 1461 Library _exportingLibrary;
1449 1462
1450 ExportedMethod(MethodMirror originalMethod, Library this._exportingLibrary) : 1463 ExportedMethod(MethodMirror originalMethod, Library this._exportingLibrary) :
1451 super(originalMethod); 1464 super(originalMethod);
1452 1465
1453 String get fileName => '${_exportingLibrary.packageName}/' + 1466 // TODO(efortuna): Refactor this code so the exported items can share this
1454 super.fileName.substring(packagePrefix.length); 1467 // behavior.
1468 String get fileName => path.join(_exportingLibrary.packageName,
1469 _exportingLibrary.mirror.qualifiedName + '.' + super.name);
1455 1470
1456 void updateExports(Map<String, Indexable> libraryExports) { 1471 void updateExports(Map<String, Indexable> libraryExports) {
1457 // TODO(efortuna): if this class points to another exported class or type 1472 // TODO(efortuna): if this class points to another exported class or type
1458 // of some sort, then that reference needs to be updated here. 1473 // of some sort, then that reference needs to be updated here.
1459 /* these need to be updated: 1474 /* these need to be updated:
1460 'qualifiedName': qualifiedName, 1475 'qualifiedName': qualifiedName,
1461 'comment': comment, 1476 'comment': comment,
1462 'commentFrom': commentInheritedFrom, 1477 'commentFrom': commentInheritedFrom,
1463 'return': new List.filled(1, returnType.toMap()), 1478 'return': new List.filled(1, returnType.toMap()),
1464 'parameters': recurseMap(parameters), 1479 'parameters': recurseMap(parameters),
(...skipping 16 matching lines...) Expand all
1481 Map<String, Exported> get exported { 1496 Map<String, Exported> get exported {
1482 var exported = {}; 1497 var exported = {};
1483 for (Map<String, Method> group in [setters, getters, constructors, 1498 for (Map<String, Method> group in [setters, getters, constructors,
1484 operators, regularMethods]) { 1499 operators, regularMethods]) {
1485 exported = _filterMap(exported, group, 1500 exported = _filterMap(exported, group,
1486 (value) => value is ExportedMethod); 1501 (value) => value is ExportedMethod);
1487 } 1502 }
1488 return exported; 1503 return exported;
1489 } 1504 }
1490 1505
1491 void addMethod(MethodMirror mirror) { 1506 /// The optional parameter [containingLibrary] is contains data for variables
1492 var method = new Method(mirror); 1507 /// defined at the top level of a library (potentially for exporting
1508 /// purposes).
1509 void addMethod(MethodMirror mirror, [Library containingLibrary]) {
1510 var method;
1511 if (containingLibrary != null && mirror.owner.qualifiedName !=
1512 containingLibrary.mirror.qualifiedName) {
1513 method = new ExportedMethod(mirror, containingLibrary);
1514 } else {
1515 method = new Method(mirror);
1516 }
1493 entityMap[docName(mirror)] = method; 1517 entityMap[docName(mirror)] = method;
1494 if (mirror.isSetter) { 1518 if (mirror.isSetter) {
1495 setters[mirror.simpleName] = method; 1519 setters[mirror.simpleName] = method;
1496 } else if (mirror.isGetter) { 1520 } else if (mirror.isGetter) {
1497 getters[mirror.simpleName] = method; 1521 getters[mirror.simpleName] = method;
1498 } else if (mirror.isConstructor) { 1522 } else if (mirror.isConstructor) {
1499 constructors[mirror.simpleName] = method; 1523 constructors[mirror.simpleName] = method;
1500 } else if (mirror.isOperator) { 1524 } else if (mirror.isOperator) {
1501 operators[mirror.simpleName] = method; 1525 operators[mirror.simpleName] = method;
1502 } else if (mirror.isRegularMethod) { 1526 } else if (mirror.isRegularMethod) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 /// Remove statics from the map of inherited items before adding them. 1682 /// Remove statics from the map of inherited items before adding them.
1659 Map _filterStatics(Map items) { 1683 Map _filterStatics(Map items) {
1660 var result = {}; 1684 var result = {};
1661 items.forEach((name, item) { 1685 items.forEach((name, item) {
1662 if (!item.isStatic) { 1686 if (!item.isStatic) {
1663 result[name] = item; 1687 result[name] = item;
1664 } 1688 }
1665 }); 1689 });
1666 return result; 1690 return result;
1667 } 1691 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698