| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.src.task.incremental_element_builder_test; | 5 library analyzer.test.src.task.incremental_element_builder_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/dart/element/visitor.dart'; | 9 import 'package:analyzer/dart/element/visitor.dart'; |
| 10 import 'package:analyzer/src/dart/ast/utilities.dart'; | 10 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 // verify delta | 473 // verify delta |
| 474 expect(helper.delta.addedConstructors, isEmpty); | 474 expect(helper.delta.addedConstructors, isEmpty); |
| 475 expect(helper.delta.removedConstructors, isEmpty); | 475 expect(helper.delta.removedConstructors, isEmpty); |
| 476 expect(helper.delta.addedAccessors, isEmpty); | 476 expect(helper.delta.addedAccessors, isEmpty); |
| 477 expect(helper.delta.removedAccessors, | 477 expect(helper.delta.removedAccessors, |
| 478 unorderedEquals([oldFieldElementB.getter, oldFieldElementB.setter])); | 478 unorderedEquals([oldFieldElementB.getter, oldFieldElementB.setter])); |
| 479 expect(helper.delta.addedMethods, isEmpty); | 479 expect(helper.delta.addedMethods, isEmpty); |
| 480 expect(helper.delta.removedMethods, isEmpty); | 480 expect(helper.delta.removedMethods, isEmpty); |
| 481 } | 481 } |
| 482 | 482 |
| 483 test_classDelta_field_syntheticAndNot_renameNonSynthetic() { |
| 484 var helper = new _ClassDeltaHelper('A'); |
| 485 _buildOldUnit(r''' |
| 486 class A { |
| 487 int foo; |
| 488 int get foo => 1; |
| 489 } |
| 490 '''); |
| 491 helper.initOld(oldUnit); |
| 492 FieldDeclaration oldFieldDeclNode = helper.oldMembers[0]; |
| 493 VariableDeclaration oldFieldNode = oldFieldDeclNode.fields.variables.single; |
| 494 FieldElement oldFieldElement = oldFieldNode.name.staticElement; |
| 495 _buildNewUnit(r''' |
| 496 class A { |
| 497 int _foo; |
| 498 int get foo => 1; |
| 499 } |
| 500 '''); |
| 501 helper.initNew(newUnit, unitDelta); |
| 502 // nodes |
| 503 FieldDeclaration newFieldDeclNode = helper.newMembers[0]; |
| 504 VariableDeclaration newFieldNode = newFieldDeclNode.fields.variables.single; |
| 505 MethodDeclaration getterNode = helper.newMembers[1]; |
| 506 expect(getterNode, same(helper.oldMembers[1])); |
| 507 // elements |
| 508 FieldElement newFieldElement = newFieldNode.name.staticElement; |
| 509 PropertyAccessorElement getterElement = getterNode.element; |
| 510 expect(newFieldElement.name, '_foo'); |
| 511 expect( |
| 512 helper.element.fields, |
| 513 unorderedMatches( |
| 514 [same(newFieldElement), same(getterElement.variable)])); |
| 515 expect( |
| 516 helper.element.accessors, |
| 517 unorderedMatches([ |
| 518 same(newFieldElement.getter), |
| 519 same(newFieldElement.setter), |
| 520 same(getterElement) |
| 521 ])); |
| 522 // verify delta |
| 523 expect(helper.delta.addedConstructors, isEmpty); |
| 524 expect(helper.delta.removedConstructors, isEmpty); |
| 525 expect(helper.delta.addedAccessors, |
| 526 unorderedEquals([newFieldElement.getter, newFieldElement.setter])); |
| 527 expect(helper.delta.removedAccessors, |
| 528 [oldFieldElement.getter, oldFieldElement.setter]); |
| 529 expect(helper.delta.addedMethods, isEmpty); |
| 530 expect(helper.delta.removedMethods, isEmpty); |
| 531 } |
| 532 |
| 483 test_classDelta_getter_add() { | 533 test_classDelta_getter_add() { |
| 484 var helper = new _ClassDeltaHelper('A'); | 534 var helper = new _ClassDeltaHelper('A'); |
| 485 _buildOldUnit(r''' | 535 _buildOldUnit(r''' |
| 486 class A { | 536 class A { |
| 487 int get aaa => 1; | 537 int get aaa => 1; |
| 488 } | 538 } |
| 489 '''); | 539 '''); |
| 490 helper.initOld(oldUnit); | 540 helper.initOld(oldUnit); |
| 491 _buildNewUnit(r''' | 541 _buildNewUnit(r''' |
| 492 class A { | 542 class A { |
| (...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2044 if (expected == null && actual == null) { | 2094 if (expected == null && actual == null) { |
| 2045 return; | 2095 return; |
| 2046 } | 2096 } |
| 2047 // Prefixes are built later. | 2097 // Prefixes are built later. |
| 2048 if (actual is PrefixElement) { | 2098 if (actual is PrefixElement) { |
| 2049 return; | 2099 return; |
| 2050 } | 2100 } |
| 2051 // Compare properties. | 2101 // Compare properties. |
| 2052 _verifyEqual('$desc name', expected.name, actual.name); | 2102 _verifyEqual('$desc name', expected.name, actual.name); |
| 2053 _verifyEqual('$desc nameOffset', expected.nameOffset, actual.nameOffset); | 2103 _verifyEqual('$desc nameOffset', expected.nameOffset, actual.nameOffset); |
| 2104 _verifyEqual('$desc isSynthetic', expected.isSynthetic, actual.isSynthetic); |
| 2054 if (expected is ElementImpl && actual is ElementImpl) { | 2105 if (expected is ElementImpl && actual is ElementImpl) { |
| 2055 _verifyEqual('$desc codeOffset', expected.codeOffset, actual.codeOffset); | 2106 _verifyEqual('$desc codeOffset', expected.codeOffset, actual.codeOffset); |
| 2056 _verifyEqual('$desc codeLength', expected.codeLength, actual.codeLength); | 2107 _verifyEqual('$desc codeLength', expected.codeLength, actual.codeLength); |
| 2057 } | 2108 } |
| 2058 if (expected is LocalElement && actual is LocalElement) { | 2109 if (expected is LocalElement && actual is LocalElement) { |
| 2059 _verifyEqual( | 2110 _verifyEqual( |
| 2060 '$desc visibleRange', expected.visibleRange, actual.visibleRange); | 2111 '$desc visibleRange', expected.visibleRange, actual.visibleRange); |
| 2061 } | 2112 } |
| 2062 _verifyEqual('$desc documentationComment', expected.documentationComment, | 2113 _verifyEqual('$desc documentationComment', expected.documentationComment, |
| 2063 actual.documentationComment); | 2114 actual.documentationComment); |
| 2064 { | 2115 { |
| 2065 var expectedEnclosing = expected.enclosingElement; | 2116 var expectedEnclosing = expected.enclosingElement; |
| 2066 var actualEnclosing = actual.enclosingElement; | 2117 var actualEnclosing = actual.enclosingElement; |
| 2067 if (expectedEnclosing != null) { | 2118 if (expectedEnclosing != null) { |
| 2068 expect(actualEnclosing, isNotNull, reason: '$desc enclosingElement'); | 2119 expect(actualEnclosing, isNotNull, reason: '$desc enclosingElement'); |
| 2069 _verifyElement(expectedEnclosing, actualEnclosing, | 2120 _verifyElement(expectedEnclosing, actualEnclosing, |
| 2070 '${expectedEnclosing.name}.$desc'); | 2121 '${expectedEnclosing.name}.$desc'); |
| 2071 } | 2122 } |
| 2072 } | 2123 } |
| 2073 // Compare implicit accessors. | 2124 // Compare implicit accessors. |
| 2074 if (expected is PropertyInducingElement && | 2125 if (expected is PropertyInducingElement && |
| 2075 actual is PropertyInducingElement && | 2126 actual is PropertyInducingElement && |
| 2076 !expected.isSynthetic) { | 2127 !expected.isSynthetic) { |
| 2077 _verifyElement(expected.getter, actual.getter, '$desc getter'); | 2128 _verifyElement(expected.getter, actual.getter, '$desc getter'); |
| 2078 _verifyElement(expected.setter, actual.setter, '$desc setter'); | 2129 _verifyElement(expected.setter, actual.setter, '$desc setter'); |
| 2079 } | 2130 } |
| 2131 // Compare implicit properties. |
| 2132 if (expected is PropertyAccessorElement && |
| 2133 actual is PropertyAccessorElement && |
| 2134 !expected.isSynthetic) { |
| 2135 _verifyElement(expected.variable, actual.variable, '$desc variable'); |
| 2136 } |
| 2080 // Compare parameters. | 2137 // Compare parameters. |
| 2081 if (expected is ExecutableElement && actual is ExecutableElement) { | 2138 if (expected is ExecutableElement && actual is ExecutableElement) { |
| 2082 List<ParameterElement> actualParameters = actual.parameters; | 2139 List<ParameterElement> actualParameters = actual.parameters; |
| 2083 List<ParameterElement> expectedParameters = expected.parameters; | 2140 List<ParameterElement> expectedParameters = expected.parameters; |
| 2084 expect(actualParameters, hasLength(expectedParameters.length)); | 2141 expect(actualParameters, hasLength(expectedParameters.length)); |
| 2085 for (int i = 0; i < expectedParameters.length; i++) { | 2142 for (int i = 0; i < expectedParameters.length; i++) { |
| 2086 _verifyElement( | 2143 _verifyElement( |
| 2087 expectedParameters[i], actualParameters[i], '$desc parameters[$i]'); | 2144 expectedParameters[i], actualParameters[i], '$desc parameters[$i]'); |
| 2088 } | 2145 } |
| 2089 } | 2146 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2129 unitMember is ClassDeclaration && unitMember.name.name == name); | 2186 unitMember is ClassDeclaration && unitMember.name.name == name); |
| 2130 } | 2187 } |
| 2131 | 2188 |
| 2132 class _MaterializeLazyElementsVisitor extends GeneralizingElementVisitor { | 2189 class _MaterializeLazyElementsVisitor extends GeneralizingElementVisitor { |
| 2133 @override | 2190 @override |
| 2134 visitExecutableElement(ExecutableElement element) { | 2191 visitExecutableElement(ExecutableElement element) { |
| 2135 element.parameters; | 2192 element.parameters; |
| 2136 super.visitExecutableElement(element); | 2193 super.visitExecutableElement(element); |
| 2137 } | 2194 } |
| 2138 } | 2195 } |
| OLD | NEW |