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

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

Issue 2060013002: Refactor strong mode to use standard Analyzer errors (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix hasImplicitCasts on the CompilationUnit Created 4 years, 6 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
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 12 matching lines...) Expand all
23 import 'package:analyzer/src/generated/element_resolver.dart'; 23 import 'package:analyzer/src/generated/element_resolver.dart';
24 import 'package:analyzer/src/generated/engine.dart'; 24 import 'package:analyzer/src/generated/engine.dart';
25 import 'package:analyzer/src/generated/error.dart'; 25 import 'package:analyzer/src/generated/error.dart';
26 import 'package:analyzer/src/generated/error_verifier.dart'; 26 import 'package:analyzer/src/generated/error_verifier.dart';
27 import 'package:analyzer/src/generated/java_core.dart'; 27 import 'package:analyzer/src/generated/java_core.dart';
28 import 'package:analyzer/src/generated/java_engine.dart'; 28 import 'package:analyzer/src/generated/java_engine.dart';
29 import 'package:analyzer/src/generated/source.dart'; 29 import 'package:analyzer/src/generated/source.dart';
30 import 'package:analyzer/src/generated/static_type_analyzer.dart'; 30 import 'package:analyzer/src/generated/static_type_analyzer.dart';
31 import 'package:analyzer/src/generated/type_system.dart'; 31 import 'package:analyzer/src/generated/type_system.dart';
32 import 'package:analyzer/src/generated/utilities_dart.dart'; 32 import 'package:analyzer/src/generated/utilities_dart.dart';
33 import 'package:analyzer/src/task/strong/info.dart'
34 show InferredType, StaticInfo;
35 33
36 export 'package:analyzer/src/dart/resolver/inheritance_manager.dart'; 34 export 'package:analyzer/src/dart/resolver/inheritance_manager.dart';
37 export 'package:analyzer/src/dart/resolver/scope.dart'; 35 export 'package:analyzer/src/dart/resolver/scope.dart';
38 export 'package:analyzer/src/generated/type_system.dart'; 36 export 'package:analyzer/src/generated/type_system.dart';
39 37
40 /** 38 /**
41 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for 39 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for
42 * violations of Dart best practices. 40 * violations of Dart best practices.
43 */ 41 */
44 class BestPracticesVerifier extends RecursiveAstVisitor<Object> { 42 class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
(...skipping 4590 matching lines...) Expand 10 before | Expand all | Expand 10 after
4635 */ 4633 */
4636 class InferenceContext { 4634 class InferenceContext {
4637 // TODO(leafp): Consider replacing these node properties with a 4635 // TODO(leafp): Consider replacing these node properties with a
4638 // hash table help in an instance of this class. 4636 // hash table help in an instance of this class.
4639 static const String _typeProperty = 4637 static const String _typeProperty =
4640 'analyzer.src.generated.InferenceContext.contextType'; 4638 'analyzer.src.generated.InferenceContext.contextType';
4641 4639
4642 /** 4640 /**
4643 * The error listener on which to record inference information. 4641 * The error listener on which to record inference information.
4644 */ 4642 */
4645 final AnalysisErrorListener _errorListener; 4643 final ErrorReporter _errorReporter;
4646 4644
4647 /** 4645 /**
4648 * If true, emit hints when types are inferred 4646 * If true, emit hints when types are inferred
4649 */ 4647 */
4650 final bool _inferenceHints; 4648 final bool _inferenceHints;
4651 4649
4652 /** 4650 /**
4653 * Type provider, needed for type matching. 4651 * Type provider, needed for type matching.
4654 */ 4652 */
4655 final TypeProvider _typeProvider; 4653 final TypeProvider _typeProvider;
(...skipping 12 matching lines...) Expand all
4668 final List<DartType> _inferredReturn = <DartType>[]; 4666 final List<DartType> _inferredReturn = <DartType>[];
4669 4667
4670 /** 4668 /**
4671 * A stack of return types for all of the enclosing 4669 * A stack of return types for all of the enclosing
4672 * functions and methods. 4670 * functions and methods.
4673 */ 4671 */
4674 // TODO(leafp) Handle the implicit union type for Futures 4672 // TODO(leafp) Handle the implicit union type for Futures
4675 // https://github.com/dart-lang/sdk/issues/25322 4673 // https://github.com/dart-lang/sdk/issues/25322
4676 final List<DartType> _returnStack = <DartType>[]; 4674 final List<DartType> _returnStack = <DartType>[];
4677 4675
4678 InferenceContext._(this._errorListener, TypeProvider typeProvider, 4676 InferenceContext._(this._errorReporter, TypeProvider typeProvider,
4679 this._typeSystem, this._inferenceHints) 4677 this._typeSystem, this._inferenceHints)
4680 : _typeProvider = typeProvider; 4678 : _typeProvider = typeProvider;
4681 4679
4682 /** 4680 /**
4683 * Get the return type of the current enclosing function, if any. 4681 * Get the return type of the current enclosing function, if any.
4684 * 4682 *
4685 * The type returned for a function is the type that is expected 4683 * The type returned for a function is the type that is expected
4686 * to be used in a return or yield context. For ordinary functions 4684 * to be used in a return or yield context. For ordinary functions
4687 * this is the same as the return type of the function. For async 4685 * this is the same as the return type of the function. For async
4688 * functions returning Future<T> and for generator functions 4686 * functions returning Future<T> and for generator functions
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4747 DartType returnType = getType(node); 4745 DartType returnType = getType(node);
4748 _returnStack.add(returnType); 4746 _returnStack.add(returnType);
4749 _inferredReturn.add(BottomTypeImpl.instance); 4747 _inferredReturn.add(BottomTypeImpl.instance);
4750 } 4748 }
4751 4749
4752 /** 4750 /**
4753 * Place an info node into the error stream indicating that a 4751 * Place an info node into the error stream indicating that a
4754 * [type] has been inferred as the type of [node]. 4752 * [type] has been inferred as the type of [node].
4755 */ 4753 */
4756 void recordInference(Expression node, DartType type) { 4754 void recordInference(Expression node, DartType type) {
4757 StaticInfo info = InferredType.create(_typeSystem, node, type); 4755 if (!_inferenceHints) {
4758 if (!_inferenceHints || info == null) {
4759 return; 4756 return;
4760 } 4757 }
4761 AnalysisError error = info.toAnalysisError(); 4758
4762 _errorListener.onError(error); 4759 ErrorCode error;
4760 if (node is Literal) {
4761 error = StrongModeCode.INFERRED_TYPE_LITERAL;
4762 } else if (node is InstanceCreationExpression) {
4763 error = StrongModeCode.INFERRED_TYPE_ALLOCATION;
4764 } else if (node is FunctionExpression) {
4765 error = StrongModeCode.INFERRED_TYPE_CLOSURE;
4766 } else {
4767 error = StrongModeCode.INFERRED_TYPE;
4768 }
4769
4770 _errorReporter.reportErrorForNode(error, node, [node, type]);
4763 } 4771 }
4764 4772
4765 List<DartType> _matchTypes(InterfaceType t1, InterfaceType t2) { 4773 List<DartType> _matchTypes(InterfaceType t1, InterfaceType t2) {
4766 if (t1 == t2) { 4774 if (t1 == t2) {
4767 return t2.typeArguments; 4775 return t2.typeArguments;
4768 } 4776 }
4769 List<DartType> tArgs1 = t1.typeArguments; 4777 List<DartType> tArgs1 = t1.typeArguments;
4770 List<DartType> tArgs2 = t2.typeArguments; 4778 List<DartType> tArgs2 = t2.typeArguments;
4771 // If t1 isn't a raw type, bail out 4779 // If t1 isn't a raw type, bail out
4772 if (tArgs1 != null && tArgs1.any((t) => !t.isDynamic)) { 4780 if (tArgs1 != null && tArgs1.any((t) => !t.isDynamic)) {
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
5566 : super(definingLibrary, source, typeProvider, errorListener, 5574 : super(definingLibrary, source, typeProvider, errorListener,
5567 nameScope: nameScope) { 5575 nameScope: nameScope) {
5568 this.elementResolver = new ElementResolver(this); 5576 this.elementResolver = new ElementResolver(this);
5569 this.typeSystem = definingLibrary.context.typeSystem; 5577 this.typeSystem = definingLibrary.context.typeSystem;
5570 bool strongModeHints = false; 5578 bool strongModeHints = false;
5571 AnalysisOptions options = definingLibrary.context.analysisOptions; 5579 AnalysisOptions options = definingLibrary.context.analysisOptions;
5572 if (options is AnalysisOptionsImpl) { 5580 if (options is AnalysisOptionsImpl) {
5573 strongModeHints = options.strongModeHints; 5581 strongModeHints = options.strongModeHints;
5574 } 5582 }
5575 this.inferenceContext = new InferenceContext._( 5583 this.inferenceContext = new InferenceContext._(
5576 errorListener, typeProvider, typeSystem, strongModeHints); 5584 errorReporter, typeProvider, typeSystem, strongModeHints);
5577 this.typeAnalyzer = new StaticTypeAnalyzer(this); 5585 this.typeAnalyzer = new StaticTypeAnalyzer(this);
5578 } 5586 }
5579 5587
5580 /** 5588 /**
5581 * Return the element representing the function containing the current node, o r `null` if 5589 * Return the element representing the function containing the current node, o r `null` if
5582 * the current node is not contained in a function. 5590 * the current node is not contained in a function.
5583 * 5591 *
5584 * @return the element representing the function containing the current node 5592 * @return the element representing the function containing the current node
5585 */ 5593 */
5586 ExecutableElement get enclosingFunction => _enclosingFunction; 5594 ExecutableElement get enclosingFunction => _enclosingFunction;
(...skipping 5343 matching lines...) Expand 10 before | Expand all | Expand 10 after
10930 return null; 10938 return null;
10931 } 10939 }
10932 if (identical(node.staticElement, variable)) { 10940 if (identical(node.staticElement, variable)) {
10933 if (node.inSetterContext()) { 10941 if (node.inSetterContext()) {
10934 result = true; 10942 result = true;
10935 } 10943 }
10936 } 10944 }
10937 return null; 10945 return null;
10938 } 10946 }
10939 } 10947 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698