| 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 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 /// Helpers for Analyzer's Element model and corelib model. | 7 /// Helpers for Analyzer's Element model and corelib model. |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart' | 9 import 'package:analyzer/dart/ast/ast.dart' |
| 10 show | 10 show |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 /// @js.JS('HTMLFontElement') | 51 /// @js.JS('HTMLFontElement') |
| 52 /// @deprecated | 52 /// @deprecated |
| 53 /// class FontElement { ... } | 53 /// class FontElement { ... } |
| 54 /// | 54 /// |
| 55 /// We could match `@deprecated` with a test function like: | 55 /// We could match `@deprecated` with a test function like: |
| 56 /// | 56 /// |
| 57 /// (v) => v.type.name == 'Deprecated' && v.type.element.library.isDartCore | 57 /// (v) => v.type.name == 'Deprecated' && v.type.element.library.isDartCore |
| 58 /// | 58 /// |
| 59 DartObject findAnnotation(Element element, bool test(DartObjectImpl value)) { | 59 DartObject findAnnotation(Element element, bool test(DartObjectImpl value)) { |
| 60 for (var metadata in element.metadata) { | 60 for (var metadata in element.metadata) { |
| 61 var value = metadata.computeConstantValue(); | 61 var value = metadata.constantValue; |
| 62 if (value != null && test(value)) return value; | 62 if (value != null && test(value)) return value; |
| 63 } | 63 } |
| 64 return null; | 64 return null; |
| 65 } | 65 } |
| 66 | 66 |
| 67 /// Searches all supertype, in order of most derived members, to see if any | 67 /// Searches all supertype, in order of most derived members, to see if any |
| 68 /// [match] a condition. If so, returns the first match, otherwise returns null. | 68 /// [match] a condition. If so, returns the first match, otherwise returns null. |
| 69 InterfaceType findSupertype(InterfaceType type, bool match(InterfaceType t)) { | 69 InterfaceType findSupertype(InterfaceType type, bool match(InterfaceType t)) { |
| 70 for (var m in type.mixins.reversed) { | 70 for (var m in type.mixins.reversed) { |
| 71 if (match(m)) return m; | 71 if (match(m)) return m; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 /// Specification (section 10.4). | 166 /// Specification (section 10.4). |
| 167 // TODO(jmesserly): this was taken from error_verifier.dart | 167 // TODO(jmesserly): this was taken from error_verifier.dart |
| 168 bool hasNoSuchMethod(ClassElement classElement) { | 168 bool hasNoSuchMethod(ClassElement classElement) { |
| 169 // TODO(jmesserly): this is slow in Analyzer. It's a linear scan through all | 169 // TODO(jmesserly): this is slow in Analyzer. It's a linear scan through all |
| 170 // methods, up through the class hierarchy. | 170 // methods, up through the class hierarchy. |
| 171 var method = classElement.lookUpMethod( | 171 var method = classElement.lookUpMethod( |
| 172 FunctionElement.NO_SUCH_METHOD_METHOD_NAME, classElement.library); | 172 FunctionElement.NO_SUCH_METHOD_METHOD_NAME, classElement.library); |
| 173 var definingClass = method?.enclosingElement; | 173 var definingClass = method?.enclosingElement; |
| 174 return definingClass != null && !definingClass.type.isObject; | 174 return definingClass != null && !definingClass.type.isObject; |
| 175 } | 175 } |
| OLD | NEW |