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 18144006: Added annotations and outputs the qualified name of the annotation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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 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 /** 5 /**
6 * **docgen** is a tool for creating machine readable representations of Dart 6 * **docgen** is a tool for creating machine readable representations of Dart
7 * code metadata, including: classes, members, comments and annotations. 7 * code metadata, including: classes, members, comments and annotations.
8 * 8 *
9 * docgen is run on a `.dart` file or a directory containing `.dart` files. 9 * docgen is run on a `.dart` file or a directory containing `.dart` files.
10 * 10 *
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 void _outputLibrary(Library result) { 204 void _outputLibrary(Library result) {
205 if (outputToJson) { 205 if (outputToJson) {
206 _writeToFile(stringify(result.toMap()), '${result.name}.json'); 206 _writeToFile(stringify(result.toMap()), '${result.name}.json');
207 } 207 }
208 if (outputToYaml) { 208 if (outputToYaml) {
209 _writeToFile(getYamlString(result.toMap()), '${result.name}.yaml'); 209 _writeToFile(getYamlString(result.toMap()), '${result.name}.yaml');
210 } 210 }
211 } 211 }
212 212
213 /** 213 /**
214 * Returns a list of meta annotaions assocated with a mirror.
Emily Fortuna 2013/06/28 01:15:06 typo: annotations
215 */
216 List<String> _getAnnotations(DeclarationMirror mirror) {
217 var annotations = mirror.metadata.where((e) =>
218 e is dart2js.Dart2JsConstructedConstantMirror);
219 return annotations.map((e) => e.type.qualifiedName).toList();
220 }
221
222 /**
214 * Returns any documentation comments associated with a mirror with 223 * Returns any documentation comments associated with a mirror with
215 * simple markdown converted to html. 224 * simple markdown converted to html.
216 */ 225 */
217 String _getComment(DeclarationMirror mirror) { 226 String _getComment(DeclarationMirror mirror) {
218 String commentText; 227 String commentText;
219 mirror.metadata.forEach((metadata) { 228 mirror.metadata.forEach((metadata) {
220 if (metadata is CommentInstanceMirror) { 229 if (metadata is CommentInstanceMirror) {
221 CommentInstanceMirror comment = metadata; 230 CommentInstanceMirror comment = metadata;
222 if (comment.isDocComment) { 231 if (comment.isDocComment) {
223 if (commentText == null) { 232 if (commentText == null) {
(...skipping 23 matching lines...) Expand all
247 /** 256 /**
248 * Returns a map of [Variable] objects constructed from inputted mirrors. 257 * Returns a map of [Variable] objects constructed from inputted mirrors.
249 */ 258 */
250 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) { 259 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) {
251 var data = {}; 260 var data = {};
252 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { 261 mirrorMap.forEach((String mirrorName, VariableMirror mirror) {
253 if (includePrivate || !mirror.isPrivate) { 262 if (includePrivate || !mirror.isPrivate) {
254 _currentMember = mirror; 263 _currentMember = mirror;
255 data[mirrorName] = new Variable(mirrorName, mirror.qualifiedName, 264 data[mirrorName] = new Variable(mirrorName, mirror.qualifiedName,
256 mirror.isFinal, mirror.isStatic, mirror.type.qualifiedName, 265 mirror.isFinal, mirror.isStatic, mirror.type.qualifiedName,
257 _getComment(mirror)); 266 _getComment(mirror), _getAnnotations(mirror));
258 } 267 }
259 }); 268 });
260 return data; 269 return data;
261 } 270 }
262 271
263 /** 272 /**
264 * Returns a map of [Method] objects constructed from inputted mirrors. 273 * Returns a map of [Method] objects constructed from inputted mirrors.
265 */ 274 */
266 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) { 275 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) {
267 var data = {}; 276 var data = {};
268 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { 277 mirrorMap.forEach((String mirrorName, MethodMirror mirror) {
269 if (includePrivate || !mirror.isPrivate) { 278 if (includePrivate || !mirror.isPrivate) {
270 _currentMember = mirror; 279 _currentMember = mirror;
271 data[mirrorName] = new Method(mirrorName, mirror.qualifiedName, 280 data[mirrorName] = new Method(mirrorName, mirror.qualifiedName,
272 mirror.isSetter, mirror.isGetter, mirror.isConstructor, 281 mirror.isSetter, mirror.isGetter, mirror.isConstructor,
273 mirror.isOperator, mirror.isStatic, mirror.returnType.qualifiedName, 282 mirror.isOperator, mirror.isStatic, mirror.returnType.qualifiedName,
274 _getComment(mirror), _getParameters(mirror.parameters)); 283 _getComment(mirror), _getParameters(mirror.parameters),
284 _getAnnotations(mirror));
275 } 285 }
276 }); 286 });
277 return data; 287 return data;
278 } 288 }
279 289
280 /** 290 /**
281 * Returns a map of [Class] objects constructed from inputted mirrors. 291 * Returns a map of [Class] objects constructed from inputted mirrors.
282 */ 292 */
283 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) { 293 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) {
284 var data = {}; 294 var data = {};
285 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { 295 mirrorMap.forEach((String mirrorName, ClassMirror mirror) {
286 if (includePrivate || !mirror.isPrivate) { 296 if (includePrivate || !mirror.isPrivate) {
287 _currentClass = mirror; 297 _currentClass = mirror;
288 var superclass = (mirror.superclass != null) ? 298 var superclass = (mirror.superclass != null) ?
289 mirror.superclass.qualifiedName : ''; 299 mirror.superclass.qualifiedName : '';
290 var interfaces = 300 var interfaces =
291 mirror.superinterfaces.map((interface) => interface.qualifiedName); 301 mirror.superinterfaces.map((interface) => interface.qualifiedName);
292 data[mirrorName] = new Class(mirrorName, mirror.qualifiedName, 302 data[mirrorName] = new Class(mirrorName, mirror.qualifiedName,
293 superclass, mirror.isAbstract, mirror.isTypedef, 303 superclass, mirror.isAbstract, mirror.isTypedef,
294 _getComment(mirror), interfaces.toList(), 304 _getComment(mirror), interfaces.toList(),
295 _getVariables(mirror.variables), _getMethods(mirror.methods)); 305 _getVariables(mirror.variables), _getMethods(mirror.methods),
306 _getAnnotations(mirror));
296 } 307 }
297 }); 308 });
298 return data; 309 return data;
299 } 310 }
300 311
301 /** 312 /**
302 * Returns a map of [Parameter] objects constructed from inputted mirrors. 313 * Returns a map of [Parameter] objects constructed from inputted mirrors.
303 */ 314 */
304 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { 315 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) {
305 var data = {}; 316 var data = {};
306 mirrorList.forEach((ParameterMirror mirror) { 317 mirrorList.forEach((ParameterMirror mirror) {
307 _currentMember = mirror; 318 _currentMember = mirror;
308 data[mirror.simpleName] = new Parameter(mirror.simpleName, 319 data[mirror.simpleName] = new Parameter(mirror.simpleName,
309 mirror.qualifiedName, mirror.isOptional, mirror.isNamed, 320 mirror.qualifiedName, mirror.isOptional, mirror.isNamed,
310 mirror.hasDefaultValue, mirror.type.qualifiedName, 321 mirror.hasDefaultValue, mirror.type.qualifiedName,
311 mirror.defaultValue); 322 mirror.defaultValue, _getAnnotations(mirror));
312 }); 323 });
313 return data; 324 return data;
314 } 325 }
315 326
316 /** 327 /**
317 * Writes text to a file in the 'docs' directory. 328 * Writes text to a file in the 'docs' directory.
318 */ 329 */
319 void _writeToFile(String text, String filename) { 330 void _writeToFile(String text, String filename) {
320 Directory dir = new Directory('docs'); 331 Directory dir = new Directory('docs');
321 if (!dir.existsSync()) { 332 if (!dir.existsSync()) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 Map<String, Variable> variables; 401 Map<String, Variable> variables;
391 402
392 /// Methods in the class. 403 /// Methods in the class.
393 Map<String, Method> methods; 404 Map<String, Method> methods;
394 405
395 String name; 406 String name;
396 String qualifiedName; 407 String qualifiedName;
397 String superclass; 408 String superclass;
398 bool isAbstract; 409 bool isAbstract;
399 bool isTypedef; 410 bool isTypedef;
411
412 /// List of the meta annotations on the class.
413 List<String> annotations;
400 414
401 Class(this.name, this.qualifiedName, this.superclass, this.isAbstract, 415 Class(this.name, this.qualifiedName, this.superclass, this.isAbstract,
402 this.isTypedef, this.comment, this.interfaces, this.variables, 416 this.isTypedef, this.comment, this.interfaces, this.variables,
403 this.methods); 417 this.methods, this.annotations);
404 418
405 /// Generates a map describing the [Class] object. 419 /// Generates a map describing the [Class] object.
406 Map toMap() { 420 Map toMap() {
407 var classMap = {}; 421 var classMap = {};
408 classMap['name'] = name; 422 classMap['name'] = name;
409 classMap['qualifiedname'] = qualifiedName; 423 classMap['qualifiedname'] = qualifiedName;
410 classMap['comment'] = comment; 424 classMap['comment'] = comment;
411 classMap['superclass'] = superclass; 425 classMap['superclass'] = superclass;
412 classMap['abstract'] = isAbstract.toString(); 426 classMap['abstract'] = isAbstract.toString();
413 classMap['typedef'] = isTypedef.toString(); 427 classMap['typedef'] = isTypedef.toString();
414 classMap['implements'] = new List.from(interfaces); 428 classMap['implements'] = new List.from(interfaces);
415 classMap['variables'] = recurseMap(variables); 429 classMap['variables'] = recurseMap(variables);
416 classMap['methods'] = recurseMap(methods); 430 classMap['methods'] = recurseMap(methods);
431 classMap['annotations'] = new List.from(annotations);
417 return classMap; 432 return classMap;
418 } 433 }
419 } 434 }
420 435
421 /** 436 /**
422 * A class containing properties of a Dart variable. 437 * A class containing properties of a Dart variable.
423 */ 438 */
424 class Variable { 439 class Variable {
425 440
426 /// Documentation comment with converted markdown. 441 /// Documentation comment with converted markdown.
427 String comment; 442 String comment;
428 443
429 String name; 444 String name;
430 String qualifiedName; 445 String qualifiedName;
431 bool isFinal; 446 bool isFinal;
432 bool isStatic; 447 bool isStatic;
433 String type; 448 String type;
449
450 /// List of the meta annotations on the variable.
451 List<String> annotations;
434 452
435 Variable(this.name, this.qualifiedName, this.isFinal, this.isStatic, 453 Variable(this.name, this.qualifiedName, this.isFinal, this.isStatic,
436 this.type, this.comment); 454 this.type, this.comment, this.annotations);
437 455
438 /// Generates a map describing the [Variable] object. 456 /// Generates a map describing the [Variable] object.
439 Map toMap() { 457 Map toMap() {
440 var variableMap = {}; 458 var variableMap = {};
441 variableMap['name'] = name; 459 variableMap['name'] = name;
442 variableMap['qualifiedname'] = qualifiedName; 460 variableMap['qualifiedname'] = qualifiedName;
443 variableMap['comment'] = comment; 461 variableMap['comment'] = comment;
444 variableMap['final'] = isFinal.toString(); 462 variableMap['final'] = isFinal.toString();
445 variableMap['static'] = isStatic.toString(); 463 variableMap['static'] = isStatic.toString();
446 variableMap['type'] = type; 464 variableMap['type'] = type;
465 variableMap['annotations'] = new List.from(annotations);
447 return variableMap; 466 return variableMap;
448 } 467 }
449 } 468 }
450 469
451 /** 470 /**
452 * A class containing properties of a Dart method. 471 * A class containing properties of a Dart method.
453 */ 472 */
454 class Method { 473 class Method {
455 474
456 /// Documentation comment with converted markdown. 475 /// Documentation comment with converted markdown.
457 String comment; 476 String comment;
458 477
459 /// Parameters for this method. 478 /// Parameters for this method.
460 Map<String, Parameter> parameters; 479 Map<String, Parameter> parameters;
461 480
462 String name; 481 String name;
463 String qualifiedName; 482 String qualifiedName;
464 bool isSetter; 483 bool isSetter;
465 bool isGetter; 484 bool isGetter;
466 bool isConstructor; 485 bool isConstructor;
467 bool isOperator; 486 bool isOperator;
468 bool isStatic; 487 bool isStatic;
469 String returnType; 488 String returnType;
470 489
490 /// List of the meta annotations on the method.
491 List<String> annotations;
492
471 Method(this.name, this.qualifiedName, this.isSetter, this.isGetter, 493 Method(this.name, this.qualifiedName, this.isSetter, this.isGetter,
472 this.isConstructor, this.isOperator, this.isStatic, this.returnType, 494 this.isConstructor, this.isOperator, this.isStatic, this.returnType,
473 this.comment, this.parameters); 495 this.comment, this.parameters, this.annotations);
474 496
475 /// Generates a map describing the [Method] object. 497 /// Generates a map describing the [Method] object.
476 Map toMap() { 498 Map toMap() {
477 var methodMap = {}; 499 var methodMap = {};
478 methodMap['name'] = name; 500 methodMap['name'] = name;
479 methodMap['qualifiedname'] = qualifiedName; 501 methodMap['qualifiedname'] = qualifiedName;
480 methodMap['comment'] = comment; 502 methodMap['comment'] = comment;
481 methodMap['type'] = isSetter ? 'setter' : isGetter ? 'getter' : 503 methodMap['type'] = isSetter ? 'setter' : isGetter ? 'getter' :
482 isOperator ? 'operator' : isConstructor ? 'constructor' : 'method'; 504 isOperator ? 'operator' : isConstructor ? 'constructor' : 'method';
483 methodMap['static'] = isStatic.toString(); 505 methodMap['static'] = isStatic.toString();
484 methodMap['return'] = returnType; 506 methodMap['return'] = returnType;
485 methodMap['parameters'] = recurseMap(parameters); 507 methodMap['parameters'] = recurseMap(parameters);
508 methodMap['annotations'] = new List.from(annotations);
486 return methodMap; 509 return methodMap;
487 } 510 }
488 } 511 }
489 512
490 /** 513 /**
491 * A class containing properties of a Dart method/function parameter. 514 * A class containing properties of a Dart method/function parameter.
492 */ 515 */
493 class Parameter { 516 class Parameter {
494 517
495 String name; 518 String name;
496 String qualifiedName; 519 String qualifiedName;
497 bool isOptional; 520 bool isOptional;
498 bool isNamed; 521 bool isNamed;
499 bool hasDefaultValue; 522 bool hasDefaultValue;
500 String type; 523 String type;
501 String defaultValue; 524 String defaultValue;
502 525
526 /// List of the meta annotations on the parameter.
527 List<String> annotations;
528
503 Parameter(this.name, this.qualifiedName, this.isOptional, this.isNamed, 529 Parameter(this.name, this.qualifiedName, this.isOptional, this.isNamed,
504 this.hasDefaultValue, this.type, this.defaultValue); 530 this.hasDefaultValue, this.type, this.defaultValue, this.annotations);
505 531
506 /// Generates a map describing the [Parameter] object. 532 /// Generates a map describing the [Parameter] object.
507 Map toMap() { 533 Map toMap() {
508 var parameterMap = {}; 534 var parameterMap = {};
509 parameterMap['name'] = name; 535 parameterMap['name'] = name;
510 parameterMap['qualifiedname'] = qualifiedName; 536 parameterMap['qualifiedname'] = qualifiedName;
511 parameterMap['optional'] = isOptional.toString(); 537 parameterMap['optional'] = isOptional.toString();
512 parameterMap['named'] = isNamed.toString(); 538 parameterMap['named'] = isNamed.toString();
513 parameterMap['default'] = hasDefaultValue.toString(); 539 parameterMap['default'] = hasDefaultValue.toString();
514 parameterMap['type'] = type; 540 parameterMap['type'] = type;
515 parameterMap['value'] = defaultValue; 541 parameterMap['value'] = defaultValue;
542 parameterMap['annotations'] = new List.from(annotations);
516 return parameterMap; 543 return parameterMap;
517 } 544 }
518 } 545 }
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