| OLD | NEW |
| 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 engine.resolver.element_resolver; | 5 library engine.resolver.element_resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'ast.dart'; | 9 import 'ast.dart'; |
| 10 import 'element.dart'; | 10 import 'element.dart'; |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 } else { | 601 } else { |
| 602 staticType = _getStaticType(target); | 602 staticType = _getStaticType(target); |
| 603 propagatedType = _getPropagatedType(target); | 603 propagatedType = _getPropagatedType(target); |
| 604 // | 604 // |
| 605 // If this method invocation is of the form 'C.m' where 'C' is a class, | 605 // If this method invocation is of the form 'C.m' where 'C' is a class, |
| 606 // then we don't call resolveInvokedElement(...) which walks up the class | 606 // then we don't call resolveInvokedElement(...) which walks up the class |
| 607 // hierarchy, instead we just look for the member in the type only. This | 607 // hierarchy, instead we just look for the member in the type only. This |
| 608 // does not apply to conditional method invocation (i.e. 'C?.m(...)'). | 608 // does not apply to conditional method invocation (i.e. 'C?.m(...)'). |
| 609 // | 609 // |
| 610 bool isConditional = node.operator.type == sc.TokenType.QUESTION_PERIOD; | 610 bool isConditional = node.operator.type == sc.TokenType.QUESTION_PERIOD; |
| 611 ClassElementImpl typeReference = getTypeReference(target, isConditional); | 611 ClassElementImpl typeReference = getTypeReference(target); |
| 612 if (typeReference != null) { | 612 if (typeReference != null) { |
| 613 staticElement = | 613 staticElement = |
| 614 propagatedElement = _resolveElement(typeReference, methodName); | 614 propagatedElement = _resolveElement(typeReference, methodName); |
| 615 } else { | 615 } else { |
| 616 staticElement = _resolveInvokedElementWithTarget( | 616 staticElement = _resolveInvokedElementWithTarget( |
| 617 target, staticType, methodName, isConditional); | 617 target, staticType, methodName, isConditional); |
| 618 propagatedElement = _resolveInvokedElementWithTarget( | 618 propagatedElement = _resolveInvokedElementWithTarget( |
| 619 target, propagatedType, methodName, isConditional); | 619 target, propagatedType, methodName, isConditional); |
| 620 } | 620 } |
| 621 } | 621 } |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 } | 849 } |
| 850 // May be annotation, resolve invocation of "const" constructor. | 850 // May be annotation, resolve invocation of "const" constructor. |
| 851 if (node.parent is Annotation) { | 851 if (node.parent is Annotation) { |
| 852 Annotation annotation = node.parent as Annotation; | 852 Annotation annotation = node.parent as Annotation; |
| 853 _resolveAnnotationElement(annotation); | 853 _resolveAnnotationElement(annotation); |
| 854 } | 854 } |
| 855 // | 855 // |
| 856 // Otherwise, the prefix is really an expression that happens to be a simple | 856 // Otherwise, the prefix is really an expression that happens to be a simple |
| 857 // identifier and this is really equivalent to a property access node. | 857 // identifier and this is really equivalent to a property access node. |
| 858 // | 858 // |
| 859 _resolvePropertyAccess(prefix, identifier, false); | 859 _resolvePropertyAccess(prefix, identifier); |
| 860 return null; | 860 return null; |
| 861 } | 861 } |
| 862 | 862 |
| 863 @override | 863 @override |
| 864 Object visitPrefixExpression(PrefixExpression node) { | 864 Object visitPrefixExpression(PrefixExpression node) { |
| 865 sc.Token operator = node.operator; | 865 sc.Token operator = node.operator; |
| 866 sc.TokenType operatorType = operator.type; | 866 sc.TokenType operatorType = operator.type; |
| 867 if (operatorType.isUserDefinableOperator || | 867 if (operatorType.isUserDefinableOperator || |
| 868 operatorType == sc.TokenType.PLUS_PLUS || | 868 operatorType == sc.TokenType.PLUS_PLUS || |
| 869 operatorType == sc.TokenType.MINUS_MINUS) { | 869 operatorType == sc.TokenType.MINUS_MINUS) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 return null; | 905 return null; |
| 906 } | 906 } |
| 907 | 907 |
| 908 @override | 908 @override |
| 909 Object visitPropertyAccess(PropertyAccess node) { | 909 Object visitPropertyAccess(PropertyAccess node) { |
| 910 Expression target = node.realTarget; | 910 Expression target = node.realTarget; |
| 911 if (target is SuperExpression && !_isSuperInValidContext(target)) { | 911 if (target is SuperExpression && !_isSuperInValidContext(target)) { |
| 912 return null; | 912 return null; |
| 913 } | 913 } |
| 914 SimpleIdentifier propertyName = node.propertyName; | 914 SimpleIdentifier propertyName = node.propertyName; |
| 915 _resolvePropertyAccess(target, propertyName, | 915 _resolvePropertyAccess(target, propertyName); |
| 916 node.operator.type == sc.TokenType.QUESTION_PERIOD); | |
| 917 return null; | 916 return null; |
| 918 } | 917 } |
| 919 | 918 |
| 920 @override | 919 @override |
| 921 Object visitRedirectingConstructorInvocation( | 920 Object visitRedirectingConstructorInvocation( |
| 922 RedirectingConstructorInvocation node) { | 921 RedirectingConstructorInvocation node) { |
| 923 ClassElement enclosingClass = _resolver.enclosingClass; | 922 ClassElement enclosingClass = _resolver.enclosingClass; |
| 924 if (enclosingClass == null) { | 923 if (enclosingClass == null) { |
| 925 // TODO(brianwilkerson) Report this error. | 924 // TODO(brianwilkerson) Report this error. |
| 926 return null; | 925 return null; |
| (...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2409 if (memberElement == null) { | 2408 if (memberElement == null) { |
| 2410 memberElement = _lookUpGetter(target, targetType, propertyName.name); | 2409 memberElement = _lookUpGetter(target, targetType, propertyName.name); |
| 2411 } | 2410 } |
| 2412 if (memberElement == null) { | 2411 if (memberElement == null) { |
| 2413 memberElement = _lookUpMethod(target, targetType, propertyName.name); | 2412 memberElement = _lookUpMethod(target, targetType, propertyName.name); |
| 2414 } | 2413 } |
| 2415 return memberElement; | 2414 return memberElement; |
| 2416 } | 2415 } |
| 2417 | 2416 |
| 2418 void _resolvePropertyAccess( | 2417 void _resolvePropertyAccess( |
| 2419 Expression target, SimpleIdentifier propertyName, bool isConditional) { | 2418 Expression target, SimpleIdentifier propertyName) { |
| 2420 DartType staticType = _getStaticType(target); | 2419 DartType staticType = _getStaticType(target); |
| 2421 DartType propagatedType = _getPropagatedType(target); | 2420 DartType propagatedType = _getPropagatedType(target); |
| 2422 Element staticElement = null; | 2421 Element staticElement = null; |
| 2423 Element propagatedElement = null; | 2422 Element propagatedElement = null; |
| 2424 // | 2423 // |
| 2425 // If this property access is of the form 'C.m' where 'C' is a class, | 2424 // If this property access is of the form 'C.m' where 'C' is a class, |
| 2426 // then we don't call resolveProperty(...) which walks up the class | 2425 // then we don't call resolveProperty(...) which walks up the class |
| 2427 // hierarchy, instead we just look for the member in the type only. This | 2426 // hierarchy, instead we just look for the member in the type only. This |
| 2428 // does not apply to conditional property accesses (i.e. 'C?.m'). | 2427 // does not apply to conditional property accesses (i.e. 'C?.m'). |
| 2429 // | 2428 // |
| 2430 ClassElementImpl typeReference = getTypeReference(target, isConditional); | 2429 ClassElementImpl typeReference = getTypeReference(target); |
| 2431 if (typeReference != null) { | 2430 if (typeReference != null) { |
| 2432 // TODO(brianwilkerson) Why are we setting the propagated element here? | 2431 // TODO(brianwilkerson) Why are we setting the propagated element here? |
| 2433 // It looks wrong. | 2432 // It looks wrong. |
| 2434 staticElement = | 2433 staticElement = |
| 2435 propagatedElement = _resolveElement(typeReference, propertyName); | 2434 propagatedElement = _resolveElement(typeReference, propertyName); |
| 2436 } else { | 2435 } else { |
| 2437 staticElement = _resolveProperty(target, staticType, propertyName); | 2436 staticElement = _resolveProperty(target, staticType, propertyName); |
| 2438 propagatedElement = | 2437 propagatedElement = |
| 2439 _resolveProperty(target, propagatedType, propertyName); | 2438 _resolveProperty(target, propagatedType, propertyName); |
| 2440 } | 2439 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2633 bool _shouldReportMissingMember(DartType type, Element member) { | 2632 bool _shouldReportMissingMember(DartType type, Element member) { |
| 2634 if (member != null || type == null || type.isDynamic || type.isBottom) { | 2633 if (member != null || type == null || type.isDynamic || type.isBottom) { |
| 2635 return false; | 2634 return false; |
| 2636 } | 2635 } |
| 2637 return true; | 2636 return true; |
| 2638 } | 2637 } |
| 2639 | 2638 |
| 2640 /** | 2639 /** |
| 2641 * Checks whether the given [expression] is a reference to a class. If it is | 2640 * Checks whether the given [expression] is a reference to a class. If it is |
| 2642 * then the element representing the class is returned, otherwise `null` is | 2641 * then the element representing the class is returned, otherwise `null` is |
| 2643 * returned. [isConditional] indicates whether [expression] is to the left | 2642 * returned. |
| 2644 * of a '?.' opertator. | |
| 2645 */ | 2643 */ |
| 2646 static ClassElementImpl getTypeReference( | 2644 static ClassElementImpl getTypeReference(Expression expression) { |
| 2647 Expression expression, bool isConditional) { | 2645 if (expression is Identifier) { |
| 2648 if (!isConditional && expression is Identifier) { | |
| 2649 Element staticElement = expression.staticElement; | 2646 Element staticElement = expression.staticElement; |
| 2650 if (staticElement is ClassElementImpl) { | 2647 if (staticElement is ClassElementImpl) { |
| 2651 return staticElement; | 2648 return staticElement; |
| 2652 } | 2649 } |
| 2653 } | 2650 } |
| 2654 return null; | 2651 return null; |
| 2655 } | 2652 } |
| 2656 | 2653 |
| 2657 /** | 2654 /** |
| 2658 * Given a [node] that can have annotations associated with it and the | 2655 * Given a [node] that can have annotations associated with it and the |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2803 | 2800 |
| 2804 @override | 2801 @override |
| 2805 Element get staticElement => null; | 2802 Element get staticElement => null; |
| 2806 | 2803 |
| 2807 @override | 2804 @override |
| 2808 accept(AstVisitor visitor) => null; | 2805 accept(AstVisitor visitor) => null; |
| 2809 | 2806 |
| 2810 @override | 2807 @override |
| 2811 void visitChildren(AstVisitor visitor) {} | 2808 void visitChildren(AstVisitor visitor) {} |
| 2812 } | 2809 } |
| OLD | NEW |