OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// Helpers for Analyzer's Element model and corelib model. | 5 /// Helpers for Analyzer's Element model and corelib model. |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart' | 7 import 'package:analyzer/dart/ast/ast.dart' |
8 show | 8 show |
9 ConstructorDeclaration, | 9 ConstructorDeclaration, |
10 Expression, | 10 Expression, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 /// @js.JS('HTMLFontElement') | 44 /// @js.JS('HTMLFontElement') |
45 /// @deprecated | 45 /// @deprecated |
46 /// class FontElement { ... } | 46 /// class FontElement { ... } |
47 /// | 47 /// |
48 /// We could match `@deprecated` with a test function like: | 48 /// We could match `@deprecated` with a test function like: |
49 /// | 49 /// |
50 /// (v) => v.type.name == 'Deprecated' && v.type.element.library.isDartCore | 50 /// (v) => v.type.name == 'Deprecated' && v.type.element.library.isDartCore |
51 /// | 51 /// |
52 DartObject findAnnotation(Element element, bool test(DartObjectImpl value)) { | 52 DartObject findAnnotation(Element element, bool test(DartObjectImpl value)) { |
53 for (var metadata in element.metadata) { | 53 for (var metadata in element.metadata) { |
54 var value = metadata.constantValue; | 54 var value = metadata.computeConstantValue(); |
55 if (value != null && test(value)) return value; | 55 if (value != null && test(value)) return value; |
56 } | 56 } |
57 return null; | 57 return null; |
58 } | 58 } |
59 | 59 |
60 /// Searches all supertype, in order of most derived members, to see if any | 60 /// Searches all supertype, in order of most derived members, to see if any |
61 /// [match] a condition. If so, returns the first match, otherwise returns null. | 61 /// [match] a condition. If so, returns the first match, otherwise returns null. |
62 InterfaceType findSupertype(InterfaceType type, bool match(InterfaceType t)) { | 62 InterfaceType findSupertype(InterfaceType type, bool match(InterfaceType t)) { |
63 for (var m in type.mixins.reversed) { | 63 for (var m in type.mixins.reversed) { |
64 if (match(m)) return m; | 64 if (match(m)) return m; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 /// const MyAnnotation(this.name/*, ... other params ... */); | 113 /// const MyAnnotation(this.name/*, ... other params ... */); |
114 /// } | 114 /// } |
115 /// | 115 /// |
116 /// @MyAnnotation('FooBar') | 116 /// @MyAnnotation('FooBar') |
117 /// main() { ... } | 117 /// main() { ... } |
118 /// | 118 /// |
119 /// If we match the annotation for the `@MyAnnotation('FooBar')` this will | 119 /// If we match the annotation for the `@MyAnnotation('FooBar')` this will |
120 /// return the string 'FooBar'. | 120 /// return the string 'FooBar'. |
121 String getAnnotationName(Element element, bool match(DartObjectImpl value)) => | 121 String getAnnotationName(Element element, bool match(DartObjectImpl value)) => |
122 findAnnotation(element, match)?.getField('name')?.toStringValue(); | 122 findAnnotation(element, match)?.getField('name')?.toStringValue(); |
OLD | NEW |