Skip to content

Commit

Permalink
reverted back to path instead of pathos and use explicit package root…
Browse files Browse the repository at this point in the history
…, just like buildbot

R=rnystrom@google.com

Review URL: https://codereview.chromium.org//19309004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25062 260f80e4-7a28-3924-810f-c04153c831b5
  • Loading branch information
janicejl committed Jul 16, 2013
1 parent cd82c36 commit 0c11634
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 63 deletions.
7 changes: 5 additions & 2 deletions pkg/docgen/lib/dart2yaml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ void _addLevel(StringBuffer yaml, Map documentData, int level) {
* Returns an escaped String form of the inputted element.
*/
String _processElement(var element) {
return "\"${element.toString().replaceAll('\\', '\\\\')
.replaceAll("\"", "\\\"")}\"\n";
var contents = element.toString()
.replaceAll('\\', r'\\')
.replaceAll('"', r'\"')
.replaceAll('\n', r'\n');
return '"$contents"\n';
}

/**
Expand Down
127 changes: 68 additions & 59 deletions pkg/docgen/lib/docgen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ String _getComment(DeclarationMirror mirror) {
}
}
});
commentText = commentText == null ? '' :
markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver)
.replaceAll('\n', ' ');

commentText = commentText == null ? '' :
markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver);
return commentText;
}

Expand Down Expand Up @@ -300,9 +300,9 @@ Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap,
mirrorMap.forEach((String mirrorName, VariableMirror mirror) {
if (includePrivate || !mirror.isPrivate) {
_currentMember = mirror;
data[mirrorName] = new Variable(mirrorName, mirror.qualifiedName,
mirror.isFinal, mirror.isStatic, mirror.type.qualifiedName,
_getComment(mirror), _getAnnotations(mirror));
data[mirrorName] = new Variable(mirrorName, mirror.isFinal,
mirror.isStatic, mirror.type.qualifiedName, _getComment(mirror),
_getAnnotations(mirror));
}
});
return data;
Expand All @@ -311,21 +311,42 @@ Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap,
/**
* Returns a map of [Method] objects constructed from inputted mirrors.
*/
Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap,
bool includePrivate) {
var data = {};
Map<String, Map<String, Method>> _getMethods
(Map<String, MethodMirror> mirrorMap, bool includePrivate) {

var setters = {};
var getters = {};
var constructors = {};
var operators = {};
var methods = {};

mirrorMap.forEach((String mirrorName, MethodMirror mirror) {
if (includePrivate || !mirror.isPrivate) {
var method = new Method(mirrorName, mirror.isStatic,
mirror.returnType.qualifiedName, _getComment(mirror),
_getParameters(mirror.parameters), _getAnnotations(mirror));
_currentMember = mirror;
data[mirrorName] = new Method(mirrorName, mirror.qualifiedName,
mirror.isSetter, mirror.isGetter, mirror.isConstructor,
mirror.isOperator, mirror.isStatic, mirror.returnType.qualifiedName,
_getComment(mirror), _getParameters(mirror.parameters),
_getAnnotations(mirror));
if (mirror.isSetter) {
setters[mirrorName] = method;
} else if (mirror.isGetter) {
getters[mirrorName] = method;
} else if (mirror.isConstructor) {
constructors[mirrorName] = method;
} else if (mirror.isOperator) {
operators[mirrorName] = method;
} else if (mirror.isRegularMethod) {
methods[mirrorName] = method;
} else {
throw new StateError('${mirror.qualifiedName} - no method type match');
}
}
});
return data;
}
return {'setters' : setters,
'getters' : getters,
'constructors' : constructors,
'operators' : operators,
'methods' : methods};
}

/**
* Returns a map of [Class] objects constructed from inputted mirrors.
Expand All @@ -340,9 +361,8 @@ Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap,
mirror.superclass.qualifiedName : '';
var interfaces =
mirror.superinterfaces.map((interface) => interface.qualifiedName);
data[mirrorName] = new Class(mirrorName, mirror.qualifiedName,
superclass, mirror.isAbstract, mirror.isTypedef,
_getComment(mirror), interfaces.toList(),
data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract,
mirror.isTypedef, _getComment(mirror), interfaces.toList(),
_getVariables(mirror.variables, includePrivate),
_getMethods(mirror.methods, includePrivate),
_getAnnotations(mirror));
Expand All @@ -358,10 +378,10 @@ Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) {
var data = {};
mirrorList.forEach((ParameterMirror mirror) {
_currentMember = mirror;
data[mirror.simpleName] = new Parameter(mirror.simpleName,
mirror.qualifiedName, mirror.isOptional, mirror.isNamed,
mirror.hasDefaultValue, mirror.type.qualifiedName,
mirror.defaultValue, _getAnnotations(mirror));
data[mirror.simpleName] = new Parameter(mirror.simpleName,
mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue,
mirror.type.qualifiedName, mirror.defaultValue,
_getAnnotations(mirror));
});
return data;
}
Expand All @@ -388,7 +408,11 @@ void _writeToFile(String text, String filename) {
Map recurseMap(Map inputMap) {
var outputMap = {};
inputMap.forEach((key, value) {
outputMap[key] = value.toMap();
if (value is Map) {
outputMap[key] = recurseMap(value);
} else {
outputMap[key] = value.toMap();
}
});
return outputMap;
}
Expand All @@ -405,8 +429,8 @@ class Library {
Map<String, Variable> variables;

/// Top-level functions in the library.
Map<String, Method> functions;

Map<String, Map<String, Method>> functions;
/// Classes defined within the library
Map<String, Class> classes;

Expand Down Expand Up @@ -443,26 +467,24 @@ class Class {
Map<String, Variable> variables;

/// Methods in the class.
Map<String, Method> methods;

Map<String, Map<String, Method>> methods;
String name;
String qualifiedName;
String superclass;
bool isAbstract;
bool isTypedef;

/// List of the meta annotations on the class.
List<String> annotations;

Class(this.name, this.qualifiedName, this.superclass, this.isAbstract,
this.isTypedef, this.comment, this.interfaces, this.variables,
this.methods, this.annotations);
Class(this.name, this.superclass, this.isAbstract, this.isTypedef,
this.comment, this.interfaces, this.variables, this.methods,
this.annotations);

/// Generates a map describing the [Class] object.
Map toMap() {
var classMap = {};
classMap['name'] = name;
classMap['qualifiedname'] = qualifiedName;
classMap['comment'] = comment;
classMap['superclass'] = superclass;
classMap['abstract'] = isAbstract.toString();
Expand All @@ -484,22 +506,20 @@ class Variable {
String comment;

String name;
String qualifiedName;
bool isFinal;
bool isStatic;
String type;

/// List of the meta annotations on the variable.
List<String> annotations;

Variable(this.name, this.qualifiedName, this.isFinal, this.isStatic,
this.type, this.comment, this.annotations);

Variable(this.name, this.isFinal, this.isStatic, this.type, this.comment,
this.annotations);
/// Generates a map describing the [Variable] object.
Map toMap() {
var variableMap = {};
variableMap['name'] = name;
variableMap['qualifiedname'] = qualifiedName;
variableMap['comment'] = comment;
variableMap['final'] = isFinal.toString();
variableMap['static'] = isStatic.toString();
Expand All @@ -521,29 +541,20 @@ class Method {
Map<String, Parameter> parameters;

String name;
String qualifiedName;
bool isSetter;
bool isGetter;
bool isConstructor;
bool isOperator;
bool isStatic;
String returnType;

/// List of the meta annotations on the method.
List<String> annotations;

Method(this.name, this.qualifiedName, this.isSetter, this.isGetter,
this.isConstructor, this.isOperator, this.isStatic, this.returnType,
this.comment, this.parameters, this.annotations);


Method(this.name, this.isStatic, this.returnType, this.comment,
this.parameters, this.annotations);

/// Generates a map describing the [Method] object.
Map toMap() {
var methodMap = {};
methodMap['name'] = name;
methodMap['qualifiedname'] = qualifiedName;
methodMap['comment'] = comment;
methodMap['type'] = isSetter ? 'setter' : isGetter ? 'getter' :
isOperator ? 'operator' : isConstructor ? 'constructor' : 'method';
methodMap['static'] = isStatic.toString();
methodMap['return'] = returnType;
methodMap['parameters'] = recurseMap(parameters);
Expand All @@ -558,7 +569,6 @@ class Method {
class Parameter {

String name;
String qualifiedName;
bool isOptional;
bool isNamed;
bool hasDefaultValue;
Expand All @@ -567,15 +577,14 @@ class Parameter {

/// List of the meta annotations on the parameter.
List<String> annotations;

Parameter(this.name, this.qualifiedName, this.isOptional, this.isNamed,
this.hasDefaultValue, this.type, this.defaultValue, this.annotations);

Parameter(this.name, this.isOptional, this.isNamed, this.hasDefaultValue,
this.type, this.defaultValue, this.annotations);
/// Generates a map describing the [Parameter] object.
Map toMap() {
var parameterMap = {};
parameterMap['name'] = name;
parameterMap['qualifiedname'] = qualifiedName;
parameterMap['optional'] = isOptional.toString();
parameterMap['named'] = isNamed.toString();
parameterMap['default'] = hasDefaultValue.toString();
Expand Down
12 changes: 10 additions & 2 deletions pkg/docgen/test/single_library_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ main() {
var classes = library.classes.values;
expect(classes.every((e) => e is Class), isTrue);

var classMethodTypes = [];
classes.forEach((e) => classMethodTypes.addAll(e.methods.values));
expect(classMethodTypes.every((e) => e is Map), isTrue);

var classMethods = [];
classes.forEach((e) => classMethods.addAll(e.methods.values));
classMethodTypes.forEach((e) => classMethods.addAll(e.values));
expect(classMethods.every((e) => e is Method), isTrue);

var methodParameters = [];
Expand All @@ -67,7 +71,11 @@ main() {
});
expect(methodParameters.every((e) => e is Parameter), isTrue);

var functions = library.functions.values;
var functionTypes = library.functions.values;
expect(functionTypes.every((e) => e is Map), isTrue);

var functions = [];
functionTypes.forEach((e) => functions.addAll(e.values));
expect(functions.every((e) => e is Method), isTrue);

var functionParameters = [];
Expand Down

0 comments on commit 0c11634

Please sign in to comment.