Skip to content

Commit 3f3eaeb

Browse files
committed
annotation with parameters.
BUG= R=rnystrom@google.com Review URL: https://codereview.chromium.org//21699002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25751 260f80e4-7a28-3924-810f-c04153c831b5
1 parent 17c19b0 commit 3f3eaeb

File tree

1 file changed

+52
-26
lines changed

1 file changed

+52
-26
lines changed

pkg/docgen/lib/docgen.dart

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ Library generateLibrary(dart2js.Dart2JsLibraryMirror library) {
238238
var result = new Library(library.qualifiedName, _commentToHtml(library),
239239
_variables(library.variables),
240240
_methods(library.functions),
241-
_classes(library.classes), _isPrivate(library));
241+
_classes(library.classes), _isHidden(library));
242242
logger.fine('Generated library for ${result.name}');
243243
return result;
244244
}
@@ -269,13 +269,14 @@ bool _isLibraryPrivate(LibraryMirror mirror) {
269269
/**
270270
* A declaration is private if itself is private, or the owner is private.
271271
*/
272-
bool _isPrivate(DeclarationMirror mirror) {
272+
// Issue(12202) - A declaration is public even if it's owner is private.
273+
bool _isHidden(DeclarationMirror mirror) {
273274
if (mirror is LibraryMirror) {
274275
return _isLibraryPrivate(mirror);
275276
} else if (mirror.owner is LibraryMirror) {
276277
return (mirror.isPrivate || _isLibraryPrivate(mirror.owner));
277278
} else {
278-
return (mirror.isPrivate || _isPrivate(mirror.owner));
279+
return (mirror.isPrivate || _isHidden(mirror.owner));
279280
}
280281
}
281282

@@ -287,9 +288,19 @@ bool _isVisible(Indexable item) {
287288
* Returns a list of meta annotations assocated with a mirror.
288289
*/
289290
List<String> _annotations(DeclarationMirror mirror) {
290-
var annotations = mirror.metadata.where((e) =>
291+
var annotationMirrors = mirror.metadata.where((e) =>
291292
e is dart2js.Dart2JsConstructedConstantMirror);
292-
return annotations.map((e) => e.type.qualifiedName).toList();
293+
var annotations = [];
294+
annotationMirrors.forEach((annotation) {
295+
var parameterList = annotation.type.variables.values
296+
.where((e) => e.isFinal)
297+
.map((e) => annotation.getField(e.simpleName).reflectee)
298+
.where((e) => e != null)
299+
.toList();
300+
annotations.add(new Annotation(annotation.type.qualifiedName,
301+
parameterList));
302+
});
303+
return annotations;
293304
}
294305

295306
/**
@@ -342,11 +353,11 @@ Map<String, Variable> _variables(Map<String, VariableMirror> mirrorMap) {
342353
// a filter. Issue(#9590).
343354
mirrorMap.forEach((String mirrorName, VariableMirror mirror) {
344355
_currentMember = mirror;
345-
if (_includePrivate || !_isPrivate(mirror)) {
356+
if (_includePrivate || !_isHidden(mirror)) {
346357
entityMap[mirror.qualifiedName] = new Variable(mirrorName, mirror.isFinal,
347358
mirror.isStatic, mirror.isConst, _type(mirror.type),
348359
_commentToHtml(mirror), _annotations(mirror), mirror.qualifiedName,
349-
_isPrivate(mirror), mirror.owner.qualifiedName);
360+
_isHidden(mirror), mirror.owner.qualifiedName);
350361
data[mirrorName] = entityMap[mirror.qualifiedName];
351362
}
352363
});
@@ -359,7 +370,7 @@ Map<String, Variable> _variables(Map<String, VariableMirror> mirrorMap) {
359370
MethodGroup _methods(Map<String, MethodMirror> mirrorMap) {
360371
var group = new MethodGroup();
361372
mirrorMap.forEach((String mirrorName, MethodMirror mirror) {
362-
if (_includePrivate || !_isPrivate(mirror)) {
373+
if (_includePrivate || !_isHidden(mirror)) {
363374
group.addMethod(mirror);
364375
}
365376
});
@@ -380,7 +391,7 @@ Class _class(ClassMirror mirror) {
380391
clazz = new Class(mirror.simpleName, superclass, _commentToHtml(mirror),
381392
interfaces.toList(), _variables(mirror.variables),
382393
_methods(mirror.methods), _annotations(mirror), _generics(mirror),
383-
mirror.qualifiedName, _isPrivate(mirror), mirror.owner.qualifiedName);
394+
mirror.qualifiedName, _isHidden(mirror), mirror.owner.qualifiedName);
384395
entityMap[mirror.qualifiedName] = clazz;
385396
}
386397
return clazz;
@@ -646,14 +657,14 @@ class Class extends Indexable {
646657
'qualifiedname': qualifiedName,
647658
'comment': comment,
648659
'superclass': validSuperclass(),
649-
'implements': new List.from(interfaces.where(_isVisible)
650-
.map((e) => e.qualifiedName)),
651-
'subclass': new List.from(subclasses),
660+
'implements': interfaces.where(_isVisible)
661+
.map((e) => e.qualifiedName).toList(),
662+
'subclass': subclasses,
652663
'variables': recurseMap(variables),
653664
'inheritedvariables': recurseMap(inheritedVariables),
654665
'methods': methods.toMap(),
655666
'inheritedmethods': inheritedMethods.toMap(),
656-
'annotations': new List.from(annotations),
667+
'annotations': annotations.map((a) => a.toMap()).toList(),
657668
'generics': recurseMap(generics)
658669
};
659670
}
@@ -689,7 +700,7 @@ class ClassGroup {
689700
entityMap[mirror.qualifiedName] = new Typedef(mirror.simpleName,
690701
mirror.value.returnType.qualifiedName, _commentToHtml(mirror),
691702
_generics(mirror), _parameters(mirror.value.parameters),
692-
_annotations(mirror), mirror.qualifiedName, _isPrivate(mirror),
703+
_annotations(mirror), mirror.qualifiedName, _isHidden(mirror),
693704
mirror.owner.qualifiedName);
694705
typedefs[mirror.simpleName] = entityMap[mirror.qualifiedName];
695706
}
@@ -712,13 +723,13 @@ class ClassGroup {
712723
}
713724

714725
Map toMap() => {
715-
'abstract': new List.from(abstractClasses.values
716-
.where(_isVisible).map((e) => e.qualifiedName)),
717-
'class': new List.from(regularClasses.values
718-
.where(_isVisible).map((e) => e.qualifiedName)),
726+
'abstract': abstractClasses.values.where(_isVisible)
727+
.map((e) => e.qualifiedName).toList(),
728+
'class': regularClasses.values.where(_isVisible)
729+
.map((e) => e.qualifiedName).toList(),
719730
'typedef': recurseMap(typedefs),
720-
'error': new List.from(errors.values
721-
.where(_isVisible).map((e) => e.qualifiedName))
731+
'error': errors.values.where(_isVisible)
732+
.map((e) => e.qualifiedName).toList()
722733
};
723734
}
724735

@@ -744,7 +755,7 @@ class Typedef extends Indexable {
744755
'comment': comment,
745756
'return': returnType,
746757
'parameters': recurseMap(parameters),
747-
'annotations': new List.from(annotations),
758+
'annotations': annotations.map((a) => a.toMap()).toList(),
748759
'generics': recurseMap(generics)
749760
};
750761
}
@@ -775,7 +786,7 @@ class Variable extends Indexable {
775786
'static': isStatic.toString(),
776787
'constant': isConst.toString(),
777788
'type': new List.filled(1, type.toMap()),
778-
'annotations': new List.from(annotations)
789+
'annotations': annotations.map((a) => a.toMap()).toList()
779790
};
780791
}
781792

@@ -825,7 +836,7 @@ class Method extends Indexable {
825836
'constant': isConst.toString(),
826837
'return': new List.filled(1, returnType.toMap()),
827838
'parameters': recurseMap(parameters),
828-
'annotations': new List.from(annotations)
839+
'annotations': annotations.map((a) => a.toMap()).toList()
829840
};
830841
}
831842

@@ -844,7 +855,7 @@ class MethodGroup {
844855
var method = new Method(mirror.simpleName, mirror.isStatic,
845856
mirror.isAbstract, mirror.isConstConstructor, _type(mirror.returnType),
846857
_commentToHtml(mirror), _parameters(mirror.parameters),
847-
_annotations(mirror), mirror.qualifiedName, _isPrivate(mirror),
858+
_annotations(mirror), mirror.qualifiedName, _isHidden(mirror),
848859
mirror.owner.qualifiedName);
849860
entityMap[mirror.qualifiedName] = method;
850861
_currentMember = mirror;
@@ -928,7 +939,7 @@ class Parameter {
928939
'default': hasDefaultValue.toString(),
929940
'type': new List.filled(1, type.toMap()),
930941
'value': defaultValue,
931-
'annotations': new List.from(annotations)
942+
'annotations': annotations.map((a) => a.toMap()).toList()
932943
};
933944
}
934945

@@ -985,6 +996,21 @@ class Type {
985996

986997
Map toMap() => {
987998
'outer': outer,
988-
'inner': new List.from(inner.map((e) => e.toMap()))
999+
'inner': inner.map((e) => e.toMap()).toList()
1000+
};
1001+
}
1002+
1003+
/**
1004+
* Holds the name of the annotation, and its parameters.
1005+
*/
1006+
class Annotation {
1007+
String qualifiedName;
1008+
List<String> parameters;
1009+
1010+
Annotation(this.qualifiedName, this.parameters);
1011+
1012+
Map toMap() => {
1013+
'name': qualifiedName,
1014+
'parameters': parameters
9891015
};
9901016
}

0 commit comments

Comments
 (0)