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.test.generated.incremental_resolver_test; | 5 library analyzer.test.generated.incremental_resolver_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/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/error/error.dart'; | 10 import 'package:analyzer/error/error.dart'; |
11 import 'package:analyzer/error/listener.dart'; | 11 import 'package:analyzer/error/listener.dart'; |
12 import 'package:analyzer/exception/exception.dart'; | 12 import 'package:analyzer/exception/exception.dart'; |
13 import 'package:analyzer/src/context/cache.dart'; | 13 import 'package:analyzer/src/context/cache.dart'; |
14 import 'package:analyzer/src/dart/ast/utilities.dart'; | 14 import 'package:analyzer/src/dart/ast/utilities.dart'; |
15 import 'package:analyzer/src/dart/element/element.dart'; | 15 import 'package:analyzer/src/dart/element/element.dart'; |
16 import 'package:analyzer/src/dart/scanner/reader.dart'; | 16 import 'package:analyzer/src/dart/scanner/reader.dart'; |
17 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 17 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
18 import 'package:analyzer/src/generated/engine.dart'; | 18 import 'package:analyzer/src/generated/engine.dart'; |
19 import 'package:analyzer/src/generated/incremental_logger.dart' as logging; | 19 import 'package:analyzer/src/generated/incremental_logger.dart' as logging; |
20 import 'package:analyzer/src/generated/incremental_resolution_validator.dart'; | 20 import 'package:analyzer/src/generated/incremental_resolution_validator.dart'; |
21 import 'package:analyzer/src/generated/incremental_resolver.dart'; | 21 import 'package:analyzer/src/generated/incremental_resolver.dart'; |
22 import 'package:analyzer/src/generated/java_engine.dart'; | 22 import 'package:analyzer/src/generated/java_engine.dart'; |
23 import 'package:analyzer/src/generated/parser.dart'; | 23 import 'package:analyzer/src/generated/parser.dart'; |
24 import 'package:analyzer/src/generated/resolver.dart'; | 24 import 'package:analyzer/src/generated/resolver.dart'; |
25 import 'package:analyzer/src/generated/source_io.dart'; | 25 import 'package:analyzer/src/generated/source_io.dart'; |
26 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 26 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; |
27 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 27 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
28 import 'package:analyzer/src/generated/utilities_collection.dart'; | 28 import 'package:analyzer/src/generated/utilities_collection.dart'; |
29 import 'package:analyzer/src/task/dart.dart'; | 29 import 'package:analyzer/src/task/dart.dart'; |
30 import 'package:analyzer/task/dart.dart'; | 30 import 'package:analyzer/task/dart.dart'; |
31 import 'package:analyzer/task/model.dart'; | 31 import 'package:analyzer/task/model.dart'; |
32 import 'package:test/test.dart'; | 32 import 'package:test/test.dart'; |
33 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 33 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
34 | 34 |
35 import 'analysis_context_factory.dart'; | 35 import 'analysis_context_factory.dart'; |
36 import 'resolver_test_case.dart'; | 36 import 'resolver_test_case.dart'; |
(...skipping 2211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2248 } | 2248 } |
2249 | 2249 |
2250 void test_scopeFor_MethodDeclaration_body() { | 2250 void test_scopeFor_MethodDeclaration_body() { |
2251 Scope scope = _scopeFor(_createResolvedMethodDeclaration().body); | 2251 Scope scope = _scopeFor(_createResolvedMethodDeclaration().body); |
2252 EngineTestCase.assertInstanceOf( | 2252 EngineTestCase.assertInstanceOf( |
2253 (obj) => obj is FunctionScope, FunctionScope, scope); | 2253 (obj) => obj is FunctionScope, FunctionScope, scope); |
2254 } | 2254 } |
2255 | 2255 |
2256 void test_scopeFor_notInCompilationUnit() { | 2256 void test_scopeFor_notInCompilationUnit() { |
2257 try { | 2257 try { |
2258 _scopeFor(AstFactory.identifier3("x")); | 2258 _scopeFor(AstTestFactory.identifier3("x")); |
2259 fail("Expected AnalysisException"); | 2259 fail("Expected AnalysisException"); |
2260 } on AnalysisException { | 2260 } on AnalysisException { |
2261 // Expected | 2261 // Expected |
2262 } | 2262 } |
2263 } | 2263 } |
2264 | 2264 |
2265 void test_scopeFor_null() { | 2265 void test_scopeFor_null() { |
2266 try { | 2266 try { |
2267 _scopeFor(null); | 2267 _scopeFor(null); |
2268 fail("Expected AnalysisException"); | 2268 fail("Expected AnalysisException"); |
2269 } on AnalysisException { | 2269 } on AnalysisException { |
2270 // Expected | 2270 // Expected |
2271 } | 2271 } |
2272 } | 2272 } |
2273 | 2273 |
2274 void test_scopeFor_unresolved() { | 2274 void test_scopeFor_unresolved() { |
2275 try { | 2275 try { |
2276 _scopeFor(AstFactory.compilationUnit()); | 2276 _scopeFor(AstTestFactory.compilationUnit()); |
2277 fail("Expected AnalysisException"); | 2277 fail("Expected AnalysisException"); |
2278 } on AnalysisException { | 2278 } on AnalysisException { |
2279 // Expected | 2279 // Expected |
2280 } | 2280 } |
2281 } | 2281 } |
2282 | 2282 |
2283 ClassDeclaration _createResolvedClassDeclaration() { | 2283 ClassDeclaration _createResolvedClassDeclaration() { |
2284 CompilationUnit unit = _createResolvedCompilationUnit(); | 2284 CompilationUnit unit = _createResolvedCompilationUnit(); |
2285 String className = "C"; | 2285 String className = "C"; |
2286 ClassDeclaration classNode = AstFactory.classDeclaration( | 2286 ClassDeclaration classNode = AstTestFactory.classDeclaration( |
2287 null, className, AstFactory.typeParameterList(), null, null, null); | 2287 null, className, AstTestFactory.typeParameterList(), null, null, null); |
2288 unit.declarations.add(classNode); | 2288 unit.declarations.add(classNode); |
2289 ClassElement classElement = ElementFactory.classElement2(className); | 2289 ClassElement classElement = ElementFactory.classElement2(className); |
2290 classNode.name.staticElement = classElement; | 2290 classNode.name.staticElement = classElement; |
2291 (unit.element as CompilationUnitElementImpl).types = <ClassElement>[ | 2291 (unit.element as CompilationUnitElementImpl).types = <ClassElement>[ |
2292 classElement | 2292 classElement |
2293 ]; | 2293 ]; |
2294 return classNode; | 2294 return classNode; |
2295 } | 2295 } |
2296 | 2296 |
2297 ClassTypeAlias _createResolvedClassTypeAlias() { | 2297 ClassTypeAlias _createResolvedClassTypeAlias() { |
2298 CompilationUnit unit = _createResolvedCompilationUnit(); | 2298 CompilationUnit unit = _createResolvedCompilationUnit(); |
2299 String className = "C"; | 2299 String className = "C"; |
2300 ClassTypeAlias classNode = AstFactory.classTypeAlias( | 2300 ClassTypeAlias classNode = AstTestFactory.classTypeAlias( |
2301 className, AstFactory.typeParameterList(), null, null, null, null); | 2301 className, AstTestFactory.typeParameterList(), null, null, null, null); |
2302 unit.declarations.add(classNode); | 2302 unit.declarations.add(classNode); |
2303 ClassElement classElement = ElementFactory.classElement2(className); | 2303 ClassElement classElement = ElementFactory.classElement2(className); |
2304 classNode.name.staticElement = classElement; | 2304 classNode.name.staticElement = classElement; |
2305 (unit.element as CompilationUnitElementImpl).types = <ClassElement>[ | 2305 (unit.element as CompilationUnitElementImpl).types = <ClassElement>[ |
2306 classElement | 2306 classElement |
2307 ]; | 2307 ]; |
2308 return classNode; | 2308 return classNode; |
2309 } | 2309 } |
2310 | 2310 |
2311 CompilationUnit _createResolvedCompilationUnit() { | 2311 CompilationUnit _createResolvedCompilationUnit() { |
2312 CompilationUnit unit = AstFactory.compilationUnit(); | 2312 CompilationUnit unit = AstTestFactory.compilationUnit(); |
2313 LibraryElementImpl library = | 2313 LibraryElementImpl library = |
2314 ElementFactory.library(AnalysisContextFactory.contextWithCore(), "lib"); | 2314 ElementFactory.library(AnalysisContextFactory.contextWithCore(), "lib"); |
2315 unit.element = library.definingCompilationUnit; | 2315 unit.element = library.definingCompilationUnit; |
2316 return unit; | 2316 return unit; |
2317 } | 2317 } |
2318 | 2318 |
2319 ConstructorDeclaration _createResolvedConstructorDeclaration() { | 2319 ConstructorDeclaration _createResolvedConstructorDeclaration() { |
2320 ClassDeclaration classNode = _createResolvedClassDeclaration(); | 2320 ClassDeclaration classNode = _createResolvedClassDeclaration(); |
2321 String constructorName = "f"; | 2321 String constructorName = "f"; |
2322 ConstructorDeclaration constructorNode = AstFactory.constructorDeclaration( | 2322 ConstructorDeclaration constructorNode = |
2323 AstFactory.identifier3(constructorName), | 2323 AstTestFactory.constructorDeclaration( |
2324 null, | 2324 AstTestFactory.identifier3(constructorName), |
2325 AstFactory.formalParameterList(), | 2325 null, |
2326 null); | 2326 AstTestFactory.formalParameterList(), |
| 2327 null); |
2327 classNode.members.add(constructorNode); | 2328 classNode.members.add(constructorNode); |
2328 ConstructorElement constructorElement = | 2329 ConstructorElement constructorElement = |
2329 ElementFactory.constructorElement2(classNode.element, null); | 2330 ElementFactory.constructorElement2(classNode.element, null); |
2330 constructorNode.element = constructorElement; | 2331 constructorNode.element = constructorElement; |
2331 (classNode.element as ClassElementImpl).constructors = <ConstructorElement>[ | 2332 (classNode.element as ClassElementImpl).constructors = <ConstructorElement>[ |
2332 constructorElement | 2333 constructorElement |
2333 ]; | 2334 ]; |
2334 return constructorNode; | 2335 return constructorNode; |
2335 } | 2336 } |
2336 | 2337 |
2337 FunctionDeclaration _createResolvedFunctionDeclaration() { | 2338 FunctionDeclaration _createResolvedFunctionDeclaration() { |
2338 CompilationUnit unit = _createResolvedCompilationUnit(); | 2339 CompilationUnit unit = _createResolvedCompilationUnit(); |
2339 String functionName = "f"; | 2340 String functionName = "f"; |
2340 FunctionDeclaration functionNode = AstFactory.functionDeclaration( | 2341 FunctionDeclaration functionNode = AstTestFactory.functionDeclaration( |
2341 null, null, functionName, AstFactory.functionExpression()); | 2342 null, null, functionName, AstTestFactory.functionExpression()); |
2342 unit.declarations.add(functionNode); | 2343 unit.declarations.add(functionNode); |
2343 FunctionElement functionElement = | 2344 FunctionElement functionElement = |
2344 ElementFactory.functionElement(functionName); | 2345 ElementFactory.functionElement(functionName); |
2345 functionNode.name.staticElement = functionElement; | 2346 functionNode.name.staticElement = functionElement; |
2346 (unit.element as CompilationUnitElementImpl).functions = <FunctionElement>[ | 2347 (unit.element as CompilationUnitElementImpl).functions = <FunctionElement>[ |
2347 functionElement | 2348 functionElement |
2348 ]; | 2349 ]; |
2349 return functionNode; | 2350 return functionNode; |
2350 } | 2351 } |
2351 | 2352 |
2352 FunctionTypeAlias _createResolvedFunctionTypeAlias() { | 2353 FunctionTypeAlias _createResolvedFunctionTypeAlias() { |
2353 CompilationUnit unit = _createResolvedCompilationUnit(); | 2354 CompilationUnit unit = _createResolvedCompilationUnit(); |
2354 FunctionTypeAlias aliasNode = AstFactory.typeAlias( | 2355 FunctionTypeAlias aliasNode = AstTestFactory.typeAlias( |
2355 AstFactory.typeName4("A"), | 2356 AstTestFactory.typeName4("A"), |
2356 "F", | 2357 "F", |
2357 AstFactory.typeParameterList(), | 2358 AstTestFactory.typeParameterList(), |
2358 AstFactory.formalParameterList()); | 2359 AstTestFactory.formalParameterList()); |
2359 unit.declarations.add(aliasNode); | 2360 unit.declarations.add(aliasNode); |
2360 SimpleIdentifier aliasName = aliasNode.name; | 2361 SimpleIdentifier aliasName = aliasNode.name; |
2361 FunctionTypeAliasElement aliasElement = | 2362 FunctionTypeAliasElement aliasElement = |
2362 new FunctionTypeAliasElementImpl.forNode(aliasName); | 2363 new FunctionTypeAliasElementImpl.forNode(aliasName); |
2363 aliasName.staticElement = aliasElement; | 2364 aliasName.staticElement = aliasElement; |
2364 (unit.element as CompilationUnitElementImpl).typeAliases = | 2365 (unit.element as CompilationUnitElementImpl).typeAliases = |
2365 <FunctionTypeAliasElement>[aliasElement]; | 2366 <FunctionTypeAliasElement>[aliasElement]; |
2366 return aliasNode; | 2367 return aliasNode; |
2367 } | 2368 } |
2368 | 2369 |
2369 MethodDeclaration _createResolvedMethodDeclaration() { | 2370 MethodDeclaration _createResolvedMethodDeclaration() { |
2370 ClassDeclaration classNode = _createResolvedClassDeclaration(); | 2371 ClassDeclaration classNode = _createResolvedClassDeclaration(); |
2371 String methodName = "f"; | 2372 String methodName = "f"; |
2372 MethodDeclaration methodNode = AstFactory.methodDeclaration( | 2373 MethodDeclaration methodNode = AstTestFactory.methodDeclaration( |
2373 null, | 2374 null, |
2374 null, | 2375 null, |
2375 null, | 2376 null, |
2376 null, | 2377 null, |
2377 AstFactory.identifier3(methodName), | 2378 AstTestFactory.identifier3(methodName), |
2378 AstFactory.formalParameterList()); | 2379 AstTestFactory.formalParameterList()); |
2379 classNode.members.add(methodNode); | 2380 classNode.members.add(methodNode); |
2380 MethodElement methodElement = | 2381 MethodElement methodElement = |
2381 ElementFactory.methodElement(methodName, null); | 2382 ElementFactory.methodElement(methodName, null); |
2382 methodNode.name.staticElement = methodElement; | 2383 methodNode.name.staticElement = methodElement; |
2383 (classNode.element as ClassElementImpl).methods = <MethodElement>[ | 2384 (classNode.element as ClassElementImpl).methods = <MethodElement>[ |
2384 methodElement | 2385 methodElement |
2385 ]; | 2386 ]; |
2386 return methodNode; | 2387 return methodNode; |
2387 } | 2388 } |
2388 | 2389 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2421 void logException(Object exception, [Object stackTrace]) { | 2422 void logException(Object exception, [Object stackTrace]) { |
2422 lastException = exception; | 2423 lastException = exception; |
2423 lastStackTrace = stackTrace; | 2424 lastStackTrace = stackTrace; |
2424 } | 2425 } |
2425 | 2426 |
2426 @override | 2427 @override |
2427 logging.LoggingTimer startTimer() { | 2428 logging.LoggingTimer startTimer() { |
2428 return new logging.LoggingTimer(this); | 2429 return new logging.LoggingTimer(this); |
2429 } | 2430 } |
2430 } | 2431 } |
OLD | NEW |