Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Unified Diff: pkg/kernel/lib/transformations/reify/asts.dart

Issue 2697873007: Merge the work on Generic Types Reification from 'dart-lang/reify' repo (Closed)
Patch Set: Get back parameter erroneously removed by previous commit Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/kernel/lib/transformations/reify/asts.dart
diff --git a/pkg/kernel/lib/transformations/reify/asts.dart b/pkg/kernel/lib/transformations/reify/asts.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0516b0b3da7bf37706f5d632e7fa9f039f9259ad
--- /dev/null
+++ b/pkg/kernel/lib/transformations/reify/asts.dart
@@ -0,0 +1,54 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library kernel.transformations.reify.ast_helpers;
+
+import 'package:kernel/ast.dart';
+
+Class getEnclosingClass(TreeNode node) {
+ TreeNode original = node;
+ while (node != null && node is! Class) {
+ node = node.parent;
+ }
+ if (node == null) {
+ throw 'internal error: enclosing class not found for $original';
+ }
+ return node;
+}
+
+Library getEnclosingLibrary(TreeNode node) {
+ TreeNode original = node;
+ while (node != null && node is! Library) {
+ node = node.parent;
+ }
+ if (node == null) {
+ throw 'internal error: enclosing library not found for $original';
+ }
+ return node;
+}
+
+Member getEnclosingMember(TreeNode node) {
+ TreeNode original = node;
+ while (node != null && node is! Member) {
+ node = node.parent;
+ }
+ if (node == null) {
+ throw 'internal error: enclosing member not found for $original';
+ }
+ return node;
+}
+
+List<TypeParameter> typeVariables(DartType type) {
+ List<TypeParameter> parameters = <TypeParameter>[];
+ collect(DartType type) {
+ if (type is InterfaceType) {
+ type.typeArguments.map(collect);
+ } else if (type is TypeParameterType) {
+ parameters.add(type.parameter);
+ }
+ }
+
+ collect(type);
+ return parameters;
+}

Powered by Google App Engine
This is Rietveld 408576698