diff --git a/modules/angular2/src/transform/annotation_processor.dart b/modules/angular2/src/transform/annotation_processor.dart index 323aa23df8..b8399d8cc3 100644 --- a/modules/angular2/src/transform/annotation_processor.dart +++ b/modules/angular2/src/transform/annotation_processor.dart @@ -1,3 +1,5 @@ +library angular2.src.transform; + import 'dart:collection' show Queue; import 'package:analyzer/src/generated/element.dart'; @@ -5,7 +7,7 @@ import 'package:analyzer/src/generated/element.dart'; /// [_annotationClass] and reporting the resulting (element, annotation) pairs. class AnnotationMatcher { /// Queue for annotations. - final initQueue = new Queue(); + final matchQueue = new Queue(); /// All the annotations we have seen for each element final _seenAnnotations = new Map>(); @@ -16,7 +18,7 @@ class AnnotationMatcher { /// Records all [_annotationClass] annotations and the [element]s they apply to. /// Returns [true] if 1) [element] is annotated with [_annotationClass] and - /// 2) ([element], [_annotationClass]) has been seen previously. + /// 2) ([element], [_annotationClass]) has not been seen previously. bool processAnnotations(ClassElement element) { var found = false; element.metadata.where((ElementAnnotation meta) { @@ -31,7 +33,7 @@ class AnnotationMatcher { .contains(meta); }).forEach((ElementAnnotation meta) { _seenAnnotations[element].add(meta); - initQueue.addLast(new AnnotationMatch(element, meta)); + matchQueue.addLast(new AnnotationMatch(element, meta)); found = true; }); return found; diff --git a/modules/angular2/src/transform/codegen.dart b/modules/angular2/src/transform/codegen.dart index 399cc27701..1fcbd8f754 100644 --- a/modules/angular2/src/transform/codegen.dart +++ b/modules/angular2/src/transform/codegen.dart @@ -1,4 +1,4 @@ -library angular2.transformer; +library angular2.src.transform; import 'package:analyzer/src/generated/ast.dart'; import 'package:analyzer/src/generated/element.dart'; @@ -17,6 +17,8 @@ class Context { final Map _libraryPrefixes; DirectiveRegistry _directiveRegistry; + /// Generates [registerType] calls for all [register]ed [AnnotationMatch] + /// objects. DirectiveRegistry get directiveRegistry => _directiveRegistry; Context({TransformLogger logger}) @@ -26,11 +28,8 @@ class Context { } void error(String errorString) { - if (_logger != null) { - _logger.error(errorString); - } else { - throw new Error(errorString); - } + if (_logger == null) throw new Error(errorString); + _logger.error(errorString); } /// If elements in [lib] should be prefixed in our generated code, returns @@ -38,21 +37,22 @@ class Context { /// library will use the same prefix. /// If [lib] does not need a prefix, returns the empty string. String _getPrefixDot(LibraryElement lib) { - var prefix = lib != null && !lib.isInSdk - ? _libraryPrefixes.putIfAbsent(lib, () => 'i${_libraryPrefixes.length}') - : null; - return prefix == null ? '' : '${prefix}.'; + if (lib == null || lib.isInSdk) return ''; + var prefix = + _libraryPrefixes.putIfAbsent(lib, () => 'i${_libraryPrefixes.length}'); + return '${prefix}.'; } } +/// Object which [register]s [AnnotationMatch] objects for code generation. abstract class DirectiveRegistry { // Adds [entry] to the `registerType` calls which will be generated. void register(AnnotationMatch entry); } -const _reflectorImport = - 'import \'package:angular2/src/reflection/reflection.dart\' ' - 'show reflector;'; +const _reflectorImport = ''' +import 'package:angular2/src/reflection/reflection.dart' show reflector; +'''; /// Default implementation to map from [LibraryElement] to [AssetId]. This /// assumes that [el.source] has a getter called [assetId]. @@ -102,6 +102,8 @@ _codegenImport(Context context, AssetId libraryId, AssetId entryPoint) { } } +// TODO(https://github.com/kegluneq/angular/issues/4): Remove calls to +// Element#node. class _DirectiveRegistryImpl implements DirectiveRegistry { final Context _context; final StringBuffer _buffer = new StringBuffer(); @@ -197,20 +199,15 @@ abstract class _TransformVisitor extends ToSourceVisitor { : this._writer = writer, super(writer); - /// Safely visit the given node. - /// @param node the node to be visited + /// Safely visit [node]. void _visitNode(AstNode node) { if (node != null) { node.accept(this); } } - /** - * Safely visit the given node, printing the prefix before the node if it is non-`null`. - * - * @param prefix the prefix to be printed if there is a node to visit - * @param node the node to be visited - */ + /// If [node] is null does nothing. Otherwise, prints [prefix], then + /// visits [node]. void _visitNodeWithPrefix(String prefix, AstNode node) { if (node != null) { _writer.print(prefix); @@ -218,12 +215,8 @@ abstract class _TransformVisitor extends ToSourceVisitor { } } - /** - * Safely visit the given node, printing the suffix after the node if it is non-`null`. - * - * @param suffix the suffix to be printed if there is a node to visit - * @param node the node to be visited - */ + /// If [node] is null does nothing. Otherwise, visits [node], then prints + /// [suffix]. void _visitNodeWithSuffix(AstNode node, String suffix) { if (node != null) { node.accept(this); diff --git a/modules/angular2/src/transform/html_transform.dart b/modules/angular2/src/transform/html_transform.dart index dcfbf7ee11..31bec5b7b6 100644 --- a/modules/angular2/src/transform/html_transform.dart +++ b/modules/angular2/src/transform/html_transform.dart @@ -1,4 +1,4 @@ -library angular2.transformer; +library angular2.src.transform; import 'dart:async'; import 'package:barback/barback.dart'; diff --git a/modules/angular2/src/transform/options.dart b/modules/angular2/src/transform/options.dart index eff1805679..5b51a3a847 100644 --- a/modules/angular2/src/transform/options.dart +++ b/modules/angular2/src/transform/options.dart @@ -1,4 +1,4 @@ -library angular2.transformer; +library angular2.src.transform; import 'package:path/path.dart' as path; diff --git a/modules/angular2/src/transform/resolvers.dart b/modules/angular2/src/transform/resolvers.dart index b6edb49727..7f23d606ad 100644 --- a/modules/angular2/src/transform/resolvers.dart +++ b/modules/angular2/src/transform/resolvers.dart @@ -1,3 +1,5 @@ +library angular2.src.transform; + import 'package:code_transformers/resolver.dart'; Resolvers createResolvers() { diff --git a/modules/angular2/src/transform/transformer.dart b/modules/angular2/src/transform/transformer.dart index 9199b08f81..10a1d49b6e 100644 --- a/modules/angular2/src/transform/transformer.dart +++ b/modules/angular2/src/transform/transformer.dart @@ -1,7 +1,4 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. -library angular2.transformer; +library angular2.src.transform; import 'dart:async'; import 'package:barback/barback.dart'; @@ -60,9 +57,12 @@ class AngularTransformer extends Transformer { .error('New entry point file $newEntryPointId already exists.'); } else { return _resolvers.get(transform).then((resolver) { - new _BootstrapFileBuilder(resolver, transform, - transform.primaryInput.id, newEntryPointId).run(); - resolver.release(); + try { + new _BootstrapFileBuilder(resolver, transform, + transform.primaryInput.id, newEntryPointId).run(); + } finally { + resolver.release(); + } }); } }); @@ -93,7 +93,7 @@ class _BootstrapFileBuilder { new ImportTraversal(_directiveInfo).traverse(entryLib); var context = new codegen.Context(logger: _transform.logger); - _directiveInfo.initQueue + _directiveInfo.matchQueue .forEach((entry) => context.directiveRegistry.register(entry)); _transform.addOutput(new Asset.fromString(_newEntryPoint, codegen diff --git a/modules/angular2/src/transform/traversal.dart b/modules/angular2/src/transform/traversal.dart index f727b16770..e762ae1ff5 100644 --- a/modules/angular2/src/transform/traversal.dart +++ b/modules/angular2/src/transform/traversal.dart @@ -1,3 +1,5 @@ +library angular2.src.transform; + import 'package:analyzer/src/generated/element.dart'; import 'package:path/path.dart' as path; diff --git a/modules/angular2/test/transform/common.dart b/modules/angular2/test/transform/common.dart index 77e3f98d53..f6a8e7de90 100644 --- a/modules/angular2/test/transform/common.dart +++ b/modules/angular2/test/transform/common.dart @@ -1,7 +1,7 @@ // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -library initialize.test.build.common; +library angular2.test.transform; // TODO(kegluneq): Remove this and use the actual Directive def'n. // Simple mock of Directive. diff --git a/modules/angular2/test/transform/transform_test.dart b/modules/angular2/test/transform/transform_test.dart index 5405d4f357..9725606180 100644 --- a/modules/angular2/test/transform/transform_test.dart +++ b/modules/angular2/test/transform/transform_test.dart @@ -1,4 +1,4 @@ -library angular2.test; +library angular2.test.transform; import 'dart:io'; import 'package:barback/barback.dart';