Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1189)

Unified Diff: modules/angular2/src/transform/codegen.dart

Issue 927373004: Initial commit of Dart transformer to generate constructor stubs, see https://github.com/angular/an… (Closed) Base URL: https://github.com/kegluneq/angular.git@master
Patch Set: Fixing review comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: modules/angular2/src/transform/codegen.dart
diff --git a/modules/angular2/src/transform/codegen.dart b/modules/angular2/src/transform/codegen.dart
index 399cc277017da693ad771bd0e2966ca75028941a..1fcbd8f7545a8c4c070fe3f4b2eb6dc32a66e827 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<LibraryElement, String> _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);
« no previous file with comments | « modules/angular2/src/transform/annotation_processor.dart ('k') | modules/angular2/src/transform/html_transform.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698