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.error_verifier; | 5 library analyzer.src.generated.error_verifier; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import "dart:math" as math; | 8 import "dart:math" as math; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 2638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2649 if (method.isGetter) { | 2649 if (method.isGetter) { |
2650 overriddenMember = _enclosingClass.lookUpInheritedConcreteGetter( | 2650 overriddenMember = _enclosingClass.lookUpInheritedConcreteGetter( |
2651 memberName, _currentLibrary); | 2651 memberName, _currentLibrary); |
2652 } else if (method.isSetter) { | 2652 } else if (method.isSetter) { |
2653 overriddenMember = _enclosingClass.lookUpInheritedConcreteSetter( | 2653 overriddenMember = _enclosingClass.lookUpInheritedConcreteSetter( |
2654 memberName, _currentLibrary); | 2654 memberName, _currentLibrary); |
2655 } else { | 2655 } else { |
2656 overriddenMember = _enclosingClass.lookUpInheritedConcreteMethod( | 2656 overriddenMember = _enclosingClass.lookUpInheritedConcreteMethod( |
2657 memberName, _currentLibrary); | 2657 memberName, _currentLibrary); |
2658 } | 2658 } |
2659 if (overriddenMember == null && !_enclosingClass.hasNoSuchMethod) { | 2659 if (overriddenMember == null && !_hasNoSuchMethod(_enclosingClass)) { |
2660 _errorReporter.reportErrorForNode( | 2660 _errorReporter.reportErrorForNode( |
2661 StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, | 2661 StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, |
2662 nameNode, | 2662 nameNode, |
2663 [memberName, _enclosingClass.displayName]); | 2663 [memberName, _enclosingClass.displayName]); |
2664 } | 2664 } |
2665 } | 2665 } |
2666 } | 2666 } |
2667 | 2667 |
2668 /** | 2668 /** |
2669 * Verify all possible conflicts of the given [constructor]'s name with other | 2669 * Verify all possible conflicts of the given [constructor]'s name with other |
(...skipping 2294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4964 * See [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], | 4964 * See [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], |
4965 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO], | 4965 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO], |
4966 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE], | 4966 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE], |
4967 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR], and | 4967 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR], and |
4968 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS]. | 4968 * [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS]. |
4969 */ | 4969 */ |
4970 void _checkForNonAbstractClassInheritsAbstractMember( | 4970 void _checkForNonAbstractClassInheritsAbstractMember( |
4971 SimpleIdentifier classNameNode) { | 4971 SimpleIdentifier classNameNode) { |
4972 if (_enclosingClass.isAbstract) { | 4972 if (_enclosingClass.isAbstract) { |
4973 return; | 4973 return; |
4974 } else if (_enclosingClass.hasNoSuchMethod) { | 4974 } else if (_hasNoSuchMethod(_enclosingClass)) { |
4975 return; | 4975 return; |
4976 } | 4976 } |
4977 // | 4977 // |
4978 // Store in local sets the set of all method and accessor names | 4978 // Store in local sets the set of all method and accessor names |
4979 // | 4979 // |
4980 HashSet<ExecutableElement> missingOverrides = | 4980 HashSet<ExecutableElement> missingOverrides = |
4981 new HashSet<ExecutableElement>(); | 4981 new HashSet<ExecutableElement>(); |
4982 // | 4982 // |
4983 // Loop through the set of all executable elements declared in the implicit | 4983 // Loop through the set of all executable elements declared in the implicit |
4984 // interface. | 4984 // interface. |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6091 ClassElement classElement = declaration.element; | 6091 ClassElement classElement = declaration.element; |
6092 if (classElement == null) { | 6092 if (classElement == null) { |
6093 return; | 6093 return; |
6094 } | 6094 } |
6095 if (!_typeSystem.isSubtypeOf( | 6095 if (!_typeSystem.isSubtypeOf( |
6096 classElement.type, _typeProvider.functionType)) { | 6096 classElement.type, _typeProvider.functionType)) { |
6097 return; | 6097 return; |
6098 } | 6098 } |
6099 // If there is a noSuchMethod method, then don't report the warning, | 6099 // If there is a noSuchMethod method, then don't report the warning, |
6100 // see dartbug.com/16078 | 6100 // see dartbug.com/16078 |
6101 if (_enclosingClass.hasNoSuchMethod) { | 6101 if (_hasNoSuchMethod(classElement)) { |
6102 return; | 6102 return; |
6103 } | 6103 } |
6104 ExecutableElement callMethod = _inheritanceManager.lookupMember( | 6104 ExecutableElement callMethod = _inheritanceManager.lookupMember( |
6105 classElement, FunctionElement.CALL_METHOD_NAME); | 6105 classElement, FunctionElement.CALL_METHOD_NAME); |
6106 if (callMethod == null || | 6106 if (callMethod == null || |
6107 callMethod is! MethodElement || | 6107 callMethod is! MethodElement || |
6108 (callMethod as MethodElement).isAbstract) { | 6108 (callMethod as MethodElement).isAbstract) { |
6109 _errorReporter.reportErrorForNode( | 6109 _errorReporter.reportErrorForNode( |
6110 StaticWarningCode.FUNCTION_WITHOUT_CALL, declaration.name); | 6110 StaticWarningCode.FUNCTION_WITHOUT_CALL, declaration.name); |
6111 } | 6111 } |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6388 // Get the parameters for MethodDeclaration or FunctionDeclaration | 6388 // Get the parameters for MethodDeclaration or FunctionDeclaration |
6389 List<ParameterElement> setterParameters = setter.parameters; | 6389 List<ParameterElement> setterParameters = setter.parameters; |
6390 // If there are no setter parameters, return no type. | 6390 // If there are no setter parameters, return no type. |
6391 if (setterParameters.length == 0) { | 6391 if (setterParameters.length == 0) { |
6392 return null; | 6392 return null; |
6393 } | 6393 } |
6394 return setterParameters[0].type; | 6394 return setterParameters[0].type; |
6395 } | 6395 } |
6396 | 6396 |
6397 /** | 6397 /** |
| 6398 * Return `true` if the given [classElement] has a noSuchMethod() method |
| 6399 * distinct from the one declared in class Object, as per the Dart Language |
| 6400 * Specification (section 10.4). |
| 6401 */ |
| 6402 bool _hasNoSuchMethod(ClassElement classElement) { |
| 6403 MethodElement method = classElement.lookUpMethod( |
| 6404 FunctionElement.NO_SUCH_METHOD_METHOD_NAME, classElement.library); |
| 6405 if (method == null) { |
| 6406 return false; |
| 6407 } |
| 6408 ClassElement definingClass = |
| 6409 method.getAncestor((Element element) => element is ClassElement); |
| 6410 return definingClass != null && !definingClass.type.isObject; |
| 6411 } |
| 6412 |
| 6413 /** |
6398 * Return `true` if the given [constructor] redirects to itself, directly or | 6414 * Return `true` if the given [constructor] redirects to itself, directly or |
6399 * indirectly. | 6415 * indirectly. |
6400 */ | 6416 */ |
6401 bool _hasRedirectingFactoryConstructorCycle(ConstructorElement constructor) { | 6417 bool _hasRedirectingFactoryConstructorCycle(ConstructorElement constructor) { |
6402 ConstructorElement nonMember(ConstructorElement constructor) { | 6418 ConstructorElement nonMember(ConstructorElement constructor) { |
6403 return constructor is ConstructorMember | 6419 return constructor is ConstructorMember |
6404 ? constructor.baseElement | 6420 ? constructor.baseElement |
6405 : constructor; | 6421 : constructor; |
6406 } | 6422 } |
6407 | 6423 |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6895 class _InvocationCollector extends RecursiveAstVisitor { | 6911 class _InvocationCollector extends RecursiveAstVisitor { |
6896 final List<String> superCalls = <String>[]; | 6912 final List<String> superCalls = <String>[]; |
6897 | 6913 |
6898 @override | 6914 @override |
6899 visitMethodInvocation(MethodInvocation node) { | 6915 visitMethodInvocation(MethodInvocation node) { |
6900 if (node.target is SuperExpression) { | 6916 if (node.target is SuperExpression) { |
6901 superCalls.add(node.methodName.name); | 6917 superCalls.add(node.methodName.name); |
6902 } | 6918 } |
6903 } | 6919 } |
6904 } | 6920 } |
OLD | NEW |