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 trydart.poi; | 5 library trydart.poi; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show |
8 Completer, | 8 Completer, |
9 Future, | 9 Future, |
10 Stream; | 10 Stream; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 'Point of interest. Cursor is immediately before highlighted character.', | 151 'Point of interest. Cursor is immediately before highlighted character.', |
152 api.Diagnostic.HINT); | 152 api.Diagnostic.HINT); |
153 | 153 |
154 Stopwatch sw = new Stopwatch()..start(); | 154 Stopwatch sw = new Stopwatch()..start(); |
155 | 155 |
156 Future future = runPoi(script, position, inputProvider, handler); | 156 Future future = runPoi(script, position, inputProvider, handler); |
157 return future.then((Element element) { | 157 return future.then((Element element) { |
158 print('Resolving took ${sw.elapsedMicroseconds}us.'); | 158 print('Resolving took ${sw.elapsedMicroseconds}us.'); |
159 sw.reset(); | 159 sw.reset(); |
160 String info = scopeInformation(element, position); | 160 String info = scopeInformation(element, position); |
| 161 sw.stop(); |
161 print(info); | 162 print(info); |
162 print('Scope information took ${sw.elapsedMicroseconds}us.'); | 163 print('Scope information took ${sw.elapsedMicroseconds}us.'); |
163 sw.reset(); | 164 sw..reset()..start(); |
164 Token token = findToken(element, position); | 165 Token token = findToken(element, position); |
165 String prefix; | 166 String prefix; |
166 if (token != null) { | 167 if (token != null) { |
167 if (token.charOffset + token.charCount <= position) { | 168 if (token.charOffset + token.charCount <= position) { |
168 // After the token; in whitespace, or in the beginning of another token. | 169 // After the token; in whitespace, or in the beginning of another token. |
169 prefix = ""; | 170 prefix = ""; |
170 } else if (token.kind == IDENTIFIER_TOKEN || | 171 } else if (token.kind == IDENTIFIER_TOKEN || |
171 token.kind == KEYWORD_TOKEN) { | 172 token.kind == KEYWORD_TOKEN) { |
172 prefix = token.value.substring(0, position - token.charOffset); | 173 prefix = token.value.substring(0, position - token.charOffset); |
173 } | 174 } |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 /// mixin), and the class side is the equivalent for static members and | 395 /// mixin), and the class side is the equivalent for static members and |
395 /// constructors. | 396 /// constructors. |
396 /// The scope chain is ordered so that the "class side" is searched before | 397 /// The scope chain is ordered so that the "class side" is searched before |
397 /// the "instance side". | 398 /// the "instance side". |
398 void serializeClassSide( | 399 void serializeClassSide( |
399 ClassElement e, | 400 ClassElement e, |
400 {bool isStatic: false, | 401 {bool isStatic: false, |
401 bool omitEnclosing: false, | 402 bool omitEnclosing: false, |
402 bool includeSuper: false}) { | 403 bool includeSuper: false}) { |
403 bool isFirst = true; | 404 bool isFirst = true; |
404 String name = e.name; | |
405 var serializeEnclosing; | 405 var serializeEnclosing; |
| 406 String kind; |
406 if (isStatic) { | 407 if (isStatic) { |
| 408 kind = 'class side'; |
407 serializeEnclosing = () { | 409 serializeEnclosing = () { |
408 serializeClassSide(e, isStatic: false, omitEnclosing: omitEnclosing); | 410 serializeClassSide(e, isStatic: false, omitEnclosing: omitEnclosing); |
409 }; | 411 }; |
410 } else { | 412 } else { |
411 name = "this($name)"; | 413 kind = 'instance side'; |
412 } | 414 } |
413 if (includeSuper) { | 415 if (includeSuper) { |
414 assert(!omitEnclosing && !isStatic); | 416 assert(!omitEnclosing && !isStatic); |
415 if (e.superclass == null) { | 417 if (e.superclass == null) { |
416 omitEnclosing = true; | 418 omitEnclosing = true; |
417 } else { | 419 } else { |
418 // Members of the superclass are represented as a separate scope. | 420 // Members of the superclass are represented as a separate scope. |
419 serializeEnclosing = () { | 421 serializeEnclosing = () { |
420 serializeClassSide( | 422 serializeClassSide( |
421 e.superclass, isStatic: false, omitEnclosing: false, | 423 e.superclass, isStatic: false, omitEnclosing: false, |
422 includeSuper: true); | 424 includeSuper: true); |
423 }; | 425 }; |
424 } | 426 } |
425 } | 427 } |
426 serialize( | 428 serialize( |
427 e, omitEnclosing: omitEnclosing, serializeEnclosing: serializeEnclosing, | 429 e, omitEnclosing: omitEnclosing, serializeEnclosing: serializeEnclosing, |
428 name: name, serializeMembers: () { | 430 kind: kind, serializeMembers: () { |
429 e.forEachLocalMember((Element member) { | 431 e.forEachLocalMember((Element member) { |
430 // Filter out members that don't belong to this "side". | 432 // Filter out members that don't belong to this "side". |
431 if (member.isStatic != isStatic) return; | 433 if (member.isConstructor) { |
| 434 // In dart2js, some constructors aren't static, but that isn't |
| 435 // convenient here. |
| 436 if (!isStatic) return; |
| 437 } else if (member.isStatic != isStatic) { |
| 438 return; |
| 439 } |
432 if (!isFirst) { | 440 if (!isFirst) { |
433 buffer.write(','); | 441 buffer.write(','); |
434 } | 442 } |
435 buffer.write('\n'); | 443 buffer.write('\n'); |
436 indented; | 444 indented; |
437 serialize(member); | 445 serialize(member); |
438 isFirst = false; | 446 isFirst = false; |
439 }); | 447 }); |
440 }); | 448 }); |
441 } | 449 } |
(...skipping 15 matching lines...) Expand all Loading... |
457 | 465 |
458 void visitCompilationUnitElement(CompilationUnitElement e) { | 466 void visitCompilationUnitElement(CompilationUnitElement e) { |
459 e.enclosingElement.accept(this); | 467 e.enclosingElement.accept(this); |
460 } | 468 } |
461 | 469 |
462 void serialize( | 470 void serialize( |
463 Element element, | 471 Element element, |
464 {bool omitEnclosing: true, | 472 {bool omitEnclosing: true, |
465 void serializeMembers(), | 473 void serializeMembers(), |
466 void serializeEnclosing(), | 474 void serializeEnclosing(), |
| 475 String kind, |
467 String name}) { | 476 String name}) { |
468 DartType type; | 477 DartType type; |
469 int category = element.kind.category; | 478 int category = element.kind.category; |
470 if (category == ElementCategory.FUNCTION || | 479 if (category == ElementCategory.FUNCTION || |
471 category == ElementCategory.VARIABLE || | 480 category == ElementCategory.VARIABLE || |
472 element.isConstructor) { | 481 element.isConstructor) { |
473 type = element.computeType(cachedCompiler); | 482 type = element.computeType(cachedCompiler); |
474 } | 483 } |
475 if (name == null) { | 484 if (name == null) { |
476 name = element.name; | 485 name = element.name; |
477 } | 486 } |
| 487 if (kind == null) { |
| 488 kind = '${element.kind}'; |
| 489 } |
478 buffer.write('{\n'); | 490 buffer.write('{\n'); |
479 indentationLevel++; | 491 indentationLevel++; |
480 if (name != '') { | 492 if (name != '') { |
481 indented | 493 indented |
482 ..write('"name": "') | 494 ..write('"name": "') |
483 ..write(name) | 495 ..write(name) |
484 ..write('",\n'); | 496 ..write('",\n'); |
485 } | 497 } |
486 indented | 498 indented |
487 ..write('"kind": "') | 499 ..write('"kind": "') |
488 ..write(element.kind) | 500 ..write(kind) |
489 ..write('"'); | 501 ..write('"'); |
490 if (type != null) { | 502 if (type != null) { |
491 buffer.write(',\n'); | 503 buffer.write(',\n'); |
492 indented | 504 indented |
493 ..write('"type": "') | 505 ..write('"type": "') |
494 ..write(type) | 506 ..write(type) |
495 ..write('"'); | 507 ..write('"'); |
496 } | 508 } |
497 if (serializeMembers != null) { | 509 if (serializeMembers != null) { |
498 buffer.write(',\n'); | 510 buffer.write(',\n'); |
(...skipping 11 matching lines...) Expand all Loading... |
510 serializeEnclosing(); | 522 serializeEnclosing(); |
511 } else { | 523 } else { |
512 element.enclosingElement.accept(this); | 524 element.enclosingElement.accept(this); |
513 } | 525 } |
514 } | 526 } |
515 indentationLevel--; | 527 indentationLevel--; |
516 buffer.write('\n'); | 528 buffer.write('\n'); |
517 indented.write('}'); | 529 indented.write('}'); |
518 } | 530 } |
519 } | 531 } |
OLD | NEW |