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

Unified Diff: lib/src/utils.dart

Issue 1100633006: Generate static calls for Object fields and methods (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Better static dispatch check Created 5 years, 8 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: lib/src/utils.dart
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 5bafdb3db1e9dff0c50c72223955f98f6d598246..a3ea4fd10473e7e0ae5de4487e950caa7ca86071 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -397,3 +397,30 @@ bool inInvocationContext(SimpleIdentifier node) {
var parent = node.parent;
return parent is MethodInvocation && parent.methodName == node;
}
+
+// TODO(vsm): Move this onto the appropriate class. Ideally, we'd attach
+// it to TypeProvider.
+
+final _objectMap = new Expando('providerToObjectMap');
+Map<String, DartType> getObjectMemberMap(TypeProvider typeProvider) {
+ Map<String, DartType> map = _objectMap[typeProvider];
+ if (map == null) {
+ map = <String, DartType>{};
+ _objectMap[typeProvider] = map;
+ var objectType = typeProvider.objectType;
+ var element = objectType.element;
+ // Only record methods (including getters) with no parameters. As parameters are contravariant wrt
+ // type, using Object's version may be too strict.
+ // Add instance methods.
+ element.methods.where((method) => !method.isStatic).forEach((method) {
+ map[method.name] = method.type;
+ });
+ // Add getters.
+ element.accessors
+ .where((member) => !member.isStatic && member.isGetter)
+ .forEach((member) {
+ map[member.name] = member.type.returnType;
+ });
+ }
+ return map;
+}

Powered by Google App Engine
This is Rietveld 408576698