| OLD | NEW |
| 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/analysis/index/index_core.dart'; | 7 import 'package:analysis_server/analysis/index/index_core.dart'; |
| 8 import 'package:analysis_server/src/services/index/index.dart'; | 8 import 'package:analysis_server/src/services/index/index.dart'; |
| 9 import 'package:analysis_server/src/services/index/index_contributor.dart'; | 9 import 'package:analysis_server/src/services/index/index_contributor.dart'; |
| 10 import 'package:analysis_server/src/services/index/index_store.dart'; | 10 import 'package:analysis_server/src/services/index/index_store.dart'; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 148 } |
| 149 }'''); | 149 }'''); |
| 150 // prepare elements | 150 // prepare elements |
| 151 Element mainElement = findElement("main"); | 151 Element mainElement = findElement("main"); |
| 152 VariableElement variableElement = findElement("v"); | 152 VariableElement variableElement = findElement("v"); |
| 153 // verify | 153 // verify |
| 154 _assertNoRecordedRelationForElement(variableElement, | 154 _assertNoRecordedRelationForElement(variableElement, |
| 155 IndexConstants.IS_READ_BY, _expectedLocation(mainElement, 'v in []')); | 155 IndexConstants.IS_READ_BY, _expectedLocation(mainElement, 'v in []')); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void test_isDefinedBy_NameElement_method() { | 158 void test_IndexableName_field() { |
| 159 _indexTestUnit(''' |
| 160 class A { |
| 161 int field; |
| 162 } |
| 163 main(A a, p) { |
| 164 print(a.field); // r |
| 165 print(p.field); // ur |
| 166 { |
| 167 var field = 42; |
| 168 print(field); // not a member |
| 169 } |
| 170 } |
| 171 '''); |
| 172 // prepare elements |
| 173 Element mainElement = findElement('main'); |
| 174 FieldElement fieldElement = findElement('field'); |
| 175 IndexableName indexable = new IndexableName('field'); |
| 176 // verify |
| 177 _assertRecordedRelation(indexable, IndexConstants.NAME_IS_DEFINED_BY, |
| 178 _expectedLocation(fieldElement, 'field;')); |
| 179 _assertRecordedRelation(indexable, IndexConstants.IS_READ_BY, |
| 180 _expectedLocationQ(mainElement, 'field); // r')); |
| 181 _assertRecordedRelation(indexable, IndexConstants.IS_READ_BY, |
| 182 _expectedLocationQU(mainElement, 'field); // ur')); |
| 183 _assertNoRecordedRelation(indexable, IndexConstants.IS_READ_BY, |
| 184 _expectedLocation(mainElement, 'field); // not a member')); |
| 185 } |
| 186 |
| 187 void test_IndexableName_isDefinedBy_localVariable_inForEach() { |
| 188 _indexTestUnit(''' |
| 189 class A { |
| 190 main() { |
| 191 for (int test in []) { |
| 192 } |
| 193 } |
| 194 } |
| 195 '''); |
| 196 // prepare elements |
| 197 LocalVariableElement testElement = findElement('test'); |
| 198 IndexableName indexable = new IndexableName('test'); |
| 199 // verify |
| 200 _assertRecordedRelation(indexable, IndexConstants.NAME_IS_DEFINED_BY, |
| 201 _expectedLocation(testElement, 'test in []')); |
| 202 } |
| 203 |
| 204 void test_IndexableName_method() { |
| 205 _indexTestUnit(''' |
| 206 class A { |
| 207 method() {} |
| 208 } |
| 209 main(A a, p) { |
| 210 a.method(); // r |
| 211 p.method(); // ur |
| 212 } |
| 213 '''); |
| 214 // prepare elements |
| 215 Element mainElement = findElement('main'); |
| 216 MethodElement methodElement = findElement('method'); |
| 217 IndexableName indexable = new IndexableName('method'); |
| 218 // verify |
| 219 _assertRecordedRelation(indexable, IndexConstants.NAME_IS_DEFINED_BY, |
| 220 _expectedLocation(methodElement, 'method() {}')); |
| 221 _assertRecordedRelation(indexable, IndexConstants.IS_INVOKED_BY, |
| 222 _expectedLocationQ(mainElement, 'method(); // r')); |
| 223 _assertRecordedRelation(indexable, IndexConstants.IS_INVOKED_BY, |
| 224 _expectedLocationQU(mainElement, 'method(); // ur')); |
| 225 } |
| 226 |
| 227 void test_IndexableName_operator_resolved() { |
| 228 _indexTestUnit(''' |
| 229 class A { |
| 230 operator +(o) {} |
| 231 operator -(o) {} |
| 232 operator ~() {} |
| 233 operator ==(o) {} |
| 234 } |
| 235 main(A a) { |
| 236 a + 5; |
| 237 a += 5; |
| 238 a == 5; |
| 239 ++a; |
| 240 --a; |
| 241 ~a; |
| 242 a++; |
| 243 a--; |
| 244 } |
| 245 '''); |
| 246 // prepare elements |
| 247 Element mainElement = findElement('main'); |
| 248 // binary |
| 249 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, |
| 250 _expectedLocationQ(mainElement, '+ 5', length: 1)); |
| 251 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, |
| 252 _expectedLocationQ(mainElement, '+= 5', length: 2)); |
| 253 _assertRecordedRelationForName('==', IndexConstants.IS_INVOKED_BY, |
| 254 _expectedLocationQ(mainElement, '== 5', length: 2)); |
| 255 // prefix |
| 256 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, |
| 257 _expectedLocationQ(mainElement, '++a', length: 2)); |
| 258 _assertRecordedRelationForName('-', IndexConstants.IS_INVOKED_BY, |
| 259 _expectedLocationQ(mainElement, '--a', length: 2)); |
| 260 _assertRecordedRelationForName('~', IndexConstants.IS_INVOKED_BY, |
| 261 _expectedLocationQ(mainElement, '~a', length: 1)); |
| 262 // postfix |
| 263 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, |
| 264 _expectedLocationQ(mainElement, '++;', length: 2)); |
| 265 _assertRecordedRelationForName('-', IndexConstants.IS_INVOKED_BY, |
| 266 _expectedLocationQ(mainElement, '--;', length: 2)); |
| 267 } |
| 268 |
| 269 void test_IndexableName_operator_unresolved() { |
| 270 _indexTestUnit(''' |
| 271 class A { |
| 272 operator +(o) {} |
| 273 operator -(o) {} |
| 274 operator ~() {} |
| 275 operator ==(o) {} |
| 276 } |
| 277 main(a) { |
| 278 a + 5; |
| 279 a += 5; |
| 280 a == 5; |
| 281 ++a; |
| 282 --a; |
| 283 ~a; |
| 284 a++; |
| 285 a--; |
| 286 } |
| 287 '''); |
| 288 // prepare elements |
| 289 Element mainElement = findElement('main'); |
| 290 // binary |
| 291 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, |
| 292 _expectedLocationQU(mainElement, '+ 5', length: 1)); |
| 293 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, |
| 294 _expectedLocationQU(mainElement, '+= 5', length: 2)); |
| 295 _assertRecordedRelationForName('==', IndexConstants.IS_INVOKED_BY, |
| 296 _expectedLocationQU(mainElement, '== 5', length: 2)); |
| 297 // prefix |
| 298 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, |
| 299 _expectedLocationQU(mainElement, '++a', length: 2)); |
| 300 _assertRecordedRelationForName('-', IndexConstants.IS_INVOKED_BY, |
| 301 _expectedLocationQU(mainElement, '--a', length: 2)); |
| 302 _assertRecordedRelationForName('~', IndexConstants.IS_INVOKED_BY, |
| 303 _expectedLocationQU(mainElement, '~a', length: 1)); |
| 304 // postfix |
| 305 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, |
| 306 _expectedLocationQU(mainElement, '++;', length: 2)); |
| 307 _assertRecordedRelationForName('-', IndexConstants.IS_INVOKED_BY, |
| 308 _expectedLocationQU(mainElement, '--;', length: 2)); |
| 309 } |
| 310 |
| 311 void test_isDefinedBy_IndexableName_method() { |
| 159 _indexTestUnit(''' | 312 _indexTestUnit(''' |
| 160 class A { | 313 class A { |
| 161 m() {} | 314 m() {} |
| 162 }'''); | 315 }'''); |
| 163 // prepare elements | 316 // prepare elements |
| 164 Element methodElement = findElement("m"); | 317 Element methodElement = findElement("m"); |
| 165 Element nameElement = new NameElement("m"); | 318 IndexableName nameIndexable = new IndexableName("m"); |
| 166 // verify | 319 // verify |
| 167 _assertRecordedRelationForElement( | 320 _assertRecordedRelationForIndexable( |
| 168 nameElement, | 321 nameIndexable, |
| 169 IndexConstants.NAME_IS_DEFINED_BY, | 322 IndexConstants.NAME_IS_DEFINED_BY, |
| 170 _expectedLocation(methodElement, 'm() {}')); | 323 _expectedLocation(methodElement, 'm() {}')); |
| 171 } | 324 } |
| 172 | 325 |
| 173 void test_isDefinedBy_NameElement_operator() { | 326 void test_isDefinedBy_IndexableName_operator() { |
| 174 _indexTestUnit(''' | 327 _indexTestUnit(''' |
| 175 class A { | 328 class A { |
| 176 operator +(o) {} | 329 operator +(o) {} |
| 177 }'''); | 330 }'''); |
| 178 // prepare elements | 331 // prepare elements |
| 179 Element methodElement = findElement("+"); | 332 Element methodElement = findElement("+"); |
| 180 Element nameElement = new NameElement("+"); | 333 IndexableName nameIndexable = new IndexableName("+"); |
| 181 // verify | 334 // verify |
| 182 _assertRecordedRelationForElement( | 335 _assertRecordedRelationForIndexable( |
| 183 nameElement, | 336 nameIndexable, |
| 184 IndexConstants.NAME_IS_DEFINED_BY, | 337 IndexConstants.NAME_IS_DEFINED_BY, |
| 185 _expectedLocation(methodElement, '+(o) {}', length: 1)); | 338 _expectedLocation(methodElement, '+(o) {}', length: 1)); |
| 186 } | 339 } |
| 187 | 340 |
| 188 void test_isExtendedBy_ClassDeclaration() { | 341 void test_isExtendedBy_ClassDeclaration() { |
| 189 _indexTestUnit(''' | 342 _indexTestUnit(''' |
| 190 class A {} // 1 | 343 class A {} // 1 |
| 191 class B extends A {} // 2 | 344 class B extends A {} // 2 |
| 192 '''); | 345 '''); |
| 193 // prepare elements | 346 // prepare elements |
| (...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 v = 1; | 1400 v = 1; |
| 1248 }'''); | 1401 }'''); |
| 1249 // prepare elements | 1402 // prepare elements |
| 1250 Element mainElement = findElement("main"); | 1403 Element mainElement = findElement("main"); |
| 1251 LocalVariableElement vElement = findElement("v"); | 1404 LocalVariableElement vElement = findElement("v"); |
| 1252 // verify | 1405 // verify |
| 1253 _assertRecordedRelationForElement(vElement, IndexConstants.IS_WRITTEN_BY, | 1406 _assertRecordedRelationForElement(vElement, IndexConstants.IS_WRITTEN_BY, |
| 1254 _expectedLocation(mainElement, 'v = 1')); | 1407 _expectedLocation(mainElement, 'v = 1')); |
| 1255 } | 1408 } |
| 1256 | 1409 |
| 1257 void test_NameElement_field() { | |
| 1258 _indexTestUnit(''' | |
| 1259 class A { | |
| 1260 int field; | |
| 1261 } | |
| 1262 main(A a, p) { | |
| 1263 print(a.field); // r | |
| 1264 print(p.field); // ur | |
| 1265 { | |
| 1266 var field = 42; | |
| 1267 print(field); // not a member | |
| 1268 } | |
| 1269 } | |
| 1270 '''); | |
| 1271 // prepare elements | |
| 1272 Element mainElement = findElement('main'); | |
| 1273 FieldElement fieldElement = findElement('field'); | |
| 1274 IndexableElement indexable = new IndexableElement(new NameElement('field')); | |
| 1275 // verify | |
| 1276 _assertRecordedRelation(indexable, IndexConstants.NAME_IS_DEFINED_BY, | |
| 1277 _expectedLocation(fieldElement, 'field;')); | |
| 1278 _assertRecordedRelation(indexable, IndexConstants.IS_READ_BY, | |
| 1279 _expectedLocationQ(mainElement, 'field); // r')); | |
| 1280 _assertRecordedRelation(indexable, IndexConstants.IS_READ_BY, | |
| 1281 _expectedLocationQU(mainElement, 'field); // ur')); | |
| 1282 _assertNoRecordedRelation(indexable, IndexConstants.IS_READ_BY, | |
| 1283 _expectedLocation(mainElement, 'field); // not a member')); | |
| 1284 } | |
| 1285 | |
| 1286 void test_NameElement_isDefinedBy_localVariable_inForEach() { | |
| 1287 _indexTestUnit(''' | |
| 1288 class A { | |
| 1289 main() { | |
| 1290 for (int test in []) { | |
| 1291 } | |
| 1292 } | |
| 1293 } | |
| 1294 '''); | |
| 1295 // prepare elements | |
| 1296 LocalVariableElement testElement = findElement('test'); | |
| 1297 IndexableElement indexable = new IndexableElement(new NameElement('test')); | |
| 1298 // verify | |
| 1299 _assertRecordedRelation(indexable, IndexConstants.NAME_IS_DEFINED_BY, | |
| 1300 _expectedLocation(testElement, 'test in []')); | |
| 1301 } | |
| 1302 | |
| 1303 void test_NameElement_method() { | |
| 1304 _indexTestUnit(''' | |
| 1305 class A { | |
| 1306 method() {} | |
| 1307 } | |
| 1308 main(A a, p) { | |
| 1309 a.method(); // r | |
| 1310 p.method(); // ur | |
| 1311 } | |
| 1312 '''); | |
| 1313 // prepare elements | |
| 1314 Element mainElement = findElement('main'); | |
| 1315 MethodElement methodElement = findElement('method'); | |
| 1316 IndexableElement indexable = | |
| 1317 new IndexableElement(new NameElement('method')); | |
| 1318 // verify | |
| 1319 _assertRecordedRelation(indexable, IndexConstants.NAME_IS_DEFINED_BY, | |
| 1320 _expectedLocation(methodElement, 'method() {}')); | |
| 1321 _assertRecordedRelation(indexable, IndexConstants.IS_INVOKED_BY, | |
| 1322 _expectedLocationQ(mainElement, 'method(); // r')); | |
| 1323 _assertRecordedRelation(indexable, IndexConstants.IS_INVOKED_BY, | |
| 1324 _expectedLocationQU(mainElement, 'method(); // ur')); | |
| 1325 } | |
| 1326 | |
| 1327 void test_NameElement_operator_resolved() { | |
| 1328 _indexTestUnit(''' | |
| 1329 class A { | |
| 1330 operator +(o) {} | |
| 1331 operator -(o) {} | |
| 1332 operator ~() {} | |
| 1333 operator ==(o) {} | |
| 1334 } | |
| 1335 main(A a) { | |
| 1336 a + 5; | |
| 1337 a += 5; | |
| 1338 a == 5; | |
| 1339 ++a; | |
| 1340 --a; | |
| 1341 ~a; | |
| 1342 a++; | |
| 1343 a--; | |
| 1344 } | |
| 1345 '''); | |
| 1346 // prepare elements | |
| 1347 Element mainElement = findElement('main'); | |
| 1348 // binary | |
| 1349 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, | |
| 1350 _expectedLocationQ(mainElement, '+ 5', length: 1)); | |
| 1351 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, | |
| 1352 _expectedLocationQ(mainElement, '+= 5', length: 2)); | |
| 1353 _assertRecordedRelationForName('==', IndexConstants.IS_INVOKED_BY, | |
| 1354 _expectedLocationQ(mainElement, '== 5', length: 2)); | |
| 1355 // prefix | |
| 1356 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, | |
| 1357 _expectedLocationQ(mainElement, '++a', length: 2)); | |
| 1358 _assertRecordedRelationForName('-', IndexConstants.IS_INVOKED_BY, | |
| 1359 _expectedLocationQ(mainElement, '--a', length: 2)); | |
| 1360 _assertRecordedRelationForName('~', IndexConstants.IS_INVOKED_BY, | |
| 1361 _expectedLocationQ(mainElement, '~a', length: 1)); | |
| 1362 // postfix | |
| 1363 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, | |
| 1364 _expectedLocationQ(mainElement, '++;', length: 2)); | |
| 1365 _assertRecordedRelationForName('-', IndexConstants.IS_INVOKED_BY, | |
| 1366 _expectedLocationQ(mainElement, '--;', length: 2)); | |
| 1367 } | |
| 1368 | |
| 1369 void test_NameElement_operator_unresolved() { | |
| 1370 _indexTestUnit(''' | |
| 1371 class A { | |
| 1372 operator +(o) {} | |
| 1373 operator -(o) {} | |
| 1374 operator ~() {} | |
| 1375 operator ==(o) {} | |
| 1376 } | |
| 1377 main(a) { | |
| 1378 a + 5; | |
| 1379 a += 5; | |
| 1380 a == 5; | |
| 1381 ++a; | |
| 1382 --a; | |
| 1383 ~a; | |
| 1384 a++; | |
| 1385 a--; | |
| 1386 } | |
| 1387 '''); | |
| 1388 // prepare elements | |
| 1389 Element mainElement = findElement('main'); | |
| 1390 // binary | |
| 1391 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, | |
| 1392 _expectedLocationQU(mainElement, '+ 5', length: 1)); | |
| 1393 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, | |
| 1394 _expectedLocationQU(mainElement, '+= 5', length: 2)); | |
| 1395 _assertRecordedRelationForName('==', IndexConstants.IS_INVOKED_BY, | |
| 1396 _expectedLocationQU(mainElement, '== 5', length: 2)); | |
| 1397 // prefix | |
| 1398 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, | |
| 1399 _expectedLocationQU(mainElement, '++a', length: 2)); | |
| 1400 _assertRecordedRelationForName('-', IndexConstants.IS_INVOKED_BY, | |
| 1401 _expectedLocationQU(mainElement, '--a', length: 2)); | |
| 1402 _assertRecordedRelationForName('~', IndexConstants.IS_INVOKED_BY, | |
| 1403 _expectedLocationQU(mainElement, '~a', length: 1)); | |
| 1404 // postfix | |
| 1405 _assertRecordedRelationForName('+', IndexConstants.IS_INVOKED_BY, | |
| 1406 _expectedLocationQU(mainElement, '++;', length: 2)); | |
| 1407 _assertRecordedRelationForName('-', IndexConstants.IS_INVOKED_BY, | |
| 1408 _expectedLocationQU(mainElement, '--;', length: 2)); | |
| 1409 } | |
| 1410 | |
| 1411 void test_nameIsInvokedBy() { | 1410 void test_nameIsInvokedBy() { |
| 1412 _indexTestUnit(''' | 1411 _indexTestUnit(''' |
| 1413 class A { | 1412 class A { |
| 1414 test(x) {} | 1413 test(x) {} |
| 1415 } | 1414 } |
| 1416 main(A a, p) { | 1415 main(A a, p) { |
| 1417 a.test(1); | 1416 a.test(1); |
| 1418 p.test(2); | 1417 p.test(2); |
| 1419 }'''); | 1418 }'''); |
| 1420 // prepare elements | 1419 // prepare elements |
| 1421 Element mainElement = findElement("main"); | 1420 Element mainElement = findElement("main"); |
| 1422 IndexableElement indexable = new IndexableElement(new NameElement('test')); | 1421 IndexableName indexable = new IndexableName('test'); |
| 1423 // verify | 1422 // verify |
| 1424 _assertRecordedRelation(indexable, IndexConstants.IS_INVOKED_BY, | 1423 _assertRecordedRelation(indexable, IndexConstants.IS_INVOKED_BY, |
| 1425 _expectedLocationQ(mainElement, 'test(1)')); | 1424 _expectedLocationQ(mainElement, 'test(1)')); |
| 1426 _assertRecordedRelation(indexable, IndexConstants.IS_INVOKED_BY, | 1425 _assertRecordedRelation(indexable, IndexConstants.IS_INVOKED_BY, |
| 1427 _expectedLocationQU(mainElement, 'test(2)')); | 1426 _expectedLocationQU(mainElement, 'test(2)')); |
| 1428 _assertNoRecordedRelation(indexable, IndexConstants.IS_READ_BY, | 1427 _assertNoRecordedRelation(indexable, IndexConstants.IS_READ_BY, |
| 1429 _expectedLocationQU(mainElement, 'test(2)')); | 1428 _expectedLocationQU(mainElement, 'test(2)')); |
| 1430 } | 1429 } |
| 1431 | 1430 |
| 1432 void test_nameIsReadBy() { | 1431 void test_nameIsReadBy() { |
| 1433 _indexTestUnit(''' | 1432 _indexTestUnit(''' |
| 1434 class A { | 1433 class A { |
| 1435 var test; | 1434 var test; |
| 1436 } | 1435 } |
| 1437 main(A a, p) { | 1436 main(A a, p) { |
| 1438 print(a.test); // a | 1437 print(a.test); // a |
| 1439 print(p.test); // p | 1438 print(p.test); // p |
| 1440 }'''); | 1439 }'''); |
| 1441 // prepare elements | 1440 // prepare elements |
| 1442 Element mainElement = findElement("main"); | 1441 Element mainElement = findElement("main"); |
| 1443 IndexableElement indexable = new IndexableElement(new NameElement('test')); | 1442 IndexableName indexable = new IndexableName('test'); |
| 1444 // verify | 1443 // verify |
| 1445 _assertRecordedRelation(indexable, IndexConstants.IS_READ_BY, | 1444 _assertRecordedRelation(indexable, IndexConstants.IS_READ_BY, |
| 1446 _expectedLocationQ(mainElement, 'test); // a')); | 1445 _expectedLocationQ(mainElement, 'test); // a')); |
| 1447 _assertRecordedRelation(indexable, IndexConstants.IS_READ_BY, | 1446 _assertRecordedRelation(indexable, IndexConstants.IS_READ_BY, |
| 1448 _expectedLocationQU(mainElement, 'test); // p')); | 1447 _expectedLocationQU(mainElement, 'test); // p')); |
| 1449 } | 1448 } |
| 1450 | 1449 |
| 1451 void test_nameIsReadWrittenBy() { | 1450 void test_nameIsReadWrittenBy() { |
| 1452 _indexTestUnit(''' | 1451 _indexTestUnit(''' |
| 1453 class A { | 1452 class A { |
| 1454 var test; | 1453 var test; |
| 1455 } | 1454 } |
| 1456 main(A a, p) { | 1455 main(A a, p) { |
| 1457 a.test += 1; | 1456 a.test += 1; |
| 1458 p.test += 2; | 1457 p.test += 2; |
| 1459 }'''); | 1458 }'''); |
| 1460 // prepare elements | 1459 // prepare elements |
| 1461 Element mainElement = findElement("main"); | 1460 Element mainElement = findElement("main"); |
| 1462 IndexableElement indexable = new IndexableElement(new NameElement('test')); | 1461 IndexableName indexable = new IndexableName('test'); |
| 1463 // verify | 1462 // verify |
| 1464 _assertRecordedRelation(indexable, IndexConstants.IS_READ_WRITTEN_BY, | 1463 _assertRecordedRelation(indexable, IndexConstants.IS_READ_WRITTEN_BY, |
| 1465 _expectedLocationQ(mainElement, 'test += 1')); | 1464 _expectedLocationQ(mainElement, 'test += 1')); |
| 1466 _assertRecordedRelation(indexable, IndexConstants.IS_READ_WRITTEN_BY, | 1465 _assertRecordedRelation(indexable, IndexConstants.IS_READ_WRITTEN_BY, |
| 1467 _expectedLocationQU(mainElement, 'test += 2')); | 1466 _expectedLocationQU(mainElement, 'test += 2')); |
| 1468 } | 1467 } |
| 1469 | 1468 |
| 1470 void test_nameIsWrittenBy() { | 1469 void test_nameIsWrittenBy() { |
| 1471 _indexTestUnit(''' | 1470 _indexTestUnit(''' |
| 1472 class A { | 1471 class A { |
| 1473 var test; | 1472 var test; |
| 1474 } | 1473 } |
| 1475 main(A a, p) { | 1474 main(A a, p) { |
| 1476 a.test = 1; | 1475 a.test = 1; |
| 1477 p.test = 2; | 1476 p.test = 2; |
| 1478 }'''); | 1477 }'''); |
| 1479 // prepare elements | 1478 // prepare elements |
| 1480 Element mainElement = findElement("main"); | 1479 Element mainElement = findElement("main"); |
| 1481 IndexableElement indexable = new IndexableElement(new NameElement('test')); | 1480 IndexableName indexable = new IndexableName('test'); |
| 1482 // verify | 1481 // verify |
| 1483 _assertRecordedRelation(indexable, IndexConstants.IS_WRITTEN_BY, | 1482 _assertRecordedRelation(indexable, IndexConstants.IS_WRITTEN_BY, |
| 1484 _expectedLocationQ(mainElement, 'test = 1')); | 1483 _expectedLocationQ(mainElement, 'test = 1')); |
| 1485 _assertRecordedRelation(indexable, IndexConstants.IS_WRITTEN_BY, | 1484 _assertRecordedRelation(indexable, IndexConstants.IS_WRITTEN_BY, |
| 1486 _expectedLocationQU(mainElement, 'test = 2')); | 1485 _expectedLocationQU(mainElement, 'test = 2')); |
| 1487 } | 1486 } |
| 1488 | 1487 |
| 1489 void test_nullUnit() { | 1488 void test_nullUnit() { |
| 1490 indexDartUnit(store, context, null); | 1489 indexDartUnit(store, context, null); |
| 1491 } | 1490 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1545 return null; | 1544 return null; |
| 1546 } | 1545 } |
| 1547 | 1546 |
| 1548 /** | 1547 /** |
| 1549 * Asserts that [recordedRelations] has an item with the expected properties. | 1548 * Asserts that [recordedRelations] has an item with the expected properties. |
| 1550 */ | 1549 */ |
| 1551 LocationImpl _assertRecordedRelationForElement( | 1550 LocationImpl _assertRecordedRelationForElement( |
| 1552 Element expectedElement, | 1551 Element expectedElement, |
| 1553 RelationshipImpl expectedRelationship, | 1552 RelationshipImpl expectedRelationship, |
| 1554 ExpectedLocation expectedLocation) { | 1553 ExpectedLocation expectedLocation) { |
| 1555 return _assertRecordedRelation(new IndexableElement(expectedElement), | 1554 return _assertRecordedRelationForIndexable( |
| 1556 expectedRelationship, expectedLocation); | 1555 new IndexableElement(expectedElement), |
| 1556 expectedRelationship, |
| 1557 expectedLocation); |
| 1557 } | 1558 } |
| 1558 | 1559 |
| 1559 /** | 1560 /** |
| 1561 * Asserts that [recordedRelations] has an item with the expected properties. |
| 1562 */ |
| 1563 LocationImpl _assertRecordedRelationForIndexable( |
| 1564 IndexableObject expectedIndexable, |
| 1565 RelationshipImpl expectedRelationship, |
| 1566 ExpectedLocation expectedLocation) { |
| 1567 return _assertRecordedRelation( |
| 1568 expectedIndexable, expectedRelationship, expectedLocation); |
| 1569 } |
| 1570 |
| 1571 /** |
| 1560 * Asserts that [recordedRelations] has an item with the expected properties. | 1572 * Asserts that [recordedRelations] has an item with the expected properties. |
| 1561 */ | 1573 */ |
| 1562 LocationImpl _assertRecordedRelationForName( | 1574 LocationImpl _assertRecordedRelationForName( |
| 1563 String expectedName, | 1575 String expectedName, |
| 1564 RelationshipImpl expectedRelationship, | 1576 RelationshipImpl expectedRelationship, |
| 1565 ExpectedLocation expectedLocation) { | 1577 ExpectedLocation expectedLocation) { |
| 1566 return _assertRecordedRelationForElement( | 1578 return _assertRecordedRelationForIndexable(new IndexableName(expectedName), |
| 1567 new NameElement(expectedName), expectedRelationship, expectedLocation); | 1579 expectedRelationship, expectedLocation); |
| 1568 } | 1580 } |
| 1569 | 1581 |
| 1570 ExpectedLocation _expectedLocation(Element element, String search, | 1582 ExpectedLocation _expectedLocation(Element element, String search, |
| 1571 {int length: -1, bool isQualified: false, bool isResolved: true}) { | 1583 {int length: -1, bool isQualified: false, bool isResolved: true}) { |
| 1572 int offset = findOffset(search); | 1584 int offset = findOffset(search); |
| 1573 if (length == -1) { | 1585 if (length == -1) { |
| 1574 length = getLeadingIdentifierLength(search); | 1586 length = getLeadingIdentifierLength(search); |
| 1575 } | 1587 } |
| 1576 return new ExpectedLocation( | 1588 return new ExpectedLocation( |
| 1577 element, offset, length, isQualified, isResolved); | 1589 element, offset, length, isQualified, isResolved); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1627 RecordedRelation(this.indexable, this.relationship, this.location); | 1639 RecordedRelation(this.indexable, this.relationship, this.location); |
| 1628 | 1640 |
| 1629 @override | 1641 @override |
| 1630 String toString() { | 1642 String toString() { |
| 1631 return 'RecordedRelation(indexable=$indexable; relationship=$relationship; ' | 1643 return 'RecordedRelation(indexable=$indexable; relationship=$relationship; ' |
| 1632 'location=$location; flags=' | 1644 'location=$location; flags=' |
| 1633 '${location.isQualified ? "Q" : ""}' | 1645 '${location.isQualified ? "Q" : ""}' |
| 1634 '${location.isResolved ? "R" : ""})'; | 1646 '${location.isResolved ? "R" : ""})'; |
| 1635 } | 1647 } |
| 1636 } | 1648 } |
| OLD | NEW |