| 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 test.src.task.dart_test; | 5 library test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/constant.dart'; | 9 import 'package:analyzer/src/generated/constant.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 2251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2262 class A {} | 2262 class A {} |
| 2263 class C { | 2263 class C { |
| 2264 static final f = ''; | 2264 static final f = ''; |
| 2265 var g = 0; | 2265 var g = 0; |
| 2266 } | 2266 } |
| 2267 '''); | 2267 '''); |
| 2268 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2268 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2269 computeResult(target, RESOLVED_UNIT5, | 2269 computeResult(target, RESOLVED_UNIT5, |
| 2270 matcher: isPartiallyResolveUnitReferencesTask); | 2270 matcher: isPartiallyResolveUnitReferencesTask); |
| 2271 // Test the outputs | 2271 // Test the outputs |
| 2272 expect(outputs[CLASSES_IN_UNIT], hasLength(2)); | 2272 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(4)); |
| 2273 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(2)); | |
| 2274 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2273 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2275 expect(unit, same(outputs[RESOLVED_UNIT5])); | 2274 expect(unit, same(outputs[RESOLVED_UNIT5])); |
| 2276 // Test the state of the AST | 2275 // Test the state of the AST |
| 2277 TopLevelVariableDeclaration a = unit.declarations[0]; | 2276 TopLevelVariableDeclaration a = unit.declarations[0]; |
| 2278 VariableDeclaration variableA = a.variables.variables[0]; | 2277 VariableDeclaration variableA = a.variables.variables[0]; |
| 2279 SimpleIdentifier initializer = variableA.initializer; | 2278 SimpleIdentifier initializer = variableA.initializer; |
| 2280 expect(initializer.staticElement, isNotNull); | 2279 expect(initializer.staticElement, isNotNull); |
| 2281 // Test the error generation | 2280 // Test the error generation |
| 2282 _fillErrorListener(PARTIALLY_RESOLVE_REFERENCES_ERRORS); | 2281 _fillErrorListener(PARTIALLY_RESOLVE_REFERENCES_ERRORS); |
| 2283 errorListener.assertErrorsWithCodes( | 2282 errorListener.assertNoErrors(); |
| 2284 <ErrorCode>[StaticWarningCode.UNDEFINED_IDENTIFIER]); | |
| 2285 } | 2283 } |
| 2286 | 2284 |
| 2287 test_perform_importExport() { | 2285 test_perform_importExport() { |
| 2288 newSource( | 2286 newSource( |
| 2289 '/a.dart', | 2287 '/a.dart', |
| 2290 ''' | 2288 ''' |
| 2291 library a; | 2289 library a; |
| 2292 class A<T> { | 2290 class A<T> { |
| 2293 T m() {} | 2291 T m() {} |
| 2294 } | 2292 } |
| 2295 '''); | 2293 '''); |
| 2296 newSource( | 2294 newSource( |
| 2297 '/b.dart', | 2295 '/b.dart', |
| 2298 ''' | 2296 ''' |
| 2299 library b; | 2297 library b; |
| 2300 export 'a.dart'; | 2298 export 'a.dart'; |
| 2301 '''); | 2299 '''); |
| 2302 Source sourceC = newSource( | 2300 Source sourceC = newSource( |
| 2303 '/c.dart', | 2301 '/c.dart', |
| 2304 ''' | 2302 ''' |
| 2305 library c; | 2303 library c; |
| 2306 import 'b.dart'; | 2304 import 'b.dart'; |
| 2307 main() { | 2305 main() { |
| 2308 new A<int>().m(); | 2306 new A<int>().m(); |
| 2309 } | 2307 } |
| 2310 '''); | 2308 '''); |
| 2311 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT5, | 2309 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT5, |
| 2312 matcher: isPartiallyResolveUnitReferencesTask); | 2310 matcher: isPartiallyResolveUnitReferencesTask); |
| 2313 // validate | 2311 // validate |
| 2314 expect(outputs[CLASSES_IN_UNIT], hasLength(0)); | |
| 2315 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(0)); | 2312 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(0)); |
| 2316 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2313 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2317 expect(unit, isNotNull); | 2314 expect(unit, isNotNull); |
| 2318 | 2315 |
| 2319 FunctionDeclaration functionDeclaration = unit.declarations[0]; | 2316 FunctionDeclaration mainFunction = unit.declarations[0]; |
| 2320 BlockFunctionBody body = functionDeclaration.functionExpression.body; | 2317 expect(mainFunction.element, isNotNull); |
| 2318 BlockFunctionBody body = mainFunction.functionExpression.body; |
| 2321 List<Statement> statements = body.block.statements; | 2319 List<Statement> statements = body.block.statements; |
| 2322 ExpressionStatement statement = statements[0]; | 2320 ExpressionStatement statement = statements[0]; |
| 2323 MethodInvocation invocation = statement.expression; | 2321 MethodInvocation invocation = statement.expression; |
| 2324 MethodElement methodElement = invocation.methodName.staticElement; | 2322 MethodElement methodElement = invocation.methodName.staticElement; |
| 2325 expect(methodElement, isNotNull); | 2323 expect(methodElement, isNull); |
| 2326 expect(methodElement.type, isNotNull); | |
| 2327 expect(methodElement.returnType.toString(), 'int'); | |
| 2328 } | 2324 } |
| 2329 } | 2325 } |
| 2330 | 2326 |
| 2331 @reflectiveTest | 2327 @reflectiveTest |
| 2332 class ResolveFunctionBodiesInUnitTaskTest extends _AbstractDartTaskTest { | 2328 class ResolveFunctionBodiesInUnitTaskTest extends _AbstractDartTaskTest { |
| 2333 void test_perform() { | 2329 void test_perform() { |
| 2334 AnalysisTarget source = newSource( | 2330 AnalysisTarget source = newSource( |
| 2335 '/test.dart', | 2331 '/test.dart', |
| 2336 ''' | 2332 ''' |
| 2337 void f() { | 2333 void f() { |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2831 /** | 2827 /** |
| 2832 * Fill [errorListener] with [result] errors in the current [task]. | 2828 * Fill [errorListener] with [result] errors in the current [task]. |
| 2833 */ | 2829 */ |
| 2834 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 2830 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 2835 List<AnalysisError> errors = task.outputs[result]; | 2831 List<AnalysisError> errors = task.outputs[result]; |
| 2836 expect(errors, isNotNull, reason: result.name); | 2832 expect(errors, isNotNull, reason: result.name); |
| 2837 errorListener = new GatheringErrorListener(); | 2833 errorListener = new GatheringErrorListener(); |
| 2838 errorListener.addAll(errors); | 2834 errorListener.addAll(errors); |
| 2839 } | 2835 } |
| 2840 } | 2836 } |
| OLD | NEW |