2015-03-20 15:37:09 -07:00
|
|
|
library angular2.transform.reflection_remover.ast_tester;
|
2015-02-27 14:42:21 -08:00
|
|
|
|
|
|
|
import 'package:analyzer/src/generated/ast.dart';
|
|
|
|
import 'package:analyzer/src/generated/element.dart';
|
2015-04-13 16:54:09 -07:00
|
|
|
import 'package:angular2/src/transform/common/names.dart';
|
2015-02-27 14:42:21 -08:00
|
|
|
|
2015-04-17 13:01:07 -07:00
|
|
|
/// An object that checks for {@link ReflectionCapabilities} syntactically, that is,
|
2015-02-27 14:42:21 -08:00
|
|
|
/// without resolution information.
|
|
|
|
class AstTester {
|
|
|
|
const AstTester();
|
|
|
|
|
|
|
|
bool isNewReflectionCapabilities(InstanceCreationExpression node) =>
|
|
|
|
'${node.constructorName.type.name}' == REFLECTION_CAPABILITIES_NAME;
|
|
|
|
|
|
|
|
bool isReflectionCapabilitiesImport(ImportDirective node) {
|
|
|
|
return node.uri.stringValue.endsWith("reflection_capabilities.dart");
|
|
|
|
}
|
2015-07-22 10:18:04 -07:00
|
|
|
|
|
|
|
bool isBootstrapImport(ImportDirective node) {
|
|
|
|
return node.uri.stringValue.endsWith("/bootstrap.dart");
|
|
|
|
}
|
2015-02-27 14:42:21 -08:00
|
|
|
}
|
|
|
|
|
2015-04-17 13:01:07 -07:00
|
|
|
/// An object that checks for {@link ReflectionCapabilities} using a fully resolved
|
2015-02-27 14:42:21 -08:00
|
|
|
/// Ast.
|
|
|
|
class ResolvedTester implements AstTester {
|
|
|
|
final ClassElement _forbiddenClass;
|
|
|
|
|
|
|
|
ResolvedTester(this._forbiddenClass);
|
|
|
|
|
|
|
|
bool isNewReflectionCapabilities(InstanceCreationExpression node) {
|
|
|
|
var typeElement = node.constructorName.type.name.bestElement;
|
|
|
|
return typeElement != null && typeElement == _forbiddenClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isReflectionCapabilitiesImport(ImportDirective node) {
|
|
|
|
return node.uriElement == _forbiddenClass.library;
|
|
|
|
}
|
2015-07-22 10:18:04 -07:00
|
|
|
|
|
|
|
bool isBootstrapImport(ImportDirective node) {
|
|
|
|
throw 'Not implemented';
|
|
|
|
}
|
2015-02-27 14:42:21 -08:00
|
|
|
}
|