| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library test.domain.analysis.notification.outline; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:analysis_server/src/constants.dart'; | |
| 10 import 'package:analysis_server/src/protocol.dart'; | |
| 11 import 'reflective_tests.dart'; | |
| 12 import 'package:unittest/unittest.dart'; | |
| 13 | |
| 14 import 'analysis_abstract.dart'; | |
| 15 | |
| 16 | |
| 17 main() { | |
| 18 runReflectiveTests(_AnalysisNotificationOutlineTest); | |
| 19 } | |
| 20 | |
| 21 | |
| 22 @ReflectiveTestCase() | |
| 23 class _AnalysisNotificationOutlineTest extends AbstractAnalysisTest { | |
| 24 Outline outline; | |
| 25 | |
| 26 Future prepareOutline() { | |
| 27 addAnalysisSubscription(AnalysisService.OUTLINE, testFile); | |
| 28 return waitForTasksFinished(); | |
| 29 } | |
| 30 | |
| 31 void processNotification(Notification notification) { | |
| 32 if (notification.event == ANALYSIS_OUTLINE) { | |
| 33 var params = new AnalysisOutlineParams.fromNotification(notification); | |
| 34 if (params.file == testFile) { | |
| 35 outline = params.outline; | |
| 36 } | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 @override | |
| 41 void setUp() { | |
| 42 super.setUp(); | |
| 43 createProject(); | |
| 44 } | |
| 45 | |
| 46 test_afterAnalysis() { | |
| 47 addTestFile(''' | |
| 48 class AAA { | |
| 49 } | |
| 50 class BBB { | |
| 51 } | |
| 52 '''); | |
| 53 return waitForTasksFinished().then((_) { | |
| 54 expect(outline, isNull); | |
| 55 return prepareOutline().then((_) { | |
| 56 Outline unitOutline = outline; | |
| 57 List<Outline> outlines = unitOutline.children; | |
| 58 expect(outlines, hasLength(2)); | |
| 59 }); | |
| 60 }); | |
| 61 } | |
| 62 | |
| 63 test_class() { | |
| 64 addTestFile(''' | |
| 65 class A { | |
| 66 int fa, fb; | |
| 67 String fc; | |
| 68 A(int i, String s); | |
| 69 A.name(num p); | |
| 70 A._privateName(num p); | |
| 71 static String ma(int pa) => null; | |
| 72 _mb(int pb); | |
| 73 String get propA => null; | |
| 74 set propB(int v) {} | |
| 75 } | |
| 76 class B { | |
| 77 B(int p); | |
| 78 }"); | |
| 79 '''); | |
| 80 return prepareOutline().then((_) { | |
| 81 Outline unitOutline = outline; | |
| 82 List<Outline> topOutlines = unitOutline.children; | |
| 83 expect(topOutlines, hasLength(2)); | |
| 84 // A | |
| 85 { | |
| 86 Outline outline_A = topOutlines[0]; | |
| 87 Element element_A = outline_A.element; | |
| 88 expect(element_A.kind, ElementKind.CLASS); | |
| 89 expect(element_A.name, "A"); | |
| 90 { | |
| 91 Location location = element_A.location; | |
| 92 expect(location.offset, testCode.indexOf("A {")); | |
| 93 expect(location.length, 1); | |
| 94 } | |
| 95 expect(element_A.parameters, null); | |
| 96 expect(element_A.returnType, null); | |
| 97 // A children | |
| 98 List<Outline> outlines_A = outline_A.children; | |
| 99 expect(outlines_A, hasLength(10)); | |
| 100 { | |
| 101 Outline outline = outlines_A[0]; | |
| 102 Element element = outline.element; | |
| 103 expect(element.kind, ElementKind.FIELD); | |
| 104 expect(element.name, "fa"); | |
| 105 expect(element.parameters, isNull); | |
| 106 expect(element.returnType, "int"); | |
| 107 } | |
| 108 { | |
| 109 Outline outline = outlines_A[1]; | |
| 110 Element element = outline.element; | |
| 111 expect(element.kind, ElementKind.FIELD); | |
| 112 expect(element.name, "fb"); | |
| 113 expect(element.parameters, isNull); | |
| 114 expect(element.returnType, "int"); | |
| 115 } | |
| 116 { | |
| 117 Outline outline = outlines_A[2]; | |
| 118 Element element = outline.element; | |
| 119 expect(element.kind, ElementKind.FIELD); | |
| 120 expect(element.name, "fc"); | |
| 121 expect(element.parameters, isNull); | |
| 122 expect(element.returnType, "String"); | |
| 123 } | |
| 124 { | |
| 125 Outline outline = outlines_A[3]; | |
| 126 Element element = outline.element; | |
| 127 expect(element.kind, ElementKind.CONSTRUCTOR); | |
| 128 expect(element.name, "A"); | |
| 129 { | |
| 130 Location location = element.location; | |
| 131 expect(location.offset, testCode.indexOf("A(int i, String s);")); | |
| 132 expect(location.length, "A".length); | |
| 133 } | |
| 134 expect(element.parameters, "(int i, String s)"); | |
| 135 expect(element.returnType, isNull); | |
| 136 expect(element.isAbstract, isFalse); | |
| 137 expect(element.isStatic, isFalse); | |
| 138 } | |
| 139 { | |
| 140 Outline outline = outlines_A[4]; | |
| 141 Element element = outline.element; | |
| 142 expect(element.kind, ElementKind.CONSTRUCTOR); | |
| 143 expect(element.name, "A.name"); | |
| 144 { | |
| 145 Location location = element.location; | |
| 146 expect(location.offset, testCode.indexOf("name(num p);")); | |
| 147 expect(location.length, "name".length); | |
| 148 } | |
| 149 expect(element.parameters, "(num p)"); | |
| 150 expect(element.returnType, isNull); | |
| 151 expect(element.isAbstract, isFalse); | |
| 152 expect(element.isStatic, isFalse); | |
| 153 } | |
| 154 { | |
| 155 Outline outline = outlines_A[5]; | |
| 156 Element element = outline.element; | |
| 157 expect(element.kind, ElementKind.CONSTRUCTOR); | |
| 158 expect(element.name, "A._privateName"); | |
| 159 { | |
| 160 Location location = element.location; | |
| 161 expect(location.offset, testCode.indexOf("_privateName(num p);")); | |
| 162 expect(location.length, "_privateName".length); | |
| 163 } | |
| 164 expect(element.parameters, "(num p)"); | |
| 165 expect(element.returnType, isNull); | |
| 166 expect(element.isAbstract, isFalse); | |
| 167 expect(element.isStatic, isFalse); | |
| 168 } | |
| 169 { | |
| 170 Outline outline = outlines_A[6]; | |
| 171 Element element = outline.element; | |
| 172 expect(element.kind, ElementKind.METHOD); | |
| 173 expect(element.name, "ma"); | |
| 174 { | |
| 175 Location location = element.location; | |
| 176 expect(location.offset, testCode.indexOf("ma(int pa) => null;")); | |
| 177 expect(location.length, "ma".length); | |
| 178 } | |
| 179 expect(element.parameters, "(int pa)"); | |
| 180 expect(element.returnType, "String"); | |
| 181 expect(element.isAbstract, isFalse); | |
| 182 expect(element.isStatic, isTrue); | |
| 183 } | |
| 184 { | |
| 185 Outline outline = outlines_A[7]; | |
| 186 Element element = outline.element; | |
| 187 expect(element.kind, ElementKind.METHOD); | |
| 188 expect(element.name, "_mb"); | |
| 189 { | |
| 190 Location location = element.location; | |
| 191 expect(location.offset, testCode.indexOf("_mb(int pb);")); | |
| 192 expect(location.length, "_mb".length); | |
| 193 } | |
| 194 expect(element.parameters, "(int pb)"); | |
| 195 expect(element.returnType, ""); | |
| 196 expect(element.isAbstract, isTrue); | |
| 197 expect(element.isStatic, isFalse); | |
| 198 } | |
| 199 { | |
| 200 Outline outline = outlines_A[8]; | |
| 201 Element element = outline.element; | |
| 202 expect(element.kind, ElementKind.GETTER); | |
| 203 expect(element.name, "propA"); | |
| 204 { | |
| 205 Location location = element.location; | |
| 206 expect(location.offset, testCode.indexOf("propA => null;")); | |
| 207 expect(location.length, "propA".length); | |
| 208 } | |
| 209 expect(element.parameters, ""); | |
| 210 expect(element.returnType, "String"); | |
| 211 } | |
| 212 { | |
| 213 Outline outline = outlines_A[9]; | |
| 214 Element element = outline.element; | |
| 215 expect(element.kind, ElementKind.SETTER); | |
| 216 expect(element.name, "propB"); | |
| 217 { | |
| 218 Location location = element.location; | |
| 219 expect(location.offset, testCode.indexOf("propB(int v) {}")); | |
| 220 expect(location.length, "propB".length); | |
| 221 } | |
| 222 expect(element.parameters, "(int v)"); | |
| 223 expect(element.returnType, ""); | |
| 224 } | |
| 225 } | |
| 226 // B | |
| 227 { | |
| 228 Outline outline_B = topOutlines[1]; | |
| 229 Element element_B = outline_B.element; | |
| 230 expect(element_B.kind, ElementKind.CLASS); | |
| 231 expect(element_B.name, "B"); | |
| 232 { | |
| 233 Location location = element_B.location; | |
| 234 expect(location.offset, testCode.indexOf("B {")); | |
| 235 expect(location.length, 1); | |
| 236 } | |
| 237 expect(element_B.parameters, null); | |
| 238 expect(element_B.returnType, null); | |
| 239 // B children | |
| 240 List<Outline> outlines_B = outline_B.children; | |
| 241 expect(outlines_B, hasLength(1)); | |
| 242 { | |
| 243 Outline outline = outlines_B[0]; | |
| 244 Element element = outline.element; | |
| 245 expect(element.kind, ElementKind.CONSTRUCTOR); | |
| 246 expect(element.name, "B"); | |
| 247 { | |
| 248 Location location = element.location; | |
| 249 expect(location.offset, testCode.indexOf("B(int p);")); | |
| 250 expect(location.length, "B".length); | |
| 251 } | |
| 252 expect(element.parameters, "(int p)"); | |
| 253 expect(element.returnType, isNull); | |
| 254 } | |
| 255 } | |
| 256 }); | |
| 257 } | |
| 258 | |
| 259 test_localFunctions() { | |
| 260 addTestFile(''' | |
| 261 class A { | |
| 262 A() { | |
| 263 int local_A() {} | |
| 264 } | |
| 265 m() { | |
| 266 local_m() {} | |
| 267 } | |
| 268 } | |
| 269 f() { | |
| 270 local_f1(int i) {} | |
| 271 local_f2(String s) { | |
| 272 local_f21(int p) {} | |
| 273 } | |
| 274 } | |
| 275 '''); | |
| 276 return prepareOutline().then((_) { | |
| 277 Outline unitOutline = outline; | |
| 278 List<Outline> topOutlines = unitOutline.children; | |
| 279 expect(topOutlines, hasLength(2)); | |
| 280 // A | |
| 281 { | |
| 282 Outline outline_A = topOutlines[0]; | |
| 283 Element element_A = outline_A.element; | |
| 284 expect(element_A.kind, ElementKind.CLASS); | |
| 285 expect(element_A.name, "A"); | |
| 286 { | |
| 287 Location location = element_A.location; | |
| 288 expect(location.offset, testCode.indexOf("A {")); | |
| 289 expect(location.length, "A".length); | |
| 290 } | |
| 291 expect(element_A.parameters, null); | |
| 292 expect(element_A.returnType, null); | |
| 293 // A children | |
| 294 List<Outline> outlines_A = outline_A.children; | |
| 295 expect(outlines_A, hasLength(2)); | |
| 296 { | |
| 297 Outline constructorOutline = outlines_A[0]; | |
| 298 Element constructorElement = constructorOutline.element; | |
| 299 expect(constructorElement.kind, ElementKind.CONSTRUCTOR); | |
| 300 expect(constructorElement.name, "A"); | |
| 301 { | |
| 302 Location location = constructorElement.location; | |
| 303 expect(location.offset, testCode.indexOf("A() {")); | |
| 304 expect(location.length, "A".length); | |
| 305 } | |
| 306 expect(constructorElement.parameters, "()"); | |
| 307 expect(constructorElement.returnType, isNull); | |
| 308 // local function | |
| 309 List<Outline> outlines_constructor = constructorOutline.children; | |
| 310 expect(outlines_constructor, hasLength(1)); | |
| 311 { | |
| 312 Outline outline = outlines_constructor[0]; | |
| 313 Element element = outline.element; | |
| 314 expect(element.kind, ElementKind.FUNCTION); | |
| 315 expect(element.name, "local_A"); | |
| 316 { | |
| 317 Location location = element.location; | |
| 318 expect(location.offset, testCode.indexOf("local_A() {}")); | |
| 319 expect(location.length, "local_A".length); | |
| 320 } | |
| 321 expect(element.parameters, "()"); | |
| 322 expect(element.returnType, "int"); | |
| 323 } | |
| 324 } | |
| 325 { | |
| 326 Outline outline_m = outlines_A[1]; | |
| 327 Element element_m = outline_m.element; | |
| 328 expect(element_m.kind, ElementKind.METHOD); | |
| 329 expect(element_m.name, "m"); | |
| 330 { | |
| 331 Location location = element_m.location; | |
| 332 expect(location.offset, testCode.indexOf("m() {")); | |
| 333 expect(location.length, "m".length); | |
| 334 } | |
| 335 expect(element_m.parameters, "()"); | |
| 336 expect(element_m.returnType, ""); | |
| 337 // local function | |
| 338 List<Outline> methodChildren = outline_m.children; | |
| 339 expect(methodChildren, hasLength(1)); | |
| 340 { | |
| 341 Outline outline = methodChildren[0]; | |
| 342 Element element = outline.element; | |
| 343 expect(element.kind, ElementKind.FUNCTION); | |
| 344 expect(element.name, "local_m"); | |
| 345 { | |
| 346 Location location = element.location; | |
| 347 expect(location.offset, testCode.indexOf("local_m() {}")); | |
| 348 expect(location.length, "local_m".length); | |
| 349 } | |
| 350 expect(element.parameters, "()"); | |
| 351 expect(element.returnType, ""); | |
| 352 } | |
| 353 } | |
| 354 } | |
| 355 // f() | |
| 356 { | |
| 357 Outline outline_f = topOutlines[1]; | |
| 358 Element element_f = outline_f.element; | |
| 359 expect(element_f.kind, ElementKind.FUNCTION); | |
| 360 expect(element_f.name, "f"); | |
| 361 { | |
| 362 Location location = element_f.location; | |
| 363 expect(location.offset, testCode.indexOf("f() {")); | |
| 364 expect(location.length, "f".length); | |
| 365 } | |
| 366 expect(element_f.parameters, "()"); | |
| 367 expect(element_f.returnType, ""); | |
| 368 // f() children | |
| 369 List<Outline> outlines_f = outline_f.children; | |
| 370 expect(outlines_f, hasLength(2)); | |
| 371 { | |
| 372 Outline outline_f1 = outlines_f[0]; | |
| 373 Element element_f1 = outline_f1.element; | |
| 374 expect(element_f1.kind, ElementKind.FUNCTION); | |
| 375 expect(element_f1.name, "local_f1"); | |
| 376 { | |
| 377 Location location = element_f1.location; | |
| 378 expect(location.offset, testCode.indexOf("local_f1(int i) {}")); | |
| 379 expect(location.length, "local_f1".length); | |
| 380 } | |
| 381 expect(element_f1.parameters, "(int i)"); | |
| 382 expect(element_f1.returnType, ""); | |
| 383 } | |
| 384 { | |
| 385 Outline outline_f2 = outlines_f[1]; | |
| 386 Element element_f2 = outline_f2.element; | |
| 387 expect(element_f2.kind, ElementKind.FUNCTION); | |
| 388 expect(element_f2.name, "local_f2"); | |
| 389 { | |
| 390 Location location = element_f2.location; | |
| 391 expect(location.offset, testCode.indexOf("local_f2(String s) {")); | |
| 392 expect(location.length, "local_f2".length); | |
| 393 } | |
| 394 expect(element_f2.parameters, "(String s)"); | |
| 395 expect(element_f2.returnType, ""); | |
| 396 // local_f2() local function | |
| 397 List<Outline> outlines_f2 = outline_f2.children; | |
| 398 expect(outlines_f2, hasLength(1)); | |
| 399 { | |
| 400 Outline outline_f21 = outlines_f2[0]; | |
| 401 Element element_f21 = outline_f21.element; | |
| 402 expect(element_f21.kind, ElementKind.FUNCTION); | |
| 403 expect(element_f21.name, "local_f21"); | |
| 404 { | |
| 405 Location location = element_f21.location; | |
| 406 expect(location.offset, testCode.indexOf("local_f21(int p) {")); | |
| 407 expect(location.length, "local_f21".length); | |
| 408 } | |
| 409 expect(element_f21.parameters, "(int p)"); | |
| 410 expect(element_f21.returnType, ""); | |
| 411 } | |
| 412 } | |
| 413 } | |
| 414 }); | |
| 415 } | |
| 416 | |
| 417 test_sourceRange_inClass() { | |
| 418 addTestFile(''' | |
| 419 class A { // leftA | |
| 420 int methodA() {} // endA | |
| 421 int methodB() {} // endB | |
| 422 } | |
| 423 '''); | |
| 424 return prepareOutline().then((_) { | |
| 425 Outline unitOutline = outline; | |
| 426 List<Outline> outlines = unitOutline.children[0].children; | |
| 427 expect(outlines, hasLength(2)); | |
| 428 // methodA | |
| 429 { | |
| 430 Outline outline = outlines[0]; | |
| 431 Element element = outline.element; | |
| 432 expect(element.kind, ElementKind.METHOD); | |
| 433 expect(element.name, "methodA"); | |
| 434 { | |
| 435 int offset = testCode.indexOf(" // leftA"); | |
| 436 int end = testCode.indexOf(" // endA"); | |
| 437 expect(outline.offset, offset); | |
| 438 expect(outline.length, end - offset); | |
| 439 } | |
| 440 } | |
| 441 // methodB | |
| 442 { | |
| 443 Outline outline = outlines[1]; | |
| 444 Element element = outline.element; | |
| 445 expect(element.kind, ElementKind.METHOD); | |
| 446 expect(element.name, "methodB"); | |
| 447 { | |
| 448 int offset = testCode.indexOf(" // endA"); | |
| 449 int end = testCode.indexOf(" // endB"); | |
| 450 expect(outline.offset, offset); | |
| 451 expect(outline.length, end - offset); | |
| 452 } | |
| 453 } | |
| 454 }); | |
| 455 } | |
| 456 | |
| 457 test_sourceRange_inClass_inVariableList() { | |
| 458 addTestFile(''' | |
| 459 class A { // leftA | |
| 460 int fieldA, fieldB, fieldC; // marker | |
| 461 int fieldD; // marker2 | |
| 462 } | |
| 463 '''); | |
| 464 return prepareOutline().then((_) { | |
| 465 Outline unitOutline = outline; | |
| 466 List<Outline> outlines = unitOutline.children[0].children; | |
| 467 expect(outlines, hasLength(4)); | |
| 468 // fieldA | |
| 469 { | |
| 470 Outline outline = outlines[0]; | |
| 471 Element element = outline.element; | |
| 472 expect(element.kind, ElementKind.FIELD); | |
| 473 expect(element.name, "fieldA"); | |
| 474 { | |
| 475 int offset = testCode.indexOf(" // leftA"); | |
| 476 int end = testCode.indexOf(", fieldB"); | |
| 477 expect(outline.offset, offset); | |
| 478 expect(outline.length, end - offset); | |
| 479 } | |
| 480 } | |
| 481 // fieldB | |
| 482 { | |
| 483 Outline outline = outlines[1]; | |
| 484 Element element = outline.element; | |
| 485 expect(element.kind, ElementKind.FIELD); | |
| 486 expect(element.name, "fieldB"); | |
| 487 { | |
| 488 int offset = testCode.indexOf(", fieldB"); | |
| 489 int end = testCode.indexOf(", fieldC"); | |
| 490 expect(outline.offset, offset); | |
| 491 expect(outline.length, end - offset); | |
| 492 } | |
| 493 } | |
| 494 // fieldC | |
| 495 { | |
| 496 Outline outline = outlines[2]; | |
| 497 Element element = outline.element; | |
| 498 expect(element.kind, ElementKind.FIELD); | |
| 499 expect(element.name, "fieldC"); | |
| 500 { | |
| 501 int offset = testCode.indexOf(", fieldC"); | |
| 502 int end = testCode.indexOf(" // marker"); | |
| 503 expect(outline.offset, offset); | |
| 504 expect(outline.length, end - offset); | |
| 505 } | |
| 506 } | |
| 507 // fieldD | |
| 508 { | |
| 509 Outline outline = outlines[3]; | |
| 510 Element element = outline.element; | |
| 511 expect(element.kind, ElementKind.FIELD); | |
| 512 expect(element.name, "fieldD"); | |
| 513 { | |
| 514 int offset = testCode.indexOf(" // marker"); | |
| 515 int end = testCode.indexOf(" // marker2"); | |
| 516 expect(outline.offset, offset); | |
| 517 expect(outline.length, end - offset); | |
| 518 } | |
| 519 } | |
| 520 }); | |
| 521 } | |
| 522 | |
| 523 test_sourceRange_inUnit() { | |
| 524 addTestFile(''' | |
| 525 class A { | |
| 526 } // endA | |
| 527 class B { | |
| 528 } // endB | |
| 529 '''); | |
| 530 return prepareOutline().then((_) { | |
| 531 Outline unitOutline = outline; | |
| 532 List<Outline> topOutlines = unitOutline.children; | |
| 533 expect(topOutlines, hasLength(2)); | |
| 534 // A | |
| 535 { | |
| 536 Outline outline = topOutlines[0]; | |
| 537 Element element = outline.element; | |
| 538 expect(element.kind, ElementKind.CLASS); | |
| 539 expect(element.name, "A"); | |
| 540 { | |
| 541 int offset = 0; | |
| 542 int end = testCode.indexOf(" // endA"); | |
| 543 expect(outline.offset, offset); | |
| 544 expect(outline.length, end - offset); | |
| 545 } | |
| 546 } | |
| 547 // B | |
| 548 { | |
| 549 Outline outline = topOutlines[1]; | |
| 550 Element element = outline.element; | |
| 551 expect(element.kind, ElementKind.CLASS); | |
| 552 expect(element.name, "B"); | |
| 553 { | |
| 554 int offset = testCode.indexOf(" // endA"); | |
| 555 int end = testCode.indexOf(" // endB"); | |
| 556 expect(outline.offset, offset); | |
| 557 expect(outline.length, end - offset); | |
| 558 } | |
| 559 } | |
| 560 }); | |
| 561 } | |
| 562 | |
| 563 test_sourceRange_inUnit_inVariableList() { | |
| 564 addTestFile(''' | |
| 565 int fieldA, fieldB, fieldC; // marker | |
| 566 int fieldD; // marker2 | |
| 567 '''); | |
| 568 return prepareOutline().then((_) { | |
| 569 Outline unitOutline = outline; | |
| 570 List<Outline> outlines = unitOutline.children; | |
| 571 expect(outlines, hasLength(4)); | |
| 572 // fieldA | |
| 573 { | |
| 574 Outline outline = outlines[0]; | |
| 575 Element element = outline.element; | |
| 576 expect(element.kind, ElementKind.TOP_LEVEL_VARIABLE); | |
| 577 expect(element.name, "fieldA"); | |
| 578 { | |
| 579 int offset = 0; | |
| 580 int end = testCode.indexOf(", fieldB"); | |
| 581 expect(outline.offset, offset); | |
| 582 expect(outline.length, end - offset); | |
| 583 } | |
| 584 } | |
| 585 // fieldB | |
| 586 { | |
| 587 Outline outline = outlines[1]; | |
| 588 Element element = outline.element; | |
| 589 expect(element.kind, ElementKind.TOP_LEVEL_VARIABLE); | |
| 590 expect(element.name, "fieldB"); | |
| 591 { | |
| 592 int offset = testCode.indexOf(", fieldB"); | |
| 593 int end = testCode.indexOf(", fieldC"); | |
| 594 expect(outline.offset, offset); | |
| 595 expect(outline.length, end - offset); | |
| 596 } | |
| 597 } | |
| 598 // fieldC | |
| 599 { | |
| 600 Outline outline = outlines[2]; | |
| 601 Element element = outline.element; | |
| 602 expect(element.kind, ElementKind.TOP_LEVEL_VARIABLE); | |
| 603 expect(element.name, "fieldC"); | |
| 604 { | |
| 605 int offset = testCode.indexOf(", fieldC"); | |
| 606 int end = testCode.indexOf(" // marker"); | |
| 607 expect(outline.offset, offset); | |
| 608 expect(outline.length, end - offset); | |
| 609 } | |
| 610 } | |
| 611 // fieldD | |
| 612 { | |
| 613 Outline outline = outlines[3]; | |
| 614 Element element = outline.element; | |
| 615 expect(element.kind, ElementKind.TOP_LEVEL_VARIABLE); | |
| 616 expect(element.name, "fieldD"); | |
| 617 { | |
| 618 int offset = testCode.indexOf(" // marker"); | |
| 619 int end = testCode.indexOf(" // marker2"); | |
| 620 expect(outline.offset, offset); | |
| 621 expect(outline.length, end - offset); | |
| 622 } | |
| 623 } | |
| 624 }); | |
| 625 } | |
| 626 | |
| 627 test_topLevel() { | |
| 628 addTestFile(''' | |
| 629 typedef String FTA(int i, String s); | |
| 630 typedef FTB(int p); | |
| 631 class A {} | |
| 632 class B {} | |
| 633 class CTA = A with B; | |
| 634 String fA(int i, String s) => null; | |
| 635 fB(int p) => null; | |
| 636 String get propA => null; | |
| 637 set propB(int v) {} | |
| 638 '''); | |
| 639 return prepareOutline().then((_) { | |
| 640 Outline unitOutline = outline; | |
| 641 List<Outline> topOutlines = unitOutline.children; | |
| 642 expect(topOutlines, hasLength(9)); | |
| 643 // FTA | |
| 644 { | |
| 645 Outline outline = topOutlines[0]; | |
| 646 Element element = outline.element; | |
| 647 expect(element.kind, ElementKind.FUNCTION_TYPE_ALIAS); | |
| 648 expect(element.name, "FTA"); | |
| 649 { | |
| 650 Location location = element.location; | |
| 651 expect(location.offset, testCode.indexOf("FTA(")); | |
| 652 expect(location.length, "FTA".length); | |
| 653 } | |
| 654 expect(element.parameters, "(int i, String s)"); | |
| 655 expect(element.returnType, "String"); | |
| 656 } | |
| 657 // FTB | |
| 658 { | |
| 659 Outline outline = topOutlines[1]; | |
| 660 Element element = outline.element; | |
| 661 expect(element.kind, ElementKind.FUNCTION_TYPE_ALIAS); | |
| 662 expect(element.name, "FTB"); | |
| 663 { | |
| 664 Location location = element.location; | |
| 665 expect(location.offset, testCode.indexOf("FTB(")); | |
| 666 expect(location.length, "FTB".length); | |
| 667 } | |
| 668 expect(element.parameters, "(int p)"); | |
| 669 expect(element.returnType, ""); | |
| 670 } | |
| 671 // CTA | |
| 672 { | |
| 673 Outline outline = topOutlines[4]; | |
| 674 Element element = outline.element; | |
| 675 expect(element.kind, ElementKind.CLASS_TYPE_ALIAS); | |
| 676 expect(element.name, "CTA"); | |
| 677 { | |
| 678 Location location = element.location; | |
| 679 expect(location.offset, testCode.indexOf("CTA =")); | |
| 680 expect(location.length, "CTA".length); | |
| 681 } | |
| 682 expect(element.parameters, isNull); | |
| 683 expect(element.returnType, isNull); | |
| 684 } | |
| 685 // fA | |
| 686 { | |
| 687 Outline outline = topOutlines[5]; | |
| 688 Element element = outline.element; | |
| 689 expect(element.kind, ElementKind.FUNCTION); | |
| 690 expect(element.name, "fA"); | |
| 691 { | |
| 692 Location location = element.location; | |
| 693 expect(location.offset, testCode.indexOf("fA(")); | |
| 694 expect(location.length, "fA".length); | |
| 695 } | |
| 696 expect(element.parameters, "(int i, String s)"); | |
| 697 expect(element.returnType, "String"); | |
| 698 } | |
| 699 // fB | |
| 700 { | |
| 701 Outline outline = topOutlines[6]; | |
| 702 Element element = outline.element; | |
| 703 expect(element.kind, ElementKind.FUNCTION); | |
| 704 expect(element.name, "fB"); | |
| 705 { | |
| 706 Location location = element.location; | |
| 707 expect(location.offset, testCode.indexOf("fB(")); | |
| 708 expect(location.length, "fB".length); | |
| 709 } | |
| 710 expect(element.parameters, "(int p)"); | |
| 711 expect(element.returnType, ""); | |
| 712 } | |
| 713 // propA | |
| 714 { | |
| 715 Outline outline = topOutlines[7]; | |
| 716 Element element = outline.element; | |
| 717 expect(element.kind, ElementKind.GETTER); | |
| 718 expect(element.name, "propA"); | |
| 719 { | |
| 720 Location location = element.location; | |
| 721 expect(element.location.offset, testCode.indexOf("propA => null;")); | |
| 722 expect(element.location.length, "propA".length); | |
| 723 } | |
| 724 expect(element.parameters, ""); | |
| 725 expect(element.returnType, "String"); | |
| 726 } | |
| 727 // propB | |
| 728 { | |
| 729 Outline outline = topOutlines[8]; | |
| 730 Element element = outline.element; | |
| 731 expect(element.kind, ElementKind.SETTER); | |
| 732 expect(element.name, "propB"); | |
| 733 { | |
| 734 Location location = element.location; | |
| 735 expect(location.offset, testCode.indexOf("propB(int v) {}")); | |
| 736 expect(location.length, "propB".length); | |
| 737 } | |
| 738 expect(element.parameters, "(int v)"); | |
| 739 expect(element.returnType, ""); | |
| 740 } | |
| 741 }); | |
| 742 } | |
| 743 } | |
| OLD | NEW |