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

Unified Diff: lib/src/util/dart.dart

Issue 986973006: Add a utility function to parse annotations in a test file. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes Created 5 years, 9 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
« no previous file with comments | « no previous file | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/util/dart.dart
diff --git a/lib/src/util/dart.dart b/lib/src/util/dart.dart
index 3ee861b23de6263d9a02f0fc307e65994db758dd..76f10b51fa15fb9240e172fbfdedb7fd3a907563 100644
--- a/lib/src/util/dart.dart
+++ b/lib/src/util/dart.dart
@@ -8,6 +8,7 @@ import 'dart:async';
import 'dart:io';
import 'dart:isolate';
+import 'package:analyzer/analyzer.dart';
import 'package:path/path.dart' as p;
import 'io.dart';
@@ -70,3 +71,13 @@ void _isolateBuffer(message) {
});
});
}
+
+/// Parse all the annotations at the beginning of a Dart file.
+///
+/// This will parse annotations until the first non-annotation production is
+/// reached.
+List<Annotation> parseAnnotations(String path) {
+ var contents = new File(path).readAsStringSync();
+ var directives = parseDirectives(contents, name: path).directives;
+ return directives.isEmpty ? [] : directives.first.metadata;
+}
« no previous file with comments | « no previous file | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698