| 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.parser_test; | 5 library analyzer.test.generated.parser_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/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | |
| 11 import 'package:analyzer/dart/element/type.dart'; | |
| 12 import 'package:analyzer/src/dart/ast/token.dart'; | 10 import 'package:analyzer/src/dart/ast/token.dart'; |
| 13 import 'package:analyzer/src/dart/ast/utilities.dart'; | 11 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 14 import 'package:analyzer/src/dart/element/element.dart'; | |
| 15 import 'package:analyzer/src/dart/scanner/reader.dart'; | 12 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| 16 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 13 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| 17 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 18 import 'package:analyzer/src/generated/error.dart'; | 15 import 'package:analyzer/src/generated/error.dart'; |
| 19 import 'package:analyzer/src/generated/incremental_scanner.dart'; | 16 import 'package:analyzer/src/generated/incremental_scanner.dart'; |
| 20 import 'package:analyzer/src/generated/parser.dart'; | 17 import 'package:analyzer/src/generated/parser.dart'; |
| 21 import 'package:analyzer/src/generated/source.dart' show Source; | 18 import 'package:analyzer/src/generated/source.dart' show Source; |
| 22 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 19 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 23 import 'package:analyzer/src/generated/testing/element_factory.dart'; | |
| 24 import 'package:analyzer/src/generated/testing/token_factory.dart'; | 20 import 'package:analyzer/src/generated/testing/token_factory.dart'; |
| 25 import 'package:analyzer/src/generated/utilities_dart.dart'; | 21 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 26 import 'package:unittest/unittest.dart' hide Configuration; | 22 import 'package:unittest/unittest.dart' hide Configuration; |
| 27 | 23 |
| 28 import '../reflective_tests.dart'; | 24 import '../reflective_tests.dart'; |
| 29 import '../utils.dart'; | 25 import '../utils.dart'; |
| 30 import 'test_support.dart'; | 26 import 'test_support.dart'; |
| 31 | 27 |
| 32 main() { | 28 main() { |
| 33 initializeTestEnvironment(); | 29 initializeTestEnvironment(); |
| 34 runReflectiveTests(ComplexParserTest); | 30 runReflectiveTests(ComplexParserTest); |
| 35 runReflectiveTests(ErrorParserTest); | 31 runReflectiveTests(ErrorParserTest); |
| 36 runReflectiveTests(IncrementalParserTest); | 32 runReflectiveTests(IncrementalParserTest); |
| 37 runReflectiveTests(NonErrorParserTest); | 33 runReflectiveTests(NonErrorParserTest); |
| 38 runReflectiveTests(RecoveryParserTest); | 34 runReflectiveTests(RecoveryParserTest); |
| 39 runReflectiveTests(ResolutionCopierTest); | |
| 40 runReflectiveTests(SimpleParserTest); | 35 runReflectiveTests(SimpleParserTest); |
| 41 } | 36 } |
| 42 | 37 |
| 43 class AnalysisErrorListener_SimpleParserTest_computeStringValue | 38 class AnalysisErrorListener_SimpleParserTest_computeStringValue |
| 44 implements AnalysisErrorListener { | 39 implements AnalysisErrorListener { |
| 45 @override | 40 @override |
| 46 void onError(AnalysisError event) { | 41 void onError(AnalysisError event) { |
| 47 fail( | 42 fail( |
| 48 "Unexpected compilation error: ${event.message} (${event.offset}, ${even
t.length})"); | 43 "Unexpected compilation error: ${event.message} (${event.offset}, ${even
t.length})"); |
| 49 } | 44 } |
| (...skipping 4190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4240 CompilationUnitMember member = declarations[0]; | 4235 CompilationUnitMember member = declarations[0]; |
| 4241 EngineTestCase.assertInstanceOf( | 4236 EngineTestCase.assertInstanceOf( |
| 4242 (obj) => obj is FunctionTypeAlias, FunctionTypeAlias, member); | 4237 (obj) => obj is FunctionTypeAlias, FunctionTypeAlias, member); |
| 4243 } | 4238 } |
| 4244 | 4239 |
| 4245 void test_unaryPlus() { | 4240 void test_unaryPlus() { |
| 4246 parseExpression("+2", [ParserErrorCode.MISSING_IDENTIFIER]); | 4241 parseExpression("+2", [ParserErrorCode.MISSING_IDENTIFIER]); |
| 4247 } | 4242 } |
| 4248 } | 4243 } |
| 4249 | 4244 |
| 4250 @reflectiveTest | |
| 4251 class ResolutionCopierTest extends EngineTestCase { | |
| 4252 void test_visitAdjacentStrings() { | |
| 4253 AdjacentStrings createNode() => new AdjacentStrings([ | |
| 4254 new SimpleStringLiteral(null, 'hello'), | |
| 4255 new SimpleStringLiteral(null, 'world') | |
| 4256 ]); | |
| 4257 | |
| 4258 AdjacentStrings fromNode = createNode(); | |
| 4259 DartType propagatedType = ElementFactory.classElement2("A").type; | |
| 4260 fromNode.propagatedType = propagatedType; | |
| 4261 DartType staticType = ElementFactory.classElement2("B").type; | |
| 4262 fromNode.staticType = staticType; | |
| 4263 | |
| 4264 AdjacentStrings toNode = createNode(); | |
| 4265 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4266 expect(toNode.propagatedType, same(propagatedType)); | |
| 4267 expect(toNode.staticType, same(staticType)); | |
| 4268 } | |
| 4269 | |
| 4270 void test_visitAnnotation() { | |
| 4271 String annotationName = "proxy"; | |
| 4272 Annotation fromNode = | |
| 4273 AstFactory.annotation(AstFactory.identifier3(annotationName)); | |
| 4274 Element element = ElementFactory.topLevelVariableElement2(annotationName); | |
| 4275 fromNode.element = element; | |
| 4276 Annotation toNode = | |
| 4277 AstFactory.annotation(AstFactory.identifier3(annotationName)); | |
| 4278 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4279 expect(toNode.element, same(element)); | |
| 4280 } | |
| 4281 | |
| 4282 void test_visitAsExpression() { | |
| 4283 AsExpression fromNode = AstFactory.asExpression( | |
| 4284 AstFactory.identifier3("x"), AstFactory.typeName4("A")); | |
| 4285 DartType propagatedType = ElementFactory.classElement2("A").type; | |
| 4286 fromNode.propagatedType = propagatedType; | |
| 4287 DartType staticType = ElementFactory.classElement2("B").type; | |
| 4288 fromNode.staticType = staticType; | |
| 4289 AsExpression toNode = AstFactory.asExpression( | |
| 4290 AstFactory.identifier3("x"), AstFactory.typeName4("A")); | |
| 4291 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4292 expect(toNode.propagatedType, same(propagatedType)); | |
| 4293 expect(toNode.staticType, same(staticType)); | |
| 4294 } | |
| 4295 | |
| 4296 void test_visitAssignmentExpression() { | |
| 4297 AssignmentExpression fromNode = AstFactory.assignmentExpression( | |
| 4298 AstFactory.identifier3("a"), | |
| 4299 TokenType.PLUS_EQ, | |
| 4300 AstFactory.identifier3("b")); | |
| 4301 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4302 MethodElement propagatedElement = | |
| 4303 ElementFactory.methodElement("+", propagatedType); | |
| 4304 fromNode.propagatedElement = propagatedElement; | |
| 4305 fromNode.propagatedType = propagatedType; | |
| 4306 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4307 MethodElement staticElement = ElementFactory.methodElement("+", staticType); | |
| 4308 fromNode.staticElement = staticElement; | |
| 4309 fromNode.staticType = staticType; | |
| 4310 AssignmentExpression toNode = AstFactory.assignmentExpression( | |
| 4311 AstFactory.identifier3("a"), | |
| 4312 TokenType.PLUS_EQ, | |
| 4313 AstFactory.identifier3("b")); | |
| 4314 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4315 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4316 expect(toNode.propagatedType, same(propagatedType)); | |
| 4317 expect(toNode.staticElement, same(staticElement)); | |
| 4318 expect(toNode.staticType, same(staticType)); | |
| 4319 } | |
| 4320 | |
| 4321 void test_visitBinaryExpression() { | |
| 4322 BinaryExpression fromNode = AstFactory.binaryExpression( | |
| 4323 AstFactory.identifier3("a"), | |
| 4324 TokenType.PLUS, | |
| 4325 AstFactory.identifier3("b")); | |
| 4326 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4327 MethodElement propagatedElement = | |
| 4328 ElementFactory.methodElement("+", propagatedType); | |
| 4329 fromNode.propagatedElement = propagatedElement; | |
| 4330 fromNode.propagatedType = propagatedType; | |
| 4331 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4332 MethodElement staticElement = ElementFactory.methodElement("+", staticType); | |
| 4333 fromNode.staticElement = staticElement; | |
| 4334 fromNode.staticType = staticType; | |
| 4335 BinaryExpression toNode = AstFactory.binaryExpression( | |
| 4336 AstFactory.identifier3("a"), | |
| 4337 TokenType.PLUS, | |
| 4338 AstFactory.identifier3("b")); | |
| 4339 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4340 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4341 expect(toNode.propagatedType, same(propagatedType)); | |
| 4342 expect(toNode.staticElement, same(staticElement)); | |
| 4343 expect(toNode.staticType, same(staticType)); | |
| 4344 } | |
| 4345 | |
| 4346 void test_visitBooleanLiteral() { | |
| 4347 BooleanLiteral fromNode = AstFactory.booleanLiteral(true); | |
| 4348 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4349 fromNode.propagatedType = propagatedType; | |
| 4350 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4351 fromNode.staticType = staticType; | |
| 4352 BooleanLiteral toNode = AstFactory.booleanLiteral(true); | |
| 4353 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4354 expect(toNode.propagatedType, same(propagatedType)); | |
| 4355 expect(toNode.staticType, same(staticType)); | |
| 4356 } | |
| 4357 | |
| 4358 void test_visitCascadeExpression() { | |
| 4359 CascadeExpression fromNode = AstFactory.cascadeExpression( | |
| 4360 AstFactory.identifier3("a"), [AstFactory.identifier3("b")]); | |
| 4361 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4362 fromNode.propagatedType = propagatedType; | |
| 4363 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4364 fromNode.staticType = staticType; | |
| 4365 CascadeExpression toNode = AstFactory.cascadeExpression( | |
| 4366 AstFactory.identifier3("a"), [AstFactory.identifier3("b")]); | |
| 4367 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4368 expect(toNode.propagatedType, same(propagatedType)); | |
| 4369 expect(toNode.staticType, same(staticType)); | |
| 4370 } | |
| 4371 | |
| 4372 void test_visitCompilationUnit() { | |
| 4373 CompilationUnit fromNode = AstFactory.compilationUnit(); | |
| 4374 CompilationUnitElement element = | |
| 4375 new CompilationUnitElementImpl("test.dart"); | |
| 4376 fromNode.element = element; | |
| 4377 CompilationUnit toNode = AstFactory.compilationUnit(); | |
| 4378 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4379 expect(toNode.element, same(element)); | |
| 4380 } | |
| 4381 | |
| 4382 void test_visitConditionalExpression() { | |
| 4383 ConditionalExpression fromNode = AstFactory.conditionalExpression( | |
| 4384 AstFactory.identifier3("c"), | |
| 4385 AstFactory.identifier3("a"), | |
| 4386 AstFactory.identifier3("b")); | |
| 4387 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4388 fromNode.propagatedType = propagatedType; | |
| 4389 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4390 fromNode.staticType = staticType; | |
| 4391 ConditionalExpression toNode = AstFactory.conditionalExpression( | |
| 4392 AstFactory.identifier3("c"), | |
| 4393 AstFactory.identifier3("a"), | |
| 4394 AstFactory.identifier3("b")); | |
| 4395 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4396 expect(toNode.propagatedType, same(propagatedType)); | |
| 4397 expect(toNode.staticType, same(staticType)); | |
| 4398 } | |
| 4399 | |
| 4400 void test_visitConstructorDeclaration() { | |
| 4401 String className = "A"; | |
| 4402 String constructorName = "c"; | |
| 4403 ConstructorDeclaration fromNode = AstFactory.constructorDeclaration( | |
| 4404 AstFactory.identifier3(className), | |
| 4405 constructorName, | |
| 4406 AstFactory.formalParameterList(), | |
| 4407 null); | |
| 4408 ConstructorElement element = ElementFactory.constructorElement2( | |
| 4409 ElementFactory.classElement2(className), constructorName); | |
| 4410 fromNode.element = element; | |
| 4411 ConstructorDeclaration toNode = AstFactory.constructorDeclaration( | |
| 4412 AstFactory.identifier3(className), | |
| 4413 constructorName, | |
| 4414 AstFactory.formalParameterList(), | |
| 4415 null); | |
| 4416 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4417 expect(toNode.element, same(element)); | |
| 4418 } | |
| 4419 | |
| 4420 void test_visitConstructorName() { | |
| 4421 ConstructorName fromNode = | |
| 4422 AstFactory.constructorName(AstFactory.typeName4("A"), "c"); | |
| 4423 ConstructorElement staticElement = ElementFactory.constructorElement2( | |
| 4424 ElementFactory.classElement2("A"), "c"); | |
| 4425 fromNode.staticElement = staticElement; | |
| 4426 ConstructorName toNode = | |
| 4427 AstFactory.constructorName(AstFactory.typeName4("A"), "c"); | |
| 4428 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4429 expect(toNode.staticElement, same(staticElement)); | |
| 4430 } | |
| 4431 | |
| 4432 void test_visitDoubleLiteral() { | |
| 4433 DoubleLiteral fromNode = AstFactory.doubleLiteral(1.0); | |
| 4434 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4435 fromNode.propagatedType = propagatedType; | |
| 4436 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4437 fromNode.staticType = staticType; | |
| 4438 DoubleLiteral toNode = AstFactory.doubleLiteral(1.0); | |
| 4439 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4440 expect(toNode.propagatedType, same(propagatedType)); | |
| 4441 expect(toNode.staticType, same(staticType)); | |
| 4442 } | |
| 4443 | |
| 4444 void test_visitExportDirective() { | |
| 4445 ExportDirective fromNode = AstFactory.exportDirective2("dart:uri"); | |
| 4446 ExportElement element = new ExportElementImpl(-1); | |
| 4447 fromNode.element = element; | |
| 4448 ExportDirective toNode = AstFactory.exportDirective2("dart:uri"); | |
| 4449 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4450 expect(toNode.element, same(element)); | |
| 4451 } | |
| 4452 | |
| 4453 void test_visitFunctionExpression() { | |
| 4454 FunctionExpression fromNode = AstFactory.functionExpression2( | |
| 4455 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody()); | |
| 4456 MethodElement element = ElementFactory.methodElement( | |
| 4457 "m", ElementFactory.classElement2("C").type); | |
| 4458 fromNode.element = element; | |
| 4459 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4460 fromNode.propagatedType = propagatedType; | |
| 4461 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4462 fromNode.staticType = staticType; | |
| 4463 FunctionExpression toNode = AstFactory.functionExpression2( | |
| 4464 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody()); | |
| 4465 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4466 expect(toNode.element, same(element)); | |
| 4467 expect(toNode.propagatedType, same(propagatedType)); | |
| 4468 expect(toNode.staticType, same(staticType)); | |
| 4469 } | |
| 4470 | |
| 4471 void test_visitFunctionExpressionInvocation() { | |
| 4472 FunctionExpressionInvocation fromNode = | |
| 4473 AstFactory.functionExpressionInvocation(AstFactory.identifier3("f")); | |
| 4474 MethodElement propagatedElement = ElementFactory.methodElement( | |
| 4475 "m", ElementFactory.classElement2("C").type); | |
| 4476 fromNode.propagatedElement = propagatedElement; | |
| 4477 MethodElement staticElement = ElementFactory.methodElement( | |
| 4478 "m", ElementFactory.classElement2("C").type); | |
| 4479 fromNode.staticElement = staticElement; | |
| 4480 FunctionExpressionInvocation toNode = | |
| 4481 AstFactory.functionExpressionInvocation(AstFactory.identifier3("f")); | |
| 4482 | |
| 4483 _copyAndVerifyInvocation(fromNode, toNode); | |
| 4484 | |
| 4485 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4486 expect(toNode.staticElement, same(staticElement)); | |
| 4487 } | |
| 4488 | |
| 4489 void test_visitImportDirective() { | |
| 4490 ImportDirective fromNode = AstFactory.importDirective3("dart:uri", null); | |
| 4491 ImportElement element = new ImportElementImpl(0); | |
| 4492 fromNode.element = element; | |
| 4493 ImportDirective toNode = AstFactory.importDirective3("dart:uri", null); | |
| 4494 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4495 expect(toNode.element, same(element)); | |
| 4496 } | |
| 4497 | |
| 4498 void test_visitIndexExpression() { | |
| 4499 IndexExpression fromNode = AstFactory.indexExpression( | |
| 4500 AstFactory.identifier3("a"), AstFactory.integer(0)); | |
| 4501 MethodElement propagatedElement = ElementFactory.methodElement( | |
| 4502 "m", ElementFactory.classElement2("C").type); | |
| 4503 MethodElement staticElement = ElementFactory.methodElement( | |
| 4504 "m", ElementFactory.classElement2("C").type); | |
| 4505 AuxiliaryElements auxiliaryElements = | |
| 4506 new AuxiliaryElements(staticElement, propagatedElement); | |
| 4507 fromNode.auxiliaryElements = auxiliaryElements; | |
| 4508 fromNode.propagatedElement = propagatedElement; | |
| 4509 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4510 fromNode.propagatedType = propagatedType; | |
| 4511 fromNode.staticElement = staticElement; | |
| 4512 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4513 fromNode.staticType = staticType; | |
| 4514 IndexExpression toNode = AstFactory.indexExpression( | |
| 4515 AstFactory.identifier3("a"), AstFactory.integer(0)); | |
| 4516 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4517 expect(toNode.auxiliaryElements, same(auxiliaryElements)); | |
| 4518 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4519 expect(toNode.propagatedType, same(propagatedType)); | |
| 4520 expect(toNode.staticElement, same(staticElement)); | |
| 4521 expect(toNode.staticType, same(staticType)); | |
| 4522 } | |
| 4523 | |
| 4524 void test_visitInstanceCreationExpression() { | |
| 4525 InstanceCreationExpression fromNode = AstFactory | |
| 4526 .instanceCreationExpression2(Keyword.NEW, AstFactory.typeName4("C")); | |
| 4527 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4528 fromNode.propagatedType = propagatedType; | |
| 4529 ConstructorElement staticElement = ElementFactory.constructorElement2( | |
| 4530 ElementFactory.classElement2("C"), null); | |
| 4531 fromNode.staticElement = staticElement; | |
| 4532 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4533 fromNode.staticType = staticType; | |
| 4534 InstanceCreationExpression toNode = AstFactory.instanceCreationExpression2( | |
| 4535 Keyword.NEW, AstFactory.typeName4("C")); | |
| 4536 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4537 expect(toNode.propagatedType, same(propagatedType)); | |
| 4538 expect(toNode.staticElement, same(staticElement)); | |
| 4539 expect(toNode.staticType, same(staticType)); | |
| 4540 } | |
| 4541 | |
| 4542 void test_visitIntegerLiteral() { | |
| 4543 IntegerLiteral fromNode = AstFactory.integer(2); | |
| 4544 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4545 fromNode.propagatedType = propagatedType; | |
| 4546 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4547 fromNode.staticType = staticType; | |
| 4548 IntegerLiteral toNode = AstFactory.integer(2); | |
| 4549 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4550 expect(toNode.propagatedType, same(propagatedType)); | |
| 4551 expect(toNode.staticType, same(staticType)); | |
| 4552 } | |
| 4553 | |
| 4554 void test_visitIsExpression() { | |
| 4555 IsExpression fromNode = AstFactory.isExpression( | |
| 4556 AstFactory.identifier3("x"), false, AstFactory.typeName4("A")); | |
| 4557 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4558 fromNode.propagatedType = propagatedType; | |
| 4559 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4560 fromNode.staticType = staticType; | |
| 4561 IsExpression toNode = AstFactory.isExpression( | |
| 4562 AstFactory.identifier3("x"), false, AstFactory.typeName4("A")); | |
| 4563 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4564 expect(toNode.propagatedType, same(propagatedType)); | |
| 4565 expect(toNode.staticType, same(staticType)); | |
| 4566 } | |
| 4567 | |
| 4568 void test_visitLibraryIdentifier() { | |
| 4569 LibraryIdentifier fromNode = | |
| 4570 AstFactory.libraryIdentifier([AstFactory.identifier3("lib")]); | |
| 4571 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4572 fromNode.propagatedType = propagatedType; | |
| 4573 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4574 fromNode.staticType = staticType; | |
| 4575 LibraryIdentifier toNode = | |
| 4576 AstFactory.libraryIdentifier([AstFactory.identifier3("lib")]); | |
| 4577 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4578 expect(toNode.propagatedType, same(propagatedType)); | |
| 4579 expect(toNode.staticType, same(staticType)); | |
| 4580 } | |
| 4581 | |
| 4582 void test_visitListLiteral() { | |
| 4583 ListLiteral fromNode = AstFactory.listLiteral(); | |
| 4584 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4585 fromNode.propagatedType = propagatedType; | |
| 4586 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4587 fromNode.staticType = staticType; | |
| 4588 ListLiteral toNode = AstFactory.listLiteral(); | |
| 4589 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4590 expect(toNode.propagatedType, same(propagatedType)); | |
| 4591 expect(toNode.staticType, same(staticType)); | |
| 4592 } | |
| 4593 | |
| 4594 void test_visitMapLiteral() { | |
| 4595 MapLiteral fromNode = AstFactory.mapLiteral2(); | |
| 4596 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4597 fromNode.propagatedType = propagatedType; | |
| 4598 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4599 fromNode.staticType = staticType; | |
| 4600 MapLiteral toNode = AstFactory.mapLiteral2(); | |
| 4601 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4602 expect(toNode.propagatedType, same(propagatedType)); | |
| 4603 expect(toNode.staticType, same(staticType)); | |
| 4604 } | |
| 4605 | |
| 4606 void test_visitMethodInvocation() { | |
| 4607 MethodInvocation fromNode = AstFactory.methodInvocation2("m"); | |
| 4608 MethodInvocation toNode = AstFactory.methodInvocation2("m"); | |
| 4609 _copyAndVerifyInvocation(fromNode, toNode); | |
| 4610 } | |
| 4611 | |
| 4612 void test_visitNamedExpression() { | |
| 4613 NamedExpression fromNode = | |
| 4614 AstFactory.namedExpression2("n", AstFactory.integer(0)); | |
| 4615 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4616 fromNode.propagatedType = propagatedType; | |
| 4617 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4618 fromNode.staticType = staticType; | |
| 4619 NamedExpression toNode = | |
| 4620 AstFactory.namedExpression2("n", AstFactory.integer(0)); | |
| 4621 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4622 expect(toNode.propagatedType, same(propagatedType)); | |
| 4623 expect(toNode.staticType, same(staticType)); | |
| 4624 } | |
| 4625 | |
| 4626 void test_visitNullLiteral() { | |
| 4627 NullLiteral fromNode = AstFactory.nullLiteral(); | |
| 4628 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4629 fromNode.propagatedType = propagatedType; | |
| 4630 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4631 fromNode.staticType = staticType; | |
| 4632 NullLiteral toNode = AstFactory.nullLiteral(); | |
| 4633 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4634 expect(toNode.propagatedType, same(propagatedType)); | |
| 4635 expect(toNode.staticType, same(staticType)); | |
| 4636 } | |
| 4637 | |
| 4638 void test_visitParenthesizedExpression() { | |
| 4639 ParenthesizedExpression fromNode = | |
| 4640 AstFactory.parenthesizedExpression(AstFactory.integer(0)); | |
| 4641 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4642 fromNode.propagatedType = propagatedType; | |
| 4643 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4644 fromNode.staticType = staticType; | |
| 4645 ParenthesizedExpression toNode = | |
| 4646 AstFactory.parenthesizedExpression(AstFactory.integer(0)); | |
| 4647 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4648 expect(toNode.propagatedType, same(propagatedType)); | |
| 4649 expect(toNode.staticType, same(staticType)); | |
| 4650 } | |
| 4651 | |
| 4652 void test_visitPartDirective() { | |
| 4653 PartDirective fromNode = AstFactory.partDirective2("part.dart"); | |
| 4654 LibraryElement element = new LibraryElementImpl.forNode( | |
| 4655 null, AstFactory.libraryIdentifier2(["lib"])); | |
| 4656 fromNode.element = element; | |
| 4657 PartDirective toNode = AstFactory.partDirective2("part.dart"); | |
| 4658 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4659 expect(toNode.element, same(element)); | |
| 4660 } | |
| 4661 | |
| 4662 void test_visitPartOfDirective() { | |
| 4663 PartOfDirective fromNode = | |
| 4664 AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["lib"])); | |
| 4665 LibraryElement element = new LibraryElementImpl.forNode( | |
| 4666 null, AstFactory.libraryIdentifier2(["lib"])); | |
| 4667 fromNode.element = element; | |
| 4668 PartOfDirective toNode = | |
| 4669 AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["lib"])); | |
| 4670 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4671 expect(toNode.element, same(element)); | |
| 4672 } | |
| 4673 | |
| 4674 void test_visitPostfixExpression() { | |
| 4675 String variableName = "x"; | |
| 4676 PostfixExpression fromNode = AstFactory.postfixExpression( | |
| 4677 AstFactory.identifier3(variableName), TokenType.PLUS_PLUS); | |
| 4678 MethodElement propagatedElement = ElementFactory.methodElement( | |
| 4679 "+", ElementFactory.classElement2("C").type); | |
| 4680 fromNode.propagatedElement = propagatedElement; | |
| 4681 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4682 fromNode.propagatedType = propagatedType; | |
| 4683 MethodElement staticElement = ElementFactory.methodElement( | |
| 4684 "+", ElementFactory.classElement2("C").type); | |
| 4685 fromNode.staticElement = staticElement; | |
| 4686 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4687 fromNode.staticType = staticType; | |
| 4688 PostfixExpression toNode = AstFactory.postfixExpression( | |
| 4689 AstFactory.identifier3(variableName), TokenType.PLUS_PLUS); | |
| 4690 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4691 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4692 expect(toNode.propagatedType, same(propagatedType)); | |
| 4693 expect(toNode.staticElement, same(staticElement)); | |
| 4694 expect(toNode.staticType, same(staticType)); | |
| 4695 } | |
| 4696 | |
| 4697 void test_visitPrefixedIdentifier() { | |
| 4698 PrefixedIdentifier fromNode = AstFactory.identifier5("p", "f"); | |
| 4699 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4700 fromNode.propagatedType = propagatedType; | |
| 4701 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4702 fromNode.staticType = staticType; | |
| 4703 PrefixedIdentifier toNode = AstFactory.identifier5("p", "f"); | |
| 4704 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4705 expect(toNode.propagatedType, same(propagatedType)); | |
| 4706 expect(toNode.staticType, same(staticType)); | |
| 4707 } | |
| 4708 | |
| 4709 void test_visitPrefixExpression() { | |
| 4710 PrefixExpression fromNode = AstFactory.prefixExpression( | |
| 4711 TokenType.PLUS_PLUS, AstFactory.identifier3("x")); | |
| 4712 MethodElement propagatedElement = ElementFactory.methodElement( | |
| 4713 "+", ElementFactory.classElement2("C").type); | |
| 4714 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4715 fromNode.propagatedElement = propagatedElement; | |
| 4716 fromNode.propagatedType = propagatedType; | |
| 4717 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4718 MethodElement staticElement = ElementFactory.methodElement( | |
| 4719 "+", ElementFactory.classElement2("C").type); | |
| 4720 fromNode.staticElement = staticElement; | |
| 4721 fromNode.staticType = staticType; | |
| 4722 PrefixExpression toNode = AstFactory.prefixExpression( | |
| 4723 TokenType.PLUS_PLUS, AstFactory.identifier3("x")); | |
| 4724 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4725 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4726 expect(toNode.propagatedType, same(propagatedType)); | |
| 4727 expect(toNode.staticElement, same(staticElement)); | |
| 4728 expect(toNode.staticType, same(staticType)); | |
| 4729 } | |
| 4730 | |
| 4731 void test_visitPropertyAccess() { | |
| 4732 PropertyAccess fromNode = | |
| 4733 AstFactory.propertyAccess2(AstFactory.identifier3("x"), "y"); | |
| 4734 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4735 fromNode.propagatedType = propagatedType; | |
| 4736 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4737 fromNode.staticType = staticType; | |
| 4738 PropertyAccess toNode = | |
| 4739 AstFactory.propertyAccess2(AstFactory.identifier3("x"), "y"); | |
| 4740 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4741 expect(toNode.propagatedType, same(propagatedType)); | |
| 4742 expect(toNode.staticType, same(staticType)); | |
| 4743 } | |
| 4744 | |
| 4745 void test_visitRedirectingConstructorInvocation() { | |
| 4746 RedirectingConstructorInvocation fromNode = | |
| 4747 AstFactory.redirectingConstructorInvocation(); | |
| 4748 ConstructorElement staticElement = ElementFactory.constructorElement2( | |
| 4749 ElementFactory.classElement2("C"), null); | |
| 4750 fromNode.staticElement = staticElement; | |
| 4751 RedirectingConstructorInvocation toNode = | |
| 4752 AstFactory.redirectingConstructorInvocation(); | |
| 4753 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4754 expect(toNode.staticElement, same(staticElement)); | |
| 4755 } | |
| 4756 | |
| 4757 void test_visitRethrowExpression() { | |
| 4758 RethrowExpression fromNode = AstFactory.rethrowExpression(); | |
| 4759 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4760 fromNode.propagatedType = propagatedType; | |
| 4761 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4762 fromNode.staticType = staticType; | |
| 4763 RethrowExpression toNode = AstFactory.rethrowExpression(); | |
| 4764 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4765 expect(toNode.propagatedType, same(propagatedType)); | |
| 4766 expect(toNode.staticType, same(staticType)); | |
| 4767 } | |
| 4768 | |
| 4769 void test_visitSimpleIdentifier() { | |
| 4770 SimpleIdentifier fromNode = AstFactory.identifier3("x"); | |
| 4771 MethodElement propagatedElement = ElementFactory.methodElement( | |
| 4772 "m", ElementFactory.classElement2("C").type); | |
| 4773 MethodElement staticElement = ElementFactory.methodElement( | |
| 4774 "m", ElementFactory.classElement2("C").type); | |
| 4775 AuxiliaryElements auxiliaryElements = | |
| 4776 new AuxiliaryElements(staticElement, propagatedElement); | |
| 4777 fromNode.auxiliaryElements = auxiliaryElements; | |
| 4778 fromNode.propagatedElement = propagatedElement; | |
| 4779 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4780 fromNode.propagatedType = propagatedType; | |
| 4781 fromNode.staticElement = staticElement; | |
| 4782 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4783 fromNode.staticType = staticType; | |
| 4784 SimpleIdentifier toNode = AstFactory.identifier3("x"); | |
| 4785 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4786 expect(toNode.auxiliaryElements, same(auxiliaryElements)); | |
| 4787 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4788 expect(toNode.propagatedType, same(propagatedType)); | |
| 4789 expect(toNode.staticElement, same(staticElement)); | |
| 4790 expect(toNode.staticType, same(staticType)); | |
| 4791 } | |
| 4792 | |
| 4793 void test_visitSimpleStringLiteral() { | |
| 4794 SimpleStringLiteral fromNode = AstFactory.string2("abc"); | |
| 4795 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4796 fromNode.propagatedType = propagatedType; | |
| 4797 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4798 fromNode.staticType = staticType; | |
| 4799 SimpleStringLiteral toNode = AstFactory.string2("abc"); | |
| 4800 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4801 expect(toNode.propagatedType, same(propagatedType)); | |
| 4802 expect(toNode.staticType, same(staticType)); | |
| 4803 } | |
| 4804 | |
| 4805 void test_visitStringInterpolation() { | |
| 4806 StringInterpolation fromNode = | |
| 4807 AstFactory.string([AstFactory.interpolationString("a", "'a'")]); | |
| 4808 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4809 fromNode.propagatedType = propagatedType; | |
| 4810 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4811 fromNode.staticType = staticType; | |
| 4812 StringInterpolation toNode = | |
| 4813 AstFactory.string([AstFactory.interpolationString("a", "'a'")]); | |
| 4814 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4815 expect(toNode.propagatedType, same(propagatedType)); | |
| 4816 expect(toNode.staticType, same(staticType)); | |
| 4817 } | |
| 4818 | |
| 4819 void test_visitSuperConstructorInvocation() { | |
| 4820 SuperConstructorInvocation fromNode = | |
| 4821 AstFactory.superConstructorInvocation(); | |
| 4822 ConstructorElement staticElement = ElementFactory.constructorElement2( | |
| 4823 ElementFactory.classElement2("C"), null); | |
| 4824 fromNode.staticElement = staticElement; | |
| 4825 SuperConstructorInvocation toNode = AstFactory.superConstructorInvocation(); | |
| 4826 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4827 expect(toNode.staticElement, same(staticElement)); | |
| 4828 } | |
| 4829 | |
| 4830 void test_visitSuperExpression() { | |
| 4831 SuperExpression fromNode = AstFactory.superExpression(); | |
| 4832 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4833 fromNode.propagatedType = propagatedType; | |
| 4834 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4835 fromNode.staticType = staticType; | |
| 4836 SuperExpression toNode = AstFactory.superExpression(); | |
| 4837 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4838 expect(toNode.propagatedType, same(propagatedType)); | |
| 4839 expect(toNode.staticType, same(staticType)); | |
| 4840 } | |
| 4841 | |
| 4842 void test_visitSymbolLiteral() { | |
| 4843 SymbolLiteral fromNode = AstFactory.symbolLiteral(["s"]); | |
| 4844 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4845 fromNode.propagatedType = propagatedType; | |
| 4846 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4847 fromNode.staticType = staticType; | |
| 4848 SymbolLiteral toNode = AstFactory.symbolLiteral(["s"]); | |
| 4849 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4850 expect(toNode.propagatedType, same(propagatedType)); | |
| 4851 expect(toNode.staticType, same(staticType)); | |
| 4852 } | |
| 4853 | |
| 4854 void test_visitThisExpression() { | |
| 4855 ThisExpression fromNode = AstFactory.thisExpression(); | |
| 4856 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4857 fromNode.propagatedType = propagatedType; | |
| 4858 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4859 fromNode.staticType = staticType; | |
| 4860 ThisExpression toNode = AstFactory.thisExpression(); | |
| 4861 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4862 expect(toNode.propagatedType, same(propagatedType)); | |
| 4863 expect(toNode.staticType, same(staticType)); | |
| 4864 } | |
| 4865 | |
| 4866 void test_visitThrowExpression() { | |
| 4867 ThrowExpression fromNode = AstFactory.throwExpression(); | |
| 4868 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4869 fromNode.propagatedType = propagatedType; | |
| 4870 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4871 fromNode.staticType = staticType; | |
| 4872 ThrowExpression toNode = AstFactory.throwExpression(); | |
| 4873 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4874 expect(toNode.propagatedType, same(propagatedType)); | |
| 4875 expect(toNode.staticType, same(staticType)); | |
| 4876 } | |
| 4877 | |
| 4878 void test_visitTypeName() { | |
| 4879 TypeName fromNode = AstFactory.typeName4("C"); | |
| 4880 DartType type = ElementFactory.classElement2("C").type; | |
| 4881 fromNode.type = type; | |
| 4882 TypeName toNode = AstFactory.typeName4("C"); | |
| 4883 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4884 expect(toNode.type, same(type)); | |
| 4885 } | |
| 4886 | |
| 4887 void _copyAndVerifyInvocation( | |
| 4888 InvocationExpression fromNode, InvocationExpression toNode) { | |
| 4889 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4890 fromNode.propagatedType = propagatedType; | |
| 4891 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4892 fromNode.staticType = staticType; | |
| 4893 | |
| 4894 DartType propagatedInvokeType = ElementFactory.classElement2("C").type; | |
| 4895 fromNode.propagatedInvokeType = propagatedInvokeType; | |
| 4896 DartType staticInvokeType = ElementFactory.classElement2("C").type; | |
| 4897 fromNode.staticInvokeType = staticInvokeType; | |
| 4898 | |
| 4899 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4900 expect(toNode.propagatedType, same(propagatedType)); | |
| 4901 expect(toNode.staticType, same(staticType)); | |
| 4902 expect(toNode.propagatedInvokeType, same(propagatedInvokeType)); | |
| 4903 expect(toNode.staticInvokeType, same(staticInvokeType)); | |
| 4904 } | |
| 4905 } | |
| 4906 | |
| 4907 /** | 4245 /** |
| 4908 * The class `SimpleParserTest` defines parser tests that test individual parsin
g method. The | 4246 * The class `SimpleParserTest` defines parser tests that test individual parsin
g method. The |
| 4909 * code fragments should be as minimal as possible in order to test the method,
but should not test | 4247 * code fragments should be as minimal as possible in order to test the method,
but should not test |
| 4910 * the interactions between the method under test and other methods. | 4248 * the interactions between the method under test and other methods. |
| 4911 * | 4249 * |
| 4912 * More complex tests should be defined in the class [ComplexParserTest]. | 4250 * More complex tests should be defined in the class [ComplexParserTest]. |
| 4913 */ | 4251 */ |
| 4914 @reflectiveTest | 4252 @reflectiveTest |
| 4915 class SimpleParserTest extends ParserTestCase { | 4253 class SimpleParserTest extends ParserTestCase { |
| 4916 void fail_parseAwaitExpression_inSync() { | 4254 void fail_parseAwaitExpression_inSync() { |
| (...skipping 6729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11646 new Scanner(null, new CharSequenceReader(source), listener); | 10984 new Scanner(null, new CharSequenceReader(source), listener); |
| 11647 Token tokenStream = scanner.tokenize(); | 10985 Token tokenStream = scanner.tokenize(); |
| 11648 // | 10986 // |
| 11649 // Parse the source. | 10987 // Parse the source. |
| 11650 // | 10988 // |
| 11651 Parser parser = new Parser(null, listener); | 10989 Parser parser = new Parser(null, listener); |
| 11652 return invokeParserMethodImpl( | 10990 return invokeParserMethodImpl( |
| 11653 parser, methodName, <Object>[tokenStream], tokenStream) as Token; | 10991 parser, methodName, <Object>[tokenStream], tokenStream) as Token; |
| 11654 } | 10992 } |
| 11655 } | 10993 } |
| OLD | NEW |