| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.test.src.task.dart_test; | 5 library analyzer.test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
| 10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| (...skipping 4108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4119 r''' | 4119 r''' |
| 4120 library lib; | 4120 library lib; |
| 4121 class A {} | 4121 class A {} |
| 4122 '''); | 4122 '''); |
| 4123 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4123 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4124 computeResult(target, RESOLVED_UNIT9); | 4124 computeResult(target, RESOLVED_UNIT9); |
| 4125 expect(outputs[RESOLVED_UNIT9], isNotNull); | 4125 expect(outputs[RESOLVED_UNIT9], isNotNull); |
| 4126 expect(outputs[CREATED_RESOLVED_UNIT9], isTrue); | 4126 expect(outputs[CREATED_RESOLVED_UNIT9], isTrue); |
| 4127 } | 4127 } |
| 4128 | 4128 |
| 4129 // Test inference of instance fields across units | 4129 /** |
| 4130 * Test inference of instance fields across units |
| 4131 */ |
| 4130 void test_perform_inference_cross_unit_instance() { | 4132 void test_perform_inference_cross_unit_instance() { |
| 4131 List<Source> sources = newSources({ | 4133 List<Source> sources = newSources({ |
| 4132 '/a.dart': ''' | 4134 '/a.dart': ''' |
| 4133 import 'b.dart'; | 4135 import 'b.dart'; |
| 4134 class A { | 4136 class A { |
| 4135 final a2 = new B().b2; | 4137 final a2 = new B().b2; |
| 4136 } | 4138 } |
| 4137 ''', | 4139 ''', |
| 4138 '/b.dart': ''' | 4140 '/b.dart': ''' |
| 4139 class B { | 4141 class B { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 4170 | 4172 |
| 4171 // A.a2 should now be resolved on the rhs, but not yet inferred. | 4173 // A.a2 should now be resolved on the rhs, but not yet inferred. |
| 4172 assertVariableDeclarationTypes( | 4174 assertVariableDeclarationTypes( |
| 4173 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); | 4175 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
| 4174 | 4176 |
| 4175 computeResult( | 4177 computeResult( |
| 4176 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9); | 4178 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9); |
| 4177 | 4179 |
| 4178 // A.a2 should now be fully resolved and inferred. | 4180 // A.a2 should now be fully resolved and inferred. |
| 4179 assertVariableDeclarationTypes( | 4181 assertVariableDeclarationTypes( |
| 4180 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); | 4182 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
| 4181 | 4183 |
| 4182 assertVariableDeclarationTypes( | 4184 assertVariableDeclarationTypes( |
| 4183 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); | 4185 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 4184 } | 4186 } |
| 4185 | 4187 |
| 4186 // Test inference of instance fields across units | 4188 /** |
| 4189 * Test inference of instance fields across units |
| 4190 */ |
| 4187 void test_perform_inference_cross_unit_instance_cyclic() { | 4191 void test_perform_inference_cross_unit_instance_cyclic() { |
| 4188 List<Source> sources = newSources({ | 4192 List<Source> sources = newSources({ |
| 4189 '/a.dart': ''' | 4193 '/a.dart': ''' |
| 4190 import 'b.dart'; | 4194 import 'b.dart'; |
| 4191 class A { | 4195 class A { |
| 4192 final a2 = new B().b2; | 4196 final a2 = new B().b2; |
| 4193 } | 4197 } |
| 4194 ''', | 4198 ''', |
| 4195 '/b.dart': ''' | 4199 '/b.dart': ''' |
| 4196 import 'a.dart'; | 4200 import 'a.dart'; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4218 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); | 4222 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 4219 | 4223 |
| 4220 computeResult( | 4224 computeResult( |
| 4221 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9); | 4225 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9); |
| 4222 | 4226 |
| 4223 // A.a2 should now be fully resolved and inferred (but not re-resolved). | 4227 // A.a2 should now be fully resolved and inferred (but not re-resolved). |
| 4224 assertVariableDeclarationTypes( | 4228 assertVariableDeclarationTypes( |
| 4225 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); | 4229 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 4226 } | 4230 } |
| 4227 | 4231 |
| 4228 // Test inference of instance fields across units with cycles | 4232 /** |
| 4233 * Test inference of instance fields across units with cycles |
| 4234 */ |
| 4229 void test_perform_inference_cross_unit_static_instance() { | 4235 void test_perform_inference_cross_unit_static_instance() { |
| 4230 List<Source> sources = newSources({ | 4236 List<Source> sources = newSources({ |
| 4231 '/a.dart': ''' | 4237 '/a.dart': ''' |
| 4232 import 'b.dart'; | 4238 import 'b.dart'; |
| 4233 class A { | 4239 class A { |
| 4234 static final a1 = B.b1; | 4240 static final a1 = B.b1; |
| 4235 final a2 = new B().b2; | 4241 final a2 = new B().b2; |
| 4236 } | 4242 } |
| 4237 ''', | 4243 ''', |
| 4238 '/b.dart': ''' | 4244 '/b.dart': ''' |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4277 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); | 4283 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 4278 assertVariableDeclarationTypes( | 4284 assertVariableDeclarationTypes( |
| 4279 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); | 4285 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 4280 | 4286 |
| 4281 computeResult( | 4287 computeResult( |
| 4282 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9); | 4288 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9); |
| 4283 | 4289 |
| 4284 assertVariableDeclarationTypes( | 4290 assertVariableDeclarationTypes( |
| 4285 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); | 4291 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); |
| 4286 assertVariableDeclarationTypes( | 4292 assertVariableDeclarationTypes( |
| 4287 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); | 4293 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
| 4288 | 4294 |
| 4289 assertVariableDeclarationTypes( | 4295 assertVariableDeclarationTypes( |
| 4290 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); | 4296 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 4291 assertVariableDeclarationTypes( | 4297 assertVariableDeclarationTypes( |
| 4292 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); | 4298 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 4293 } | 4299 } |
| 4294 | 4300 |
| 4295 // Test inference between static and instance fields | 4301 /** |
| 4302 * Test inference between static and instance fields |
| 4303 */ |
| 4296 void test_perform_inference_instance() { | 4304 void test_perform_inference_instance() { |
| 4297 List<Source> sources = newSources({ | 4305 List<Source> sources = newSources({ |
| 4298 '/a.dart': ''' | 4306 '/a.dart': ''' |
| 4299 import 'b.dart'; | 4307 import 'b.dart'; |
| 4300 class A { | 4308 class A { |
| 4301 final a2 = new B().b2; | 4309 final a2 = new B().b2; |
| 4302 } | 4310 } |
| 4303 | 4311 |
| 4304 class B { | 4312 class B { |
| 4305 final b2 = 1; | 4313 final b2 = 1; |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5001 } | 5009 } |
| 5002 ''' | 5010 ''' |
| 5003 }); | 5011 }); |
| 5004 List<dynamic> units = | 5012 List<dynamic> units = |
| 5005 computeLibraryResults(sources, RESOLVED_UNIT11).toList(); | 5013 computeLibraryResults(sources, RESOLVED_UNIT11).toList(); |
| 5006 CompilationUnit unit0 = units[0]; | 5014 CompilationUnit unit0 = units[0]; |
| 5007 CompilationUnit unit1 = units[1]; | 5015 CompilationUnit unit1 = units[1]; |
| 5008 CompilationUnit unit2 = units[2]; | 5016 CompilationUnit unit2 = units[2]; |
| 5009 | 5017 |
| 5010 InterfaceType intType = context.typeProvider.intType; | 5018 InterfaceType intType = context.typeProvider.intType; |
| 5019 DartType dynamicType = context.typeProvider.dynamicType; |
| 5011 | 5020 |
| 5012 assertVariableDeclarationTypes( | 5021 assertVariableDeclarationTypes( |
| 5013 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); | 5022 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
| 5014 | 5023 |
| 5015 assertVariableDeclarationTypes( | 5024 assertVariableDeclarationTypes( |
| 5016 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); | 5025 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 5017 | 5026 |
| 5018 List<Statement> statements = | 5027 List<Statement> statements = |
| 5019 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); | 5028 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 5020 | 5029 |
| 5021 assertAssignmentStatementTypes(statements[1], intType, intType); | 5030 assertAssignmentStatementTypes(statements[1], intType, dynamicType); |
| 5022 } | 5031 } |
| 5023 | 5032 |
| 5024 // Test inference interactions between local variables and fields | 5033 // Test inference interactions between local variables and fields |
| 5025 void test_perform_inference_cross_unit_instance_member() { | 5034 void test_perform_inference_cross_unit_instance_member() { |
| 5026 List<Source> sources = newSources({ | 5035 List<Source> sources = newSources({ |
| 5027 '/a.dart': ''' | 5036 '/a.dart': ''' |
| 5028 import 'b.dart'; | 5037 import 'b.dart'; |
| 5029 var bar = new B(); | 5038 var bar = new B(); |
| 5030 void foo() { | 5039 void foo() { |
| 5031 String x = bar.f.z; | 5040 String x = bar.f.z; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5143 } | 5152 } |
| 5144 ''' | 5153 ''' |
| 5145 }); | 5154 }); |
| 5146 List<dynamic> units = | 5155 List<dynamic> units = |
| 5147 computeLibraryResults(sources, RESOLVED_UNIT11).toList(); | 5156 computeLibraryResults(sources, RESOLVED_UNIT11).toList(); |
| 5148 CompilationUnit unit0 = units[0]; | 5157 CompilationUnit unit0 = units[0]; |
| 5149 CompilationUnit unit1 = units[1]; | 5158 CompilationUnit unit1 = units[1]; |
| 5150 CompilationUnit unit2 = units[2]; | 5159 CompilationUnit unit2 = units[2]; |
| 5151 | 5160 |
| 5152 InterfaceType intType = context.typeProvider.intType; | 5161 InterfaceType intType = context.typeProvider.intType; |
| 5162 DartType dynamicType = context.typeProvider.dynamicType; |
| 5153 | 5163 |
| 5154 assertVariableDeclarationTypes( | 5164 assertVariableDeclarationTypes( |
| 5155 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); | 5165 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); |
| 5156 assertVariableDeclarationTypes( | 5166 assertVariableDeclarationTypes( |
| 5157 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); | 5167 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
| 5158 | 5168 |
| 5159 assertVariableDeclarationTypes( | 5169 assertVariableDeclarationTypes( |
| 5160 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); | 5170 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 5161 assertVariableDeclarationTypes( | 5171 assertVariableDeclarationTypes( |
| 5162 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); | 5172 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 5163 | 5173 |
| 5164 List<Statement> statements = | 5174 List<Statement> statements = |
| 5165 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); | 5175 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 5166 | 5176 |
| 5167 assertAssignmentStatementTypes(statements[1], intType, intType); | 5177 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 5168 assertAssignmentStatementTypes(statements[2], intType, intType); | 5178 assertAssignmentStatementTypes(statements[2], intType, dynamicType); |
| 5169 } | 5179 } |
| 5170 | 5180 |
| 5171 // Test inference across units (non-cyclic) | 5181 // Test inference across units (non-cyclic) |
| 5172 void test_perform_inference_local_variables() { | 5182 void test_perform_inference_local_variables() { |
| 5173 AnalysisTarget source = newSource( | 5183 AnalysisTarget source = newSource( |
| 5174 '/test.dart', | 5184 '/test.dart', |
| 5175 ''' | 5185 ''' |
| 5176 test() { | 5186 test() { |
| 5177 int x = 3; | 5187 int x = 3; |
| 5178 x = "hi"; | 5188 x = "hi"; |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5737 /** | 5747 /** |
| 5738 * Fill [errorListener] with [result] errors in the current [task]. | 5748 * Fill [errorListener] with [result] errors in the current [task]. |
| 5739 */ | 5749 */ |
| 5740 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 5750 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 5741 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; | 5751 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; |
| 5742 expect(errors, isNotNull, reason: result.name); | 5752 expect(errors, isNotNull, reason: result.name); |
| 5743 errorListener = new GatheringErrorListener(); | 5753 errorListener = new GatheringErrorListener(); |
| 5744 errorListener.addAll(errors); | 5754 errorListener.addAll(errors); |
| 5745 } | 5755 } |
| 5746 } | 5756 } |
| OLD | NEW |