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 services.src.correction.namespace; | 5 library services.src.correction.namespace; |
6 | 6 |
7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
9 import 'package:analyzer/src/generated/resolver.dart'; | 9 import 'package:analyzer/src/generated/resolver.dart'; |
10 | 10 |
11 | 11 |
12 /** | 12 /** |
| 13 * Returns the [Element] exported from the given [LibraryElement]. |
| 14 */ |
| 15 Element getExportedElement(LibraryElement library, String name) { |
| 16 if (library == null) { |
| 17 return null; |
| 18 } |
| 19 return getExportNamespaceForLibrary(library)[name]; |
| 20 } |
| 21 |
| 22 |
| 23 /** |
13 * Returns the namespace of the given [ExportElement]. | 24 * Returns the namespace of the given [ExportElement]. |
14 */ | 25 */ |
15 Map<String, Element> getExportNamespaceForDirective(ExportElement exp) { | 26 Map<String, Element> getExportNamespaceForDirective(ExportElement exp) { |
16 Namespace namespace = | 27 Namespace namespace = |
17 new NamespaceBuilder().createExportNamespaceForDirective(exp); | 28 new NamespaceBuilder().createExportNamespaceForDirective(exp); |
18 return namespace.definedNames; | 29 return namespace.definedNames; |
19 } | 30 } |
20 | 31 |
21 | 32 |
22 /** | 33 /** |
23 * Returns the export namespace of the given [LibraryElement]. | 34 * Returns the export namespace of the given [LibraryElement]. |
24 */ | 35 */ |
25 Map<String, Element> getExportNamespaceForLibrary(LibraryElement library) { | 36 Map<String, Element> getExportNamespaceForLibrary(LibraryElement library) { |
26 Namespace namespace = | 37 Namespace namespace = |
27 new NamespaceBuilder().createExportNamespaceForLibrary(library); | 38 new NamespaceBuilder().createExportNamespaceForLibrary(library); |
28 return namespace.definedNames; | 39 return namespace.definedNames; |
29 } | 40 } |
30 | 41 |
31 | 42 |
32 /** | 43 /** |
33 * Returns the [Element] exported from the given [LibraryElement]. | |
34 */ | |
35 Element getExportedElement(LibraryElement library, String name) { | |
36 if (library == null) { | |
37 return null; | |
38 } | |
39 return getExportNamespaceForLibrary(library)[name]; | |
40 } | |
41 | |
42 | |
43 /** | |
44 * Returns the [ImportElement] that is referenced by [prefixNode] with | 44 * Returns the [ImportElement] that is referenced by [prefixNode] with |
45 * an [PrefixElement], maybe `null`. | 45 * an [PrefixElement], maybe `null`. |
46 */ | 46 */ |
47 ImportElement getImportElement(SimpleIdentifier prefixNode) { | 47 ImportElement getImportElement(SimpleIdentifier prefixNode) { |
48 if (prefixNode.parent is ImportDirective) { | 48 if (prefixNode.parent is ImportDirective) { |
49 ImportDirective importDirective = prefixNode.parent; | 49 ImportDirective importDirective = prefixNode.parent; |
50 return importDirective.element; | 50 return importDirective.element; |
51 } | 51 } |
52 ImportElementInfo info = internal_getImportElementInfo(prefixNode); | 52 ImportElementInfo info = internal_getImportElementInfo(prefixNode); |
53 return info != null ? info.element : null; | 53 return info != null ? info.element : null; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 180 |
181 | 181 |
182 /** | 182 /** |
183 * Information about [ImportElement] and place where it is referenced using | 183 * Information about [ImportElement] and place where it is referenced using |
184 * [PrefixElement]. | 184 * [PrefixElement]. |
185 */ | 185 */ |
186 class ImportElementInfo { | 186 class ImportElementInfo { |
187 ImportElement element; | 187 ImportElement element; |
188 int periodEnd; | 188 int periodEnd; |
189 } | 189 } |
OLD | NEW |