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

Side by Side Diff: pkg/analyzer/test/generated/all_the_rest_test.dart

Issue 1572073003: Don't log stack trace for a bad package URL in a source file. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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.test.generated.all_the_rest_test; 5 library analyzer.test.generated.all_the_rest_test;
6 6
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/dart/element/type.dart'; 8 import 'package:analyzer/dart/element/type.dart';
9 import 'package:analyzer/file_system/physical_file_system.dart'; 9 import 'package:analyzer/file_system/physical_file_system.dart';
10 import 'package:analyzer/src/dart/element/element.dart'; 10 import 'package:analyzer/src/dart/element/element.dart';
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 _setupVariableDeclaration("v", false, true); 568 _setupVariableDeclaration("v", false, true);
569 expect(_findConstants(), isEmpty); 569 expect(_findConstants(), isEmpty);
570 } 570 }
571 571
572 void test_visitVariableDeclaration_static_const_inClass() { 572 void test_visitVariableDeclaration_static_const_inClass() {
573 VariableDeclaration field = 573 VariableDeclaration field =
574 _setupFieldDeclaration('C', 'f', Keyword.CONST, isStatic: true); 574 _setupFieldDeclaration('C', 'f', Keyword.CONST, isStatic: true);
575 expect(_findConstants(), contains(field.element)); 575 expect(_findConstants(), contains(field.element));
576 } 576 }
577 577
578 void 578 void test_visitVariableDeclaration_static_const_inClassWithConstConstructor() {
skybrian 2016/01/09 08:19:54 Not sure what dartfmt is doing here; it seems to h
Brian Wilkerson 2016/01/09 16:02:39 I'm not sure either, but we always format, regardl
579 test_visitVariableDeclaration_static_const_inClassWithConstConstructor() {
580 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.CONST, 579 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.CONST,
581 isStatic: true, hasConstConstructor: true); 580 isStatic: true, hasConstConstructor: true);
582 expect(_findConstants(), contains(field.element)); 581 expect(_findConstants(), contains(field.element));
583 } 582 }
584 583
585 void 584 void test_visitVariableDeclaration_static_final_inClassWithConstConstructor() {
586 test_visitVariableDeclaration_static_final_inClassWithConstConstructor() {
587 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, 585 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL,
588 isStatic: true, hasConstConstructor: true); 586 isStatic: true, hasConstConstructor: true);
589 expect(_findConstants(), isNot(contains(field.element))); 587 expect(_findConstants(), isNot(contains(field.element)));
590 } 588 }
591 589
592 void 590 void test_visitVariableDeclaration_uninitialized_final_inClassWithConstConstru ctor() {
593 test_visitVariableDeclaration_uninitialized_final_inClassWithConstConstruc tor() {
594 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, 591 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL,
595 isInitialized: false, hasConstConstructor: true); 592 isInitialized: false, hasConstConstructor: true);
596 expect(_findConstants(), isNot(contains(field.element))); 593 expect(_findConstants(), isNot(contains(field.element)));
597 } 594 }
598 595
599 void test_visitVariableDeclaration_uninitialized_static_const_inClass() { 596 void test_visitVariableDeclaration_uninitialized_static_const_inClass() {
600 _setupFieldDeclaration('C', 'f', Keyword.CONST, 597 _setupFieldDeclaration('C', 'f', Keyword.CONST,
601 isStatic: true, isInitialized: false); 598 isStatic: true, isInitialized: false);
602 expect(_findConstants(), isEmpty); 599 expect(_findConstants(), isEmpty);
603 } 600 }
(...skipping 13 matching lines...) Expand all
617 Set<ConstantEvaluationTarget> _findConstants() { 614 Set<ConstantEvaluationTarget> _findConstants() {
618 ConstantFinder finder = new ConstantFinder(_context, _source, _source); 615 ConstantFinder finder = new ConstantFinder(_context, _source, _source);
619 _node.accept(finder); 616 _node.accept(finder);
620 Set<ConstantEvaluationTarget> constants = finder.constantsToCompute; 617 Set<ConstantEvaluationTarget> constants = finder.constantsToCompute;
621 expect(constants, isNotNull); 618 expect(constants, isNotNull);
622 return constants; 619 return constants;
623 } 620 }
624 621
625 ConstructorElement _setupConstructorDeclaration(String name, bool isConst) { 622 ConstructorElement _setupConstructorDeclaration(String name, bool isConst) {
626 Keyword constKeyword = isConst ? Keyword.CONST : null; 623 Keyword constKeyword = isConst ? Keyword.CONST : null;
627 ConstructorDeclaration constructorDeclaration = 624 ConstructorDeclaration constructorDeclaration = AstFactory
628 AstFactory.constructorDeclaration2( 625 .constructorDeclaration2(
629 constKeyword, 626 constKeyword,
630 null, 627 null,
631 null, 628 null,
632 name, 629 name,
633 AstFactory.formalParameterList(), 630 AstFactory.formalParameterList(),
634 null, 631 null,
635 AstFactory.blockFunctionBody2()); 632 AstFactory.blockFunctionBody2());
636 ClassElement classElement = ElementFactory.classElement2(name); 633 ClassElement classElement = ElementFactory.classElement2(name);
637 ConstructorElement element = 634 ConstructorElement element =
638 ElementFactory.constructorElement(classElement, name, isConst); 635 ElementFactory.constructorElement(classElement, name, isConst);
(...skipping 20 matching lines...) Expand all
659 FieldDeclaration fieldDeclaration = AstFactory.fieldDeclaration2( 656 FieldDeclaration fieldDeclaration = AstFactory.fieldDeclaration2(
660 isStatic, keyword, <VariableDeclaration>[variableDeclaration]); 657 isStatic, keyword, <VariableDeclaration>[variableDeclaration]);
661 ClassDeclaration classDeclaration = 658 ClassDeclaration classDeclaration =
662 AstFactory.classDeclaration(null, className, null, null, null, null); 659 AstFactory.classDeclaration(null, className, null, null, null, null);
663 classDeclaration.members.add(fieldDeclaration); 660 classDeclaration.members.add(fieldDeclaration);
664 _node = classDeclaration; 661 _node = classDeclaration;
665 ClassElementImpl classElement = ElementFactory.classElement2(className); 662 ClassElementImpl classElement = ElementFactory.classElement2(className);
666 classElement.fields = <FieldElement>[fieldElement]; 663 classElement.fields = <FieldElement>[fieldElement];
667 classDeclaration.name.staticElement = classElement; 664 classDeclaration.name.staticElement = classElement;
668 if (hasConstConstructor) { 665 if (hasConstConstructor) {
669 ConstructorDeclaration constructorDeclaration = 666 ConstructorDeclaration constructorDeclaration = AstFactory
670 AstFactory.constructorDeclaration2( 667 .constructorDeclaration2(
671 Keyword.CONST, 668 Keyword.CONST,
672 null, 669 null,
673 AstFactory.identifier3(className), 670 AstFactory.identifier3(className),
674 null, 671 null,
675 AstFactory.formalParameterList(), 672 AstFactory.formalParameterList(),
676 null, 673 null,
677 AstFactory.blockFunctionBody2()); 674 AstFactory.blockFunctionBody2());
678 classDeclaration.members.add(constructorDeclaration); 675 classDeclaration.members.add(constructorDeclaration);
679 ConstructorElement constructorElement = 676 ConstructorElement constructorElement =
680 ElementFactory.constructorElement(classElement, '', true); 677 ElementFactory.constructorElement(classElement, '', true);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 @i(1) 870 @i(1)
874 f() {} 871 f() {}
875 } 872 }
876 '''); 873 ''');
877 _evaluateAnnotation(compilationUnit, "C", "f"); 874 _evaluateAnnotation(compilationUnit, "C", "f");
878 } 875 }
879 876
880 void test_computeValues_cycle() { 877 void test_computeValues_cycle() {
881 TestLogger logger = new TestLogger(); 878 TestLogger logger = new TestLogger();
882 AnalysisEngine.instance.logger = logger; 879 AnalysisEngine.instance.logger = logger;
883 Source librarySource = addSource(r''' 880 try {
884 const int a = c; 881 Source librarySource = addSource(r'''
885 const int b = a; 882 const int a = c;
886 const int c = b;'''); 883 const int b = a;
887 LibraryElement libraryElement = resolve2(librarySource); 884 const int c = b;''');
888 CompilationUnit unit = 885 LibraryElement libraryElement = resolve2(librarySource);
889 analysisContext.resolveCompilationUnit(librarySource, libraryElement); 886 CompilationUnit unit =
890 analysisContext.computeErrors(librarySource); 887 analysisContext.resolveCompilationUnit(librarySource, libraryElement);
891 expect(unit, isNotNull); 888 analysisContext.computeErrors(librarySource);
892 ConstantValueComputer computer = _makeConstantValueComputer(); 889 expect(unit, isNotNull);
893 computer.add(unit, librarySource, librarySource); 890 ConstantValueComputer computer = _makeConstantValueComputer();
894 computer.computeValues(); 891 computer.add(unit, librarySource, librarySource);
895 NodeList<CompilationUnitMember> members = unit.declarations; 892 computer.computeValues();
896 expect(members, hasLength(3)); 893 NodeList<CompilationUnitMember> members = unit.declarations;
897 _validate(false, (members[0] as TopLevelVariableDeclaration).variables); 894 expect(members, hasLength(3));
898 _validate(false, (members[1] as TopLevelVariableDeclaration).variables); 895 _validate(false, (members[0] as TopLevelVariableDeclaration).variables);
899 _validate(false, (members[2] as TopLevelVariableDeclaration).variables); 896 _validate(false, (members[1] as TopLevelVariableDeclaration).variables);
897 _validate(false, (members[2] as TopLevelVariableDeclaration).variables);
898 } finally {
899 AnalysisEngine.instance.logger = Logger.NULL;
900 }
900 } 901 }
901 902
902 void test_computeValues_dependentVariables() { 903 void test_computeValues_dependentVariables() {
903 Source librarySource = addSource(r''' 904 Source librarySource = addSource(r'''
904 const int b = a; 905 const int b = a;
905 const int a = 0;'''); 906 const int a = 0;''');
906 LibraryElement libraryElement = resolve2(librarySource); 907 LibraryElement libraryElement = resolve2(librarySource);
907 CompilationUnit unit = 908 CompilationUnit unit =
908 analysisContext.resolveCompilationUnit(librarySource, libraryElement); 909 analysisContext.resolveCompilationUnit(librarySource, libraryElement);
909 expect(unit, isNotNull); 910 expect(unit, isNotNull);
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 const A(int i, int j) : k = 2 * i + j; 1326 const A(int i, int j) : k = 2 * i + j;
1326 final int k; 1327 final int k;
1327 }'''); 1328 }''');
1328 EvaluationResultImpl result = 1329 EvaluationResultImpl result =
1329 _evaluateTopLevelVariable(compilationUnit, "foo"); 1330 _evaluateTopLevelVariable(compilationUnit, "foo");
1330 Map<String, DartObjectImpl> fields = _assertType(result, "A"); 1331 Map<String, DartObjectImpl> fields = _assertType(result, "A");
1331 expect(fields, hasLength(1)); 1332 expect(fields, hasLength(1));
1332 _assertIntField(fields, "k", 13); 1333 _assertIntField(fields, "k", 13);
1333 } 1334 }
1334 1335
1335 void 1336 void test_instanceCreationExpression_computedField_namedOptionalWithDefault() {
1336 test_instanceCreationExpression_computedField_namedOptionalWithDefault() {
1337 _checkInstanceCreationOptionalParams(false, true, true); 1337 _checkInstanceCreationOptionalParams(false, true, true);
1338 } 1338 }
1339 1339
1340 void 1340 void test_instanceCreationExpression_computedField_namedOptionalWithoutDefault () {
1341 test_instanceCreationExpression_computedField_namedOptionalWithoutDefault( ) {
1342 _checkInstanceCreationOptionalParams(false, true, false); 1341 _checkInstanceCreationOptionalParams(false, true, false);
1343 } 1342 }
1344 1343
1345 void 1344 void test_instanceCreationExpression_computedField_unnamedOptionalWithDefault( ) {
1346 test_instanceCreationExpression_computedField_unnamedOptionalWithDefault() {
1347 _checkInstanceCreationOptionalParams(false, false, true); 1345 _checkInstanceCreationOptionalParams(false, false, true);
1348 } 1346 }
1349 1347
1350 void 1348 void test_instanceCreationExpression_computedField_unnamedOptionalWithoutDefau lt() {
1351 test_instanceCreationExpression_computedField_unnamedOptionalWithoutDefaul t() {
1352 _checkInstanceCreationOptionalParams(false, false, false); 1349 _checkInstanceCreationOptionalParams(false, false, false);
1353 } 1350 }
1354 1351
1355 void test_instanceCreationExpression_computedField_usesConstConstructor() { 1352 void test_instanceCreationExpression_computedField_usesConstConstructor() {
1356 CompilationUnit compilationUnit = resolveSource(r''' 1353 CompilationUnit compilationUnit = resolveSource(r'''
1357 const foo = const A(3); 1354 const foo = const A(3);
1358 class A { 1355 class A {
1359 const A(int i) : b = const B(4); 1356 const A(int i) : b = const B(4);
1360 final int b; 1357 final int b;
1361 } 1358 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 int x; 1431 int x;
1435 const A(this.x) 1432 const A(this.x)
1436 }'''); 1433 }''');
1437 EvaluationResultImpl result = 1434 EvaluationResultImpl result =
1438 _evaluateTopLevelVariable(compilationUnit, "foo"); 1435 _evaluateTopLevelVariable(compilationUnit, "foo");
1439 Map<String, DartObjectImpl> fields = _assertType(result, "A"); 1436 Map<String, DartObjectImpl> fields = _assertType(result, "A");
1440 expect(fields, hasLength(1)); 1437 expect(fields, hasLength(1));
1441 _assertIntField(fields, "x", 42); 1438 _assertIntField(fields, "x", 42);
1442 } 1439 }
1443 1440
1444 void 1441 void test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithDef ault() {
1445 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithDefa ult() {
1446 _checkInstanceCreationOptionalParams(true, true, true); 1442 _checkInstanceCreationOptionalParams(true, true, true);
1447 } 1443 }
1448 1444
1449 void 1445 void test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithout Default() {
1450 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithoutD efault() {
1451 _checkInstanceCreationOptionalParams(true, true, false); 1446 _checkInstanceCreationOptionalParams(true, true, false);
1452 } 1447 }
1453 1448
1454 void 1449 void test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithD efault() {
1455 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithDe fault() {
1456 _checkInstanceCreationOptionalParams(true, false, true); 1450 _checkInstanceCreationOptionalParams(true, false, true);
1457 } 1451 }
1458 1452
1459 void 1453 void test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWitho utDefault() {
1460 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithou tDefault() {
1461 _checkInstanceCreationOptionalParams(true, false, false); 1454 _checkInstanceCreationOptionalParams(true, false, false);
1462 } 1455 }
1463 1456
1464 void test_instanceCreationExpression_implicitSuper() { 1457 void test_instanceCreationExpression_implicitSuper() {
1465 CompilationUnit compilationUnit = resolveSource(r''' 1458 CompilationUnit compilationUnit = resolveSource(r'''
1466 const foo = const B(4); 1459 const foo = const B(4);
1467 class A { 1460 class A {
1468 const A() : x = 3; 1461 const A() : x = 3;
1469 final int x; 1462 final int x;
1470 } 1463 }
(...skipping 3386 matching lines...) Expand 10 before | Expand all | Expand 10 after
4857 expect(types, hasLength(1)); 4850 expect(types, hasLength(1));
4858 ClassElement type = types[0]; 4851 ClassElement type = types[0];
4859 expect(type.typeParameters, hasLength(1)); 4852 expect(type.typeParameters, hasLength(1));
4860 expect(type.typeParameters[0].name, equals('T')); 4853 expect(type.typeParameters[0].name, equals('T'));
4861 } 4854 }
4862 4855
4863 void test_visitConstructorDeclaration_external() { 4856 void test_visitConstructorDeclaration_external() {
4864 ElementHolder holder = new ElementHolder(); 4857 ElementHolder holder = new ElementHolder();
4865 ElementBuilder builder = new ElementBuilder(holder); 4858 ElementBuilder builder = new ElementBuilder(holder);
4866 String className = "A"; 4859 String className = "A";
4867 ConstructorDeclaration constructorDeclaration = 4860 ConstructorDeclaration constructorDeclaration = AstFactory
4868 AstFactory.constructorDeclaration2( 4861 .constructorDeclaration2(
4869 null, 4862 null,
4870 null, 4863 null,
4871 AstFactory.identifier3(className), 4864 AstFactory.identifier3(className),
4872 null, 4865 null,
4873 AstFactory.formalParameterList(), 4866 AstFactory.formalParameterList(),
4874 null, 4867 null,
4875 AstFactory.blockFunctionBody2()); 4868 AstFactory.blockFunctionBody2());
4876 constructorDeclaration.externalKeyword = 4869 constructorDeclaration.externalKeyword =
4877 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); 4870 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
4878 constructorDeclaration.accept(builder); 4871 constructorDeclaration.accept(builder);
4879 List<ConstructorElement> constructors = holder.constructors; 4872 List<ConstructorElement> constructors = holder.constructors;
4880 expect(constructors, hasLength(1)); 4873 expect(constructors, hasLength(1));
4881 ConstructorElement constructor = constructors[0]; 4874 ConstructorElement constructor = constructors[0];
4882 expect(constructor, isNotNull); 4875 expect(constructor, isNotNull);
4883 expect(constructor.isExternal, isTrue); 4876 expect(constructor.isExternal, isTrue);
4884 expect(constructor.isFactory, isFalse); 4877 expect(constructor.isFactory, isFalse);
4885 expect(constructor.name, ""); 4878 expect(constructor.name, "");
4886 expect(constructor.functions, hasLength(0)); 4879 expect(constructor.functions, hasLength(0));
4887 expect(constructor.labels, hasLength(0)); 4880 expect(constructor.labels, hasLength(0));
4888 expect(constructor.localVariables, hasLength(0)); 4881 expect(constructor.localVariables, hasLength(0));
4889 expect(constructor.parameters, hasLength(0)); 4882 expect(constructor.parameters, hasLength(0));
4890 } 4883 }
4891 4884
4892 void test_visitConstructorDeclaration_factory() { 4885 void test_visitConstructorDeclaration_factory() {
4893 ElementHolder holder = new ElementHolder(); 4886 ElementHolder holder = new ElementHolder();
4894 ElementBuilder builder = new ElementBuilder(holder); 4887 ElementBuilder builder = new ElementBuilder(holder);
4895 String className = "A"; 4888 String className = "A";
4896 ConstructorDeclaration constructorDeclaration = 4889 ConstructorDeclaration constructorDeclaration = AstFactory
4897 AstFactory.constructorDeclaration2( 4890 .constructorDeclaration2(
4898 null, 4891 null,
4899 Keyword.FACTORY, 4892 Keyword.FACTORY,
4900 AstFactory.identifier3(className), 4893 AstFactory.identifier3(className),
4901 null, 4894 null,
4902 AstFactory.formalParameterList(), 4895 AstFactory.formalParameterList(),
4903 null, 4896 null,
4904 AstFactory.blockFunctionBody2()); 4897 AstFactory.blockFunctionBody2());
4905 constructorDeclaration.accept(builder); 4898 constructorDeclaration.accept(builder);
4906 List<ConstructorElement> constructors = holder.constructors; 4899 List<ConstructorElement> constructors = holder.constructors;
4907 expect(constructors, hasLength(1)); 4900 expect(constructors, hasLength(1));
4908 ConstructorElement constructor = constructors[0]; 4901 ConstructorElement constructor = constructors[0];
4909 expect(constructor, isNotNull); 4902 expect(constructor, isNotNull);
4910 expect(constructor.isExternal, isFalse); 4903 expect(constructor.isExternal, isFalse);
4911 expect(constructor.isFactory, isTrue); 4904 expect(constructor.isFactory, isTrue);
4912 expect(constructor.name, ""); 4905 expect(constructor.name, "");
4913 expect(constructor.functions, hasLength(0)); 4906 expect(constructor.functions, hasLength(0));
4914 expect(constructor.labels, hasLength(0)); 4907 expect(constructor.labels, hasLength(0));
4915 expect(constructor.localVariables, hasLength(0)); 4908 expect(constructor.localVariables, hasLength(0));
4916 expect(constructor.parameters, hasLength(0)); 4909 expect(constructor.parameters, hasLength(0));
4917 } 4910 }
4918 4911
4919 void test_visitConstructorDeclaration_minimal() { 4912 void test_visitConstructorDeclaration_minimal() {
4920 ElementHolder holder = new ElementHolder(); 4913 ElementHolder holder = new ElementHolder();
4921 ElementBuilder builder = new ElementBuilder(holder); 4914 ElementBuilder builder = new ElementBuilder(holder);
4922 String className = "A"; 4915 String className = "A";
4923 ConstructorDeclaration constructorDeclaration = 4916 ConstructorDeclaration constructorDeclaration = AstFactory
4924 AstFactory.constructorDeclaration2( 4917 .constructorDeclaration2(
4925 null, 4918 null,
4926 null, 4919 null,
4927 AstFactory.identifier3(className), 4920 AstFactory.identifier3(className),
4928 null, 4921 null,
4929 AstFactory.formalParameterList(), 4922 AstFactory.formalParameterList(),
4930 null, 4923 null,
4931 AstFactory.blockFunctionBody2()); 4924 AstFactory.blockFunctionBody2());
4932 constructorDeclaration.documentationComment = AstFactory 4925 constructorDeclaration.documentationComment = AstFactory
4933 .documentationComment( 4926 .documentationComment(
4934 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 4927 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
(...skipping 11 matching lines...) Expand all
4946 expect(constructor.labels, hasLength(0)); 4939 expect(constructor.labels, hasLength(0));
4947 expect(constructor.localVariables, hasLength(0)); 4940 expect(constructor.localVariables, hasLength(0));
4948 expect(constructor.parameters, hasLength(0)); 4941 expect(constructor.parameters, hasLength(0));
4949 } 4942 }
4950 4943
4951 void test_visitConstructorDeclaration_named() { 4944 void test_visitConstructorDeclaration_named() {
4952 ElementHolder holder = new ElementHolder(); 4945 ElementHolder holder = new ElementHolder();
4953 ElementBuilder builder = new ElementBuilder(holder); 4946 ElementBuilder builder = new ElementBuilder(holder);
4954 String className = "A"; 4947 String className = "A";
4955 String constructorName = "c"; 4948 String constructorName = "c";
4956 ConstructorDeclaration constructorDeclaration = 4949 ConstructorDeclaration constructorDeclaration = AstFactory
4957 AstFactory.constructorDeclaration2( 4950 .constructorDeclaration2(
4958 null, 4951 null,
4959 null, 4952 null,
4960 AstFactory.identifier3(className), 4953 AstFactory.identifier3(className),
4961 constructorName, 4954 constructorName,
4962 AstFactory.formalParameterList(), 4955 AstFactory.formalParameterList(),
4963 null, 4956 null,
4964 AstFactory.blockFunctionBody2()); 4957 AstFactory.blockFunctionBody2());
4965 constructorDeclaration.accept(builder); 4958 constructorDeclaration.accept(builder);
4966 List<ConstructorElement> constructors = holder.constructors; 4959 List<ConstructorElement> constructors = holder.constructors;
4967 expect(constructors, hasLength(1)); 4960 expect(constructors, hasLength(1));
4968 ConstructorElement constructor = constructors[0]; 4961 ConstructorElement constructor = constructors[0];
4969 expect(constructor, isNotNull); 4962 expect(constructor, isNotNull);
4970 expect(constructor.isExternal, isFalse); 4963 expect(constructor.isExternal, isFalse);
4971 expect(constructor.isFactory, isFalse); 4964 expect(constructor.isFactory, isFalse);
4972 expect(constructor.name, constructorName); 4965 expect(constructor.name, constructorName);
4973 expect(constructor.functions, hasLength(0)); 4966 expect(constructor.functions, hasLength(0));
4974 expect(constructor.labels, hasLength(0)); 4967 expect(constructor.labels, hasLength(0));
4975 expect(constructor.localVariables, hasLength(0)); 4968 expect(constructor.localVariables, hasLength(0));
4976 expect(constructor.parameters, hasLength(0)); 4969 expect(constructor.parameters, hasLength(0));
4977 expect(constructorDeclaration.name.staticElement, same(constructor)); 4970 expect(constructorDeclaration.name.staticElement, same(constructor));
4978 expect(constructorDeclaration.element, same(constructor)); 4971 expect(constructorDeclaration.element, same(constructor));
4979 } 4972 }
4980 4973
4981 void test_visitConstructorDeclaration_unnamed() { 4974 void test_visitConstructorDeclaration_unnamed() {
4982 ElementHolder holder = new ElementHolder(); 4975 ElementHolder holder = new ElementHolder();
4983 ElementBuilder builder = new ElementBuilder(holder); 4976 ElementBuilder builder = new ElementBuilder(holder);
4984 String className = "A"; 4977 String className = "A";
4985 ConstructorDeclaration constructorDeclaration = 4978 ConstructorDeclaration constructorDeclaration = AstFactory
4986 AstFactory.constructorDeclaration2( 4979 .constructorDeclaration2(
4987 null, 4980 null,
4988 null, 4981 null,
4989 AstFactory.identifier3(className), 4982 AstFactory.identifier3(className),
4990 null, 4983 null,
4991 AstFactory.formalParameterList(), 4984 AstFactory.formalParameterList(),
4992 null, 4985 null,
4993 AstFactory.blockFunctionBody2()); 4986 AstFactory.blockFunctionBody2());
4994 constructorDeclaration.accept(builder); 4987 constructorDeclaration.accept(builder);
4995 List<ConstructorElement> constructors = holder.constructors; 4988 List<ConstructorElement> constructors = holder.constructors;
4996 expect(constructors, hasLength(1)); 4989 expect(constructors, hasLength(1));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
5056 expect(variable.isPublic, isTrue); 5049 expect(variable.isPublic, isTrue);
5057 expect(variable.isSynthetic, isFalse); 5050 expect(variable.isSynthetic, isFalse);
5058 expect(variable.name, variableName); 5051 expect(variable.name, variableName);
5059 } 5052 }
5060 5053
5061 void test_visitDefaultFormalParameter_noType() { 5054 void test_visitDefaultFormalParameter_noType() {
5062 // p = 0 5055 // p = 0
5063 ElementHolder holder = new ElementHolder(); 5056 ElementHolder holder = new ElementHolder();
5064 ElementBuilder builder = new ElementBuilder(holder); 5057 ElementBuilder builder = new ElementBuilder(holder);
5065 String parameterName = 'p'; 5058 String parameterName = 'p';
5066 DefaultFormalParameter formalParameter = 5059 DefaultFormalParameter formalParameter = AstFactory
5067 AstFactory.positionalFormalParameter( 5060 .positionalFormalParameter(
5068 AstFactory.simpleFormalParameter3(parameterName), 5061 AstFactory.simpleFormalParameter3(parameterName),
5069 AstFactory.integer(0)); 5062 AstFactory.integer(0));
5070 formalParameter.accept(builder); 5063 formalParameter.accept(builder);
5071 5064
5072 List<ParameterElement> parameters = holder.parameters; 5065 List<ParameterElement> parameters = holder.parameters;
5073 expect(parameters, hasLength(1)); 5066 expect(parameters, hasLength(1));
5074 ParameterElement parameter = parameters[0]; 5067 ParameterElement parameter = parameters[0];
5075 expect(parameter.hasImplicitType, isTrue); 5068 expect(parameter.hasImplicitType, isTrue);
5076 expect(parameter.isConst, isFalse); 5069 expect(parameter.isConst, isFalse);
5077 expect(parameter.isDeprecated, isFalse); 5070 expect(parameter.isDeprecated, isFalse);
(...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after
6462 6455
6463 void test_locate_FunctionDeclaration() { 6456 void test_locate_FunctionDeclaration() {
6464 AstNode id = _findNodeIn("f", "int f() => 3;"); 6457 AstNode id = _findNodeIn("f", "int f() => 3;");
6465 FunctionDeclaration declaration = 6458 FunctionDeclaration declaration =
6466 id.getAncestor((node) => node is FunctionDeclaration); 6459 id.getAncestor((node) => node is FunctionDeclaration);
6467 Element element = ElementLocator.locate(declaration); 6460 Element element = ElementLocator.locate(declaration);
6468 EngineTestCase.assertInstanceOf( 6461 EngineTestCase.assertInstanceOf(
6469 (obj) => obj is FunctionElement, FunctionElement, element); 6462 (obj) => obj is FunctionElement, FunctionElement, element);
6470 } 6463 }
6471 6464
6472 void 6465 void test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalPa rameter() {
6473 test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalPar ameter() {
6474 AstNode id = _findNodeIndexedIn( 6466 AstNode id = _findNodeIndexedIn(
6475 "Class", 6467 "Class",
6476 2, 6468 2,
6477 r''' 6469 r'''
6478 class Class { 6470 class Class {
6479 const Class.name(); 6471 const Class.name();
6480 } 6472 }
6481 void main(@Class.name() parameter) { 6473 void main(@Class.name() parameter) {
6482 }'''); 6474 }''');
6483 Element element = ElementLocator.locate(id); 6475 Element element = ElementLocator.locate(id);
6484 EngineTestCase.assertInstanceOf( 6476 EngineTestCase.assertInstanceOf(
6485 (obj) => obj is ClassElement, ClassElement, element); 6477 (obj) => obj is ClassElement, ClassElement, element);
6486 } 6478 }
6487 6479
6488 void 6480 void test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormal Parameter() {
6489 test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormalP arameter() {
6490 AstNode id = _findNodeIndexedIn( 6481 AstNode id = _findNodeIndexedIn(
6491 "Class", 6482 "Class",
6492 2, 6483 2,
6493 r''' 6484 r'''
6494 class Class { 6485 class Class {
6495 const Class(); 6486 const Class();
6496 } 6487 }
6497 void main(@Class() parameter) { 6488 void main(@Class() parameter) {
6498 }'''); 6489 }''');
6499 Element element = ElementLocator.locate(id); 6490 Element element = ElementLocator.locate(id);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
6586 Element element = ElementLocator.locate(node); 6577 Element element = ElementLocator.locate(node);
6587 EngineTestCase.assertInstanceOf( 6578 EngineTestCase.assertInstanceOf(
6588 (obj) => obj is ConstructorElement, ConstructorElement, element); 6579 (obj) => obj is ConstructorElement, ConstructorElement, element);
6589 } 6580 }
6590 6581
6591 void test_locate_InstanceCreationExpression_type_prefixedIdentifier() { 6582 void test_locate_InstanceCreationExpression_type_prefixedIdentifier() {
6592 // prepare: new pref.A() 6583 // prepare: new pref.A()
6593 SimpleIdentifier identifier = AstFactory.identifier3("A"); 6584 SimpleIdentifier identifier = AstFactory.identifier3("A");
6594 PrefixedIdentifier prefixedIdentifier = 6585 PrefixedIdentifier prefixedIdentifier =
6595 AstFactory.identifier4("pref", identifier); 6586 AstFactory.identifier4("pref", identifier);
6596 InstanceCreationExpression creation = 6587 InstanceCreationExpression creation = AstFactory
6597 AstFactory.instanceCreationExpression2( 6588 .instanceCreationExpression2(
6598 Keyword.NEW, AstFactory.typeName3(prefixedIdentifier)); 6589 Keyword.NEW, AstFactory.typeName3(prefixedIdentifier));
6599 // set ClassElement 6590 // set ClassElement
6600 ClassElement classElement = ElementFactory.classElement2("A"); 6591 ClassElement classElement = ElementFactory.classElement2("A");
6601 identifier.staticElement = classElement; 6592 identifier.staticElement = classElement;
6602 // set ConstructorElement 6593 // set ConstructorElement
6603 ConstructorElement constructorElement = 6594 ConstructorElement constructorElement =
6604 ElementFactory.constructorElement2(classElement, null); 6595 ElementFactory.constructorElement2(classElement, null);
6605 creation.constructorName.staticElement = constructorElement; 6596 creation.constructorName.staticElement = constructorElement;
6606 // verify that "A" is resolved to ConstructorElement 6597 // verify that "A" is resolved to ConstructorElement
6607 Element element = ElementLocator.locate(identifier); 6598 Element element = ElementLocator.locate(identifier);
6608 expect(element, same(classElement)); 6599 expect(element, same(classElement));
6609 } 6600 }
6610 6601
6611 void test_locate_InstanceCreationExpression_type_simpleIdentifier() { 6602 void test_locate_InstanceCreationExpression_type_simpleIdentifier() {
6612 // prepare: new A() 6603 // prepare: new A()
6613 SimpleIdentifier identifier = AstFactory.identifier3("A"); 6604 SimpleIdentifier identifier = AstFactory.identifier3("A");
6614 InstanceCreationExpression creation = 6605 InstanceCreationExpression creation = AstFactory
6615 AstFactory.instanceCreationExpression2( 6606 .instanceCreationExpression2(
6616 Keyword.NEW, AstFactory.typeName3(identifier)); 6607 Keyword.NEW, AstFactory.typeName3(identifier));
6617 // set ClassElement 6608 // set ClassElement
6618 ClassElement classElement = ElementFactory.classElement2("A"); 6609 ClassElement classElement = ElementFactory.classElement2("A");
6619 identifier.staticElement = classElement; 6610 identifier.staticElement = classElement;
6620 // set ConstructorElement 6611 // set ConstructorElement
6621 ConstructorElement constructorElement = 6612 ConstructorElement constructorElement =
6622 ElementFactory.constructorElement2(classElement, null); 6613 ElementFactory.constructorElement2(classElement, null);
6623 creation.constructorName.staticElement = constructorElement; 6614 creation.constructorName.staticElement = constructorElement;
6624 // verify that "A" is resolved to ConstructorElement 6615 // verify that "A" is resolved to ConstructorElement
6625 Element element = ElementLocator.locate(identifier); 6616 Element element = ElementLocator.locate(identifier);
(...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after
8110 } 8101 }
8111 8102
8112 ReferenceFinder _createReferenceFinder(ConstantEvaluationTarget source) => 8103 ReferenceFinder _createReferenceFinder(ConstantEvaluationTarget source) =>
8113 new ReferenceFinder((ConstantEvaluationTarget dependency) { 8104 new ReferenceFinder((ConstantEvaluationTarget dependency) {
8114 _referenceGraph.addEdge(source, dependency); 8105 _referenceGraph.addEdge(source, dependency);
8115 }); 8106 });
8116 SuperConstructorInvocation _makeTailSuperConstructorInvocation( 8107 SuperConstructorInvocation _makeTailSuperConstructorInvocation(
8117 String name, bool isConst) { 8108 String name, bool isConst) {
8118 List<ConstructorInitializer> initializers = 8109 List<ConstructorInitializer> initializers =
8119 new List<ConstructorInitializer>(); 8110 new List<ConstructorInitializer>();
8120 ConstructorDeclaration constructorDeclaration = 8111 ConstructorDeclaration constructorDeclaration = AstFactory
8121 AstFactory.constructorDeclaration(AstFactory.identifier3(name), null, 8112 .constructorDeclaration(AstFactory.identifier3(name), null,
8122 AstFactory.formalParameterList(), initializers); 8113 AstFactory.formalParameterList(), initializers);
8123 if (isConst) { 8114 if (isConst) {
8124 constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0); 8115 constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0);
8125 } 8116 }
8126 ClassElementImpl classElement = ElementFactory.classElement2(name); 8117 ClassElementImpl classElement = ElementFactory.classElement2(name);
8127 SuperConstructorInvocation superConstructorInvocation = 8118 SuperConstructorInvocation superConstructorInvocation =
8128 AstFactory.superConstructorInvocation(); 8119 AstFactory.superConstructorInvocation();
8129 ConstructorElementImpl constructorElement = 8120 ConstructorElementImpl constructorElement =
8130 ElementFactory.constructorElement(classElement, name, isConst); 8121 ElementFactory.constructorElement(classElement, name, isConst);
8131 _tail = constructorElement; 8122 _tail = constructorElement;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
8245 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); 8236 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI));
8246 expect(UriKind.fromEncoding(0x58), same(null)); 8237 expect(UriKind.fromEncoding(0x58), same(null));
8247 } 8238 }
8248 8239
8249 void test_getEncoding() { 8240 void test_getEncoding() {
8250 expect(UriKind.DART_URI.encoding, 0x64); 8241 expect(UriKind.DART_URI.encoding, 0x64);
8251 expect(UriKind.FILE_URI.encoding, 0x66); 8242 expect(UriKind.FILE_URI.encoding, 0x66);
8252 expect(UriKind.PACKAGE_URI.encoding, 0x70); 8243 expect(UriKind.PACKAGE_URI.encoding, 0x70);
8253 } 8244 }
8254 } 8245 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698