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

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

Issue 2364733002: Issue 27300. Report HintCode.ABSTRACT_SUPER_MEMBER_REFERENCE. (Closed)
Patch Set: Fixes for false positives. Created 4 years, 2 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | pkg/analyzer/lib/src/task/dart.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // static String _HASHCODE_GETTER_NAME = "hashCode"; 45 // static String _HASHCODE_GETTER_NAME = "hashCode";
46 46
47 static String _NULL_TYPE_NAME = "Null"; 47 static String _NULL_TYPE_NAME = "Null";
48 48
49 static String _TO_INT_METHOD_NAME = "toInt"; 49 static String _TO_INT_METHOD_NAME = "toInt";
50 50
51 /** 51 /**
52 * The class containing the AST nodes being visited, or `null` if we are not i n the scope of 52 * The class containing the AST nodes being visited, or `null` if we are not i n the scope of
53 * a class. 53 * a class.
54 */ 54 */
55 ClassElement _enclosingClass; 55 ClassElementImpl _enclosingClass;
56 56
57 /** 57 /**
58 * A flag indicating whether a surrounding member (compilation unit or class) 58 * A flag indicating whether a surrounding member (compilation unit or class)
59 * is deprecated. 59 * is deprecated.
60 */ 60 */
61 bool inDeprecatedMember; 61 bool inDeprecatedMember;
62 62
63 /** 63 /**
64 * The error reporter by which errors will be reported. 64 * The error reporter by which errors will be reported.
65 */ 65 */
(...skipping 14 matching lines...) Expand all
80 * The type system primitives 80 * The type system primitives
81 */ 81 */
82 TypeSystem _typeSystem; 82 TypeSystem _typeSystem;
83 83
84 /** 84 /**
85 * The current library 85 * The current library
86 */ 86 */
87 LibraryElement _currentLibrary; 87 LibraryElement _currentLibrary;
88 88
89 /** 89 /**
90 * The inheritance manager used to find overridden methods.
91 */
92 InheritanceManager _manager;
93
94 /**
90 * Create a new instance of the [BestPracticesVerifier]. 95 * Create a new instance of the [BestPracticesVerifier].
91 * 96 *
92 * @param errorReporter the error reporter 97 * @param errorReporter the error reporter
93 */ 98 */
94 BestPracticesVerifier( 99 BestPracticesVerifier(this._errorReporter, TypeProvider typeProvider,
95 this._errorReporter, TypeProvider typeProvider, this._currentLibrary, 100 this._currentLibrary, this._manager,
96 {TypeSystem typeSystem}) 101 {TypeSystem typeSystem})
97 : _nullType = typeProvider.nullType, 102 : _nullType = typeProvider.nullType,
98 _futureNullType = typeProvider.futureNullType, 103 _futureNullType = typeProvider.futureNullType,
99 _typeSystem = typeSystem ?? new TypeSystemImpl() { 104 _typeSystem = typeSystem ?? new TypeSystemImpl() {
100 inDeprecatedMember = _currentLibrary.isDeprecated; 105 inDeprecatedMember = _currentLibrary.isDeprecated;
101 } 106 }
102 107
103 @override 108 @override
104 Object visitAnnotation(Annotation node) { 109 Object visitAnnotation(Annotation node) {
105 if (node.elementAnnotation?.isFactory == true) { 110 if (node.elementAnnotation?.isFactory == true) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 157
153 @override 158 @override
154 Object visitBinaryExpression(BinaryExpression node) { 159 Object visitBinaryExpression(BinaryExpression node) {
155 _checkForDivisionOptimizationHint(node); 160 _checkForDivisionOptimizationHint(node);
156 _checkForDeprecatedMemberUse(node.bestElement, node); 161 _checkForDeprecatedMemberUse(node.bestElement, node);
157 return super.visitBinaryExpression(node); 162 return super.visitBinaryExpression(node);
158 } 163 }
159 164
160 @override 165 @override
161 Object visitClassDeclaration(ClassDeclaration node) { 166 Object visitClassDeclaration(ClassDeclaration node) {
162 ClassElement outerClass = _enclosingClass; 167 ClassElementImpl outerClass = _enclosingClass;
163 bool wasInDeprecatedMember = inDeprecatedMember; 168 bool wasInDeprecatedMember = inDeprecatedMember;
164 ClassElement element = node.element; 169 ClassElement element = AbstractClassElementImpl.getImpl(node.element);
165 if (element != null && element.isDeprecated) { 170 if (element != null && element.isDeprecated) {
166 inDeprecatedMember = true; 171 inDeprecatedMember = true;
167 } 172 }
168 try { 173 try {
169 _enclosingClass = element; 174 _enclosingClass = element;
170 // Commented out until we decide that we want this hint in the analyzer 175 // Commented out until we decide that we want this hint in the analyzer
171 // checkForOverrideEqualsButNotHashCode(node); 176 // checkForOverrideEqualsButNotHashCode(node);
172 return super.visitClassDeclaration(node); 177 return super.visitClassDeclaration(node);
173 } finally { 178 } finally {
174 _enclosingClass = outerClass; 179 _enclosingClass = outerClass;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 _checkForMissingReturn(node.returnType, node.body); 281 _checkForMissingReturn(node.returnType, node.body);
277 _checkForUnnecessaryNoSuchMethod(node); 282 _checkForUnnecessaryNoSuchMethod(node);
278 return super.visitMethodDeclaration(node); 283 return super.visitMethodDeclaration(node);
279 } finally { 284 } finally {
280 inDeprecatedMember = wasInDeprecatedMember; 285 inDeprecatedMember = wasInDeprecatedMember;
281 } 286 }
282 } 287 }
283 288
284 @override 289 @override
285 Object visitMethodInvocation(MethodInvocation node) { 290 Object visitMethodInvocation(MethodInvocation node) {
291 Expression realTarget = node.realTarget;
292 _checkForAbstractSuperMemberReference(realTarget, node.methodName);
286 _checkForCanBeNullAfterNullAware( 293 _checkForCanBeNullAfterNullAware(
287 node.realTarget, node.operator, null, node.methodName); 294 realTarget, node.operator, null, node.methodName);
288 DartType staticInvokeType = node.staticInvokeType; 295 DartType staticInvokeType = node.staticInvokeType;
289 if (staticInvokeType is InterfaceType) { 296 if (staticInvokeType is InterfaceType) {
290 MethodElement methodElement = staticInvokeType.lookUpMethod( 297 MethodElement methodElement = staticInvokeType.lookUpMethod(
291 FunctionElement.CALL_METHOD_NAME, _currentLibrary); 298 FunctionElement.CALL_METHOD_NAME, _currentLibrary);
292 _checkForDeprecatedMemberUse(methodElement, node); 299 _checkForDeprecatedMemberUse(methodElement, node);
293 } 300 }
294 return super.visitMethodInvocation(node); 301 return super.visitMethodInvocation(node);
295 } 302 }
296 303
297 @override 304 @override
298 Object visitPostfixExpression(PostfixExpression node) { 305 Object visitPostfixExpression(PostfixExpression node) {
299 _checkForDeprecatedMemberUse(node.bestElement, node); 306 _checkForDeprecatedMemberUse(node.bestElement, node);
300 return super.visitPostfixExpression(node); 307 return super.visitPostfixExpression(node);
301 } 308 }
302 309
303 @override 310 @override
304 Object visitPrefixExpression(PrefixExpression node) { 311 Object visitPrefixExpression(PrefixExpression node) {
305 _checkForDeprecatedMemberUse(node.bestElement, node); 312 _checkForDeprecatedMemberUse(node.bestElement, node);
306 return super.visitPrefixExpression(node); 313 return super.visitPrefixExpression(node);
307 } 314 }
308 315
309 @override 316 @override
310 Object visitPropertyAccess(PropertyAccess node) { 317 Object visitPropertyAccess(PropertyAccess node) {
318 Expression realTarget = node.realTarget;
319 _checkForAbstractSuperMemberReference(realTarget, node.propertyName);
311 _checkForCanBeNullAfterNullAware( 320 _checkForCanBeNullAfterNullAware(
312 node.realTarget, node.operator, node.propertyName, null); 321 realTarget, node.operator, node.propertyName, null);
313 return super.visitPropertyAccess(node); 322 return super.visitPropertyAccess(node);
314 } 323 }
315 324
316 @override 325 @override
317 Object visitRedirectingConstructorInvocation( 326 Object visitRedirectingConstructorInvocation(
318 RedirectingConstructorInvocation node) { 327 RedirectingConstructorInvocation node) {
319 _checkForDeprecatedMemberUse(node.staticElement, node); 328 _checkForDeprecatedMemberUse(node.staticElement, node);
320 return super.visitRedirectingConstructorInvocation(node); 329 return super.visitRedirectingConstructorInvocation(node);
321 } 330 }
322 331
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 // the is not case 411 // the is not case
403 _errorReporter.reportErrorForNode( 412 _errorReporter.reportErrorForNode(
404 HintCode.TYPE_CHECK_IS_NOT_NULL, node); 413 HintCode.TYPE_CHECK_IS_NOT_NULL, node);
405 } 414 }
406 return true; 415 return true;
407 } 416 }
408 } 417 }
409 return false; 418 return false;
410 } 419 }
411 420
421 void _checkForAbstractSuperMemberReference(
422 Expression target, SimpleIdentifier name) {
423 if (target is SuperExpression) {
424 Element element = name.staticElement;
425 if (element is ExecutableElement && element.isAbstract) {
426 if (!_enclosingClass.hasNoSuchMethod) {
427 ExecutableElement concrete = null;
428 if (element.kind == ElementKind.METHOD) {
429 concrete = _enclosingClass.lookUpInheritedConcreteMethod(
430 element.displayName, _currentLibrary);
431 } else if (element.kind == ElementKind.GETTER) {
432 concrete = _enclosingClass.lookUpInheritedConcreteGetter(
433 element.displayName, _currentLibrary);
434 } else if (element.kind == ElementKind.SETTER) {
435 concrete = _enclosingClass.lookUpInheritedConcreteSetter(
436 element.displayName, _currentLibrary);
437 }
438 if (concrete == null) {
439 _errorReporter.reportTypeErrorForNode(
440 HintCode.ABSTRACT_SUPER_MEMBER_REFERENCE,
441 name,
442 [element.kind.displayName, name.name]);
443 }
444 }
445 }
446 }
447 }
448
412 /** 449 /**
413 * This verifies that the passed expression can be assigned to its correspondi ng parameters. 450 * This verifies that the passed expression can be assigned to its correspondi ng parameters.
414 * 451 *
415 * This method corresponds to ErrorVerifier.checkForArgumentTypeNotAssignable. 452 * This method corresponds to ErrorVerifier.checkForArgumentTypeNotAssignable.
416 * 453 *
417 * TODO (jwren) In the ErrorVerifier there are other warnings that we could ha ve a corresponding 454 * TODO (jwren) In the ErrorVerifier there are other warnings that we could ha ve a corresponding
418 * hint for: see other callers of ErrorVerifier.checkForArgumentTypeNotAssigna ble(..). 455 * hint for: see other callers of ErrorVerifier.checkForArgumentTypeNotAssigna ble(..).
419 * 456 *
420 * @param expression the expression to evaluate 457 * @param expression the expression to evaluate
421 * @param expectedStaticType the expected static type of the parameter 458 * @param expectedStaticType the expected static type of the parameter
(...skipping 3862 matching lines...) Expand 10 before | Expand all | Expand 10 after
4284 // dead code analysis 4321 // dead code analysis
4285 unit.accept( 4322 unit.accept(
4286 new DeadCodeVerifier(errorReporter, typeSystem: _context.typeSystem)); 4323 new DeadCodeVerifier(errorReporter, typeSystem: _context.typeSystem));
4287 unit.accept(_usedLocalElementsVisitor); 4324 unit.accept(_usedLocalElementsVisitor);
4288 // dart2js analysis 4325 // dart2js analysis
4289 if (_enableDart2JSHints) { 4326 if (_enableDart2JSHints) {
4290 unit.accept(new Dart2JSVerifier(errorReporter)); 4327 unit.accept(new Dart2JSVerifier(errorReporter));
4291 } 4328 }
4292 // Dart best practices 4329 // Dart best practices
4293 unit.accept(new BestPracticesVerifier( 4330 unit.accept(new BestPracticesVerifier(
4294 errorReporter, _context.typeProvider, _library, 4331 errorReporter, _context.typeProvider, _library, _manager,
4295 typeSystem: _context.typeSystem)); 4332 typeSystem: _context.typeSystem));
4296 unit.accept(new OverrideVerifier(errorReporter, _manager)); 4333 unit.accept(new OverrideVerifier(errorReporter, _manager));
4297 // Find to-do comments 4334 // Find to-do comments
4298 new ToDoFinder(errorReporter).findIn(unit); 4335 new ToDoFinder(errorReporter).findIn(unit);
4299 // pub analysis 4336 // pub analysis
4300 // TODO(danrubel/jwren) Commented out until bugs in the pub verifier are 4337 // TODO(danrubel/jwren) Commented out until bugs in the pub verifier are
4301 // fixed 4338 // fixed
4302 // unit.accept(new PubVerifier(context, errorReporter)); 4339 // unit.accept(new PubVerifier(context, errorReporter));
4303 } 4340 }
4304 } 4341 }
(...skipping 2971 matching lines...) Expand 10 before | Expand all | Expand 10 after
7276 DartType contextType = node.staticInvokeType; 7313 DartType contextType = node.staticInvokeType;
7277 if (contextType is FunctionType) { 7314 if (contextType is FunctionType) {
7278 DartType originalType = node.function.staticType; 7315 DartType originalType = node.function.staticType;
7279 DartType returnContextType = InferenceContext.getContext(node); 7316 DartType returnContextType = InferenceContext.getContext(node);
7280 TypeSystem ts = typeSystem; 7317 TypeSystem ts = typeSystem;
7281 if (returnContextType != null && 7318 if (returnContextType != null &&
7282 node.typeArguments == null && 7319 node.typeArguments == null &&
7283 originalType is FunctionType && 7320 originalType is FunctionType &&
7284 originalType.typeFormals.isNotEmpty && 7321 originalType.typeFormals.isNotEmpty &&
7285 ts is StrongTypeSystemImpl) { 7322 ts is StrongTypeSystemImpl) {
7286 contextType = ts.inferGenericFunctionCall(typeProvider, originalType, 7323 contextType = ts.inferGenericFunctionCall(
7287 DartType.EMPTY_LIST, DartType.EMPTY_LIST, originalType.returnType, r eturnContextType); 7324 typeProvider,
7325 originalType,
7326 DartType.EMPTY_LIST,
7327 DartType.EMPTY_LIST,
7328 originalType.returnType,
7329 returnContextType);
7288 } 7330 }
7289 7331
7290 InferenceContext.setType(node.argumentList, contextType); 7332 InferenceContext.setType(node.argumentList, contextType);
7291 } 7333 }
7292 } 7334 }
7293 7335
7294 void _inferFormalParameterList(FormalParameterList node, DartType type) { 7336 void _inferFormalParameterList(FormalParameterList node, DartType type) {
7295 if (typeAnalyzer.inferFormalParameterList(node, type)) { 7337 if (typeAnalyzer.inferFormalParameterList(node, type)) {
7296 // TODO(leafp): This gets dropped on the floor if we're in the field 7338 // TODO(leafp): This gets dropped on the floor if we're in the field
7297 // inference task. We should probably keep these infos. 7339 // inference task. We should probably keep these infos.
(...skipping 3894 matching lines...) Expand 10 before | Expand all | Expand 10 after
11192 return null; 11234 return null;
11193 } 11235 }
11194 if (identical(node.staticElement, variable)) { 11236 if (identical(node.staticElement, variable)) {
11195 if (node.inSetterContext()) { 11237 if (node.inSetterContext()) {
11196 result = true; 11238 result = true;
11197 } 11239 }
11198 } 11240 }
11199 return null; 11241 return null;
11200 } 11242 }
11201 } 11243 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | pkg/analyzer/lib/src/task/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698