@@ -2,32 +2,33 @@ library angular2.transform.reflection_remover.rewriter;
22
33import 'package:analyzer/src/generated/ast.dart' ;
44import 'package:angular2/src/transform/common/logging.dart' ;
5+ import 'package:angular2/src/transform/common/mirror_matcher.dart' ;
56import 'package:angular2/src/transform/common/mirror_mode.dart' ;
67import 'package:angular2/src/transform/common/names.dart' ;
78import 'package:path/path.dart' as path;
89
9- import 'ast_tester.dart' ;
1010import 'codegen.dart' ;
1111
1212class Rewriter {
1313 final String _code;
1414 final Codegen _codegen;
15- final AstTester _tester ;
15+ final MirrorMatcher _mirrorMatcher ;
1616 final MirrorMode _mirrorMode;
1717 final bool _writeStaticInit;
1818
1919 Rewriter (this ._code, this ._codegen,
20- {AstTester tester ,
20+ {MirrorMatcher mirrorMatcher ,
2121 MirrorMode mirrorMode: MirrorMode .none,
2222 bool writeStaticInit: true })
2323 : _mirrorMode = mirrorMode,
2424 _writeStaticInit = writeStaticInit,
25- _tester = tester == null ? const AstTester () : tester;
25+ _mirrorMatcher =
26+ mirrorMatcher == null ? const MirrorMatcher () : mirrorMatcher;
2627
2728 /// Rewrites the provided code removing imports of the
2829 /// {@link ReflectionCapabilities} library and instantiations of
2930 /// {@link ReflectionCapabilities}, as detected by the (potentially) provided
30- /// {@link AstTester }.
31+ /// {@link MirrorMatcher }.
3132 ///
3233 /// To the extent possible, this method does not change line numbers or
3334 /// offsets in the provided code to facilitate debugging via source maps.
@@ -62,9 +63,9 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor<Object> {
6263 Object visitImportDirective (ImportDirective node) {
6364 buf.write (_rewriter._code.substring (_currentIndex, node.offset));
6465 _currentIndex = node.offset;
65- if (_rewriter._tester. isReflectionCapabilitiesImport (node)) {
66+ if (_rewriter._mirrorMatcher. hasReflectionCapabilitiesUri (node)) {
6667 _rewriteReflectionCapabilitiesImport (node);
67- } else if (_rewriter._tester. isBootstrapImport (node)) {
68+ } else if (_rewriter._mirrorMatcher. hasBootstrapUri (node)) {
6869 _rewriteBootstrapImportToStatic (node);
6970 }
7071 if (! _importAdded && _rewriter._writeStaticInit) {
@@ -78,7 +79,8 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor<Object> {
7879 @override
7980 Object visitAssignmentExpression (AssignmentExpression node) {
8081 if (node.rightHandSide is InstanceCreationExpression &&
81- _rewriter._tester.isNewReflectionCapabilities (node.rightHandSide)) {
82+ _rewriter._mirrorMatcher
83+ .isNewReflectionCapabilities (node.rightHandSide)) {
8284 reflectionCapabilityAssignments.add (node);
8385 _rewriteReflectionCapabilitiesAssignment (node);
8486 }
@@ -87,7 +89,7 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor<Object> {
8789
8890 @override
8991 Object visitInstanceCreationExpression (InstanceCreationExpression node) {
90- if (_rewriter._tester .isNewReflectionCapabilities (node) &&
92+ if (_rewriter._mirrorMatcher .isNewReflectionCapabilities (node) &&
9193 ! reflectionCapabilityAssignments.contains (node.parent)) {
9294 logger.error ('Unexpected format in creation of '
9395 '${REFLECTION_CAPABILITIES_NAME }' );
@@ -112,10 +114,10 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor<Object> {
112114
113115 _rewriteBootstrapImportToStatic (ImportDirective node) {
114116 if (_rewriter._writeStaticInit) {
115- // rewrite ` bootstrap.dart` to `bootstrap_static.dart`
117+ // rewrite bootstrap import to its static version.
116118 buf.write (_rewriter._code.substring (_currentIndex, node.offset));
117119 // TODO(yjbanov): handle import "..." show/hide ...
118- buf.write ("import 'package:angular2/bootstrap_static.dart ';" );
120+ buf.write ("import '$ BOOTSTRAP_STATIC_URI ';" );
119121 } else {
120122 // leave it as is
121123 buf.write (_rewriter._code.substring (_currentIndex, node.end));
0 commit comments