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

Side by Side Diff: pkg/analysis_server/test/services/index/dart_index_contributor_test.dart

Issue 971833003: Optimize top-level element declarations search. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
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 test.services.src.index.dart_index_contributor; 5 library test.services.src.index.dart_index_contributor;
6 6
7 import 'package:analysis_server/src/services/index/index.dart'; 7 import 'package:analysis_server/src/services/index/index.dart';
8 import 'package:analysis_server/src/services/index/index_contributor.dart'; 8 import 'package:analysis_server/src/services/index/index_contributor.dart';
9 import 'package:analysis_server/src/services/index/index_store.dart'; 9 import 'package:analysis_server/src/services/index/index_store.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 expectedRelationship == recordedRelation.relationship) && 58 expectedRelationship == recordedRelation.relationship) &&
59 (expectedLocation == null || 59 (expectedLocation == null ||
60 _equalsLocation(recordedRelation.location, expectedLocation)); 60 _equalsLocation(recordedRelation.location, expectedLocation));
61 } 61 }
62 62
63 63
64 @reflectiveTest 64 @reflectiveTest
65 class DartUnitContributorTest extends AbstractSingleUnitTest { 65 class DartUnitContributorTest extends AbstractSingleUnitTest {
66 IndexStore store = new MockIndexStore(); 66 IndexStore store = new MockIndexStore();
67 List<RecordedRelation> recordedRelations = <RecordedRelation>[]; 67 List<RecordedRelation> recordedRelations = <RecordedRelation>[];
68 List<Element> recordedTopElements = <Element>[];
68 69
69 CompilationUnitElement importedUnit({int index: 0}) { 70 CompilationUnitElement importedUnit({int index: 0}) {
70 List<ImportElement> imports = testLibraryElement.imports; 71 List<ImportElement> imports = testLibraryElement.imports;
71 return imports[index].importedLibrary.definingCompilationUnit; 72 return imports[index].importedLibrary.definingCompilationUnit;
72 } 73 }
73 74
74 void setUp() { 75 void setUp() {
75 super.setUp(); 76 super.setUp();
76 when(store.aboutToIndexDart(context, anyObject)).thenReturn(true); 77 when(store.aboutToIndexDart(context, anyObject)).thenReturn(true);
77 when( 78 when(
78 store.recordRelationship( 79 store.recordRelationship(
79 anyObject, 80 anyObject,
80 anyObject, 81 anyObject,
81 anyObject)).thenInvoke( 82 anyObject)).thenInvoke(
82 (Element element, Relationship relationship, Location location) { 83 (Element element, Relationship relationship, Location location) {
83 recordedRelations.add( 84 recordedRelations.add(
84 new RecordedRelation(element, relationship, location)); 85 new RecordedRelation(element, relationship, location));
85 }); 86 });
87 when(store.recordTopDeclaration(anyObject)).thenInvoke((Element element) {
88 recordedTopElements.add(element);
89 });
86 } 90 }
87 91
88 void test_definesClass() { 92 void test_definesClass() {
89 _indexTestUnit('class A {}'); 93 _indexTestUnit('class A {}');
90 // prepare elements 94 // prepare elements
91 ClassElement classElement = findElement("A"); 95 ClassElement classElement = findElement("A");
92 // verify 96 // verify
93 _assertDefinesTopLevelElement( 97 _assertDefinesTopLevelElement(classElement);
94 IndexConstants.DEFINES,
95 _expectedLocation(classElement, 'A {}'));
96 } 98 }
97 99
98 void test_definesClassAlias() { 100 void test_definesClassAlias() {
99 _indexTestUnit(''' 101 _indexTestUnit('''
100 class Mix {} 102 class Mix {}
101 class MyClass = Object with Mix;'''); 103 class MyClass = Object with Mix;''');
102 // prepare elements 104 // prepare elements
103 Element classElement = findElement("MyClass"); 105 Element classElement = findElement("MyClass");
104 // verify 106 // verify
105 _assertDefinesTopLevelElement( 107 _assertDefinesTopLevelElement(classElement);
106 IndexConstants.DEFINES,
107 _expectedLocation(classElement, 'MyClass ='));
108 } 108 }
109 109
110 void test_definesClassEnum() { 110 void test_definesClassEnum() {
111 _indexTestUnit('enum MyEnum {A, B, c}'); 111 _indexTestUnit('enum MyEnum {A, B, c}');
112 // prepare elements 112 // prepare elements
113 ClassElement classElement = findElement("MyEnum"); 113 ClassElement classElement = findElement("MyEnum");
114 // verify 114 // verify
115 _assertDefinesTopLevelElement( 115 _assertDefinesTopLevelElement(classElement);
116 IndexConstants.DEFINES,
117 _expectedLocation(classElement, 'MyEnum {'));
118 } 116 }
119 117
120 void test_definesFunction() { 118 void test_definesFunction() {
121 _indexTestUnit('myFunction() {}'); 119 _indexTestUnit('myFunction() {}');
122 // prepare elements 120 // prepare elements
123 FunctionElement functionElement = findElement("myFunction"); 121 FunctionElement functionElement = findElement("myFunction");
124 // verify 122 // verify
125 _assertDefinesTopLevelElement( 123 _assertDefinesTopLevelElement(functionElement);
126 IndexConstants.DEFINES,
127 _expectedLocation(functionElement, 'myFunction() {}'));
128 } 124 }
129 125
130 126
131 void test_definesFunctionType() { 127 void test_definesFunctionType() {
132 _indexTestUnit('typedef MyFunction(int p);'); 128 _indexTestUnit('typedef MyFunction(int p);');
133 // prepare elements 129 // prepare elements
134 FunctionTypeAliasElement typeAliasElement = findElement("MyFunction"); 130 FunctionTypeAliasElement typeAliasElement = findElement("MyFunction");
135 // verify 131 // verify
136 _assertDefinesTopLevelElement( 132 _assertDefinesTopLevelElement(typeAliasElement);
137 IndexConstants.DEFINES,
138 _expectedLocation(typeAliasElement, 'MyFunction(int p);'));
139 } 133 }
140 134
141 void test_definesVariable() { 135 void test_definesVariable() {
142 _indexTestUnit('var myVar = 42;'); 136 _indexTestUnit('var myVar = 42;');
143 // prepare elements 137 // prepare elements
144 VariableElement varElement = findElement("myVar"); 138 VariableElement varElement = findElement("myVar");
145 // verify 139 // verify
146 _assertDefinesTopLevelElement( 140 _assertDefinesTopLevelElement(varElement);
147 IndexConstants.DEFINES,
148 _expectedLocation(varElement, 'myVar = 42;'));
149 } 141 }
150 142
151 void test_forIn() { 143 void test_forIn() {
152 _indexTestUnit(''' 144 _indexTestUnit('''
153 main() { 145 main() {
154 for (var v in []) { 146 for (var v in []) {
155 } 147 }
156 }'''); 148 }''');
157 // prepare elements 149 // prepare elements
158 Element mainElement = findElement("main"); 150 Element mainElement = findElement("main");
(...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 1635
1644 void test_nullUnit() { 1636 void test_nullUnit() {
1645 indexDartUnit(store, context, null); 1637 indexDartUnit(store, context, null);
1646 } 1638 }
1647 1639
1648 void test_nullUnitElement() { 1640 void test_nullUnitElement() {
1649 CompilationUnit unit = new CompilationUnit(null, null, [], [], null); 1641 CompilationUnit unit = new CompilationUnit(null, null, [], [], null);
1650 indexDartUnit(store, context, unit); 1642 indexDartUnit(store, context, unit);
1651 } 1643 }
1652 1644
1653 void _assertDefinesTopLevelElement(Relationship relationship, 1645 void _assertDefinesTopLevelElement(Element element) {
1654 ExpectedLocation expectedLocation) { 1646 ExpectedLocation location = new ExpectedLocation(element, element.nameOffset ,
1655 _assertRecordedRelation(testLibraryElement, relationship, expectedLocation); 1647 element.name.length, false, true);
1656 _assertRecordedRelation( 1648 _assertRecordedRelation(testLibraryElement, IndexConstants.DEFINES, location );
1657 UniverseElement.INSTANCE, 1649 expect(recordedTopElements, contains(element));
1658 relationship,
1659 expectedLocation);
1660 } 1650 }
1661 1651
1662 /** 1652 /**
1663 * Asserts that [recordedRelations] has no item with the specified properties. 1653 * Asserts that [recordedRelations] has no item with the specified properties.
1664 */ 1654 */
1665 void _assertNoRecordedRelation(Element element, Relationship relationship, 1655 void _assertNoRecordedRelation(Element element, Relationship relationship,
1666 ExpectedLocation location) { 1656 ExpectedLocation location) {
1667 for (RecordedRelation recordedRelation in recordedRelations) { 1657 for (RecordedRelation recordedRelation in recordedRelations) {
1668 if (_equalsRecordedRelation( 1658 if (_equalsRecordedRelation(
1669 recordedRelation, 1659 recordedRelation,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 1758
1769 RecordedRelation(this.element, this.relationship, this.location); 1759 RecordedRelation(this.element, this.relationship, this.location);
1770 1760
1771 @override 1761 @override
1772 String toString() { 1762 String toString() {
1773 return 'RecordedRelation(element=$element; relationship=$relationship; ' 1763 return 'RecordedRelation(element=$element; relationship=$relationship; '
1774 'location=$location; flags=' '${location.isQualified ? "Q" : ""}' 1764 'location=$location; flags=' '${location.isQualified ? "Q" : ""}'
1775 '${location.isResolved ? "R" : ""})'; 1765 '${location.isResolved ? "R" : ""})';
1776 } 1766 }
1777 } 1767 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698