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; |
+} |