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

Side by Side Diff: pkg/docgen/lib/src/models/model_helpers.dart

Issue 716913005: Replace ResolvedNode by ConstantExpression. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years, 1 month 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 | « pkg/docgen/lib/src/models/annotation.dart ('k') | pkg/docgen/test/metadata_test.dart » ('j') | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library docgen.model_helpers; 5 library docgen.model_helpers;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:compiler/src/constants/expressions.dart';
10
9 import '../exports/dart2js_mirrors.dart' as dart2js_mirrors; 11 import '../exports/dart2js_mirrors.dart' as dart2js_mirrors;
10 import '../exports/mirrors_util.dart' as dart2js_util; 12 import '../exports/mirrors_util.dart' as dart2js_util;
11 import '../exports/source_mirrors.dart'; 13 import '../exports/source_mirrors.dart';
12 import '../exports/libraries.dart'; 14 import '../exports/libraries.dart';
13 15
14 import '../library_helpers.dart' show includePrivateMembers; 16 import '../library_helpers.dart' show includePrivateMembers;
15 import '../package_helpers.dart'; 17 import '../package_helpers.dart';
16 18
17 import 'annotation.dart'; 19 import 'annotation.dart';
18 import 'generic.dart'; 20 import 'generic.dart';
(...skipping 27 matching lines...) Expand all
46 (key, val) => val.mirror.isOperator)), 48 (key, val) => val.mirror.isOperator)),
47 'methods': recurseMap(_filterMap(mapToExpand, 49 'methods': recurseMap(_filterMap(mapToExpand,
48 (key, val) => val.mirror.isRegularMethod && !val.mirror.isOperator)) 50 (key, val) => val.mirror.isRegularMethod && !val.mirror.isOperator))
49 }; 51 };
50 52
51 String getDefaultValue(ParameterMirror mirror) { 53 String getDefaultValue(ParameterMirror mirror) {
52 if (!mirror.hasDefaultValue) return null; 54 if (!mirror.hasDefaultValue) return null;
53 return '${mirror.defaultValue}'; 55 return '${mirror.defaultValue}';
54 } 56 }
55 57
56 // TODO(johnniwinther): Use the `ConstExp` classes instead of `ResolvedNode`.
57 /// Returns a list of meta annotations assocated with a mirror. 58 /// Returns a list of meta annotations assocated with a mirror.
58 List<Annotation> createAnnotations(DeclarationMirror mirror, 59 List<Annotation> createAnnotations(DeclarationMirror mirror,
59 Library owningLibrary) { 60 Library owningLibrary) {
60 var annotations = []; 61 var annotations = [];
61 for (dart2js_mirrors.ResolvedNode node in 62 var info = new AnnotationInfo(mirror, owningLibrary);
62 dart2js_mirrors.BackDoor.metadataSyntaxOf(mirror)) { 63 for (var expr in dart2js_mirrors.BackDoor.metadataSyntaxOf(mirror)) {
63 var docgenAnnotation = new Annotation(node, owningLibrary); 64 var docgenAnnotation = expr.accept(const AnnotationCreator(), info);
64 if (!_SKIPPED_ANNOTATIONS.contains(dart2js_util.qualifiedNameOf( 65 if (docgenAnnotation != null &&
65 docgenAnnotation.mirror))) { 66 !_SKIPPED_ANNOTATIONS.contains(
67 dart2js_util.qualifiedNameOf(docgenAnnotation.mirror))) {
66 annotations.add(docgenAnnotation); 68 annotations.add(docgenAnnotation);
67 } 69 }
68 } 70 }
69 return annotations; 71 return annotations;
70 } 72 }
71 73
74 class AnnotationInfo {
75 final Mirror mirror;
76 final Library owningLibrary;
77
78 AnnotationInfo(this.mirror, this.owningLibrary);
79 }
80
81 class AnnotationCreator
82 extends ConstantExpressionVisitor<AnnotationInfo, Annotation> {
83
84 const AnnotationCreator();
85
86 Annotation createAnnotation(var element,
87 AnnotationInfo context,
88 [List<String> parameters = const <String>[]]) {
89 var mirror =
90 dart2js_mirrors.BackDoor.getMirrorFromElement(context.mirror, element);
91 if (mirror != null) {
92 return new Annotation(context.owningLibrary, mirror, parameters);
93 }
94 return null;
95 }
96
97 @override
98 Annotation visitBinary(BinaryConstantExpression exp,
99 [AnnotationInfo context]) {
100 return null;
101 }
102
103 @override
104 Annotation visitConcatenate(ConcatenateConstantExpression exp,
105 [AnnotationInfo context]) {
106 return null;
107 }
108
109 @override
110 Annotation visitConditional(ConditionalConstantExpression exp,
111 [AnnotationInfo context]) {
112 return null;
113 }
114
115 @override
116 Annotation visitConstructed(ConstructedConstantExpresssion exp,
117 [AnnotationInfo context]) {
118 return createAnnotation(exp.target, context,
119 exp.arguments.map((a) => a.getText()).toList());
120 }
121
122 @override
123 Annotation visitFunction(FunctionConstantExpression exp,
124 [AnnotationInfo context]) {
125 return createAnnotation(exp.element, context);
126 }
127
128 @override
129 Annotation visitList(ListConstantExpression exp,
130 [AnnotationInfo context]) {
131 return null;
132 }
133
134 @override
135 Annotation visitMap(MapConstantExpression exp,
136 [AnnotationInfo context]) {
137 return null;
138 }
139
140 @override
141 Annotation visitPrimitive(PrimitiveConstantExpression exp,
142 [AnnotationInfo context]) {
143 return null;
144 }
145
146 @override
147 Annotation visitSymbol(SymbolConstantExpression exp,
148 [AnnotationInfo context]) {
149 return null;
150 }
151
152 @override
153 Annotation visitType(TypeConstantExpression exp,
154 [AnnotationInfo context]) {
155 return null;
156 }
157
158 @override
159 Annotation visitUnary(UnaryConstantExpression exp,
160 [AnnotationInfo context]) {
161 return null;
162 }
163
164 @override
165 Annotation visitVariable(VariableConstantExpression exp,
166 [AnnotationInfo context]) {
167 return createAnnotation(exp.element, context);
168 }
169 }
170
72 /// A declaration is private if itself is private, or the owner is private. 171 /// A declaration is private if itself is private, or the owner is private.
73 bool isHidden(DeclarationSourceMirror mirror) { 172 bool isHidden(DeclarationSourceMirror mirror) {
74 if (mirror is LibraryMirror) { 173 if (mirror is LibraryMirror) {
75 return _isLibraryPrivate(mirror); 174 return _isLibraryPrivate(mirror);
76 } else if (mirror.owner is LibraryMirror) { 175 } else if (mirror.owner is LibraryMirror) {
77 return (mirror.isPrivate || _isLibraryPrivate(mirror.owner) || 176 return (mirror.isPrivate || _isLibraryPrivate(mirror.owner) ||
78 mirror.isNameSynthetic); 177 mirror.isNameSynthetic);
79 } else { 178 } else {
80 return (mirror.isPrivate || isHidden(mirror.owner) || 179 return (mirror.isPrivate || isHidden(mirror.owner) ||
81 mirror.isNameSynthetic); 180 mirror.isNameSynthetic);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // the time. 359 // the time.
261 var sdkLibrary = LIBRARIES[dart2js_util.nameOf(mirror)]; 360 var sdkLibrary = LIBRARIES[dart2js_util.nameOf(mirror)];
262 if (sdkLibrary != null) { 361 if (sdkLibrary != null) {
263 return !sdkLibrary.documented; 362 return !sdkLibrary.documented;
264 } else if (dart2js_util.nameOf(mirror).startsWith('_') || dart2js_util.nameOf( 363 } else if (dart2js_util.nameOf(mirror).startsWith('_') || dart2js_util.nameOf(
265 mirror).contains('._')) { 364 mirror).contains('._')) {
266 return true; 365 return true;
267 } 366 }
268 return false; 367 return false;
269 } 368 }
OLDNEW
« no previous file with comments | « pkg/docgen/lib/src/models/annotation.dart ('k') | pkg/docgen/test/metadata_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698