OLD | NEW |
1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
3 | 3 |
4 library engine.sdk.io; | 4 library engine.sdk.io; |
5 | 5 |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 import 'java_core.dart'; | 7 import 'java_core.dart'; |
8 import 'java_io.dart'; | 8 import 'java_io.dart'; |
9 import 'java_engine.dart'; | 9 import 'java_engine.dart'; |
10 import 'java_engine_io.dart'; | 10 import 'java_engine_io.dart'; |
11 import 'source_io.dart'; | 11 import 'source_io.dart'; |
12 import 'error.dart'; | 12 import 'error.dart'; |
13 import 'scanner.dart'; | 13 import 'scanner.dart'; |
14 import 'ast.dart'; | 14 import 'ast.dart'; |
15 import 'parser.dart'; | 15 import 'parser.dart'; |
16 import 'sdk.dart'; | 16 import 'sdk.dart'; |
17 import 'engine.dart'; | 17 import 'engine.dart'; |
18 | 18 |
| 19 |
19 /** | 20 /** |
20 * Instances of the class {@code DirectoryBasedDartSdk} represent a Dart SDK ins
talled in a | 21 * Instances of the class {@code DirectoryBasedDartSdk} represent a Dart SDK ins
talled in a |
21 * specified directory. | 22 * specified directory. |
22 * @coverage dart.engine.sdk | 23 * @coverage dart.engine.sdk |
23 */ | 24 */ |
24 class DirectoryBasedDartSdk implements DartSdk { | 25 class DirectoryBasedDartSdk implements DartSdk { |
| 26 |
25 /** | 27 /** |
26 * The {@link AnalysisContext} which is used for all of the sources in this {@
link DartSdk}. | 28 * The {@link AnalysisContext} which is used for all of the sources in this {@
link DartSdk}. |
27 */ | 29 */ |
28 InternalAnalysisContext _analysisContext; | 30 InternalAnalysisContext _analysisContext; |
| 31 |
29 /** | 32 /** |
30 * The directory containing the SDK. | 33 * The directory containing the SDK. |
31 */ | 34 */ |
32 JavaFile _sdkDirectory; | 35 JavaFile _sdkDirectory; |
| 36 |
33 /** | 37 /** |
34 * The revision number of this SDK, or {@code "0"} if the revision number cann
ot be discovered. | 38 * The revision number of this SDK, or {@code "0"} if the revision number cann
ot be discovered. |
35 */ | 39 */ |
36 String _sdkVersion; | 40 String _sdkVersion; |
| 41 |
37 /** | 42 /** |
38 * The file containing the Dartium executable. | 43 * The file containing the Dartium executable. |
39 */ | 44 */ |
40 JavaFile _dartiumExecutable; | 45 JavaFile _dartiumExecutable; |
| 46 |
41 /** | 47 /** |
42 * The file containing the VM executable. | 48 * The file containing the VM executable. |
43 */ | 49 */ |
44 JavaFile _vmExecutable; | 50 JavaFile _vmExecutable; |
| 51 |
45 /** | 52 /** |
46 * A mapping from Dart library URI's to the library represented by that URI. | 53 * A mapping from Dart library URI's to the library represented by that URI. |
47 */ | 54 */ |
48 LibraryMap _libraryMap; | 55 LibraryMap _libraryMap; |
| 56 |
49 /** | 57 /** |
50 * The name of the directory within the SDK directory that contains executable
s. | 58 * The name of the directory within the SDK directory that contains executable
s. |
51 */ | 59 */ |
52 static String _BIN_DIRECTORY_NAME = "bin"; | 60 static String _BIN_DIRECTORY_NAME = "bin"; |
| 61 |
53 /** | 62 /** |
54 * The name of the directory within the SDK directory that contains Chromium. | 63 * The name of the directory within the SDK directory that contains Chromium. |
55 */ | 64 */ |
56 static String _CHROMIUM_DIRECTORY_NAME = "chromium"; | 65 static String _CHROMIUM_DIRECTORY_NAME = "chromium"; |
| 66 |
57 /** | 67 /** |
58 * The name of the environment variable whose value is the path to the default
Dart SDK directory. | 68 * The name of the environment variable whose value is the path to the default
Dart SDK directory. |
59 */ | 69 */ |
60 static String _DART_SDK_ENVIRONMENT_VARIABLE_NAME = "DART_SDK"; | 70 static String _DART_SDK_ENVIRONMENT_VARIABLE_NAME = "DART_SDK"; |
| 71 |
61 /** | 72 /** |
62 * The name of the file containing the Dartium executable on Linux. | 73 * The name of the file containing the Dartium executable on Linux. |
63 */ | 74 */ |
64 static String _DARTIUM_EXECUTABLE_NAME_LINUX = "chrome"; | 75 static String _DARTIUM_EXECUTABLE_NAME_LINUX = "chrome"; |
| 76 |
65 /** | 77 /** |
66 * The name of the file containing the Dartium executable on Macintosh. | 78 * The name of the file containing the Dartium executable on Macintosh. |
67 */ | 79 */ |
68 static String _DARTIUM_EXECUTABLE_NAME_MAC = "Chromium.app/Contents/MacOS/Chro
mium"; | 80 static String _DARTIUM_EXECUTABLE_NAME_MAC = "Chromium.app/Contents/MacOS/Chro
mium"; |
| 81 |
69 /** | 82 /** |
70 * The name of the file containing the Dartium executable on Windows. | 83 * The name of the file containing the Dartium executable on Windows. |
71 */ | 84 */ |
72 static String _DARTIUM_EXECUTABLE_NAME_WIN = "Chrome.exe"; | 85 static String _DARTIUM_EXECUTABLE_NAME_WIN = "Chrome.exe"; |
| 86 |
73 /** | 87 /** |
74 * The name of the {@link System} property whose value is the path to the defa
ult Dart SDK | 88 * The name of the {@link System} property whose value is the path to the defa
ult Dart SDK |
75 * directory. | 89 * directory. |
76 */ | 90 */ |
77 static String _DEFAULT_DIRECTORY_PROPERTY_NAME = "com.google.dart.sdk"; | 91 static String _DEFAULT_DIRECTORY_PROPERTY_NAME = "com.google.dart.sdk"; |
78 /** | 92 |
79 * The version number that is returned when the real version number could not
be determined. | |
80 */ | |
81 static String _DEFAULT_VERSION = "0"; | |
82 /** | 93 /** |
83 * The name of the directory within the SDK directory that contains documentat
ion for the | 94 * The name of the directory within the SDK directory that contains documentat
ion for the |
84 * libraries. | 95 * libraries. |
85 */ | 96 */ |
86 static String _DOCS_DIRECTORY_NAME = "docs"; | 97 static String _DOCS_DIRECTORY_NAME = "docs"; |
| 98 |
87 /** | 99 /** |
88 * The suffix added to the name of a library to derive the name of the file co
ntaining the | 100 * The suffix added to the name of a library to derive the name of the file co
ntaining the |
89 * documentation for that library. | 101 * documentation for that library. |
90 */ | 102 */ |
91 static String _DOC_FILE_SUFFIX = "_api.json"; | 103 static String _DOC_FILE_SUFFIX = "_api.json"; |
| 104 |
92 /** | 105 /** |
93 * The name of the directory within the SDK directory that contains the librar
ies file. | 106 * The name of the directory within the SDK directory that contains the librar
ies file. |
94 */ | 107 */ |
95 static String _INTERNAL_DIR = "_internal"; | 108 static String _INTERNAL_DIR = "_internal"; |
| 109 |
96 /** | 110 /** |
97 * The name of the directory within the SDK directory that contains the librar
ies. | 111 * The name of the directory within the SDK directory that contains the librar
ies. |
98 */ | 112 */ |
99 static String _LIB_DIRECTORY_NAME = "lib"; | 113 static String _LIB_DIRECTORY_NAME = "lib"; |
| 114 |
100 /** | 115 /** |
101 * The name of the libraries file. | 116 * The name of the libraries file. |
102 */ | 117 */ |
103 static String _LIBRARIES_FILE = "libraries.dart"; | 118 static String _LIBRARIES_FILE = "libraries.dart"; |
| 119 |
104 /** | 120 /** |
105 * The name of the file within the SDK directory that contains the revision nu
mber of the SDK. | 121 * The name of the file within the SDK directory that contains the revision nu
mber of the SDK. |
106 */ | 122 */ |
107 static String _REVISION_FILE_NAME = "revision"; | 123 static String _REVISION_FILE_NAME = "revision"; |
| 124 |
108 /** | 125 /** |
109 * The name of the file containing the VM executable on the Windows operating
system. | 126 * The name of the file containing the VM executable on the Windows operating
system. |
110 */ | 127 */ |
111 static String _VM_EXECUTABLE_NAME_WIN = "dart.exe"; | 128 static String _VM_EXECUTABLE_NAME_WIN = "dart.exe"; |
| 129 |
112 /** | 130 /** |
113 * The name of the file containing the VM executable on non-Windows operating
systems. | 131 * The name of the file containing the VM executable on non-Windows operating
systems. |
114 */ | 132 */ |
115 static String _VM_EXECUTABLE_NAME = "dart"; | 133 static String _VM_EXECUTABLE_NAME = "dart"; |
| 134 |
116 /** | 135 /** |
117 * Return the default Dart SDK, or {@code null} if the directory containing th
e default SDK cannot | 136 * Return the default Dart SDK, or {@code null} if the directory containing th
e default SDK cannot |
118 * be determined (or does not exist). | 137 * be determined (or does not exist). |
119 * @return the default Dart SDK | 138 * @return the default Dart SDK |
120 */ | 139 */ |
121 static DirectoryBasedDartSdk get defaultSdk { | 140 static DirectoryBasedDartSdk get defaultSdk { |
122 JavaFile sdkDirectory = defaultSdkDirectory; | 141 JavaFile sdkDirectory = defaultSdkDirectory; |
123 if (sdkDirectory == null) { | 142 if (sdkDirectory == null) { |
124 return null; | 143 return null; |
125 } | 144 } |
126 return new DirectoryBasedDartSdk(sdkDirectory); | 145 return new DirectoryBasedDartSdk(sdkDirectory); |
127 } | 146 } |
| 147 |
128 /** | 148 /** |
129 * Return the default directory for the Dart SDK, or {@code null} if the direc
tory cannot be | 149 * Return the default directory for the Dart SDK, or {@code null} if the direc
tory cannot be |
130 * determined (or does not exist). The default directory is provided by a {@li
nk System} property | 150 * determined (or does not exist). The default directory is provided by a {@li
nk System} property |
131 * named {@code com.google.dart.sdk}, or, if the property is not defined, an e
nvironment variable | 151 * named {@code com.google.dart.sdk}, or, if the property is not defined, an e
nvironment variable |
132 * named {@code DART_SDK}. | 152 * named {@code DART_SDK}. |
133 * @return the default directory for the Dart SDK | 153 * @return the default directory for the Dart SDK |
134 */ | 154 */ |
135 static JavaFile get defaultSdkDirectory { | 155 static JavaFile get defaultSdkDirectory { |
136 String sdkProperty = JavaSystemIO.getProperty(_DEFAULT_DIRECTORY_PROPERTY_NA
ME); | 156 String sdkProperty = JavaSystemIO.getProperty(_DEFAULT_DIRECTORY_PROPERTY_NA
ME); |
137 if (sdkProperty == null) { | 157 if (sdkProperty == null) { |
138 sdkProperty = JavaSystemIO.getenv(_DART_SDK_ENVIRONMENT_VARIABLE_NAME); | 158 sdkProperty = JavaSystemIO.getenv(_DART_SDK_ENVIRONMENT_VARIABLE_NAME); |
139 if (sdkProperty == null) { | 159 if (sdkProperty == null) { |
140 return null; | 160 return null; |
141 } | 161 } |
142 } | 162 } |
143 JavaFile sdkDirectory = new JavaFile(sdkProperty); | 163 JavaFile sdkDirectory = new JavaFile(sdkProperty); |
144 if (!sdkDirectory.exists()) { | 164 if (!sdkDirectory.exists()) { |
145 return null; | 165 return null; |
146 } | 166 } |
147 return sdkDirectory; | 167 return sdkDirectory; |
148 } | 168 } |
| 169 |
149 /** | 170 /** |
150 * Initialize a newly created SDK to represent the Dart SDK installed in the g
iven directory. | 171 * Initialize a newly created SDK to represent the Dart SDK installed in the g
iven directory. |
151 * @param sdkDirectory the directory containing the SDK | 172 * @param sdkDirectory the directory containing the SDK |
152 */ | 173 */ |
153 DirectoryBasedDartSdk(JavaFile sdkDirectory) { | 174 DirectoryBasedDartSdk(JavaFile sdkDirectory) { |
154 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); | 175 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); |
155 initializeSdk(); | 176 initializeSdk(); |
156 initializeLibraryMap(); | 177 initializeLibraryMap(); |
157 _analysisContext = new AnalysisContextImpl(); | 178 _analysisContext = new AnalysisContextImpl(); |
158 _analysisContext.sourceFactory = new SourceFactory.con2([new DartUriResolver
(this)]); | 179 _analysisContext.sourceFactory = new SourceFactory.con2([new DartUriResolver
(this)]); |
159 List<String> uris2 = uris; | 180 List<String> uris2 = uris; |
160 ChangeSet changeSet = new ChangeSet(); | 181 ChangeSet changeSet = new ChangeSet(); |
161 for (String uri in uris2) { | 182 for (String uri in uris2) { |
162 changeSet.added(_analysisContext.sourceFactory.forUri(uri)); | 183 changeSet.added(_analysisContext.sourceFactory.forUri(uri)); |
163 } | 184 } |
164 _analysisContext.applyChanges(changeSet); | 185 _analysisContext.applyChanges(changeSet); |
165 } | 186 } |
166 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) => new F
ileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), kind); | 187 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) => new F
ileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), kind); |
167 AnalysisContext get context => _analysisContext; | 188 AnalysisContext get context => _analysisContext; |
| 189 |
168 /** | 190 /** |
169 * Return the file containing the Dartium executable, or {@code null} if it do
es not exist. | 191 * Return the file containing the Dartium executable, or {@code null} if it do
es not exist. |
170 * @return the file containing the Dartium executable | 192 * @return the file containing the Dartium executable |
171 */ | 193 */ |
172 JavaFile get dartiumExecutable { | 194 JavaFile get dartiumExecutable { |
173 { | 195 { |
174 if (_dartiumExecutable == null) { | 196 if (_dartiumExecutable == null) { |
175 JavaFile file = new JavaFile.relative(dartiumWorkingDirectory, dartiumBi
naryName); | 197 JavaFile file = new JavaFile.relative(dartiumWorkingDirectory, dartiumBi
naryName); |
176 if (file.exists()) { | 198 if (file.exists()) { |
177 _dartiumExecutable = file; | 199 _dartiumExecutable = file; |
178 } | 200 } |
179 } | 201 } |
180 } | 202 } |
181 return _dartiumExecutable; | 203 return _dartiumExecutable; |
182 } | 204 } |
| 205 |
183 /** | 206 /** |
184 * Return the directory where dartium can be found in the Dart SDK (the direct
ory that will be the | 207 * Return the directory where dartium can be found in the Dart SDK (the direct
ory that will be the |
185 * working directory is Dartium is invoked without changing the default). | 208 * working directory is Dartium is invoked without changing the default). |
186 * @return the directory where dartium can be found | 209 * @return the directory where dartium can be found |
187 */ | 210 */ |
188 JavaFile get dartiumWorkingDirectory => new JavaFile.relative(_sdkDirectory.ge
tParentFile(), _CHROMIUM_DIRECTORY_NAME); | 211 JavaFile get dartiumWorkingDirectory => new JavaFile.relative(_sdkDirectory.ge
tParentFile(), _CHROMIUM_DIRECTORY_NAME); |
| 212 |
189 /** | 213 /** |
190 * Return the directory containing the SDK. | 214 * Return the directory containing the SDK. |
191 * @return the directory containing the SDK | 215 * @return the directory containing the SDK |
192 */ | 216 */ |
193 JavaFile get directory => _sdkDirectory; | 217 JavaFile get directory => _sdkDirectory; |
| 218 |
194 /** | 219 /** |
195 * Return the directory containing documentation for the SDK. | 220 * Return the directory containing documentation for the SDK. |
196 * @return the SDK's documentation directory | 221 * @return the SDK's documentation directory |
197 */ | 222 */ |
198 JavaFile get docDirectory => new JavaFile.relative(_sdkDirectory, _DOCS_DIRECT
ORY_NAME); | 223 JavaFile get docDirectory => new JavaFile.relative(_sdkDirectory, _DOCS_DIRECT
ORY_NAME); |
| 224 |
199 /** | 225 /** |
200 * Return the auxiliary documentation file for the given library, or {@code nu
ll} if no such file | 226 * Return the auxiliary documentation file for the given library, or {@code nu
ll} if no such file |
201 * exists. | 227 * exists. |
202 * @param libraryName the name of the library associated with the documentatio
n file to be | 228 * @param libraryName the name of the library associated with the documentatio
n file to be |
203 * returned | 229 * returned |
204 * @return the auxiliary documentation file for the library | 230 * @return the auxiliary documentation file for the library |
205 */ | 231 */ |
206 JavaFile getDocFileFor(String libraryName) { | 232 JavaFile getDocFileFor(String libraryName) { |
207 JavaFile dir = docDirectory; | 233 JavaFile dir = docDirectory; |
208 if (!dir.exists()) { | 234 if (!dir.exists()) { |
209 return null; | 235 return null; |
210 } | 236 } |
211 JavaFile libDir = new JavaFile.relative(dir, libraryName); | 237 JavaFile libDir = new JavaFile.relative(dir, libraryName); |
212 JavaFile docFile = new JavaFile.relative(libDir, "${libraryName}${_DOC_FILE_
SUFFIX}"); | 238 JavaFile docFile = new JavaFile.relative(libDir, "${libraryName}${_DOC_FILE_
SUFFIX}"); |
213 if (docFile.exists()) { | 239 if (docFile.exists()) { |
214 return docFile; | 240 return docFile; |
215 } | 241 } |
216 return null; | 242 return null; |
217 } | 243 } |
| 244 |
218 /** | 245 /** |
219 * Return the directory within the SDK directory that contains the libraries. | 246 * Return the directory within the SDK directory that contains the libraries. |
220 * @return the directory that contains the libraries | 247 * @return the directory that contains the libraries |
221 */ | 248 */ |
222 JavaFile get libraryDirectory => new JavaFile.relative(_sdkDirectory, _LIB_DIR
ECTORY_NAME); | 249 JavaFile get libraryDirectory => new JavaFile.relative(_sdkDirectory, _LIB_DIR
ECTORY_NAME); |
223 List<SdkLibrary> get sdkLibraries => _libraryMap.sdkLibraries; | 250 List<SdkLibrary> get sdkLibraries => _libraryMap.sdkLibraries; |
| 251 SdkLibrary getSdkLibrary(String dartUri) => _libraryMap.getLibrary(dartUri); |
| 252 |
224 /** | 253 /** |
225 * Return the revision number of this SDK, or {@code "0"} if the revision numb
er cannot be | 254 * Return the revision number of this SDK, or {@code "0"} if the revision numb
er cannot be |
226 * discovered. | 255 * discovered. |
227 * @return the revision number of this SDK | 256 * @return the revision number of this SDK |
228 */ | 257 */ |
229 String get sdkVersion { | 258 String get sdkVersion { |
230 { | 259 { |
231 if (_sdkVersion == null) { | 260 if (_sdkVersion == null) { |
232 _sdkVersion = _DEFAULT_VERSION; | 261 _sdkVersion = DartSdk.DEFAULT_VERSION; |
233 JavaFile revisionFile = new JavaFile.relative(_sdkDirectory, _REVISION_F
ILE_NAME); | 262 JavaFile revisionFile = new JavaFile.relative(_sdkDirectory, _REVISION_F
ILE_NAME); |
234 try { | 263 try { |
235 String revision = revisionFile.readAsStringSync(); | 264 String revision = revisionFile.readAsStringSync(); |
236 if (revision != null) { | 265 if (revision != null) { |
237 _sdkVersion = revision; | 266 _sdkVersion = revision; |
238 } | 267 } |
239 } on IOException catch (exception) { | 268 } on IOException catch (exception) { |
240 } | 269 } |
241 } | 270 } |
242 } | 271 } |
243 return _sdkVersion; | 272 return _sdkVersion; |
244 } | 273 } |
| 274 |
245 /** | 275 /** |
246 * Return an array containing the library URI's for the libraries defined in t
his SDK. | 276 * Return an array containing the library URI's for the libraries defined in t
his SDK. |
247 * @return the library URI's for the libraries defined in this SDK | 277 * @return the library URI's for the libraries defined in this SDK |
248 */ | 278 */ |
249 List<String> get uris => _libraryMap.uris; | 279 List<String> get uris => _libraryMap.uris; |
| 280 |
250 /** | 281 /** |
251 * Return the file containing the VM executable, or {@code null} if it does no
t exist. | 282 * Return the file containing the VM executable, or {@code null} if it does no
t exist. |
252 * @return the file containing the VM executable | 283 * @return the file containing the VM executable |
253 */ | 284 */ |
254 JavaFile get vmExecutable { | 285 JavaFile get vmExecutable { |
255 { | 286 { |
256 if (_vmExecutable == null) { | 287 if (_vmExecutable == null) { |
257 JavaFile file = new JavaFile.relative(new JavaFile.relative(_sdkDirector
y, _BIN_DIRECTORY_NAME), binaryName); | 288 JavaFile file = new JavaFile.relative(new JavaFile.relative(_sdkDirector
y, _BIN_DIRECTORY_NAME), binaryName); |
258 if (file.exists()) { | 289 if (file.exists()) { |
259 _vmExecutable = file; | 290 _vmExecutable = file; |
260 } | 291 } |
261 } | 292 } |
262 } | 293 } |
263 return _vmExecutable; | 294 return _vmExecutable; |
264 } | 295 } |
| 296 |
265 /** | 297 /** |
266 * Return {@code true} if this SDK includes documentation. | 298 * Return {@code true} if this SDK includes documentation. |
267 * @return {@code true} if this installation of the SDK has documentation | 299 * @return {@code true} if this installation of the SDK has documentation |
268 */ | 300 */ |
269 bool hasDocumentation() => docDirectory.exists(); | 301 bool hasDocumentation() => docDirectory.exists(); |
| 302 |
270 /** | 303 /** |
271 * Return {@code true} if the Dartium binary is available. | 304 * Return {@code true} if the Dartium binary is available. |
272 * @return {@code true} if the Dartium binary is available | 305 * @return {@code true} if the Dartium binary is available |
273 */ | 306 */ |
274 bool isDartiumInstalled() => dartiumExecutable != null; | 307 bool isDartiumInstalled() => dartiumExecutable != null; |
275 Source mapDartUri(ContentCache contentCache, String dartUri) { | 308 Source mapDartUri(ContentCache contentCache, String dartUri) { |
276 SdkLibrary library = _libraryMap.getLibrary(dartUri); | 309 SdkLibrary library = getSdkLibrary(dartUri); |
277 if (library == null) { | 310 if (library == null) { |
278 return null; | 311 return null; |
279 } | 312 } |
280 return new FileBasedSource.con2(contentCache, new JavaFile.relative(libraryD
irectory, library.path), UriKind.DART_URI); | 313 return new FileBasedSource.con2(contentCache, new JavaFile.relative(libraryD
irectory, library.path), UriKind.DART_URI); |
281 } | 314 } |
| 315 |
282 /** | 316 /** |
283 * Ensure that the dart VM is executable. If it is not, make it executable and
log that it was | 317 * Ensure that the dart VM is executable. If it is not, make it executable and
log that it was |
284 * necessary for us to do so. | 318 * necessary for us to do so. |
285 */ | 319 */ |
286 void ensureVmIsExecutable() { | 320 void ensureVmIsExecutable() { |
287 } | 321 } |
| 322 |
288 /** | 323 /** |
289 * Return the name of the file containing the VM executable. | 324 * Return the name of the file containing the VM executable. |
290 * @return the name of the file containing the VM executable | 325 * @return the name of the file containing the VM executable |
291 */ | 326 */ |
292 String get binaryName { | 327 String get binaryName { |
293 if (OSUtilities.isWindows()) { | 328 if (OSUtilities.isWindows()) { |
294 return _VM_EXECUTABLE_NAME_WIN; | 329 return _VM_EXECUTABLE_NAME_WIN; |
295 } else { | 330 } else { |
296 return _VM_EXECUTABLE_NAME; | 331 return _VM_EXECUTABLE_NAME; |
297 } | 332 } |
298 } | 333 } |
| 334 |
299 /** | 335 /** |
300 * Return the name of the file containing the Dartium executable. | 336 * Return the name of the file containing the Dartium executable. |
301 * @return the name of the file containing the Dartium executable | 337 * @return the name of the file containing the Dartium executable |
302 */ | 338 */ |
303 String get dartiumBinaryName { | 339 String get dartiumBinaryName { |
304 if (OSUtilities.isWindows()) { | 340 if (OSUtilities.isWindows()) { |
305 return _DARTIUM_EXECUTABLE_NAME_WIN; | 341 return _DARTIUM_EXECUTABLE_NAME_WIN; |
306 } else if (OSUtilities.isMac()) { | 342 } else if (OSUtilities.isMac()) { |
307 return _DARTIUM_EXECUTABLE_NAME_MAC; | 343 return _DARTIUM_EXECUTABLE_NAME_MAC; |
308 } else { | 344 } else { |
309 return _DARTIUM_EXECUTABLE_NAME_LINUX; | 345 return _DARTIUM_EXECUTABLE_NAME_LINUX; |
310 } | 346 } |
311 } | 347 } |
| 348 |
312 /** | 349 /** |
313 * Read all of the configuration files to initialize the library maps. | 350 * Read all of the configuration files to initialize the library maps. |
314 */ | 351 */ |
315 void initializeLibraryMap() { | 352 void initializeLibraryMap() { |
316 try { | 353 try { |
317 JavaFile librariesFile = new JavaFile.relative(new JavaFile.relative(libra
ryDirectory, _INTERNAL_DIR), _LIBRARIES_FILE); | 354 JavaFile librariesFile = new JavaFile.relative(new JavaFile.relative(libra
ryDirectory, _INTERNAL_DIR), _LIBRARIES_FILE); |
318 String contents = librariesFile.readAsStringSync(); | 355 String contents = librariesFile.readAsStringSync(); |
319 _libraryMap = new SdkLibrariesReader().readFrom(librariesFile, contents); | 356 _libraryMap = new SdkLibrariesReader().readFrom(librariesFile, contents); |
320 } catch (exception) { | 357 } catch (exception) { |
321 AnalysisEngine.instance.logger.logError3(exception); | 358 AnalysisEngine.instance.logger.logError3(exception); |
322 _libraryMap = new LibraryMap(); | 359 _libraryMap = new LibraryMap(); |
323 } | 360 } |
324 } | 361 } |
| 362 |
325 /** | 363 /** |
326 * Initialize the state of the SDK. | 364 * Initialize the state of the SDK. |
327 */ | 365 */ |
328 void initializeSdk() { | 366 void initializeSdk() { |
329 if (!OSUtilities.isWindows()) { | 367 if (!OSUtilities.isWindows()) { |
330 ensureVmIsExecutable(); | 368 ensureVmIsExecutable(); |
331 } | 369 } |
332 } | 370 } |
333 } | 371 } |
| 372 |
334 /** | 373 /** |
335 * Instances of the class {@code SdkLibrariesReader} read and parse the librarie
s file | 374 * Instances of the class {@code SdkLibrariesReader} read and parse the librarie
s file |
336 * (dart-sdk/lib/_internal/libraries.dart) for information about the libraries i
n an SDK. The | 375 * (dart-sdk/lib/_internal/libraries.dart) for information about the libraries i
n an SDK. The |
337 * library information is represented as a Dart file containing a single top-lev
el variable whose | 376 * library information is represented as a Dart file containing a single top-lev
el variable whose |
338 * value is a const map. The keys of the map are the names of libraries defined
in the SDK and the | 377 * value is a const map. The keys of the map are the names of libraries defined
in the SDK and the |
339 * values in the map are info objects defining the library. For example, a subse
t of a typical SDK | 378 * values in the map are info objects defining the library. For example, a subse
t of a typical SDK |
340 * might have a libraries file that looks like the following: | 379 * might have a libraries file that looks like the following: |
341 * <pre> | 380 * <pre> |
342 * final Map<String, LibraryInfo> LIBRARIES = const <LibraryInfo> { | 381 * final Map<String, LibraryInfo> LIBRARIES = const <LibraryInfo> { |
343 * // Used by VM applications | 382 * // Used by VM applications |
344 * "builtin" : const LibraryInfo( | 383 * "builtin" : const LibraryInfo( |
345 * "builtin/builtin_runtime.dart", | 384 * "builtin/builtin_runtime.dart", |
346 * category: "Server", | 385 * category: "Server", |
347 * platforms: VM_PLATFORM), | 386 * platforms: VM_PLATFORM), |
348 * "compiler" : const LibraryInfo( | 387 * "compiler" : const LibraryInfo( |
349 * "compiler/compiler.dart", | 388 * "compiler/compiler.dart", |
350 * category: "Tools", | 389 * category: "Tools", |
351 * platforms: 0), | 390 * platforms: 0), |
352 * }; | 391 * }; |
353 * </pre> | 392 * </pre> |
354 * @coverage dart.engine.sdk | 393 * @coverage dart.engine.sdk |
355 */ | 394 */ |
356 class SdkLibrariesReader { | 395 class SdkLibrariesReader { |
| 396 |
357 /** | 397 /** |
358 * Return the library map read from the given source. | 398 * Return the library map read from the given source. |
359 * @return the library map read from the given source | 399 * @return the library map read from the given source |
360 */ | 400 */ |
361 LibraryMap readFrom(JavaFile librariesFile, String libraryFileContents) { | 401 LibraryMap readFrom(JavaFile librariesFile, String libraryFileContents) { |
362 List<bool> foundError = [false]; | 402 List<bool> foundError = [false]; |
363 AnalysisErrorListener errorListener = new AnalysisErrorListener_10(foundErro
r); | 403 AnalysisErrorListener errorListener = new AnalysisErrorListener_9(foundError
); |
364 Source source = new FileBasedSource.con2(null, librariesFile, UriKind.FILE_U
RI); | 404 Source source = new FileBasedSource.con2(null, librariesFile, UriKind.FILE_U
RI); |
365 StringScanner scanner = new StringScanner(source, libraryFileContents, error
Listener); | 405 StringScanner scanner = new StringScanner(source, libraryFileContents, error
Listener); |
366 Parser parser = new Parser(source, errorListener); | 406 Parser parser = new Parser(source, errorListener); |
367 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize()); | 407 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize()); |
368 SdkLibrariesReader_LibraryBuilder libraryBuilder = new SdkLibrariesReader_Li
braryBuilder(); | 408 SdkLibrariesReader_LibraryBuilder libraryBuilder = new SdkLibrariesReader_Li
braryBuilder(); |
369 if (!foundError[0]) { | 409 if (!foundError[0]) { |
370 unit.accept(libraryBuilder); | 410 unit.accept(libraryBuilder); |
371 } | 411 } |
372 return libraryBuilder.librariesMap; | 412 return libraryBuilder.librariesMap; |
373 } | 413 } |
374 } | 414 } |
375 class SdkLibrariesReader_LibraryBuilder extends RecursiveASTVisitor<Object> { | 415 class SdkLibrariesReader_LibraryBuilder extends RecursiveASTVisitor<Object> { |
| 416 |
376 /** | 417 /** |
377 * The prefix added to the name of a library to form the URI used in code to r
eference the | 418 * The prefix added to the name of a library to form the URI used in code to r
eference the |
378 * library. | 419 * library. |
379 */ | 420 */ |
380 static String _LIBRARY_PREFIX = "dart:"; | 421 static String _LIBRARY_PREFIX = "dart:"; |
| 422 |
381 /** | 423 /** |
382 * The name of the optional parameter used to indicate whether the library is
an implementation | 424 * The name of the optional parameter used to indicate whether the library is
an implementation |
383 * library. | 425 * library. |
384 */ | 426 */ |
385 static String _IMPLEMENTATION = "implementation"; | 427 static String _IMPLEMENTATION = "implementation"; |
| 428 |
386 /** | 429 /** |
387 * The name of the optional parameter used to indicate whether the library is
documented. | 430 * The name of the optional parameter used to indicate whether the library is
documented. |
388 */ | 431 */ |
389 static String _DOCUMENTED = "documented"; | 432 static String _DOCUMENTED = "documented"; |
| 433 |
390 /** | 434 /** |
391 * The name of the optional parameter used to specify the category of the libr
ary. | 435 * The name of the optional parameter used to specify the category of the libr
ary. |
392 */ | 436 */ |
393 static String _CATEGORY = "category"; | 437 static String _CATEGORY = "category"; |
| 438 |
394 /** | 439 /** |
395 * The name of the optional parameter used to specify the platforms on which t
he library can be | 440 * The name of the optional parameter used to specify the platforms on which t
he library can be |
396 * used. | 441 * used. |
397 */ | 442 */ |
398 static String _PLATFORMS = "platforms"; | 443 static String _PLATFORMS = "platforms"; |
| 444 |
399 /** | 445 /** |
400 * The value of the {@link #PLATFORMS platforms} parameter used to specify tha
t the library can | 446 * The value of the {@link #PLATFORMS platforms} parameter used to specify tha
t the library can |
401 * be used on the VM. | 447 * be used on the VM. |
402 */ | 448 */ |
403 static String _VM_PLATFORM = "VM_PLATFORM"; | 449 static String _VM_PLATFORM = "VM_PLATFORM"; |
| 450 |
404 /** | 451 /** |
405 * The library map that is populated by visiting the AST structure parsed from
the contents of | 452 * The library map that is populated by visiting the AST structure parsed from
the contents of |
406 * the libraries file. | 453 * the libraries file. |
407 */ | 454 */ |
408 LibraryMap _librariesMap = new LibraryMap(); | 455 LibraryMap _librariesMap = new LibraryMap(); |
| 456 |
409 /** | 457 /** |
410 * Return the library map that was populated by visiting the AST structure par
sed from the | 458 * Return the library map that was populated by visiting the AST structure par
sed from the |
411 * contents of the libraries file. | 459 * contents of the libraries file. |
412 * @return the library map describing the contents of the SDK | 460 * @return the library map describing the contents of the SDK |
413 */ | 461 */ |
414 LibraryMap get librariesMap => _librariesMap; | 462 LibraryMap get librariesMap => _librariesMap; |
415 Object visitMapLiteralEntry(MapLiteralEntry node) { | 463 Object visitMapLiteralEntry(MapLiteralEntry node) { |
416 String libraryName = null; | 464 String libraryName = null; |
417 Expression key2 = node.key; | 465 Expression key2 = node.key; |
418 if (key2 is SimpleStringLiteral) { | 466 if (key2 is SimpleStringLiteral) { |
(...skipping 25 matching lines...) Expand all Loading... |
444 } | 492 } |
445 } | 493 } |
446 } | 494 } |
447 } | 495 } |
448 } | 496 } |
449 _librariesMap.setLibrary(libraryName, library); | 497 _librariesMap.setLibrary(libraryName, library); |
450 } | 498 } |
451 return null; | 499 return null; |
452 } | 500 } |
453 } | 501 } |
454 class AnalysisErrorListener_10 implements AnalysisErrorListener { | 502 class AnalysisErrorListener_9 implements AnalysisErrorListener { |
455 List<bool> foundError; | 503 List<bool> foundError; |
456 AnalysisErrorListener_10(this.foundError); | 504 AnalysisErrorListener_9(this.foundError); |
457 void onError(AnalysisError error) { | 505 void onError(AnalysisError error) { |
458 foundError[0] = true; | 506 foundError[0] = true; |
459 } | 507 } |
460 } | 508 } |
OLD | NEW |