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