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

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

Issue 1062723002: Implement the new '?.' operator in analyzer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Bump analyzer version. 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 unified diff | Download patch | Annotate | Revision Log
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 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 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } else if (methodName.name == FunctionElement.LOAD_LIBRARY_NAME && 586 } else if (methodName.name == FunctionElement.LOAD_LIBRARY_NAME &&
587 _isDeferredPrefix(target)) { 587 _isDeferredPrefix(target)) {
588 LibraryElement importedLibrary = _getImportedLibrary(target); 588 LibraryElement importedLibrary = _getImportedLibrary(target);
589 methodName.staticElement = importedLibrary.loadLibraryFunction; 589 methodName.staticElement = importedLibrary.loadLibraryFunction;
590 return null; 590 return null;
591 } else { 591 } else {
592 staticType = _getStaticType(target); 592 staticType = _getStaticType(target);
593 propagatedType = _getPropagatedType(target); 593 propagatedType = _getPropagatedType(target);
594 // 594 //
595 // If this method invocation is of the form 'C.m' where 'C' is a class, 595 // If this method invocation is of the form 'C.m' where 'C' is a class,
596 // then we don't call resolveInvokedElement(..) which walks up the class 596 // then we don't call resolveInvokedElement(..) which walks up the class
Brian Wilkerson 2015/04/05 19:55:45 ".." --> "..."
Paul Berry 2015/04/05 20:49:43 Done.
597 // hierarchy, instead we just look for the member in the type only. 597 // hierarchy, instead we just look for the member in the type only. This
598 // does not apply to conditional method invocation (i.e. 'C?.m(...)').
598 // 599 //
599 ClassElementImpl typeReference = getTypeReference(target); 600 bool isConditional = node.operator.type == sc.TokenType.QUESTION_PERIOD;
601 ClassElementImpl typeReference = getTypeReference(target, isConditional);
600 if (typeReference != null) { 602 if (typeReference != null) {
601 staticElement = 603 staticElement =
602 propagatedElement = _resolveElement(typeReference, methodName); 604 propagatedElement = _resolveElement(typeReference, methodName);
603 } else { 605 } else {
604 staticElement = 606 staticElement =
605 _resolveInvokedElementWithTarget(target, staticType, methodName); 607 _resolveInvokedElementWithTarget(target, staticType, methodName);
606 propagatedElement = _resolveInvokedElementWithTarget( 608 propagatedElement = _resolveInvokedElementWithTarget(
607 target, propagatedType, methodName); 609 target, propagatedType, methodName);
608 } 610 }
609 } 611 }
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 } 850 }
849 // May be annotation, resolve invocation of "const" constructor. 851 // May be annotation, resolve invocation of "const" constructor.
850 if (node.parent is Annotation) { 852 if (node.parent is Annotation) {
851 Annotation annotation = node.parent as Annotation; 853 Annotation annotation = node.parent as Annotation;
852 _resolveAnnotationElement(annotation); 854 _resolveAnnotationElement(annotation);
853 } 855 }
854 // 856 //
855 // Otherwise, the prefix is really an expression that happens to be a simple 857 // Otherwise, the prefix is really an expression that happens to be a simple
856 // identifier and this is really equivalent to a property access node. 858 // identifier and this is really equivalent to a property access node.
857 // 859 //
858 _resolvePropertyAccess(prefix, identifier); 860 _resolvePropertyAccess(prefix, identifier, false);
859 return null; 861 return null;
860 } 862 }
861 863
862 @override 864 @override
863 Object visitPrefixExpression(PrefixExpression node) { 865 Object visitPrefixExpression(PrefixExpression node) {
864 sc.Token operator = node.operator; 866 sc.Token operator = node.operator;
865 sc.TokenType operatorType = operator.type; 867 sc.TokenType operatorType = operator.type;
866 if (operatorType.isUserDefinableOperator || 868 if (operatorType.isUserDefinableOperator ||
867 operatorType == sc.TokenType.PLUS_PLUS || 869 operatorType == sc.TokenType.PLUS_PLUS ||
868 operatorType == sc.TokenType.MINUS_MINUS) { 870 operatorType == sc.TokenType.MINUS_MINUS) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 return null; 906 return null;
905 } 907 }
906 908
907 @override 909 @override
908 Object visitPropertyAccess(PropertyAccess node) { 910 Object visitPropertyAccess(PropertyAccess node) {
909 Expression target = node.realTarget; 911 Expression target = node.realTarget;
910 if (target is SuperExpression && !_isSuperInValidContext(target)) { 912 if (target is SuperExpression && !_isSuperInValidContext(target)) {
911 return null; 913 return null;
912 } 914 }
913 SimpleIdentifier propertyName = node.propertyName; 915 SimpleIdentifier propertyName = node.propertyName;
914 _resolvePropertyAccess(target, propertyName); 916 _resolvePropertyAccess(target, propertyName,
917 node.operator.type == sc.TokenType.QUESTION_PERIOD);
915 return null; 918 return null;
916 } 919 }
917 920
918 @override 921 @override
919 Object visitRedirectingConstructorInvocation( 922 Object visitRedirectingConstructorInvocation(
920 RedirectingConstructorInvocation node) { 923 RedirectingConstructorInvocation node) {
921 ClassElement enclosingClass = _resolver.enclosingClass; 924 ClassElement enclosingClass = _resolver.enclosingClass;
922 if (enclosingClass == null) { 925 if (enclosingClass == null) {
923 // TODO(brianwilkerson) Report this error. 926 // TODO(brianwilkerson) Report this error.
924 return null; 927 return null;
(...skipping 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after
2436 if (memberElement == null) { 2439 if (memberElement == null) {
2437 memberElement = _lookUpGetter(target, targetType, propertyName.name); 2440 memberElement = _lookUpGetter(target, targetType, propertyName.name);
2438 } 2441 }
2439 if (memberElement == null) { 2442 if (memberElement == null) {
2440 memberElement = _lookUpMethod(target, targetType, propertyName.name); 2443 memberElement = _lookUpMethod(target, targetType, propertyName.name);
2441 } 2444 }
2442 return memberElement; 2445 return memberElement;
2443 } 2446 }
2444 2447
2445 void _resolvePropertyAccess( 2448 void _resolvePropertyAccess(
2446 Expression target, SimpleIdentifier propertyName) { 2449 Expression target, SimpleIdentifier propertyName, bool isConditional) {
2447 DartType staticType = _getStaticType(target); 2450 DartType staticType = _getStaticType(target);
2448 DartType propagatedType = _getPropagatedType(target); 2451 DartType propagatedType = _getPropagatedType(target);
2449 Element staticElement = null; 2452 Element staticElement = null;
2450 Element propagatedElement = null; 2453 Element propagatedElement = null;
2451 // 2454 //
2452 // If this property access is of the form 'C.m' where 'C' is a class, 2455 // If this property access is of the form 'C.m' where 'C' is a class,
2453 // then we don't call resolveProperty(..) which walks up the class 2456 // then we don't call resolveProperty(..) which walks up the class
Brian Wilkerson 2015/04/05 19:55:45 ".." --> "..."
Paul Berry 2015/04/05 20:49:43 Done.
2454 // hierarchy, instead we just look for the member in the type only. 2457 // hierarchy, instead we just look for the member in the type only. This
2458 // does not apply to conditional property accesses (i.e. 'C?.m').
2455 // 2459 //
2456 ClassElementImpl typeReference = getTypeReference(target); 2460 ClassElementImpl typeReference = getTypeReference(target, isConditional);
2457 if (typeReference != null) { 2461 if (typeReference != null) {
2458 // TODO(brianwilkerson) Why are we setting the propagated element here? 2462 // TODO(brianwilkerson) Why are we setting the propagated element here?
2459 // It looks wrong. 2463 // It looks wrong.
2460 staticElement = 2464 staticElement =
2461 propagatedElement = _resolveElement(typeReference, propertyName); 2465 propagatedElement = _resolveElement(typeReference, propertyName);
2462 } else { 2466 } else {
2463 staticElement = _resolveProperty(target, staticType, propertyName); 2467 staticElement = _resolveProperty(target, staticType, propertyName);
2464 propagatedElement = 2468 propagatedElement =
2465 _resolveProperty(target, propagatedType, propertyName); 2469 _resolveProperty(target, propagatedType, propertyName);
2466 } 2470 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
2694 bool _shouldReportMissingMember(DartType type, Element member) { 2698 bool _shouldReportMissingMember(DartType type, Element member) {
2695 if (member != null || type == null || type.isDynamic || type.isBottom) { 2699 if (member != null || type == null || type.isDynamic || type.isBottom) {
2696 return false; 2700 return false;
2697 } 2701 }
2698 return true; 2702 return true;
2699 } 2703 }
2700 2704
2701 /** 2705 /**
2702 * Checks whether the given [expression] is a reference to a class. If it is 2706 * Checks whether the given [expression] is a reference to a class. If it is
2703 * then the element representing the class is returned, otherwise `null` is 2707 * then the element representing the class is returned, otherwise `null` is
2704 * returned. 2708 * returned. [isConditional] indicates whether [expression] is to the left
2709 * of a '?.' opertator.
2705 */ 2710 */
2706 static ClassElementImpl getTypeReference(Expression expression) { 2711 static ClassElementImpl getTypeReference(
2707 if (expression is Identifier) { 2712 Expression expression, bool isConditional) {
2713 if (!isConditional && expression is Identifier) {
2708 Element staticElement = expression.staticElement; 2714 Element staticElement = expression.staticElement;
2709 if (staticElement is ClassElementImpl) { 2715 if (staticElement is ClassElementImpl) {
2710 return staticElement; 2716 return staticElement;
2711 } 2717 }
2712 } 2718 }
2713 return null; 2719 return null;
2714 } 2720 }
2715 2721
2716 /** 2722 /**
2717 * Helper function for `maybeMergeExecutableElements` that does the actual 2723 * Helper function for `maybeMergeExecutableElements` that does the actual
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2908 2914
2909 @override 2915 @override
2910 Element get staticElement => null; 2916 Element get staticElement => null;
2911 2917
2912 @override 2918 @override
2913 accept(AstVisitor visitor) => null; 2919 accept(AstVisitor visitor) => null;
2914 2920
2915 @override 2921 @override
2916 void visitChildren(AstVisitor visitor) {} 2922 void visitChildren(AstVisitor visitor) {}
2917 } 2923 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698