feat(dart/transform) Remove import of dart:mirrors
+ Precede the call to `new ReflectionCapabilities()` with our generated code which populates the reflection map statically. + Add the import of our generated code. + Once we are generating all necessary code, we will remove the import of reflection_capabilities.dart and the instantiation of `ReflectionCapabilities`, cutting the dependency on dart:mirrors. Closes #761
This commit is contained in:
@ -9,7 +9,7 @@ import 'package:code_transformers/resolver.dart';
|
||||
import 'annotation_processor.dart';
|
||||
import 'codegen.dart' as codegen;
|
||||
import 'find_bootstrap.dart';
|
||||
import 'html_transform.dart';
|
||||
import 'find_reflection_capabilities.dart';
|
||||
import 'logging.dart' as log;
|
||||
import 'options.dart';
|
||||
import 'resolvers.dart';
|
||||
@ -25,61 +25,72 @@ class AngularTransformer extends Transformer {
|
||||
|
||||
AngularTransformer(this.options) : _resolvers = createResolvers();
|
||||
|
||||
static const _bootstrapEntryPointParam = 'bootstrap_entry_point';
|
||||
static const _entryPointParam = 'entry_point';
|
||||
static const _newEntryPointParam = 'new_entry_point';
|
||||
static const _htmlEntryPointParam = 'html_entry_point';
|
||||
|
||||
factory AngularTransformer.asPlugin(BarbackSettings settings) {
|
||||
var bootstrapEntryPoint = settings.configuration[_bootstrapEntryPointParam];
|
||||
var entryPoint = settings.configuration[_entryPointParam];
|
||||
var newEntryPoint = settings.configuration[_newEntryPointParam];
|
||||
if (newEntryPoint == null) {
|
||||
newEntryPoint = entryPoint.replaceFirst('.dart', '.bootstrap.dart');
|
||||
}
|
||||
var htmlEntryPoint = settings.configuration[_htmlEntryPointParam];
|
||||
var config = settings.configuration;
|
||||
return new AngularTransformer(new TransformerOptions(
|
||||
bootstrapEntryPoint, entryPoint, newEntryPoint, htmlEntryPoint));
|
||||
config[entryPointParam],
|
||||
reflectionEntryPoint: config[reflectionEntryPointParam],
|
||||
newEntryPoint: config[newEntryPointParam]));
|
||||
}
|
||||
|
||||
bool isPrimary(AssetId id) =>
|
||||
options.entryPoint == id.path || options.htmlEntryPoint == id.path;
|
||||
bool isPrimary(AssetId id) => options.reflectionEntryPoint == id.path;
|
||||
|
||||
Future apply(Transform transform) {
|
||||
log.init(transform);
|
||||
|
||||
if (transform.primaryInput.id.path == options.entryPoint) {
|
||||
return _buildBootstrapFile(transform);
|
||||
} else if (transform.primaryInput.id.path == options.htmlEntryPoint) {
|
||||
return transformHtmlEntryPoint(options, transform);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future _buildBootstrapFile(Transform transform) {
|
||||
var bootstrapEntryPointId = new AssetId(
|
||||
transform.primaryInput.id.package, options.bootstrapEntryPoint);
|
||||
var entryPointId =
|
||||
new AssetId(transform.primaryInput.id.package, options.entryPoint);
|
||||
var reflectionEntryPointId = new AssetId(
|
||||
transform.primaryInput.id.package, options.reflectionEntryPoint);
|
||||
var newEntryPointId =
|
||||
new AssetId(transform.primaryInput.id.package, options.newEntryPoint);
|
||||
return transform.hasInput(newEntryPointId).then((exists) {
|
||||
if (exists) {
|
||||
|
||||
var reflectionExists = transform.hasInput(reflectionEntryPointId);
|
||||
var newEntryPointExists = transform.hasInput(newEntryPointId);
|
||||
|
||||
Resolver myResolver;
|
||||
return Future
|
||||
.wait([reflectionExists, newEntryPointExists])
|
||||
.then((existsList) {
|
||||
if (!existsList[0]) {
|
||||
log.logger.error('Reflection entry point file '
|
||||
'${reflectionEntryPointId} does not exist.');
|
||||
} else if (existsList[1]) {
|
||||
log.logger
|
||||
.error('New entry point file $newEntryPointId already exists.');
|
||||
} else {
|
||||
return _resolvers.get(transform).then((resolver) {
|
||||
return _resolvers
|
||||
.get(transform, [entryPointId, reflectionEntryPointId])
|
||||
.then((resolver) {
|
||||
myResolver = resolver;
|
||||
try {
|
||||
new _BootstrapFileBuilder(resolver, transform,
|
||||
transform.primaryInput.id, bootstrapEntryPointId,
|
||||
newEntryPointId).run();
|
||||
String reflectionCapabilitiesCreation = findReflectionCapabilities(
|
||||
resolver, reflectionEntryPointId, newEntryPointId);
|
||||
|
||||
transform.addOutput(new Asset.fromString(
|
||||
reflectionEntryPointId, reflectionCapabilitiesCreation));
|
||||
// Find the call to `new ReflectionCapabilities()`
|
||||
// Generate new source.
|
||||
} catch (err, stackTrace) {
|
||||
log.logger.error('${err}: ${stackTrace}',
|
||||
asset: bootstrapEntryPointId);
|
||||
asset: reflectionEntryPointId);
|
||||
rethrow;
|
||||
}
|
||||
|
||||
try {
|
||||
new _BootstrapFileBuilder(
|
||||
resolver, transform, entryPointId, newEntryPointId).run();
|
||||
} catch (err, stackTrace) {
|
||||
log.logger.error('${err}: ${stackTrace}',
|
||||
asset: transform.primaryInput.id);
|
||||
rethrow;
|
||||
} finally {
|
||||
resolver.release();
|
||||
}
|
||||
});
|
||||
}
|
||||
}).whenComplete(() {
|
||||
if (myResolver != null) {
|
||||
myResolver.release();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -87,21 +98,18 @@ class AngularTransformer extends Transformer {
|
||||
class _BootstrapFileBuilder {
|
||||
final Resolver _resolver;
|
||||
final Transform _transform;
|
||||
final AssetId _bootstrapEntryPoint;
|
||||
final AssetId _entryPoint;
|
||||
final AssetId _newEntryPoint;
|
||||
|
||||
_BootstrapFileBuilder(Resolver resolver, Transform transform,
|
||||
this._entryPoint, this._bootstrapEntryPoint, this._newEntryPoint)
|
||||
this._entryPoint, this._newEntryPoint)
|
||||
: _resolver = resolver,
|
||||
_transform = transform;
|
||||
|
||||
/// Adds the new entry point file to the transform. Should only be ran once.
|
||||
void run() {
|
||||
var entryLib = _resolver.getLibrary(_entryPoint);
|
||||
|
||||
Set<BootstrapCallInfo> bootstrapCalls = findBootstrapCalls(
|
||||
_resolver, _resolver.getLibrary(_bootstrapEntryPoint));
|
||||
Set<BootstrapCallInfo> bootstrapCalls =
|
||||
findBootstrapCalls(_resolver, _resolver.getLibrary(_entryPoint));
|
||||
|
||||
log.logger.info('found ${bootstrapCalls.length} call(s) to `bootstrap`');
|
||||
bootstrapCalls.forEach((BootstrapCallInfo info) {
|
||||
@ -123,8 +131,7 @@ class _BootstrapFileBuilder {
|
||||
matcher.matchQueue
|
||||
.forEach((entry) => context.directiveRegistry.register(entry));
|
||||
|
||||
_transform.addOutput(new Asset.fromString(_newEntryPoint, codegen
|
||||
.codegenEntryPoint(context,
|
||||
entryPoint: entryLib, newEntryPoint: _newEntryPoint)));
|
||||
_transform.addOutput(new Asset.fromString(_newEntryPoint,
|
||||
codegen.codegenEntryPoint(context, newEntryPoint: _newEntryPoint)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user