| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Code transform for @observable. The core transformation is relatively | 6 * Code transform for @observable. The core transformation is relatively |
| 7 * straightforward, and essentially like an editor refactoring. | 7 * straightforward, and essentially like an editor refactoring. |
| 8 */ | 8 */ |
| 9 library observe.transform; | 9 library observe.transform; |
| 10 | 10 |
| 11 import 'dart:async'; | 11 import 'dart:async'; |
| 12 | 12 |
| 13 import 'package:analyzer_experimental/src/generated/java_core.dart' show CharSeq
uence; |
| 13 import 'package:analyzer_experimental/src/generated/ast.dart'; | 14 import 'package:analyzer_experimental/src/generated/ast.dart'; |
| 14 import 'package:analyzer_experimental/src/generated/error.dart'; | 15 import 'package:analyzer_experimental/src/generated/error.dart'; |
| 15 import 'package:analyzer_experimental/src/generated/parser.dart'; | 16 import 'package:analyzer_experimental/src/generated/parser.dart'; |
| 16 import 'package:analyzer_experimental/src/generated/scanner.dart'; | 17 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
| 17 import 'package:barback/barback.dart'; | 18 import 'package:barback/barback.dart'; |
| 18 import 'package:source_maps/refactor.dart'; | 19 import 'package:source_maps/refactor.dart'; |
| 19 import 'package:source_maps/span.dart' show SourceFile; | 20 import 'package:source_maps/span.dart' show SourceFile; |
| 20 | 21 |
| 21 /** | 22 /** |
| 22 * A [Transformer] that replaces observables based on dirty-checking with an | 23 * A [Transformer] that replaces observables based on dirty-checking with an |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 span: _getSpan(sourceFile, declaration)); | 84 span: _getSpan(sourceFile, declaration)); |
| 84 } | 85 } |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 return code; | 88 return code; |
| 88 } | 89 } |
| 89 | 90 |
| 90 /** Parse [code] using analyzer_experimental. */ | 91 /** Parse [code] using analyzer_experimental. */ |
| 91 CompilationUnit _parseCompilationUnit(String code) { | 92 CompilationUnit _parseCompilationUnit(String code) { |
| 92 var errorListener = new _ErrorCollector(); | 93 var errorListener = new _ErrorCollector(); |
| 93 var scanner = new StringScanner(null, code, errorListener); | 94 var reader = new CharSequenceReader(new CharSequence(code)); |
| 95 var scanner = new Scanner(null, reader, errorListener); |
| 94 var token = scanner.tokenize(); | 96 var token = scanner.tokenize(); |
| 95 var parser = new Parser(null, errorListener); | 97 var parser = new Parser(null, errorListener); |
| 96 return parser.parseCompilationUnit(token); | 98 return parser.parseCompilationUnit(token); |
| 97 } | 99 } |
| 98 | 100 |
| 99 class _ErrorCollector extends AnalysisErrorListener { | 101 class _ErrorCollector extends AnalysisErrorListener { |
| 100 final errors = <AnalysisError>[]; | 102 final errors = <AnalysisError>[]; |
| 101 onError(error) => errors.add(error); | 103 onError(error) => errors.add(error); |
| 102 } | 104 } |
| 103 | 105 |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 406 |
| 405 Token _findFieldSeperator(Token token) { | 407 Token _findFieldSeperator(Token token) { |
| 406 while (token != null) { | 408 while (token != null) { |
| 407 if (token.type == TokenType.COMMA || token.type == TokenType.SEMICOLON) { | 409 if (token.type == TokenType.COMMA || token.type == TokenType.SEMICOLON) { |
| 408 break; | 410 break; |
| 409 } | 411 } |
| 410 token = token.next; | 412 token = token.next; |
| 411 } | 413 } |
| 412 return token; | 414 return token; |
| 413 } | 415 } |
| OLD | NEW |