| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Holds a couple utility functions used at various places in the system. | 5 /// Holds a couple utility functions used at various places in the system. |
| 6 library dev_compiler.src.utils; | 6 library dev_compiler.src.utils; |
| 7 | 7 |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 InterfaceType fillDynamicTypeArgs(InterfaceType t, TypeProvider types) => | 390 InterfaceType fillDynamicTypeArgs(InterfaceType t, TypeProvider types) => |
| 391 t.substitute4(new List.filled(t.typeArguments.length, types.dynamicType)); | 391 t.substitute4(new List.filled(t.typeArguments.length, types.dynamicType)); |
| 392 | 392 |
| 393 /// Similar to [SimpleIdentifier] inGetterContext, inSetterContext, and | 393 /// Similar to [SimpleIdentifier] inGetterContext, inSetterContext, and |
| 394 /// inDeclarationContext, this method returns true if [node] is used in an | 394 /// inDeclarationContext, this method returns true if [node] is used in an |
| 395 /// invocation context such as a MethodInvocation. | 395 /// invocation context such as a MethodInvocation. |
| 396 bool inInvocationContext(SimpleIdentifier node) { | 396 bool inInvocationContext(SimpleIdentifier node) { |
| 397 var parent = node.parent; | 397 var parent = node.parent; |
| 398 return parent is MethodInvocation && parent.methodName == node; | 398 return parent is MethodInvocation && parent.methodName == node; |
| 399 } | 399 } |
| 400 |
| 401 // TODO(vsm): Move this onto the appropriate class. Ideally, we'd attach |
| 402 // it to TypeProvider. |
| 403 |
| 404 final _objectMap = new Expando('providerToObjectMap'); |
| 405 Map<String, DartType> getObjectMemberMap(TypeProvider typeProvider) { |
| 406 Map<String, DartType> map = _objectMap[typeProvider]; |
| 407 if (map == null) { |
| 408 map = <String, DartType>{}; |
| 409 _objectMap[typeProvider] = map; |
| 410 var objectType = typeProvider.objectType; |
| 411 var element = objectType.element; |
| 412 // Only record methods (including getters) with no parameters. As parameter
s are contravariant wrt |
| 413 // type, using Object's version may be too strict. |
| 414 // Add instance methods. |
| 415 element.methods.where((method) => !method.isStatic).forEach((method) { |
| 416 map[method.name] = method.type; |
| 417 }); |
| 418 // Add getters. |
| 419 element.accessors |
| 420 .where((member) => !member.isStatic && member.isGetter) |
| 421 .forEach((member) { |
| 422 map[member.name] = member.type.returnType; |
| 423 }); |
| 424 } |
| 425 return map; |
| 426 } |
| OLD | NEW |