2015-03-20 15:37:09 -07:00
|
|
|
library angular2.transform.reflection_remover.codegen;
|
2015-02-27 14:42:21 -08:00
|
|
|
|
|
|
|
|
import 'package:path/path.dart' as path;
|
|
|
|
|
|
|
|
|
|
import 'package:angular2/src/transform/common/names.dart';
|
|
|
|
|
|
|
|
|
|
class Codegen {
|
|
|
|
|
static const _PREFIX_BASE = 'ngStaticInit';
|
|
|
|
|
|
|
|
|
|
/// The prefix used to import our generated file.
|
|
|
|
|
final String prefix;
|
2015-04-09 17:49:11 -07:00
|
|
|
/// The import uris
|
|
|
|
|
final Iterable<String> importUris;
|
2015-02-27 14:42:21 -08:00
|
|
|
|
2015-04-09 17:49:11 -07:00
|
|
|
Codegen(String reflectionEntryPointPath, Iterable<String> newEntryPointPaths,
|
2015-02-27 14:42:21 -08:00
|
|
|
{String prefix})
|
|
|
|
|
: this.prefix = prefix == null ? _PREFIX_BASE : prefix,
|
2015-07-01 13:20:12 -07:00
|
|
|
importUris = newEntryPointPaths.map((p) => path
|
|
|
|
|
.relative(p, from: path.dirname(reflectionEntryPointPath))
|
|
|
|
|
.replaceAll('\\', '/')) {
|
2015-02-27 14:42:21 -08:00
|
|
|
if (this.prefix.isEmpty) throw new ArgumentError.value('(empty)', 'prefix');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Generates code to import the library containing the method which sets up
|
|
|
|
|
/// Angular2 reflection statically.
|
|
|
|
|
///
|
|
|
|
|
/// The code generated here should follow the example of code generated for
|
2015-04-17 13:01:07 -07:00
|
|
|
/// an {@link ImportDirective} node.
|
2015-02-27 14:42:21 -08:00
|
|
|
String codegenImport() {
|
2015-04-09 17:49:11 -07:00
|
|
|
var count = 0;
|
|
|
|
|
return importUris
|
|
|
|
|
.map((importUri) => 'import \'${importUri}\' as ${prefix}${count++};')
|
|
|
|
|
.join('');
|
2015-02-27 14:42:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Generates code to call the method which sets up Angular2 reflection
|
|
|
|
|
/// statically.
|
2015-07-22 10:18:04 -07:00
|
|
|
String codegenSetupReflectionCall() {
|
2015-04-09 17:49:11 -07:00
|
|
|
var count = 0;
|
|
|
|
|
return importUris
|
2015-07-15 23:15:44 -07:00
|
|
|
.map((_) => '${prefix}${count++}.${SETUP_METHOD_NAME}();')
|
2015-04-09 17:49:11 -07:00
|
|
|
.join('');
|
2015-02-27 14:42:21 -08:00
|
|
|
}
|
|
|
|
|
}
|