1- library angular2.transformer ;
1+ library angular2.src.transform ;
22
33import 'package:analyzer/src/generated/ast.dart' ;
44import 'package:analyzer/src/generated/element.dart' ;
@@ -17,6 +17,8 @@ class Context {
1717 final Map <LibraryElement , String > _libraryPrefixes;
1818
1919 DirectiveRegistry _directiveRegistry;
20+ /// Generates [registerType] calls for all [register] ed [AnnotationMatch]
21+ /// objects.
2022 DirectiveRegistry get directiveRegistry => _directiveRegistry;
2123
2224 Context ({TransformLogger logger})
@@ -26,33 +28,31 @@ class Context {
2628 }
2729
2830 void error (String errorString) {
29- if (_logger != null ) {
30- _logger.error (errorString);
31- } else {
32- throw new Error (errorString);
33- }
31+ if (_logger == null ) throw new Error (errorString);
32+ _logger.error (errorString);
3433 }
3534
3635 /// If elements in [lib] should be prefixed in our generated code, returns
3736 /// the appropriate prefix followed by a `.` . Future items from the same
3837 /// library will use the same prefix.
3938 /// If [lib] does not need a prefix, returns the empty string.
4039 String _getPrefixDot (LibraryElement lib) {
41- var prefix = lib != null && ! lib.isInSdk
42- ? _libraryPrefixes. putIfAbsent (lib, () => 'i${ _libraryPrefixes . length }' )
43- : null ;
44- return prefix == null ? '' : '${prefix }.' ;
40+ if ( lib == null || lib.isInSdk) return '' ;
41+ var prefix =
42+ _libraryPrefixes. putIfAbsent (lib, () => 'i${ _libraryPrefixes . length }' ) ;
43+ return '${prefix }.' ;
4544 }
4645}
4746
47+ /// Object which [register] s [AnnotationMatch] objects for code generation.
4848abstract class DirectiveRegistry {
4949 // Adds [entry] to the `registerType` calls which will be generated.
5050 void register (AnnotationMatch entry);
5151}
5252
53- const _reflectorImport =
54- ' import \ ' package:angular2/src/reflection/reflection.dart\' '
55- 'show reflector; ' ;
53+ const _reflectorImport = '''
54+ import 'package:angular2/src/reflection/reflection.dart' show reflector;
55+ '' ' ;
5656
5757/// Default implementation to map from [LibraryElement] to [AssetId] . This
5858/// assumes that [el.source] has a getter called [assetId] .
@@ -102,6 +102,8 @@ _codegenImport(Context context, AssetId libraryId, AssetId entryPoint) {
102102 }
103103}
104104
105+ // TODO(https://github.com/kegluneq/angular/issues/4): Remove calls to
106+ // Element#node.
105107class _DirectiveRegistryImpl implements DirectiveRegistry {
106108 final Context _context;
107109 final StringBuffer _buffer = new StringBuffer ();
@@ -197,33 +199,24 @@ abstract class _TransformVisitor extends ToSourceVisitor {
197199 : this ._writer = writer,
198200 super (writer);
199201
200- /// Safely visit the given node.
201- /// @param node the node to be visited
202+ /// Safely visit [node] .
202203 void _visitNode (AstNode node) {
203204 if (node != null ) {
204205 node.accept (this );
205206 }
206207 }
207208
208- /**
209- * Safely visit the given node, printing the prefix before the node if it is non-`null` .
210- *
211- * @param prefix the prefix to be printed if there is a node to visit
212- * @param node the node to be visited
213- */
209+ /// If [node] is null does nothing. Otherwise, prints [prefix] , then
210+ /// visits [node] .
214211 void _visitNodeWithPrefix (String prefix, AstNode node) {
215212 if (node != null ) {
216213 _writer.print (prefix);
217214 node.accept (this );
218215 }
219216 }
220217
221- /**
222- * Safely visit the given node, printing the suffix after the node if it is non-`null` .
223- *
224- * @param suffix the suffix to be printed if there is a node to visit
225- * @param node the node to be visited
226- */
218+ /// If [node] is null does nothing. Otherwise, visits [node] , then prints
219+ /// [suffix] .
227220 void _visitNodeWithSuffix (AstNode node, String suffix) {
228221 if (node != null ) {
229222 node.accept (this );
0 commit comments