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

Unified Diff: pkg/analyzer/test/src/task/incremental_element_builder_test.dart

Issue 1119683004: Incrementally build unit member elements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/task/incremental_element_builder.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/task/incremental_element_builder_test.dart
diff --git a/pkg/analyzer/test/src/task/incremental_element_builder_test.dart b/pkg/analyzer/test/src/task/incremental_element_builder_test.dart
index b33f95c07058f001935a028baac78ff6d8b0bc22..56b622613cceea65ffbbb992e95e692af99c876e 100644
--- a/pkg/analyzer/test/src/task/incremental_element_builder_test.dart
+++ b/pkg/analyzer/test/src/task/incremental_element_builder_test.dart
@@ -23,6 +23,7 @@ class IncrementalCompilationUnitElementBuilderTest extends AbstractContextTest {
Source source;
String oldCode;
CompilationUnit oldUnit;
+ CompilationUnitElement unitElement;
String newCode;
CompilationUnit newUnit;
@@ -217,16 +218,350 @@ import 'dart:math';
}
}
+ test_unitMembers_accessor_add() {
+ _buildOldUnit(r'''
+get a => 1;
+''');
+ _buildNewUnit(r'''
+get a => 1;
+get b => 2;
+''');
+ List<CompilationUnitMember> oldNodes = oldUnit.declarations;
+ List<CompilationUnitMember> newNodes = newUnit.declarations;
+ // nodes
+ FunctionDeclaration node1 = newNodes[0];
+ FunctionDeclaration node2 = newNodes[1];
+ expect(node1, same(oldNodes[0]));
+ // elements
+ PropertyAccessorElement elementA = node1.element;
+ PropertyAccessorElement elementB = node2.element;
+ expect(elementA, isNotNull);
+ expect(elementB, isNotNull);
+ expect(elementA.name, 'a');
+ expect(elementB.name, 'b');
+ // unit.types
+ expect(unitElement.topLevelVariables,
+ unorderedEquals([elementA.variable, elementB.variable]));
+ expect(unitElement.accessors, unorderedEquals([elementA, elementB]));
+ }
+
+ test_unitMembers_class_add() {
+ _buildOldUnit(r'''
+class A {}
+''');
+ _buildNewUnit(r'''
+class A {}
+class B {}
+''');
+ List<CompilationUnitMember> oldNodes = oldUnit.declarations;
+ List<CompilationUnitMember> newNodes = newUnit.declarations;
+ // nodes
+ CompilationUnitMember nodeA = newNodes[0];
+ CompilationUnitMember nodeB = newNodes[1];
+ expect(nodeA, same(oldNodes[0]));
+ // elements
+ ClassElement elementA = nodeA.element;
+ ClassElement elementB = nodeB.element;
+ expect(elementA, isNotNull);
+ expect(elementB, isNotNull);
+ expect(elementA.name, 'A');
+ expect(elementB.name, 'B');
+ // unit.types
+ expect(unitElement.types, unorderedEquals([elementA, elementB]));
+ }
+
+ test_unitMembers_class_comments() {
+ _buildOldUnit(r'''
+/// reference [bool] type.
+class A {}
+/// reference [int] type.
+class B {}
+/// reference [double] and [B] types.
+class C {}
+''');
+ _buildNewUnit(r'''
+/// reference [double] and [B] types.
+class C {}
+/// reference [bool] type.
+class A {}
+/// reference [int] type.
+class B {}
+''');
+ List<CompilationUnitMember> oldNodes = oldUnit.declarations;
+ List<CompilationUnitMember> newNodes = newUnit.declarations;
+ {
+ CompilationUnitMember newNode = newNodes[0];
+ expect(newNode, same(oldNodes[2]));
+ expect(getNodeText(newNode), r'''
+/// reference [double] and [B] types.
+class C {}''');
+ ClassElement element = newNode.element;
+ expect(element, isNotNull);
+ expect(element.name, 'C');
+ expect(element.nameOffset, newCode.indexOf('C {}'));
+ // [double] and [B] are still resolved
+ {
+ var docReferences = newNode.documentationComment.references;
+ expect(docReferences, hasLength(2));
+ expect(docReferences[0].identifier.staticElement.name, 'double');
+ expect(docReferences[1].identifier.staticElement,
+ same(newNodes[2].element));
+ }
+ }
+ {
+ CompilationUnitMember newNode = newNodes[1];
+ expect(newNode, same(oldNodes[0]));
+ expect(getNodeText(newNode), r'''
+/// reference [bool] type.
+class A {}''');
+ ClassElement element = newNode.element;
+ expect(element, isNotNull);
+ expect(element.name, 'A');
+ expect(element.nameOffset, newCode.indexOf('A {}'));
+ // [bool] is still resolved
+ {
+ var docReferences = newNode.documentationComment.references;
+ expect(docReferences, hasLength(1));
+ expect(docReferences[0].identifier.staticElement.name, 'bool');
+ }
+ }
+ {
+ CompilationUnitMember newNode = newNodes[2];
+ expect(newNode, same(oldNodes[1]));
+ expect(getNodeText(newNode), r'''
+/// reference [int] type.
+class B {}''');
+ ClassElement element = newNode.element;
+ expect(element, isNotNull);
+ expect(element.name, 'B');
+ expect(element.nameOffset, newCode.indexOf('B {}'));
+ // [int] is still resolved
+ {
+ var docReferences = newNode.documentationComment.references;
+ expect(docReferences, hasLength(1));
+ expect(docReferences[0].identifier.staticElement.name, 'int');
+ }
+ }
+ }
+
+ test_unitMembers_class_reorder() {
+ _buildOldUnit(r'''
+class A {}
+class B {}
+class C {}
+''');
+ _buildNewUnit(r'''
+class C {}
+class A {}
+class B {}
+''');
+ List<CompilationUnitMember> oldNodes = oldUnit.declarations;
+ List<CompilationUnitMember> newNodes = newUnit.declarations;
+ {
+ CompilationUnitMember newNode = newNodes[0];
+ expect(newNode, same(oldNodes[2]));
+ expect(getNodeText(newNode), 'class C {}');
+ ClassElement element = newNode.element;
+ expect(element, isNotNull);
+ expect(element.name, 'C');
+ expect(element.nameOffset, newCode.indexOf('C {}'));
+ }
+ {
+ CompilationUnitMember newNode = newNodes[1];
+ expect(newNode, same(oldNodes[0]));
+ expect(getNodeText(newNode), 'class A {}');
+ ClassElement element = newNode.element;
+ expect(element, isNotNull);
+ expect(element.name, 'A');
+ expect(element.nameOffset, newCode.indexOf('A {}'));
+ }
+ {
+ CompilationUnitMember newNode = newNodes[2];
+ expect(newNode, same(oldNodes[1]));
+ expect(getNodeText(newNode), 'class B {}');
+ ClassElement element = newNode.element;
+ expect(element, isNotNull);
+ expect(element.name, 'B');
+ expect(element.nameOffset, newCode.indexOf('B {}'));
+ }
+ }
+
+ test_unitMembers_enum_add() {
+ _buildOldUnit(r'''
+enum A {A1, A2}
+''');
+ _buildNewUnit(r'''
+enum A {A1, A2}
+enum B {B1, B2}
+''');
+ List<CompilationUnitMember> oldNodes = oldUnit.declarations;
+ List<CompilationUnitMember> newNodes = newUnit.declarations;
+ // nodes
+ CompilationUnitMember nodeA = newNodes[0];
+ CompilationUnitMember nodeB = newNodes[1];
+ expect(nodeA, same(oldNodes[0]));
+ // elements
+ ClassElement elementA = nodeA.element;
+ ClassElement elementB = nodeB.element;
+ expect(elementA, isNotNull);
+ expect(elementB, isNotNull);
+ expect(elementA.name, 'A');
+ expect(elementB.name, 'B');
+ // unit.types
+ expect(unitElement.enums, unorderedEquals([elementA, elementB]));
+ }
+
+ test_unitMembers_function_add() {
+ _buildOldUnit(r'''
+a() {}
+''');
+ _buildNewUnit(r'''
+a() {}
+b() {}
+''');
+ List<CompilationUnitMember> oldNodes = oldUnit.declarations;
+ List<CompilationUnitMember> newNodes = newUnit.declarations;
+ // nodes
+ CompilationUnitMember nodeA = newNodes[0];
+ CompilationUnitMember nodeB = newNodes[1];
+ expect(nodeA, same(oldNodes[0]));
+ // elements
+ FunctionElement elementA = nodeA.element;
+ FunctionElement elementB = nodeB.element;
+ expect(elementA, isNotNull);
+ expect(elementB, isNotNull);
+ expect(elementA.name, 'a');
+ expect(elementB.name, 'b');
+ // unit.types
+ expect(unitElement.functions, unorderedEquals([elementA, elementB]));
+ }
+
+ test_unitMembers_functionTypeAlias_add() {
+ _buildOldUnit(r'''
+typedef A();
+''');
+ _buildNewUnit(r'''
+typedef A();
+typedef B();
+''');
+ List<CompilationUnitMember> oldNodes = oldUnit.declarations;
+ List<CompilationUnitMember> newNodes = newUnit.declarations;
+ // nodes
+ CompilationUnitMember nodeA = newNodes[0];
+ CompilationUnitMember nodeB = newNodes[1];
+ expect(nodeA, same(oldNodes[0]));
+ // elements
+ FunctionTypeAliasElement elementA = nodeA.element;
+ FunctionTypeAliasElement elementB = nodeB.element;
+ expect(elementA, isNotNull);
+ expect(elementB, isNotNull);
+ expect(elementA.name, 'A');
+ expect(elementB.name, 'B');
+ // unit.types
+ expect(
+ unitElement.functionTypeAliases, unorderedEquals([elementA, elementB]));
+ }
+
+ test_unitMembers_topLevelVariable_add() {
+ _buildOldUnit(r'''
+int a, b;
+''');
+ _buildNewUnit(r'''
+int a, b;
+int c, d;
+''');
+ List<CompilationUnitMember> oldNodes = oldUnit.declarations;
+ List<CompilationUnitMember> newNodes = newUnit.declarations;
+ // nodes
+ TopLevelVariableDeclaration node1 = newNodes[0];
+ TopLevelVariableDeclaration node2 = newNodes[1];
+ expect(node1, same(oldNodes[0]));
+ // elements
+ TopLevelVariableElement elementA = node1.variables.variables[0].element;
+ TopLevelVariableElement elementB = node1.variables.variables[1].element;
+ TopLevelVariableElement elementC = node2.variables.variables[0].element;
+ TopLevelVariableElement elementD = node2.variables.variables[1].element;
+ expect(elementA, isNotNull);
+ expect(elementB, isNotNull);
+ expect(elementC, isNotNull);
+ expect(elementD, isNotNull);
+ expect(elementA.name, 'a');
+ expect(elementB.name, 'b');
+ expect(elementC.name, 'c');
+ expect(elementD.name, 'd');
+ // unit.types
+ expect(unitElement.topLevelVariables,
+ unorderedEquals([elementA, elementB, elementC, elementD]));
+ expect(unitElement.accessors, unorderedEquals([
+ elementA.getter,
+ elementA.setter,
+ elementB.getter,
+ elementB.setter,
+ elementC.getter,
+ elementC.setter,
+ elementD.getter,
+ elementD.setter
+ ]));
+ }
+
+ test_unitMembers_topLevelVariableDeclaration() {
+ _buildOldUnit(r'''
+bool a = 1, b = 2;
+int c = 3;
+''');
+ _buildNewUnit(r'''
+int c = 3;
+
+bool a =1, b = 2;
+''');
+ List<CompilationUnitMember> oldNodes = oldUnit.declarations;
+ List<CompilationUnitMember> newNodes = newUnit.declarations;
+ {
+ TopLevelVariableDeclaration newNode = newNodes[0];
+ expect(newNode, same(oldNodes[1]));
+ expect(getNodeText(newNode), 'int c = 3;');
+ {
+ TopLevelVariableElement element =
+ newNode.variables.variables[0].element;
+ expect(element, isNotNull);
+ expect(element.name, 'c');
+ expect(element.nameOffset, newCode.indexOf('c = 3'));
+ }
+ }
+ {
+ TopLevelVariableDeclaration newNode = newNodes[1];
+ expect(newNode, same(oldNodes[0]));
+ expect(getNodeText(newNode), 'bool a =1, b = 2;');
+ {
+ TopLevelVariableElement element =
+ newNode.variables.variables[0].element;
+ expect(element, isNotNull);
+ expect(element.name, 'a');
+ expect(element.nameOffset, newCode.indexOf('a =1'));
+ }
+ {
+ TopLevelVariableElement element =
+ newNode.variables.variables[1].element;
+ expect(element, isNotNull);
+ expect(element.name, 'b');
+ expect(element.nameOffset, newCode.indexOf('b = 2'));
+ }
+ }
+ }
+
void _buildNewUnit(String newCode) {
this.newCode = newCode;
context.setContents(source, newCode);
newUnit = context.parseCompilationUnit(source);
new IncrementalCompilationUnitElementBuilder(oldUnit, newUnit).build();
+ expect(newUnit.element, unitElement);
}
void _buildOldUnit(String oldCode) {
this.oldCode = oldCode;
source = newSource('/test.dart', oldCode);
oldUnit = context.resolveCompilationUnit2(source, source);
+ unitElement = oldUnit.element;
+ expect(unitElement, isNotNull);
}
}
« no previous file with comments | « pkg/analyzer/lib/src/task/incremental_element_builder.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698