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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 List<ClassElement> getImmediateSuperclasses(ClassElement c) { | 148 List<ClassElement> getImmediateSuperclasses(ClassElement c) { |
149 var result = <ClassElement>[]; | 149 var result = <ClassElement>[]; |
150 for (var m in c.mixins.reversed) { | 150 for (var m in c.mixins.reversed) { |
151 result.add(m.element); | 151 result.add(m.element); |
152 } | 152 } |
153 var s = c.supertype; | 153 var s = c.supertype; |
154 if (s != null) result.add(s.element); | 154 if (s != null) result.add(s.element); |
155 return result; | 155 return result; |
156 } | 156 } |
157 | 157 |
| 158 /// Returns true if the library [l] is dart:_runtime. |
| 159 // TODO(jmesserly): unlike other methods in this file, this one wouldn't be |
| 160 // suitable for upstream to Analyzer, as it's DDC specific. |
158 bool isSdkInternalRuntime(LibraryElement l) => | 161 bool isSdkInternalRuntime(LibraryElement l) => |
159 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; | 162 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; |
| 163 |
| 164 /// Return `true` if the given [classElement] has a noSuchMethod() method |
| 165 /// distinct from the one declared in class Object, as per the Dart Language |
| 166 /// Specification (section 10.4). |
| 167 // TODO(jmesserly): this was taken from error_verifier.dart |
| 168 bool hasNoSuchMethod(ClassElement classElement) { |
| 169 // TODO(jmesserly): this is slow in Analyzer. It's a linear scan through all |
| 170 // methods, up through the class hierarchy. |
| 171 var method = classElement.lookUpMethod( |
| 172 FunctionElement.NO_SUCH_METHOD_METHOD_NAME, classElement.library); |
| 173 var definingClass = method?.enclosingElement; |
| 174 return definingClass != null && !definingClass.type.isObject; |
| 175 } |
OLD | NEW |