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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 2252183002: Fix calling object methods and properties on function types (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix calling object methods and properties on function types Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library analyzer.src.generated.resolver; 5 library analyzer.src.generated.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 9595 matching lines...) Expand 10 before | Expand all | Expand 10 after
9606 9606
9607 /** 9607 /**
9608 * Return the type representing the built-in type 'Type'. 9608 * Return the type representing the built-in type 'Type'.
9609 */ 9609 */
9610 InterfaceType get typeType; 9610 InterfaceType get typeType;
9611 9611
9612 /** 9612 /**
9613 * Return the type representing typenames that can't be resolved. 9613 * Return the type representing typenames that can't be resolved.
9614 */ 9614 */
9615 DartType get undefinedType; 9615 DartType get undefinedType;
9616
9617 /**
9618 * Return 'true' if [id] is the name of a getter on
9619 * the Object type.
9620 */
9621 bool isObjectGetter(SimpleIdentifier id);
Jennifer Messerly 2016/08/17 21:26:24 maybe pass in the String name here? it seems like
Leaf 2016/08/17 22:07:05 Done.
9622
9623 /**
9624 * Return 'true' if [id] is the name of a method on
9625 * the Object type.
9626 */
9627 bool isObjectMethod(SimpleIdentifier id);
9628
9629 /**
9630 * Return 'true' if [id] is the name of a method or getter on
9631 * the Object type.
9632 */
9633 bool isObjectProperty(SimpleIdentifier id);
Brian Wilkerson 2016/08/17 21:24:15 I think the analyzer code is generally fairly cons
Leaf 2016/08/17 22:07:05 Done.
9634 }
9635
9636 /**
9637 * Provide common functionality shared by the various TypeProvider
9638 * implementations
Jennifer Messerly 2016/08/17 21:26:24 nit: should end with period
Leaf 2016/08/17 22:07:05 Done.
9639 */
9640 abstract class TypeProviderBaseMixin {
9641 InterfaceType get boolType;
Brian Wilkerson 2016/08/17 21:24:15 Should this just implement TypeProvider (rather th
Leaf 2016/08/17 22:07:05 Nice. Didn't realize you could do this, much bett
9642 InterfaceType get doubleType;
9643 InterfaceType get intType;
9644 List<InterfaceType> get nonSubtypableTypes => <InterfaceType>[
9645 nullType,
9646 numType,
9647 intType,
9648 doubleType,
9649 boolType,
9650 stringType
9651 ];
9652 InterfaceType get nullType;
9653 InterfaceType get numType;
9654 InterfaceType get objectType;
9655 InterfaceType get stringType;
9656
9657 bool isObjectGetter(SimpleIdentifier id) {
9658 PropertyAccessorElement element = objectType.element.getGetter(id.name);
9659 return (element != null && !element.isStatic);
9660 }
9661
9662 bool isObjectMethod(SimpleIdentifier id) {
9663 MethodElement element = objectType.element.getMethod(id.name);
9664 return (element != null && !element.isStatic);
9665 }
9666
9667 bool isObjectProperty(SimpleIdentifier id) {
9668 return isObjectGetter(id) || isObjectMethod(id);
9669 }
9616 } 9670 }
9617 9671
9618 /** 9672 /**
9619 * Instances of the class `TypeProviderImpl` provide access to types defined by the language 9673 * Instances of the class `TypeProviderImpl` provide access to types defined by the language
9620 * by looking for those types in the element model for the core library. 9674 * by looking for those types in the element model for the core library.
9621 */ 9675 */
9622 class TypeProviderImpl implements TypeProvider { 9676 class TypeProviderImpl extends Object
9677 with TypeProviderBaseMixin
Jennifer Messerly 2016/08/17 21:26:24 in current Dart, this is equivalent to "extends Ty
Leaf 2016/08/17 22:07:05 Done.
9678 implements TypeProvider {
9623 /** 9679 /**
9624 * The type representing the built-in type 'bool'. 9680 * The type representing the built-in type 'bool'.
9625 */ 9681 */
9626 InterfaceType _boolType; 9682 InterfaceType _boolType;
9627 9683
9628 /** 9684 /**
9629 * The type representing the type 'bottom'. 9685 * The type representing the type 'bottom'.
9630 */ 9686 */
9631 DartType _bottomType; 9687 DartType _bottomType;
9632 9688
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
9802 @override 9858 @override
9803 InterfaceType get iterableType => _iterableType; 9859 InterfaceType get iterableType => _iterableType;
9804 9860
9805 @override 9861 @override
9806 InterfaceType get listType => _listType; 9862 InterfaceType get listType => _listType;
9807 9863
9808 @override 9864 @override
9809 InterfaceType get mapType => _mapType; 9865 InterfaceType get mapType => _mapType;
9810 9866
9811 @override 9867 @override
9812 List<InterfaceType> get nonSubtypableTypes => <InterfaceType>[
9813 nullType,
9814 numType,
9815 intType,
9816 doubleType,
9817 boolType,
9818 stringType
9819 ];
9820
9821 @override
9822 DartObjectImpl get nullObject { 9868 DartObjectImpl get nullObject {
9823 if (_nullObject == null) { 9869 if (_nullObject == null) {
9824 _nullObject = new DartObjectImpl(nullType, NullState.NULL_STATE); 9870 _nullObject = new DartObjectImpl(nullType, NullState.NULL_STATE);
9825 } 9871 }
9826 return _nullObject; 9872 return _nullObject;
9827 } 9873 }
9828 9874
9829 @override 9875 @override
9830 InterfaceType get nullType => _nullType; 9876 InterfaceType get nullType => _nullType;
9831 9877
(...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after
11104 return null; 11150 return null;
11105 } 11151 }
11106 if (identical(node.staticElement, variable)) { 11152 if (identical(node.staticElement, variable)) {
11107 if (node.inSetterContext()) { 11153 if (node.inSetterContext()) {
11108 result = true; 11154 result = true;
11109 } 11155 }
11110 } 11156 }
11111 return null; 11157 return null;
11112 } 11158 }
11113 } 11159 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/element_resolver.dart ('k') | pkg/analyzer/lib/src/generated/testing/test_type_provider.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698