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

Unified Diff: pkg/docgen/lib/docgen.dart

Issue 16948010: added Command Line Arguments, support for directories, hiding private data, not parsing the SDK, rem (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 months 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 side-by-side diff with in-line comments
Download patch
Index: pkg/docgen/lib/docgen.dart
diff --git a/pkg/docgen/bin/docgen.dart b/pkg/docgen/lib/docgen.dart
similarity index 67%
rename from pkg/docgen/bin/docgen.dart
rename to pkg/docgen/lib/docgen.dart
index 308df289271e71bab2ec5e94b542b2fccffffff0..c05a630675ac610e55f3dd1a79110bba47fd5fe7 100644
--- a/pkg/docgen/bin/docgen.dart
+++ b/pkg/docgen/lib/docgen.dart
@@ -18,36 +18,45 @@ library docgen;
import 'dart:io';
import 'dart:json';
import 'dart:async';
-import '../lib/dart2yaml.dart';
-import '../lib/src/dart2js_mirrors.dart';
import 'package:markdown/markdown.dart' as markdown;
-import '../../args/lib/args.dart';
-import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart';
-import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart';
+import 'package:args/args.dart';
+import 'dart2yaml.dart';
+import 'package:compiler_unsupported/implementation/mirrors/dart2js_mirror.dart';
+import 'package:compiler_unsupported/implementation/mirrors/mirrors.dart';
+import 'package:compiler_unsupported/implementation/mirrors/mirrors_util.dart';
+
+/// Unique ID, will get incremented everytime an ID is requested.
+int _uid = 0;
+
+int getID() => _uid++;
/**
- * Entry function to create YAML documentation from Dart files.
+ * Returns a ArgParser with all the flags and options created.
*/
-void main() {
- // TODO(tmandel): Use args library once flags are clear.
- Options opts = new Options();
- Docgen docgen = new Docgen();
-
- if (opts.arguments.length > 0) {
- List<Path> libraries = [new Path(opts.arguments[0])];
- Path sdkDirectory = new Path("../../../sdk/");
- var workingMirrors = analyze(libraries, sdkDirectory,
- options: ['--preserve-comments', '--categories=Client,Server']);
- workingMirrors.then( (MirrorSystem mirrorSystem) {
- var mirrors = mirrorSystem.libraries.values;
- if (mirrors.isEmpty) {
- print("no LibraryMirrors");
- } else {
- docgen.libraries = mirrors;
- docgen.documentLibraries();
- }
+ArgParser createArgParser(Docgen docgen) {
+ var parser = new ArgParser();
+ parser.addFlag("help", abbr: "h", help: "Prints help and usage information",
Andrei Mouravski 2013/06/18 02:42:36 Move help text to a new line.
janicejl 2013/06/18 18:42:46 Done.
+ negatable: false, callback: (help) {
Andrei Mouravski 2013/06/18 02:42:36 Move callback to a new line.
janicejl 2013/06/18 18:42:46 Done.
+ if (help) print(parser.getUsage());
+ });
+ parser.addFlag("yaml", abbr: "y", help: "Outputs to YAML",
+ defaultsTo: true, negatable: true, callback: (yaml) {
+ docgen.outputToYaml = yaml;
+ });
+ parser.addFlag("json", abbr: "j", help: "Outputs to JSON",
+ defaultsTo: false, negatable: true, callback: (json) {
+ docgen.outputToJson = json;
});
- }
+ parser.addFlag("hide-private", help: "Hides private declarations" ,
+ defaultsTo: false, negatable: false, callback: (hidePrivate) {
+ docgen.hidePrivate = hidePrivate;
+ });
+ parser.addFlag("sdk", help: "Flag to parse SDK Library files",
+ defaultsTo: true, negatable: true, callback: (sdk) {
+ docgen.sdk = sdk;
+ });
+
+ return parser;
}
/**
@@ -59,7 +68,9 @@ class Docgen {
List<LibraryMirror> _libraries;
/// Saves list of libraries for Docgen object.
- void set libraries(value) => _libraries = value;
+ void set libraries(value) {
+ _libraries = value;
+ }
/// Current library being documented to be used for comment links.
LibraryMirror _currentLibrary;
@@ -70,10 +81,6 @@ class Docgen {
/// Current member being documented to be used for comment links.
MemberMirror _currentMember;
- /// Should the output file type be JSON?
- // TODO(tmandel): Add flag to allow for output to JSON.
- bool outputToJson = false;
-
/// Resolves reference links
markdown.Resolver linkResolver;
@@ -85,21 +92,33 @@ class Docgen {
fixReference(name, _currentLibrary, _currentClass, _currentMember);
}
+ /// Should the output file type be YAML?
+ bool outputToYaml;
+ /// Should the output file type be JSON?
+ bool outputToJson;
+ /// Should the output file hide private declarations?
+ bool hidePrivate;
+ /// Should the output include SDK libraries?
+ bool sdk;
+
/**
* Creates documentation for filtered libraries.
*/
void documentLibraries() {
- //TODO(tmandel): Filter libraries and determine output type using flags.
_libraries.forEach((library) {
- _currentLibrary = library;
- var result = new Library(library.qualifiedName, _getComment(library),
- _getVariables(library.variables), _getMethods(library.functions),
- _getClasses(library.classes));
- if (outputToJson) {
- _writeToFile(stringify(result.toMap()), "${result.name}.json");
- } else {
- _writeToFile(getYamlString(result.toMap()), "${result.name}.yaml");
- }
+ // Files belong to the SDK have a uri that begins with "dart:".
+ if (sdk || !library.uri.toString().startsWith("dart:")) {
+ _currentLibrary = library;
+ var result = new Library(library.qualifiedName, _getComment(library),
+ _getVariables(library.variables), _getMethods(library.functions),
+ _getClasses(library.classes), getID());
+ if (outputToJson) {
+ _writeToFile(stringify(result.toMap()), "${result.name}.json");
+ }
+ if (outputToYaml) {
+ _writeToFile(getYamlString(result.toMap()), "${result.name}.yaml");
+ }
+ }
});
}
@@ -121,8 +140,9 @@ class Docgen {
}
}
});
- return commentText == null ? "" :
+ commentText = commentText == null ? "" :
markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver);
+ return commentText.replaceAll("\n", "<br/>");
}
/**
@@ -141,9 +161,12 @@ class Docgen {
Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) {
var data = {};
mirrorMap.forEach((String mirrorName, VariableMirror mirror) {
- _currentMember = mirror;
- data[mirrorName] = new Variable(mirrorName, mirror.isFinal,
- mirror.isStatic, mirror.type.toString(), _getComment(mirror));
+ if (!hidePrivate || !mirror.isPrivate) {
+ _currentMember = mirror;
+ data[mirrorName] = new Variable(mirrorName, mirror.isFinal,
+ mirror.isStatic, mirror.type.toString(), _getComment(mirror),
+ getID());
+ }
});
return data;
}
@@ -154,11 +177,13 @@ class Docgen {
Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) {
var data = {};
mirrorMap.forEach((String mirrorName, MethodMirror mirror) {
- _currentMember = mirror;
- data[mirrorName] = new Method(mirrorName, mirror.isSetter,
- mirror.isGetter, mirror.isConstructor, mirror.isOperator,
- mirror.isStatic, mirror.returnType.toString(), _getComment(mirror),
- _getParameters(mirror.parameters));
+ if (!hidePrivate || !mirror.isPrivate) {
+ _currentMember = mirror;
+ data[mirrorName] = new Method(mirrorName, mirror.isSetter,
+ mirror.isGetter, mirror.isConstructor, mirror.isOperator,
+ mirror.isStatic, mirror.returnType.toString(), _getComment(mirror),
+ _getParameters(mirror.parameters), getID());
+ }
});
return data;
}
@@ -169,16 +194,17 @@ class Docgen {
Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) {
var data = {};
mirrorMap.forEach((String mirrorName, ClassMirror mirror) {
- _currentClass = mirror;
- var superclass;
- if (mirror.superclass != null) {
- superclass = mirror.superclass.qualifiedName;
+ if (!hidePrivate || !mirror.isPrivate) {
+ _currentClass = mirror;
+ var superclass = (mirror.superclass != null) ?
+ mirror.superclass.qualifiedName : "";
+ var interfaces =
+ mirror.superinterfaces.map((interface) => interface.qualifiedName);
+ data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract,
+ mirror.isTypedef, _getComment(mirror), interfaces.toList(),
+ _getVariables(mirror.variables), _getMethods(mirror.methods),
+ getID());
}
- var interfaces =
- mirror.superinterfaces.map((interface) => interface.qualifiedName);
- data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract,
- mirror.isTypedef, _getComment(mirror), interfaces,
- _getVariables(mirror.variables), _getMethods(mirror.methods));
});
return data;
}
@@ -192,7 +218,7 @@ class Docgen {
_currentMember = mirror;
data[mirror.simpleName] = new Parameter(mirror.simpleName,
mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue,
- mirror.type.toString(), mirror.defaultValue);
+ mirror.type.toString(), mirror.defaultValue, getID());
});
return data;
}
@@ -214,6 +240,9 @@ Map recurseMap(Map inputMap) {
*/
class Library {
+ /// Unique ID number for resolving links.
+ int id;
+
/// Documentation comment with converted markdown.
String comment;
@@ -229,11 +258,12 @@ class Library {
String name;
Library(this.name, this.comment, this.variables,
- this.functions, this.classes);
+ this.functions, this.classes, this.id);
/// Generates a map describing the [Library] object.
Map toMap() {
var libraryMap = {};
+ libraryMap["id"] = id;
libraryMap["name"] = name;
libraryMap["comment"] = comment;
libraryMap["variables"] = recurseMap(variables);
@@ -249,6 +279,9 @@ class Library {
// TODO(tmandel): Figure out how to do typedefs (what is needed)
class Class {
+ /// Unique ID number for resolving links.
+ int id;
+
/// Documentation comment with converted markdown.
String comment;
@@ -267,11 +300,12 @@ class Class {
bool isTypedef;
Class(this.name, this.superclass, this.isAbstract, this.isTypedef,
- this.comment, this.interfaces, this.variables, this.methods);
+ this.comment, this.interfaces, this.variables, this.methods, this.id);
/// Generates a map describing the [Class] object.
Map toMap() {
var classMap = {};
+ classMap["id"] = id;
classMap["name"] = name;
classMap["comment"] = comment;
classMap["superclass"] = superclass;
@@ -289,6 +323,9 @@ class Class {
*/
class Variable {
+ /// Unique ID number for resolving links.
+ int id;
+
/// Documentation comment with converted markdown.
String comment;
@@ -297,11 +334,13 @@ class Variable {
bool isStatic;
String type;
- Variable(this.name, this.isFinal, this.isStatic, this.type, this.comment);
+ Variable(this.name, this.isFinal, this.isStatic, this.type,
+ this.comment, this.id);
/// Generates a map describing the [Variable] object.
Map toMap() {
var variableMap = {};
+ variableMap["id"] = id;
variableMap["name"] = name;
variableMap["comment"] = comment;
variableMap["final"] = isFinal.toString();
@@ -316,6 +355,9 @@ class Variable {
*/
class Method {
+ /// Unique ID number for resolving links.
+ int id;
+
/// Documentation comment with converted markdown.
String comment;
@@ -332,11 +374,12 @@ class Method {
Method(this.name, this.isSetter, this.isGetter, this.isConstructor,
this.isOperator, this.isStatic, this.returnType, this.comment,
- this.parameters);
+ this.parameters, this.id);
/// Generates a map describing the [Method] object.
Map toMap() {
var methodMap = {};
+ methodMap["id"] = id;
methodMap["name"] = name;
methodMap["comment"] = comment;
methodMap["type"] = isSetter ? "setter" : isGetter ? "getter" :
@@ -353,6 +396,9 @@ class Method {
*/
class Parameter {
+ /// Unique ID number for resolving links.
+ int id;
+
String name;
bool isOptional;
bool isNamed;
@@ -361,11 +407,12 @@ class Parameter {
String defaultValue;
Parameter(this.name, this.isOptional, this.isNamed, this.hasDefaultValue,
- this.type, this.defaultValue);
+ this.type, this.defaultValue, this.id);
/// Generates a map describing the [Parameter] object.
Map toMap() {
var parameterMap = {};
+ parameterMap["id"] = id;
parameterMap["name"] = name;
parameterMap["optional"] = isOptional.toString();
parameterMap["named"] = isNamed.toString();
@@ -385,7 +432,7 @@ void _writeToFile(String text, String filename) {
dir.createSync();
}
File file = new File('docs/$filename');
- if (!file.exists()) {
+ if (!file.existsSync()) {
file.createSync();
}
file.openSync();

Powered by Google App Engine
This is Rietveld 408576698