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.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 5123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5134 } | 5134 } |
5135 } | 5135 } |
5136 } | 5136 } |
5137 } | 5137 } |
5138 } | 5138 } |
5139 | 5139 |
5140 /** | 5140 /** |
5141 * Instances of the class `OverrideVerifier` visit all of the declarations in a compilation | 5141 * Instances of the class `OverrideVerifier` visit all of the declarations in a compilation |
5142 * unit to verify that if they have an override annotation it is being used corr ectly. | 5142 * unit to verify that if they have an override annotation it is being used corr ectly. |
5143 */ | 5143 */ |
5144 class OverrideVerifier extends RecursiveAstVisitor<Object> { | 5144 class OverrideVerifier extends RecursiveAstVisitor { |
5145 /** | 5145 /** |
5146 * The error reporter used to report errors. | 5146 * The error reporter used to report errors. |
5147 */ | 5147 */ |
5148 final ErrorReporter _errorReporter; | 5148 final ErrorReporter _errorReporter; |
5149 | 5149 |
5150 /** | 5150 /** |
5151 * The inheritance manager used to find overridden methods. | 5151 * The inheritance manager used to find overridden methods. |
5152 */ | 5152 */ |
5153 final InheritanceManager _manager; | 5153 final InheritanceManager _manager; |
5154 | 5154 |
5155 /** | 5155 /** |
5156 * Initialize a newly created verifier to look for inappropriate uses of the o verride annotation. | 5156 * Initialize a newly created verifier to look for inappropriate uses of the o verride annotation. |
5157 * | 5157 * |
5158 * @param errorReporter the error reporter used to report errors | 5158 * @param errorReporter the error reporter used to report errors |
5159 * @param manager the inheritance manager used to find overridden methods | 5159 * @param manager the inheritance manager used to find overridden methods |
5160 */ | 5160 */ |
5161 OverrideVerifier(this._errorReporter, this._manager); | 5161 OverrideVerifier(this._errorReporter, this._manager); |
5162 | 5162 |
5163 @override | 5163 @override |
5164 Object visitFieldDeclaration(FieldDeclaration node) { | 5164 visitFieldDeclaration(FieldDeclaration node) { |
5165 for (VariableDeclaration field in node.fields.variables) { | 5165 for (VariableDeclaration field in node.fields.variables) { |
5166 VariableElement fieldElement = field.element; | 5166 VariableElement fieldElement = field.element; |
5167 if (fieldElement is FieldElement && _isOverride(fieldElement)) { | 5167 if (fieldElement is FieldElement && _isOverride(fieldElement)) { |
5168 PropertyAccessorElement getterElement = fieldElement.getter; | 5168 PropertyAccessorElement getter = fieldElement.getter; |
5169 if (_getOverriddenMember(getterElement) == null) { | 5169 PropertyAccessorElement setter = fieldElement.setter; |
5170 if (!(_getOverriddenMember(getter) != null || | |
pquitslund
2016/07/26 05:32:49
Is it possible for `getter` to be null here? Do w
scheglov
2016/07/26 05:48:23
If other parts of analyzer work correctly, there s
Brian Wilkerson
2016/07/27 14:24:41
I'd rather that we just make other parts of analyz
| |
5171 setter != null && _getOverriddenMember(setter) != null)) { | |
5170 _errorReporter.reportErrorForNode( | 5172 _errorReporter.reportErrorForNode( |
5171 HintCode.OVERRIDE_ON_NON_OVERRIDING_GETTER, field.name); | 5173 HintCode.OVERRIDE_ON_NON_OVERRIDING_FIELD, field.name); |
5172 } | 5174 } |
5173 } | 5175 } |
5174 } | 5176 } |
5175 return super.visitFieldDeclaration(node); | |
5176 } | 5177 } |
5177 | 5178 |
5178 @override | 5179 @override |
5179 Object visitMethodDeclaration(MethodDeclaration node) { | 5180 visitMethodDeclaration(MethodDeclaration node) { |
5180 ExecutableElement element = node.element; | 5181 ExecutableElement element = node.element; |
5181 if (_isOverride(element)) { | 5182 if (_isOverride(element)) { |
5182 if (_getOverriddenMember(element) == null) { | 5183 if (_getOverriddenMember(element) == null) { |
5183 if (element is MethodElement) { | 5184 if (element is MethodElement) { |
5184 _errorReporter.reportErrorForNode( | 5185 _errorReporter.reportErrorForNode( |
5185 HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD, node.name); | 5186 HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD, node.name); |
5186 } else if (element is PropertyAccessorElement) { | 5187 } else if (element is PropertyAccessorElement) { |
5187 if (element.isGetter) { | 5188 if (element.isGetter) { |
5188 _errorReporter.reportErrorForNode( | 5189 _errorReporter.reportErrorForNode( |
5189 HintCode.OVERRIDE_ON_NON_OVERRIDING_GETTER, node.name); | 5190 HintCode.OVERRIDE_ON_NON_OVERRIDING_GETTER, node.name); |
5190 } else { | 5191 } else { |
5191 _errorReporter.reportErrorForNode( | 5192 _errorReporter.reportErrorForNode( |
5192 HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER, node.name); | 5193 HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER, node.name); |
5193 } | 5194 } |
5194 } | 5195 } |
5195 } | 5196 } |
5196 } | 5197 } |
5197 return super.visitMethodDeclaration(node); | |
5198 } | 5198 } |
5199 | 5199 |
5200 /** | 5200 /** |
5201 * Return the member that overrides the given member. | 5201 * Return the member that overrides the given member. |
5202 * | 5202 * |
5203 * @param member the member that overrides the returned member | 5203 * @param member the member that overrides the returned member |
5204 * @return the member that overrides the given member | 5204 * @return the member that overrides the given member |
5205 */ | 5205 */ |
5206 ExecutableElement _getOverriddenMember(ExecutableElement member) { | 5206 ExecutableElement _getOverriddenMember(ExecutableElement member) { |
5207 LibraryElement library = member.library; | 5207 LibraryElement library = member.library; |
(...skipping 5881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11089 return null; | 11089 return null; |
11090 } | 11090 } |
11091 if (identical(node.staticElement, variable)) { | 11091 if (identical(node.staticElement, variable)) { |
11092 if (node.inSetterContext()) { | 11092 if (node.inSetterContext()) { |
11093 result = true; | 11093 result = true; |
11094 } | 11094 } |
11095 } | 11095 } |
11096 return null; | 11096 return null; |
11097 } | 11097 } |
11098 } | 11098 } |
OLD | NEW |