Index: pkg/observe/lib/transformer.dart |
=================================================================== |
--- pkg/observe/lib/transformer.dart (revision 37373) |
+++ pkg/observe/lib/transformer.dart (working copy) |
@@ -8,6 +8,7 @@ |
import 'dart:async'; |
+import 'package:analyzer/analyzer.dart'; |
import 'package:analyzer/src/generated/ast.dart'; |
import 'package:analyzer/src/generated/error.dart'; |
import 'package:analyzer/src/generated/parser.dart'; |
@@ -84,7 +85,7 @@ |
TextEditTransaction _transformCompilationUnit( |
String inputCode, SourceFile sourceFile, TransformLogger logger) { |
- var unit = _parseCompilationUnit(inputCode); |
+ var unit = parseCompilationUnit(inputCode, suppressErrors: true); |
var code = new TextEditTransaction(inputCode, sourceFile); |
for (var directive in unit.directives) { |
if (directive is LibraryDirective && _hasObservable(directive)) { |
@@ -109,21 +110,6 @@ |
return code; |
} |
-/// Parse [code] using analyzer. |
-CompilationUnit _parseCompilationUnit(String code) { |
- var errorListener = new _ErrorCollector(); |
- var reader = new CharSequenceReader(code); |
- var scanner = new Scanner(null, reader, errorListener); |
- var token = scanner.tokenize(); |
- var parser = new Parser(null, errorListener); |
- return parser.parseCompilationUnit(token); |
-} |
- |
-class _ErrorCollector extends AnalysisErrorListener { |
- final errors = <AnalysisError>[]; |
- onError(error) => errors.add(error); |
-} |
- |
_getSpan(SourceFile file, AstNode node) => file.span(node.offset, node.end); |
/// True if the node has the `@observable` or `@published` annotation. |
@@ -143,7 +129,7 @@ |
bool _isAnnotationContant(Annotation m, String name) => |
m.name.name == name && m.constructorName == null && m.arguments == null; |
-bool _isAnnotationType(Annotation m, String name) => m.name == name; |
+bool _isAnnotationType(Annotation m, String name) => m.name.name == name; |
void _transformClass(ClassDeclaration cls, TextEditTransaction code, |
SourceFile file, TransformLogger logger) { |