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

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

Issue 2199903002: Create synthetic FieldElement(s) (don't use non-synthetic ones) for non-synthetic class getters/set… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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/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/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 expect(method.labels, hasLength(0)); 1584 expect(method.labels, hasLength(0));
1585 expect(method.localVariables, hasLength(0)); 1585 expect(method.localVariables, hasLength(0));
1586 expect(method.parameters, hasLength(0)); 1586 expect(method.parameters, hasLength(0));
1587 expect(method.typeParameters, hasLength(0)); 1587 expect(method.typeParameters, hasLength(0));
1588 expect(method.isAbstract, isTrue); 1588 expect(method.isAbstract, isTrue);
1589 expect(method.isExternal, isFalse); 1589 expect(method.isExternal, isFalse);
1590 expect(method.isStatic, isFalse); 1590 expect(method.isStatic, isFalse);
1591 expect(method.isSynthetic, isFalse); 1591 expect(method.isSynthetic, isFalse);
1592 } 1592 }
1593 1593
1594 void test_visitMethodDeclaration_duplicateField_synthetic() {
1595 buildElementsForText(r'''
1596 class A {
1597 int f;
1598 int get f => 42;
1599 }
1600 ''');
1601 ClassDeclaration classNode = compilationUnit.declarations.single;
1602 // ClassElement
1603 ClassElement classElement = classNode.element;
1604 expect(classElement.fields, hasLength(2));
1605 expect(classElement.accessors, hasLength(3));
1606 FieldElement notSyntheticFieldElement = classElement.fields
1607 .singleWhere((f) => f.displayName == 'f' && !f.isSynthetic);
1608 FieldElement syntheticFieldElement = classElement.fields
1609 .singleWhere((f) => f.displayName == 'f' && f.isSynthetic);
1610 PropertyAccessorElement syntheticGetterElement = classElement.accessors
1611 .singleWhere(
1612 (a) => a.displayName == 'f' && a.isGetter && a.isSynthetic);
1613 PropertyAccessorElement syntheticSetterElement = classElement.accessors
1614 .singleWhere(
1615 (a) => a.displayName == 'f' && a.isSetter && a.isSynthetic);
1616 PropertyAccessorElement notSyntheticGetterElement = classElement.accessors
1617 .singleWhere(
1618 (a) => a.displayName == 'f' && a.isGetter && !a.isSynthetic);
1619 expect(notSyntheticFieldElement.getter, same(syntheticGetterElement));
1620 expect(notSyntheticFieldElement.setter, same(syntheticSetterElement));
1621 expect(syntheticFieldElement.getter, same(notSyntheticGetterElement));
1622 expect(syntheticFieldElement.setter, isNull);
1623 // class members nodes and their elements
1624 FieldDeclaration fieldDeclNode = classNode.members[0];
1625 VariableDeclaration fieldNode = fieldDeclNode.fields.variables.single;
1626 MethodDeclaration getterNode = classNode.members[1];
1627 expect(fieldNode.element, notSyntheticFieldElement);
1628 expect(getterNode.element, notSyntheticGetterElement);
1629 }
1630
1594 void test_visitMethodDeclaration_external() { 1631 void test_visitMethodDeclaration_external() {
1595 // external m(); 1632 // external m();
1596 ElementHolder holder = new ElementHolder(); 1633 ElementHolder holder = new ElementHolder();
1597 ElementBuilder builder = _makeBuilder(holder); 1634 ElementBuilder builder = _makeBuilder(holder);
1598 String methodName = "m"; 1635 String methodName = "m";
1599 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( 1636 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2(
1600 null, 1637 null,
1601 null, 1638 null,
1602 null, 1639 null,
1603 null, 1640 null,
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after
2558 null, 2595 null,
2559 null, 2596 null,
2560 AstFactory.identifier3("main"), 2597 AstFactory.identifier3("main"),
2561 AstFactory.formalParameterList([formalParameter]), 2598 AstFactory.formalParameterList([formalParameter]),
2562 body); 2599 body);
2563 } 2600 }
2564 } 2601 }
2565 2602
2566 @reflectiveTest 2603 @reflectiveTest
2567 class ElementLocatorTest extends ResolverTestCase { 2604 class ElementLocatorTest extends ResolverTestCase {
2568 void test_locate_ExportDirective() {
2569 AstNode id = _findNodeIn("export", "export 'dart:core';");
2570 Element element = ElementLocator.locate(id);
2571 EngineTestCase.assertInstanceOf(
2572 (obj) => obj is ExportElement, ExportElement, element);
2573 }
2574
2575 void test_locate_Identifier_libraryDirective() {
2576 AstNode id = _findNodeIn("foo", "library foo.bar;");
2577 Element element = ElementLocator.locate(id);
2578 EngineTestCase.assertInstanceOf(
2579 (obj) => obj is LibraryElement, LibraryElement, element);
2580 }
2581
2582 void fail_locate_Identifier_partOfDirective() { 2605 void fail_locate_Identifier_partOfDirective() {
2583 // Can't resolve the library element without the library declaration. 2606 // Can't resolve the library element without the library declaration.
2584 // AstNode id = findNodeIn("foo", "part of foo.bar;"); 2607 // AstNode id = findNodeIn("foo", "part of foo.bar;");
2585 // Element element = ElementLocator.locate(id); 2608 // Element element = ElementLocator.locate(id);
2586 // assertInstanceOf(LibraryElement.class, element); 2609 // assertInstanceOf(LibraryElement.class, element);
2587 fail("Test this case"); 2610 fail("Test this case");
2588 } 2611 }
2589 2612
2590 @override 2613 @override
2591 void reset() { 2614 void reset() {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2636 class A { 2659 class A {
2637 A.bar() {} 2660 A.bar() {}
2638 }'''); 2661 }''');
2639 ConstructorDeclaration declaration = 2662 ConstructorDeclaration declaration =
2640 id.getAncestor((node) => node is ConstructorDeclaration); 2663 id.getAncestor((node) => node is ConstructorDeclaration);
2641 Element element = ElementLocator.locate(declaration); 2664 Element element = ElementLocator.locate(declaration);
2642 EngineTestCase.assertInstanceOf( 2665 EngineTestCase.assertInstanceOf(
2643 (obj) => obj is ConstructorElement, ConstructorElement, element); 2666 (obj) => obj is ConstructorElement, ConstructorElement, element);
2644 } 2667 }
2645 2668
2669 void test_locate_ExportDirective() {
2670 AstNode id = _findNodeIn("export", "export 'dart:core';");
2671 Element element = ElementLocator.locate(id);
2672 EngineTestCase.assertInstanceOf(
2673 (obj) => obj is ExportElement, ExportElement, element);
2674 }
2675
2646 void test_locate_FunctionDeclaration() { 2676 void test_locate_FunctionDeclaration() {
2647 AstNode id = _findNodeIn("f", "int f() => 3;"); 2677 AstNode id = _findNodeIn("f", "int f() => 3;");
2648 FunctionDeclaration declaration = 2678 FunctionDeclaration declaration =
2649 id.getAncestor((node) => node is FunctionDeclaration); 2679 id.getAncestor((node) => node is FunctionDeclaration);
2650 Element element = ElementLocator.locate(declaration); 2680 Element element = ElementLocator.locate(declaration);
2651 EngineTestCase.assertInstanceOf( 2681 EngineTestCase.assertInstanceOf(
2652 (obj) => obj is FunctionElement, FunctionElement, element); 2682 (obj) => obj is FunctionElement, FunctionElement, element);
2653 } 2683 }
2654 2684
2655 void 2685 void
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2717 (obj) => obj is ConstructorElement, ConstructorElement, element); 2747 (obj) => obj is ConstructorElement, ConstructorElement, element);
2718 } 2748 }
2719 2749
2720 void test_locate_Identifier_fieldName() { 2750 void test_locate_Identifier_fieldName() {
2721 AstNode id = _findNodeIn("x", "class A { var x; }"); 2751 AstNode id = _findNodeIn("x", "class A { var x; }");
2722 Element element = ElementLocator.locate(id); 2752 Element element = ElementLocator.locate(id);
2723 EngineTestCase.assertInstanceOf( 2753 EngineTestCase.assertInstanceOf(
2724 (obj) => obj is FieldElement, FieldElement, element); 2754 (obj) => obj is FieldElement, FieldElement, element);
2725 } 2755 }
2726 2756
2757 void test_locate_Identifier_libraryDirective() {
2758 AstNode id = _findNodeIn("foo", "library foo.bar;");
2759 Element element = ElementLocator.locate(id);
2760 EngineTestCase.assertInstanceOf(
2761 (obj) => obj is LibraryElement, LibraryElement, element);
2762 }
2763
2727 void test_locate_Identifier_propertyAccess() { 2764 void test_locate_Identifier_propertyAccess() {
2728 AstNode id = _findNodeIn( 2765 AstNode id = _findNodeIn(
2729 "length", 2766 "length",
2730 r''' 2767 r'''
2731 void main() { 2768 void main() {
2732 int x = 'foo'.length; 2769 int x = 'foo'.length;
2733 }'''); 2770 }''');
2734 Element element = ElementLocator.locate(id); 2771 Element element = ElementLocator.locate(id);
2735 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, 2772 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement,
2736 PropertyAccessorElement, element); 2773 PropertyAccessorElement, element);
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
3460 } 3497 }
3461 3498
3462 void test_conditionalCall_rhs2() { 3499 void test_conditionalCall_rhs2() {
3463 _assertFalse("null?.b(throw '');"); 3500 _assertFalse("null?.b(throw '');");
3464 } 3501 }
3465 3502
3466 void test_creation() { 3503 void test_creation() {
3467 expect(new ExitDetector(), isNotNull); 3504 expect(new ExitDetector(), isNotNull);
3468 } 3505 }
3469 3506
3470 void test_doStatement_return() {
3471 _assertTrue("{ do { return null; } while (1 == 2); }");
3472 }
3473
3474 void test_doStatement_throwCondition() {
3475 _assertTrue("{ do {} while (throw ''); }");
3476 }
3477
3478 void test_doStatement_break_and_throw() { 3507 void test_doStatement_break_and_throw() {
3479 _assertFalse("{ do { if (1==1) break; throw 'T'; } while (0==1); }"); 3508 _assertFalse("{ do { if (1==1) break; throw 'T'; } while (0==1); }");
3480 } 3509 }
3481 3510
3482 void test_doStatement_continue_and_throw() { 3511 void test_doStatement_continue_and_throw() {
3483 _assertFalse("{ do { if (1==1) continue; throw 'T'; } while (0==1); }"); 3512 _assertFalse("{ do { if (1==1) continue; throw 'T'; } while (0==1); }");
3484 } 3513 }
3485 3514
3486 void test_doStatement_continueInSwitch_and_throw() { 3515 void test_doStatement_continueDoInSwitch_and_throw() {
3487 _assertFalse(''' 3516 _assertFalse('''
3488 { 3517 {
3489 do { 3518 D: do {
3490 switch (1) { 3519 switch (1) {
3491 L: case 0: continue; 3520 L: case 0: continue D;
3492 M: case 1: break; 3521 M: case 1: break;
3493 } 3522 }
3494 throw 'T'; 3523 throw 'T';
3495 } while (0 == 1); 3524 } while (0 == 1);
3496 }'''); 3525 }''');
3497 } 3526 }
3498 3527
3499 void test_doStatement_continueDoInSwitch_and_throw() { 3528 void test_doStatement_continueInSwitch_and_throw() {
3500 _assertFalse(''' 3529 _assertFalse('''
3501 { 3530 {
3502 D: do { 3531 do {
3503 switch (1) { 3532 switch (1) {
3504 L: case 0: continue D; 3533 L: case 0: continue;
3505 M: case 1: break; 3534 M: case 1: break;
3506 } 3535 }
3507 throw 'T'; 3536 throw 'T';
3508 } while (0 == 1); 3537 } while (0 == 1);
3509 }'''); 3538 }''');
3510 } 3539 }
3511 3540
3541 void test_doStatement_return() {
3542 _assertTrue("{ do { return null; } while (1 == 2); }");
3543 }
3544
3545 void test_doStatement_throwCondition() {
3546 _assertTrue("{ do {} while (throw ''); }");
3547 }
3548
3512 void test_doStatement_true_break() { 3549 void test_doStatement_true_break() {
3513 _assertFalse("{ do { break; } while (true); }"); 3550 _assertFalse("{ do { break; } while (true); }");
3514 } 3551 }
3515 3552
3516 void test_doStatement_true_continue() { 3553 void test_doStatement_true_continue() {
3517 _assertTrue("{ do { continue; } while (true); }"); 3554 _assertTrue("{ do { continue; } while (true); }");
3518 } 3555 }
3519 3556
3520 void test_doStatement_true_continueWithLabel() { 3557 void test_doStatement_true_continueWithLabel() {
3521 _assertTrue("{ x: do { continue x; } while (true); }"); 3558 _assertTrue("{ x: do { continue x; } while (true); }");
3522 } 3559 }
3523 3560
3524
3525 void test_doStatement_true_if_return() { 3561 void test_doStatement_true_if_return() {
3526 _assertTrue("{ do { if (true) {return null;} } while (true); }"); 3562 _assertTrue("{ do { if (true) {return null;} } while (true); }");
3527 } 3563 }
3528 3564
3529 void test_doStatement_true_noBreak() { 3565 void test_doStatement_true_noBreak() {
3530 _assertTrue("{ do {} while (true); }"); 3566 _assertTrue("{ do {} while (true); }");
3531 } 3567 }
3532 3568
3533 void test_doStatement_true_return() { 3569 void test_doStatement_true_return() {
3534 _assertTrue("{ do { return null; } while (true); }"); 3570 _assertTrue("{ do { return null; } while (true); }");
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
3917 } 3953 }
3918 3954
3919 void test_whileStatement_throwCondition() { 3955 void test_whileStatement_throwCondition() {
3920 _assertTrue("{ while (throw '') {} }"); 3956 _assertTrue("{ while (throw '') {} }");
3921 } 3957 }
3922 3958
3923 void test_whileStatement_true_break() { 3959 void test_whileStatement_true_break() {
3924 _assertFalse("{ while (true) { break; } }"); 3960 _assertFalse("{ while (true) { break; } }");
3925 } 3961 }
3926 3962
3963 void test_whileStatement_true_break_and_throw() {
3964 _assertFalse("{ while (true) { if (1==1) break; throw 'T'; } }");
3965 }
3966
3927 void test_whileStatement_true_continue() { 3967 void test_whileStatement_true_continue() {
3928 _assertTrue("{ while (true) { continue; } }"); 3968 _assertTrue("{ while (true) { continue; } }");
3929 } 3969 }
3930 3970
3931 void test_whileStatement_true_continueWithLabel() { 3971 void test_whileStatement_true_continueWithLabel() {
3932 _assertTrue("{ x: while (true) { continue x; } }"); 3972 _assertTrue("{ x: while (true) { continue x; } }");
3933 } 3973 }
3934 3974
3935 void test_whileStatement_true_doStatement_scopeRequired() { 3975 void test_whileStatement_true_doStatement_scopeRequired() {
3936 _assertTrue("{ while (true) { x: do { continue x; } while (true); } }"); 3976 _assertTrue("{ while (true) { x: do { continue x; } while (true); } }");
3937 } 3977 }
3938 3978
3939 void test_whileStatement_true_if_return() { 3979 void test_whileStatement_true_if_return() {
3940 _assertTrue("{ while (true) { if (true) {return null;} } }"); 3980 _assertTrue("{ while (true) { if (true) {return null;} } }");
3941 } 3981 }
3942 3982
3943 void test_whileStatement_true_noBreak() { 3983 void test_whileStatement_true_noBreak() {
3944 _assertTrue("{ while (true) {} }"); 3984 _assertTrue("{ while (true) {} }");
3945 } 3985 }
3946 3986
3947 void test_whileStatement_true_return() { 3987 void test_whileStatement_true_return() {
3948 _assertTrue("{ while (true) { return null; } }"); 3988 _assertTrue("{ while (true) { return null; } }");
3949 } 3989 }
3950 3990
3951 void test_whileStatement_true_throw() { 3991 void test_whileStatement_true_throw() {
3952 _assertTrue("{ while (true) { throw ''; } }"); 3992 _assertTrue("{ while (true) { throw ''; } }");
3953 } 3993 }
3954 3994
3955 void test_whileStatement_true_break_and_throw() {
3956 _assertFalse("{ while (true) { if (1==1) break; throw 'T'; } }");
3957 }
3958
3959 void _assertFalse(String source) { 3995 void _assertFalse(String source) {
3960 _assertHasReturn(false, source); 3996 _assertHasReturn(false, source);
3961 } 3997 }
3962 3998
3963 void _assertHasReturn(bool expectedResult, String source) { 3999 void _assertHasReturn(bool expectedResult, String source) {
3964 Statement statement = ParserTestCase.parseStatement(source); 4000 Statement statement = ParserTestCase.parseStatement(source);
3965 expect(ExitDetector.exits(statement), expectedResult); 4001 expect(ExitDetector.exits(statement), expectedResult);
3966 } 4002 }
3967 4003
3968 void _assertTrue(String source) { 4004 void _assertTrue(String source) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
4078 if (1 < 2) { 4114 if (1 < 2) {
4079 break x; 4115 break x;
4080 } 4116 }
4081 return; 4117 return;
4082 } 4118 }
4083 } 4119 }
4084 '''); 4120 ''');
4085 _assertNthStatementDoesNotExit(source, 0); 4121 _assertNthStatementDoesNotExit(source, 0);
4086 } 4122 }
4087 4123
4088 void test_whileStatement_switchWithBreakWithLabel() {
4089 Source source = addSource(r'''
4090 void f() {
4091 x: while (true) {
4092 switch (true) {
4093 case false: break;
4094 case true: break x;
4095 }
4096 }
4097 }
4098 ''');
4099 _assertNthStatementDoesNotExit(source, 0);
4100 }
4101
4102 void test_whileStatement_breakWithLabel_afterExting() { 4124 void test_whileStatement_breakWithLabel_afterExting() {
4103 Source source = addSource(r''' 4125 Source source = addSource(r'''
4104 void f() { 4126 void f() {
4105 x: while (true) { 4127 x: while (true) {
4106 return; 4128 return;
4107 if (1 < 2) { 4129 if (1 < 2) {
4108 break x; 4130 break x;
4109 } 4131 }
4110 } 4132 }
4111 } 4133 }
4112 '''); 4134 ''');
4113 _assertNthStatementExits(source, 0); 4135 _assertNthStatementExits(source, 0);
4114 } 4136 }
4115 4137
4138 void test_whileStatement_switchWithBreakWithLabel() {
4139 Source source = addSource(r'''
4140 void f() {
4141 x: while (true) {
4142 switch (true) {
4143 case false: break;
4144 case true: break x;
4145 }
4146 }
4147 }
4148 ''');
4149 _assertNthStatementDoesNotExit(source, 0);
4150 }
4151
4116 void test_yieldStatement_plain() { 4152 void test_yieldStatement_plain() {
4117 Source source = addSource(r''' 4153 Source source = addSource(r'''
4118 void f() sync* { 4154 void f() sync* {
4119 yield 1; 4155 yield 1;
4120 } 4156 }
4121 '''); 4157 ''');
4122 _assertNthStatementDoesNotExit(source, 0); 4158 _assertNthStatementDoesNotExit(source, 0);
4123 } 4159 }
4124 4160
4125 void test_yieldStatement_star_plain() { 4161 void test_yieldStatement_star_plain() {
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
4508 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); 4544 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI));
4509 expect(UriKind.fromEncoding(0x58), same(null)); 4545 expect(UriKind.fromEncoding(0x58), same(null));
4510 } 4546 }
4511 4547
4512 void test_getEncoding() { 4548 void test_getEncoding() {
4513 expect(UriKind.DART_URI.encoding, 0x64); 4549 expect(UriKind.DART_URI.encoding, 0x64);
4514 expect(UriKind.FILE_URI.encoding, 0x66); 4550 expect(UriKind.FILE_URI.encoding, 0x66);
4515 expect(UriKind.PACKAGE_URI.encoding, 0x70); 4551 expect(UriKind.PACKAGE_URI.encoding, 0x70);
4516 } 4552 }
4517 } 4553 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/incremental_element_builder.dart ('k') | pkg/analyzer/test/src/context/context_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698