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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 ClassElement, | 46 ClassElement, |
47 CompilationUnitElement, | 47 CompilationUnitElement, |
48 Element, | 48 Element, |
49 ElementCategory, | 49 ElementCategory, |
50 FunctionElement, | 50 FunctionElement, |
51 LibraryElement, | 51 LibraryElement, |
52 ScopeContainerElement; | 52 ScopeContainerElement; |
53 | 53 |
54 import 'package:compiler/implementation/elements/modelx.dart' as modelx; | 54 import 'package:compiler/implementation/elements/modelx.dart' as modelx; |
55 | 55 |
| 56 import 'package:compiler/implementation/elements/modelx.dart' show |
| 57 DeclarationSite; |
| 58 |
56 import 'package:compiler/implementation/dart_types.dart' show | 59 import 'package:compiler/implementation/dart_types.dart' show |
57 DartType; | 60 DartType; |
58 | 61 |
59 import 'package:compiler/implementation/scanner/scannerlib.dart' show | 62 import 'package:compiler/implementation/scanner/scannerlib.dart' show |
60 EOF_TOKEN, | 63 EOF_TOKEN, |
61 IDENTIFIER_TOKEN, | 64 IDENTIFIER_TOKEN, |
62 KEYWORD_TOKEN, | 65 KEYWORD_TOKEN, |
63 PartialClassElement, | 66 PartialClassElement, |
64 PartialElement, | 67 PartialElement, |
65 Token; | 68 Token; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 return repeat(); | 326 return repeat(); |
324 } | 327 } |
325 }); | 328 }); |
326 } | 329 } |
327 | 330 |
328 /// Find the token corresponding to [position] in [element]. The method only | 331 /// Find the token corresponding to [position] in [element]. The method only |
329 /// works for instances of [PartialElement] or [LibraryElement]. Support for | 332 /// works for instances of [PartialElement] or [LibraryElement]. Support for |
330 /// [LibraryElement] is currently limited, and works only for named libraries. | 333 /// [LibraryElement] is currently limited, and works only for named libraries. |
331 Token findToken(modelx.ElementX element, int position) { | 334 Token findToken(modelx.ElementX element, int position) { |
332 Token beginToken; | 335 Token beginToken; |
333 if (element is PartialElement) { | 336 DeclarationSite site = element.declarationSite; |
334 beginToken = (element as PartialElement).beginToken; | 337 if (site is PartialElement) { |
335 } else if (element is PartialClassElement) { | 338 beginToken = site.beginToken; |
336 beginToken = element.beginToken; | |
337 } else if (element.isLibrary) { | 339 } else if (element.isLibrary) { |
338 // TODO(ahe): Generalize support for library elements (and update above | 340 // TODO(ahe): Generalize support for library elements (and update above |
339 // documentation). | 341 // documentation). |
340 modelx.LibraryElementX lib = element; | 342 modelx.LibraryElementX lib = element; |
341 var tag = lib.libraryTag; | 343 var tag = lib.libraryTag; |
342 if (tag != null) { | 344 if (tag != null) { |
343 beginToken = tag.libraryKeyword; | 345 beginToken = tag.libraryKeyword; |
344 } | 346 } |
345 } else { | 347 } else { |
346 beginToken = element.position; | 348 beginToken = element.position; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 element.accept(visitor); | 415 element.accept(visitor); |
414 return '${visitor.buffer}'; | 416 return '${visitor.buffer}'; |
415 } | 417 } |
416 | 418 |
417 class FindPositionVisitor extends ElementVisitor { | 419 class FindPositionVisitor extends ElementVisitor { |
418 final int position; | 420 final int position; |
419 Element element; | 421 Element element; |
420 | 422 |
421 FindPositionVisitor(this.position, this.element); | 423 FindPositionVisitor(this.position, this.element); |
422 | 424 |
423 visitElement(Element e) { | 425 visitElement(modelx.ElementX e) { |
424 if (e is PartialElement) { | 426 DeclarationSite site = e.declarationSite; |
425 if ((e as PartialElement).beginToken.charOffset <= position && | 427 if (site is PartialElement) { |
426 position < (e as PartialElement).endToken.next.charOffset) { | 428 if (site.beginToken.charOffset <= position && |
| 429 position < site.endToken.next.charOffset) { |
427 element = e; | 430 element = e; |
428 } | 431 } |
429 } | 432 } |
430 } | 433 } |
431 | 434 |
432 visitClassElement(ClassElement e) { | 435 visitClassElement(ClassElement e) { |
433 if (e is PartialClassElement) { | 436 if (e is PartialClassElement) { |
434 if (e.beginToken.charOffset <= position && | 437 if (e.beginToken.charOffset <= position && |
435 position < e.endToken.next.charOffset) { | 438 position < e.endToken.next.charOffset) { |
436 element = e; | 439 element = e; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 buffer.write('\n'); | 709 buffer.write('\n'); |
707 indented.write('}'); | 710 indented.write('}'); |
708 } | 711 } |
709 } | 712 } |
710 | 713 |
711 modelx.ScopeX localScope(modelx.LibraryElementX element) => element.localScope; | 714 modelx.ScopeX localScope(modelx.LibraryElementX element) => element.localScope; |
712 | 715 |
713 modelx.ImportScope importScope(modelx.LibraryElementX element) { | 716 modelx.ImportScope importScope(modelx.LibraryElementX element) { |
714 return element.importScope; | 717 return element.importScope; |
715 } | 718 } |
OLD | NEW |