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 analyzer.src.generated.element_resolver; | 5 library analyzer.src.generated.element_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/syntactic_entity.dart'; | 10 import 'package:analyzer/dart/ast/syntactic_entity.dart'; |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 errorCode = null; | 752 errorCode = null; |
753 } | 753 } |
754 } | 754 } |
755 } | 755 } |
756 } | 756 } |
757 generatedWithTypePropagation = true; | 757 generatedWithTypePropagation = true; |
758 } | 758 } |
759 if (errorCode == null) { | 759 if (errorCode == null) { |
760 return null; | 760 return null; |
761 } | 761 } |
| 762 |
762 if (identical( | 763 if (identical( |
763 errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION) || | 764 errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION) || |
764 identical(errorCode, | 765 identical(errorCode, |
765 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT) || | 766 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT) || |
766 identical(errorCode, StaticTypeWarningCode.UNDEFINED_FUNCTION)) { | 767 identical(errorCode, StaticTypeWarningCode.UNDEFINED_FUNCTION)) { |
767 if (!_resolver.nameScope.shouldIgnoreUndefined(methodName)) { | 768 if (!_resolver.nameScope.shouldIgnoreUndefined(methodName)) { |
768 _resolver.errorReporter | 769 _resolver.errorReporter |
769 .reportErrorForNode(errorCode, methodName, [methodName.name]); | 770 .reportErrorForNode(errorCode, methodName, [methodName.name]); |
770 } | 771 } |
771 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { | 772 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 if (constructor != null) { | 810 if (constructor != null) { |
810 _recordUndefinedNode( | 811 _recordUndefinedNode( |
811 typeReference, | 812 typeReference, |
812 StaticTypeWarningCode.UNDEFINED_METHOD_WITH_CONSTRUCTOR, | 813 StaticTypeWarningCode.UNDEFINED_METHOD_WITH_CONSTRUCTOR, |
813 methodName, | 814 methodName, |
814 [methodName.name, typeReference.name]); | 815 [methodName.name, typeReference.name]); |
815 return null; | 816 return null; |
816 } | 817 } |
817 } | 818 } |
818 } | 819 } |
| 820 |
819 targetTypeName = targetType?.displayName; | 821 targetTypeName = targetType?.displayName; |
820 ErrorCode proxyErrorCode = (generatedWithTypePropagation | 822 ErrorCode proxyErrorCode = (generatedWithTypePropagation |
821 ? HintCode.UNDEFINED_METHOD | 823 ? HintCode.UNDEFINED_METHOD |
822 : StaticTypeWarningCode.UNDEFINED_METHOD); | 824 : StaticTypeWarningCode.UNDEFINED_METHOD); |
| 825 |
823 _recordUndefinedNode(targetType.element, proxyErrorCode, methodName, | 826 _recordUndefinedNode(targetType.element, proxyErrorCode, methodName, |
824 [methodName.name, targetTypeName]); | 827 [methodName.name, targetTypeName]); |
825 } | 828 } |
826 } else if (identical( | 829 } else if (identical( |
827 errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD)) { | 830 errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD)) { |
828 // Generate the type name. | 831 // Generate the type name. |
829 // The error code will never be generated via type propagation | 832 // The error code will never be generated via type propagation |
830 DartType getSuperType(DartType type) { | 833 DartType getSuperType(DartType type) { |
831 if (type is InterfaceType && !type.isObject) { | 834 if (type is InterfaceType && !type.isObject) { |
832 return type.superclass; | 835 return type.superclass; |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 Element _convertSetterToGetter(Element element) { | 1411 Element _convertSetterToGetter(Element element) { |
1409 // TODO(brianwilkerson) Determine whether and why the element could ever be | 1412 // TODO(brianwilkerson) Determine whether and why the element could ever be |
1410 // a setter. | 1413 // a setter. |
1411 if (element is PropertyAccessorElement) { | 1414 if (element is PropertyAccessorElement) { |
1412 return element.variable.getter; | 1415 return element.variable.getter; |
1413 } | 1416 } |
1414 return element; | 1417 return element; |
1415 } | 1418 } |
1416 | 1419 |
1417 /** | 1420 /** |
1418 * Return `true` if the given [element] is not a proxy. See | 1421 * Return `true` if the given [element] is or inherits from a class marked |
1419 * [ClassElement.isOrInheritsProxy]. | 1422 * with `@proxy`. |
| 1423 * |
| 1424 * See [ClassElement.isOrInheritsProxy]. |
1420 */ | 1425 */ |
1421 bool _doesntHaveProxy(Element element) => | 1426 bool _hasProxy(Element element) => |
1422 !(element is ClassElement && element.isOrInheritsProxy); | 1427 !_resolver.strongMode && |
| 1428 element is ClassElement && |
| 1429 element.isOrInheritsProxy; |
1423 | 1430 |
1424 /** | 1431 /** |
1425 * Look for any declarations of the given [identifier] that are imported using | 1432 * Look for any declarations of the given [identifier] that are imported using |
1426 * a prefix. Return the element that was found, or `null` if the name is not | 1433 * a prefix. Return the element that was found, or `null` if the name is not |
1427 * imported using a prefix. | 1434 * imported using a prefix. |
1428 */ | 1435 */ |
1429 Element _findImportWithoutPrefix(SimpleIdentifier identifier) { | 1436 Element _findImportWithoutPrefix(SimpleIdentifier identifier) { |
1430 Element element = null; | 1437 Element element = null; |
1431 Scope nameScope = _resolver.nameScope; | 1438 Scope nameScope = _resolver.nameScope; |
1432 List<ImportElement> imports = _definingLibrary.imports; | 1439 List<ImportElement> imports = _definingLibrary.imports; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1631 return true; | 1638 return true; |
1632 } else if (!_enableStrictCallChecks && | 1639 } else if (!_enableStrictCallChecks && |
1633 (type.isDartCoreFunction || type.isObject)) { | 1640 (type.isDartCoreFunction || type.isObject)) { |
1634 return true; | 1641 return true; |
1635 } else if (type is InterfaceType) { | 1642 } else if (type is InterfaceType) { |
1636 ClassElement classElement = type.element; | 1643 ClassElement classElement = type.element; |
1637 // 16078 from Gilad: If the type is a Functor with the @proxy annotation, | 1644 // 16078 from Gilad: If the type is a Functor with the @proxy annotation, |
1638 // treat it as an executable type. | 1645 // treat it as an executable type. |
1639 // example code: NonErrorResolverTest. | 1646 // example code: NonErrorResolverTest. |
1640 // test_invocationOfNonFunction_proxyOnFunctionClass() | 1647 // test_invocationOfNonFunction_proxyOnFunctionClass() |
1641 if (classElement.isProxy && | 1648 if (!_resolver.strongMode && |
| 1649 classElement.isProxy && |
1642 type.isSubtypeOf(_resolver.typeProvider.functionType)) { | 1650 type.isSubtypeOf(_resolver.typeProvider.functionType)) { |
1643 return true; | 1651 return true; |
1644 } | 1652 } |
1645 MethodElement methodElement = classElement.lookUpMethod( | 1653 MethodElement methodElement = classElement.lookUpMethod( |
1646 FunctionElement.CALL_METHOD_NAME, _definingLibrary); | 1654 FunctionElement.CALL_METHOD_NAME, _definingLibrary); |
1647 return methodElement != null; | 1655 return methodElement != null; |
1648 } | 1656 } |
1649 return false; | 1657 return false; |
1650 } | 1658 } |
1651 | 1659 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1866 /** | 1874 /** |
1867 * Record that the given [node] is undefined, causing an error to be reported | 1875 * Record that the given [node] is undefined, causing an error to be reported |
1868 * if appropriate. The [declaringElement] is the element inside which no | 1876 * if appropriate. The [declaringElement] is the element inside which no |
1869 * declaration was found. If this element is a proxy, no error will be | 1877 * declaration was found. If this element is a proxy, no error will be |
1870 * reported. If null, then an error will always be reported. The [errorCode] | 1878 * reported. If null, then an error will always be reported. The [errorCode] |
1871 * is the error code to report. The [arguments] are the arguments to the error | 1879 * is the error code to report. The [arguments] are the arguments to the error |
1872 * message. | 1880 * message. |
1873 */ | 1881 */ |
1874 void _recordUndefinedNode(Element declaringElement, ErrorCode errorCode, | 1882 void _recordUndefinedNode(Element declaringElement, ErrorCode errorCode, |
1875 AstNode node, List<Object> arguments) { | 1883 AstNode node, List<Object> arguments) { |
1876 if (_doesntHaveProxy(declaringElement)) { | 1884 if (!_hasProxy(declaringElement)) { |
1877 _resolver.errorReporter.reportErrorForNode(errorCode, node, arguments); | 1885 _resolver.errorReporter.reportErrorForNode(errorCode, node, arguments); |
1878 } | 1886 } |
1879 } | 1887 } |
1880 | 1888 |
1881 /** | 1889 /** |
1882 * Record that the given [offset]/[length] is undefined, causing an error to | 1890 * Record that the given [offset]/[length] is undefined, causing an error to |
1883 * be reported if appropriate. The [declaringElement] is the element inside | 1891 * be reported if appropriate. The [declaringElement] is the element inside |
1884 * which no declaration was found. If this element is a proxy, no error will | 1892 * which no declaration was found. If this element is a proxy, no error will |
1885 * be reported. If null, then an error will always be reported. The | 1893 * be reported. If null, then an error will always be reported. The |
1886 * [errorCode] is the error code to report. The [arguments] are arguments to | 1894 * [errorCode] is the error code to report. The [arguments] are arguments to |
1887 * the error message. | 1895 * the error message. |
1888 */ | 1896 */ |
1889 void _recordUndefinedOffset(Element declaringElement, ErrorCode errorCode, | 1897 void _recordUndefinedOffset(Element declaringElement, ErrorCode errorCode, |
1890 int offset, int length, List<Object> arguments) { | 1898 int offset, int length, List<Object> arguments) { |
1891 if (_doesntHaveProxy(declaringElement)) { | 1899 if (!_hasProxy(declaringElement)) { |
1892 _resolver.errorReporter | 1900 _resolver.errorReporter |
1893 .reportErrorForOffset(errorCode, offset, length, arguments); | 1901 .reportErrorForOffset(errorCode, offset, length, arguments); |
1894 } | 1902 } |
1895 } | 1903 } |
1896 | 1904 |
1897 /** | 1905 /** |
1898 * Record that the given [token] is undefined, causing an error to be reported | 1906 * Record that the given [token] is undefined, causing an error to be reported |
1899 * if appropriate. The [declaringElement] is the element inside which no | 1907 * if appropriate. The [declaringElement] is the element inside which no |
1900 * declaration was found. If this element is a proxy, no error will be | 1908 * declaration was found. If this element is a proxy, no error will be |
1901 * reported. If null, then an error will always be reported. The [errorCode] | 1909 * reported. If null, then an error will always be reported. The [errorCode] |
1902 * is the error code to report. The [arguments] are arguments to the error | 1910 * is the error code to report. The [arguments] are arguments to the error |
1903 * message. | 1911 * message. |
1904 */ | 1912 */ |
1905 void _recordUndefinedToken(Element declaringElement, ErrorCode errorCode, | 1913 void _recordUndefinedToken(Element declaringElement, ErrorCode errorCode, |
1906 Token token, List<Object> arguments) { | 1914 Token token, List<Object> arguments) { |
1907 if (_doesntHaveProxy(declaringElement)) { | 1915 if (!_hasProxy(declaringElement)) { |
1908 _resolver.errorReporter.reportErrorForToken(errorCode, token, arguments); | 1916 _resolver.errorReporter.reportErrorForToken(errorCode, token, arguments); |
1909 } | 1917 } |
1910 } | 1918 } |
1911 | 1919 |
1912 void _resolveAnnotationConstructorInvocationArguments( | 1920 void _resolveAnnotationConstructorInvocationArguments( |
1913 Annotation annotation, ConstructorElement constructor) { | 1921 Annotation annotation, ConstructorElement constructor) { |
1914 ArgumentList argumentList = annotation.arguments; | 1922 ArgumentList argumentList = annotation.arguments; |
1915 // error will be reported in ConstantVerifier | 1923 // error will be reported in ConstantVerifier |
1916 if (argumentList == null) { | 1924 if (argumentList == null) { |
1917 return; | 1925 return; |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2649 | 2657 |
2650 @override | 2658 @override |
2651 Element get staticElement => null; | 2659 Element get staticElement => null; |
2652 | 2660 |
2653 @override | 2661 @override |
2654 E accept<E>(AstVisitor<E> visitor) => null; | 2662 E accept<E>(AstVisitor<E> visitor) => null; |
2655 | 2663 |
2656 @override | 2664 @override |
2657 void visitChildren(AstVisitor visitor) {} | 2665 void visitChildren(AstVisitor visitor) {} |
2658 } | 2666 } |
OLD | NEW |