@@ -242,20 +242,31 @@ class AnnotationExtractor {
242
242
243
243
/// Extracts all of the annotations for the specified class.
244
244
AnnotatedType extractAnnotations (ClassElement cls) {
245
- if (resolver.getImportUri (cls.library, from: outputId) == null ) {
246
- warn ('Dropping annotations for ${cls .name } because the '
247
- 'containing file cannot be imported (must be in a lib folder).' , cls);
248
- return null ;
249
- }
250
-
245
+ var classElement = cls;
251
246
var visitor = new _AnnotationVisitor (_annotationElements);
252
- cls.node.accept (visitor);
247
+ while (classElement != null ) {
248
+ if (resolver.getImportUri (classElement.library, from: outputId) == null ) {
249
+ warn ('Dropping annotations for ${classElement .name } because the '
250
+ 'containing file cannot be imported (must be in a lib folder).' , classElement);
251
+ return null ;
252
+ }
253
+ if (classElement.node != null ) {
254
+ classElement.node.accept (visitor);
255
+ }
256
+
257
+ if (classElement.supertype != null ) {
258
+ visitor.visitingSupertype = true ;
259
+ classElement = classElement.supertype.element;
260
+ } else {
261
+ classElement = null ;
262
+ }
263
+ }
253
264
254
265
if (! visitor.hasAnnotations) return null ;
255
266
256
267
var type = new AnnotatedType (cls);
257
268
type.annotations = visitor.classAnnotations
258
- .where ((annotation) {
269
+ .where ((Annotation annotation) {
259
270
var element = annotation.element;
260
271
if (element != null && ! element.isPublic) {
261
272
warn ('Annotation $annotation is not public.' ,
@@ -277,6 +288,7 @@ class AnnotationExtractor {
277
288
element.enclosingElement.type.isAssignableTo (formatterType.type);
278
289
}).toList ();
279
290
291
+ if (type.annotations.isEmpty) return null ;
280
292
281
293
var memberAnnotations = {};
282
294
visitor.memberAnnotations.forEach ((memberName, annotations) {
@@ -293,8 +305,6 @@ class AnnotationExtractor {
293
305
_foldMemberAnnotations (memberAnnotations, type);
294
306
}
295
307
296
- if (type.annotations.isEmpty) return null ;
297
-
298
308
return type;
299
309
}
300
310
@@ -309,10 +319,6 @@ class AnnotationExtractor {
309
319
return element.enclosingElement.type.isAssignableTo (
310
320
directiveType.type);
311
321
});
312
- if (ngAnnotations.isEmpty) {
313
- warn ('Found field annotation but no class directives.' , type.type);
314
- return ;
315
- }
316
322
317
323
var mapType = resolver.getType ('dart.core.Map' ).type;
318
324
// Find acceptable constructors- ones which take a param named 'map'
@@ -410,15 +416,17 @@ class _AnnotationVisitor extends GeneralizingAstVisitor {
410
416
final List <Element > allowedMemberAnnotations;
411
417
final List <Annotation > classAnnotations = [];
412
418
final Map <String , List <Annotation >> memberAnnotations = {};
419
+ var visitingSupertype = false ;
413
420
414
421
_AnnotationVisitor (this .allowedMemberAnnotations);
415
422
416
423
void visitAnnotation (Annotation annotation) {
417
424
var parent = annotation.parent;
418
425
if (parent is ! Declaration ) return ;
419
426
420
- if (parent.element is ClassElement ) {
427
+ if (parent.element is ClassElement && ! visitingSupertype ) {
421
428
classAnnotations.add (annotation);
429
+
422
430
} else if (allowedMemberAnnotations.contains (annotation.element)) {
423
431
if (parent is MethodDeclaration ) {
424
432
memberAnnotations.putIfAbsent (parent.name.name, () => [])
0 commit comments