OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library kernel.transformations.reify.ast_helpers; |
| 6 |
| 7 import 'package:kernel/ast.dart'; |
| 8 |
| 9 Class getEnclosingClass(TreeNode node) { |
| 10 TreeNode original = node; |
| 11 while (node != null && node is! Class) { |
| 12 node = node.parent; |
| 13 } |
| 14 if (node == null) { |
| 15 throw 'internal error: enclosing class not found for $original'; |
| 16 } |
| 17 return node; |
| 18 } |
| 19 |
| 20 Library getEnclosingLibrary(TreeNode node) { |
| 21 TreeNode original = node; |
| 22 while (node != null && node is! Library) { |
| 23 node = node.parent; |
| 24 } |
| 25 if (node == null) { |
| 26 throw 'internal error: enclosing library not found for $original'; |
| 27 } |
| 28 return node; |
| 29 } |
| 30 |
| 31 Member getEnclosingMember(TreeNode node) { |
| 32 TreeNode original = node; |
| 33 while (node != null && node is! Member) { |
| 34 node = node.parent; |
| 35 } |
| 36 if (node == null) { |
| 37 throw 'internal error: enclosing member not found for $original'; |
| 38 } |
| 39 return node; |
| 40 } |
| 41 |
| 42 List<TypeParameter> typeVariables(DartType type) { |
| 43 List<TypeParameter> parameters = <TypeParameter>[]; |
| 44 collect(DartType type) { |
| 45 if (type is InterfaceType) { |
| 46 type.typeArguments.map(collect); |
| 47 } else if (type is TypeParameterType) { |
| 48 parameters.add(type.parameter); |
| 49 } |
| 50 } |
| 51 |
| 52 collect(type); |
| 53 return parameters; |
| 54 } |
OLD | NEW |