Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(786)

Side by Side Diff: pkg/analyzer-experimental/lib/src/generated/source.dart

Issue 12253009: Fresh drop of analyzer-experimental. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.source; 4 library engine.source;
5 5
6 import 'dart:io';
7 import 'dart:uri';
6 import 'java_core.dart'; 8 import 'java_core.dart';
9 import 'package:analyzer-experimental/src/generated/sdk.dart' show DartSdk;
7 10
8 /** 11 /**
12 * Instances of the class {@code FileUriResolver} resolve {@code file} URI's.
13 */
14 class FileUriResolver extends UriResolver {
15 /**
16 * The name of the {@code file} scheme.
17 */
18 static String _FILE_SCHEME = "file";
19 /**
20 * Return {@code true} if the given URI is a {@code file} URI.
21 * @param uri the URI being tested
22 * @return {@code true} if the given URI is a {@code file} URI
23 */
24 static bool isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME;
25 /**
26 * Initialize a newly created resolver to resolve {@code file} URI's relative to the given root
27 * directory.
28 */
29 FileUriResolver() : super() {
30 }
31 Source resolveAbsolute(SourceFactory factory, Uri uri) {
32 if (!isFileUri(uri)) {
33 return null;
34 }
35 return new FileBasedSource.con1(factory, newFileFromUri(uri));
36 }
37 }
38 /**
39 * Instances of the class {@code DartUriResolver} resolve {@code dart} URI's.
40 */
41 class DartUriResolver extends UriResolver {
42 /**
43 * The Dart SDK against which URI's are to be resolved.
44 */
45 DartSdk _sdk;
46 /**
47 * The name of the {@code dart} scheme.
48 */
49 static String _DART_SCHEME = "dart";
50 /**
51 * Return {@code true} if the given URI is a {@code dart:} URI.
52 * @param uri the URI being tested
53 * @return {@code true} if the given URI is a {@code dart:} URI
54 */
55 static bool isDartUri(Uri uri) => uri.scheme == _DART_SCHEME;
56 /**
57 * Initialize a newly created resolver to resolve Dart URI's against the given platform within the
58 * given Dart SDK.
59 * @param sdk the Dart SDK against which URI's are to be resolved
60 */
61 DartUriResolver(DartSdk sdk) {
62 this._sdk = sdk;
63 }
64 Source resolveAbsolute(SourceFactory factory, Uri uri) {
65 if (!isDartUri(uri)) {
66 return null;
67 }
68 File resolvedFile = _sdk.mapDartUri(uri.toString());
69 return new FileBasedSource.con2(factory, resolvedFile, true);
70 }
71 }
72 /**
73 * Instances of the class {@code FileBasedSource} implement a source that repres ents a file.
74 */
75 class FileBasedSource implements Source {
76 /**
77 * The source factory that created this source and that should be used to reso lve URI's against
78 * this source.
79 */
80 SourceFactory _factory;
81 /**
82 * The file represented by this source.
83 */
84 File _file;
85 /**
86 * A flag indicating whether this source is in one of the system libraries.
87 */
88 bool _inSystemLibrary = false;
89 /**
90 * Initialize a newly created source object. The source object is assumed to n ot be in a system
91 * library.
92 * @param factory the source factory that created this source
93 * @param file the file represented by this source
94 */
95 FileBasedSource.con1(SourceFactory factory, File file) {
96 _jtd_constructor_243_impl(factory, file);
97 }
98 _jtd_constructor_243_impl(SourceFactory factory, File file) {
99 _jtd_constructor_244_impl(factory, file, false);
100 }
101 /**
102 * Initialize a newly created source object.
103 * @param factory the source factory that created this source
104 * @param file the file represented by this source
105 * @param inSystemLibrary {@code true} if this source is in one of the system libraries
106 */
107 FileBasedSource.con2(SourceFactory factory2, File file3, bool inSystemLibrary2 ) {
108 _jtd_constructor_244_impl(factory2, file3, inSystemLibrary2);
109 }
110 _jtd_constructor_244_impl(SourceFactory factory2, File file3, bool inSystemLib rary2) {
111 this._factory = factory2;
112 this._file = file3;
113 this._inSystemLibrary = inSystemLibrary2;
114 }
115 bool operator ==(Object object) => object != null && identical(this.runtimeTyp e, object.runtimeType) && _file == ((object as FileBasedSource))._file;
116 void getContents(Source_ContentReceiver receiver) {
117 receiver.accept2(_file.readAsStringSync());
118 }
119 String get fullName => _file.fullPathSync();
120 String get shortName => _file.name;
121 int get hashCode => _file.hashCode;
122 bool isInSystemLibrary() => _inSystemLibrary;
123 Source resolve(String uri) => _factory.resolveUri(this, uri);
124 String toString() {
125 if (_file == null) {
126 return "<unknown source>";
127 }
128 return _file.fullPathSync();
129 }
130 /**
131 * Return the file represented by this source. This is an internal method that is only intended to
132 * be used by {@link UriResolver}.
133 * @return the file represented by this source
134 */
135 File get file => _file;
136 }
137 /**
138 * Instances of the class {@link DirectoryBasedSourceContainer} represent a sour ce container that
139 * contains all sources within a given directory.
140 */
141 class DirectoryBasedSourceContainer implements SourceContainer {
142 /**
143 * Append the system file separator to the given path unless the path already ends with a
144 * separator.
145 * @param path the path to which the file separator is to be added
146 * @return a path that ends with the system file separator
147 */
148 static String appendFileSeparator(String path) {
149 if (path == null || path.length <= 0 || path.codeUnitAt(path.length - 1) == System.pathSeparatorChar) {
150 return path;
151 }
152 return "${path}${System.pathSeparator}";
153 }
154 /**
155 * The container's path (not {@code null}).
156 */
157 String _path;
158 /**
159 * Construct a container representing the specified directory and containing a ny sources whose{@link Source#getFullName()} starts with the directory's path. T his is a convenience method,
160 * fully equivalent to {@link DirectoryBasedSourceContainer#DirectoryBasedSour ceContainer(String)}.
161 * @param directory the directory (not {@code null})
162 */
163 DirectoryBasedSourceContainer.con1(File directory) {
164 _jtd_constructor_241_impl(directory);
165 }
166 _jtd_constructor_241_impl(File directory) {
167 _jtd_constructor_242_impl(directory.fullPathSync());
168 }
169 /**
170 * Construct a container representing the specified path and containing any so urces whose{@link Source#getFullName()} starts with the specified path.
171 * @param path the path (not {@code null} and not empty)
172 */
173 DirectoryBasedSourceContainer.con2(String path3) {
174 _jtd_constructor_242_impl(path3);
175 }
176 _jtd_constructor_242_impl(String path3) {
177 this._path = appendFileSeparator(path3);
178 }
179 bool contains(Source source) => source.fullName.startsWith(_path);
180 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && ((ob j as DirectoryBasedSourceContainer)).path == path;
181 /**
182 * Answer the receiver's path, used to determine if a source is contained in t he receiver.
183 * @return the path (not {@code null}, not empty)
184 */
185 String get path => _path;
186 int get hashCode => _path.hashCode;
187 }
188 /**
189 * Instances of the class {@code PackageUriResolver} resolve {@code package} URI 's in the context of
190 * an application.
191 */
192 class PackageUriResolver extends UriResolver {
193 /**
194 * The package directories that {@code package} URI's are assumed to be relati ve to.
195 */
196 List<File> _packagesDirectories;
197 /**
198 * The name of the {@code package} scheme.
199 */
200 static String _PACKAGE_SCHEME = "package";
201 /**
202 * Return {@code true} if the given URI is a {@code package} URI.
203 * @param uri the URI being tested
204 * @return {@code true} if the given URI is a {@code package} URI
205 */
206 static bool isPackageUri(Uri uri) => uri.scheme == _PACKAGE_SCHEME;
207 /**
208 * Initialize a newly created resolver to resolve {@code package} URI's relati ve to the given
209 * package directories.
210 * @param packagesDirectories the package directories that {@code package} URI 's are assumed to be
211 * relative to
212 */
213 PackageUriResolver(List<File> packagesDirectories) {
214 if (packagesDirectories.length < 1) {
215 throw new IllegalArgumentException("At least one package directory must be provided");
216 }
217 this._packagesDirectories = packagesDirectories;
218 }
219 Source resolveAbsolute(SourceFactory factory, Uri uri) {
220 if (!isPackageUri(uri)) {
221 return null;
222 }
223 String path4 = uri.path;
224 if (path4 == null) {
225 path4 = uri.path;
226 if (path4 == null) {
227 return null;
228 }
229 }
230 for (File packagesDirectory in _packagesDirectories) {
231 File resolvedFile = newRelativeFile(packagesDirectory, path4);
232 if (resolvedFile.existsSync()) {
233 return new FileBasedSource.con1(factory, resolvedFile);
234 }
235 }
236 return new FileBasedSource.con1(factory, newRelativeFile(_packagesDirectorie s[0], path4));
237 }
238 }
239 /**
240 * The abstract class {@code UriResolver} defines the behavior of objects that a re used to resolve
241 * URI's for a source factory. Subclasses of this class are expected to resolve a single scheme of
242 * absolute URI.
243 */
244 abstract class UriResolver {
245 /**
246 * Initialize a newly created resolver.
247 */
248 UriResolver() : super() {
249 }
250 /**
251 * Working on behalf of the given source factory, resolve the (possibly relati ve) contained URI
252 * against the URI associated with the containing source object. Return a {@li nk Source source}representing the file to which it was resolved, or {@code null} if it could not be resolved.
253 * @param factory the source factory requesting the resolution of the URI
254 * @param containingSource the source containing the given URI
255 * @param containedUri the (possibly relative) URI to be resolved against the containing source
256 * @return a {@link Source source} representing the URI to which given URI was resolved
257 */
258 Source resolve(SourceFactory factory, Source containingSource, Uri containedUr i) {
259 if (containedUri.isAbsolute()) {
260 return resolveAbsolute(factory, containedUri);
261 } else {
262 return resolveRelative(factory, containingSource, containedUri);
263 }
264 }
265 /**
266 * Resolve the given absolute URI. Return a {@link Source source} representing the file to which
267 * it was resolved, or {@code null} if it could not be resolved.
268 * @param uri the URI to be resolved
269 * @return a {@link Source source} representing the URI to which given URI was resolved
270 */
271 Source resolveAbsolute(SourceFactory factory, Uri uri);
272 /**
273 * Resolve the relative (contained) URI against the URI associated with the co ntaining source
274 * object. Return a {@link Source source} representing the file to which it wa s resolved, or{@code null} if it could not be resolved.
275 * @param containingSource the source containing the given URI
276 * @param containedUri the (possibly relative) URI to be resolved against the containing source
277 * @return a {@link Source source} representing the URI to which given URI was resolved
278 */
279 Source resolveRelative(SourceFactory factory, Source containingSource, Uri con tainedUri) {
280 if (containingSource is FileBasedSource) {
281 try {
282 Uri resolvedUri = newUriFromFile(((containingSource as FileBasedSource)) .file).resolveUri(containedUri);
283 return new FileBasedSource.con1(factory, newFileFromUri(resolvedUri));
284 } on JavaException catch (exception) {
285 }
286 }
287 return null;
288 }
289 }
290 /**
291 * Instances of the class {@code SourceFactory} resolve possibly relative URI's against an existing{@link Source source}.
292 */
293 class SourceFactory {
294 /**
295 * The resolvers used to resolve absolute URI's.
296 */
297 List<UriResolver> _resolvers;
298 /**
299 * A cache of content used to override the default content of a source.
300 */
301 ContentCache _contentCache;
302 /**
303 * Initialize a newly created source factory.
304 * @param contentCache the cache holding content used to override the default content of a source.
305 * @param resolvers the resolvers used to resolve absolute URI's
306 */
307 SourceFactory.con1(ContentCache contentCache2, List<UriResolver> resolvers2) {
308 _jtd_constructor_247_impl(contentCache2, resolvers2);
309 }
310 _jtd_constructor_247_impl(ContentCache contentCache2, List<UriResolver> resolv ers2) {
311 this._contentCache = contentCache2;
312 this._resolvers = resolvers2;
313 }
314 /**
315 * Initialize a newly created source factory.
316 * @param resolvers the resolvers used to resolve absolute URI's
317 */
318 SourceFactory.con2(List<UriResolver> resolvers) {
319 _jtd_constructor_248_impl(resolvers);
320 }
321 _jtd_constructor_248_impl(List<UriResolver> resolvers) {
322 _jtd_constructor_247_impl(new ContentCache(), [resolvers]);
323 }
324 /**
325 * Return a source container representing the given directory
326 * @param directory the directory (not {@code null})
327 * @return the source container representing the directory (not {@code null})
328 */
329 SourceContainer forDirectory(File directory) => new DirectoryBasedSourceContai ner.con1(directory);
330 /**
331 * Return a source object representing the given file.
332 * @param file the file to be represented by the returned source object
333 * @return a source object representing the given file
334 */
335 Source forFile(File file) => new FileBasedSource.con1(this, file);
336 /**
337 * Return a source object representing the given absolute URI, or {@code null} if the URI is not a
338 * valid URI or if it is not an absolute URI.
339 * @param absoluteUri the absolute URI to be resolved
340 * @return a source object representing the absolute URI
341 */
342 Source forUri(String absoluteUri) {
343 try {
344 Uri uri = new Uri.fromComponents(path: absoluteUri);
345 if (uri.isAbsolute()) {
346 return resolveUri2(null, uri);
347 }
348 } on URISyntaxException catch (exception) {
349 }
350 return null;
351 }
352 /**
353 * Return a source object representing the URI that results from resolving the given (possibly
354 * relative) contained URI against the URI associated with an existing source object, or{@code null} if either the contained URI is invalid or if it cannot be resolved against the
355 * source object's URI.
356 * @param containingSource the source containing the given URI
357 * @param containedUri the (possibly relative) URI to be resolved against the containing source
358 * @return the source representing the contained URI
359 */
360 Source resolveUri(Source containingSource, String containedUri) {
361 try {
362 return resolveUri2(containingSource, new Uri.fromComponents(path: containe dUri));
363 } on URISyntaxException catch (exception) {
364 return null;
365 }
366 }
367 /**
368 * Set the contents of the given source to the given contents. This has the ef fect of overriding
369 * the default contents of the source. If the contents are {@code null} the ov erride is removed so
370 * that the default contents will be returned.
371 * @param source the source whose contents are being overridden
372 * @param contents the new contents of the source
373 */
374 void setContents(Source source, String contents) {
375 _contentCache.setContents(source, contents);
376 }
377 /**
378 * Return the contents of the given source, or {@code null} if this factory do es not override the
379 * contents of the source.
380 * <p>
381 * <b>Note:</b> This method is not intended to be used except by{@link FileBas edSource#getContents(com.google.dart.engine.source.Source.ContentReceiver)}.
382 * @param source the source whose content is to be returned
383 * @return the contents of the given source
384 */
385 String getContents(Source source) => _contentCache.getContents(source);
386 /**
387 * Return a source object representing the URI that results from resolving the given (possibly
388 * relative) contained URI against the URI associated with an existing source object, or{@code null} if either the contained URI is invalid or if it cannot be resolved against the
389 * source object's URI.
390 * @param containingSource the source containing the given URI
391 * @param containedUri the (possibly relative) URI to be resolved against the containing source
392 * @return the source representing the contained URI
393 */
394 Source resolveUri2(Source containingSource, Uri containedUri) {
395 for (UriResolver resolver in _resolvers) {
396 Source result = resolver.resolve(this, containingSource, containedUri);
397 if (result != null) {
398 return result;
399 }
400 }
401 return null;
402 }
403 }
404 /**
9 * The interface {@code Source} defines the behavior of objects representing sou rce code that can be 405 * The interface {@code Source} defines the behavior of objects representing sou rce code that can be
10 * compiled. 406 * compiled.
11 */ 407 */
12 abstract class Source { 408 abstract class Source {
13 /** 409 /**
14 * Return {@code true} if the given object is a source that represents the sam e source code as 410 * Return {@code true} if the given object is a source that represents the sam e source code as
15 * this source. 411 * this source.
16 * @param object the object to be compared with this object 412 * @param object the object to be compared with this object
17 * @return {@code true} if the given object is a source that represents the sa me source code as 413 * @return {@code true} if the given object is a source that represents the sa me source code as
18 * this source 414 * this source
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 * @param contents the contents of the source 465 * @param contents the contents of the source
70 */ 466 */
71 accept(CharBuffer contents); 467 accept(CharBuffer contents);
72 /** 468 /**
73 * Accept the contents of a source represented as a string. 469 * Accept the contents of a source represented as a string.
74 * @param contents the contents of the source 470 * @param contents the contents of the source
75 */ 471 */
76 void accept2(String contents); 472 void accept2(String contents);
77 } 473 }
78 /** 474 /**
475 * Instances of class {@code ContentCache} hold content used to override the def ault content of a{@link Source}.
476 */
477 class ContentCache {
478 /**
479 * A table mapping sources to the contents of those sources. This is used to o verride the default
480 * contents of a source.
481 */
482 Map<Source, String> _contentMap = new Map<Source, String>();
483 /**
484 * Return the contents of the given source, or {@code null} if this cache does not override the
485 * contents of the source.
486 * <p>
487 * <b>Note:</b> This method is not intended to be used except by{@link SourceF actory#getContents(com.google.dart.engine.source.Source.ContentReceiver)}.
488 * @param source the source whose content is to be returned
489 * @return the contents of the given source
490 */
491 String getContents(Source source) => _contentMap[source];
492 /**
493 * Set the contents of the given source to the given contents. This has the ef fect of overriding
494 * the default contents of the source. If the contents are {@code null} the ov erride is removed so
495 * that the default contents will be returned.
496 * @param source the source whose contents are being overridden
497 * @param contents the new contents of the source
498 */
499 void setContents(Source source, String contents) {
500 if (contents == null) {
501 _contentMap.remove(source);
502 } else {
503 _contentMap[source] = contents;
504 }
505 }
506 }
507 /**
508 * The interface {@code SourceContainer} is used by clients to define a collecti on of sources
509 * <p>
510 * Source containers are not used within analysis engine, but can be used by cli ents to group
511 * sources for the purposes of accessing composite dependency information. For e xample, the Eclipse
512 * client uses source containers to represent Eclipse projects, which allows it to easily compute
513 * project-level dependencies.
514 */
515 abstract class SourceContainer {
516 /**
517 * Determine if the specified source is part of the receiver's collection of s ources.
518 * @param source the source in question
519 * @return {@code true} if the receiver contains the source, else {@code false }
520 */
521 bool contains(Source source);
522 }
523 /**
79 * Instances of the class {@code LineInfo} encapsulate information about line an d column information 524 * Instances of the class {@code LineInfo} encapsulate information about line an d column information
80 * within a source file. 525 * within a source file.
81 */ 526 */
82 class LineInfo { 527 class LineInfo {
83 /** 528 /**
84 * An array containing the offsets of the first character of each line in the source code. 529 * An array containing the offsets of the first character of each line in the source code.
85 */ 530 */
86 List<int> _lineStarts; 531 List<int> _lineStarts;
87 /** 532 /**
88 * Initialize a newly created set of line information to represent the data en coded in the given 533 * Initialize a newly created set of line information to represent the data en coded in the given
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 /** 583 /**
139 * Return the one-based index of the column containing the character. 584 * Return the one-based index of the column containing the character.
140 * @return the one-based index of the column containing the character 585 * @return the one-based index of the column containing the character
141 */ 586 */
142 int get columnNumber => _columnNumber; 587 int get columnNumber => _columnNumber;
143 /** 588 /**
144 * Return the one-based index of the line containing the character. 589 * Return the one-based index of the line containing the character.
145 * @return the one-based index of the line containing the character 590 * @return the one-based index of the line containing the character
146 */ 591 */
147 int get lineNumber => _lineNumber; 592 int get lineNumber => _lineNumber;
593 }
594 /**
595 * The enumeration {@code SourceKind} defines the different kinds of sources tha t are known to the
596 * analysis engine.
597 */
598 class SourceKind {
599 /**
600 * A source containing HTML. The HTML might or might not contain Dart scripts.
601 */
602 static final SourceKind HTML = new SourceKind('HTML', 0);
603 /**
604 * A Dart compilation unit that is not a part of another library. Libraries mi ght or might not
605 * contain any directives, including a library directive.
606 */
607 static final SourceKind LIBRARY = new SourceKind('LIBRARY', 1);
608 /**
609 * A Dart compilation unit that is part of another library. Parts contain a pa rt-of directive.
610 */
611 static final SourceKind PART = new SourceKind('PART', 2);
612 /**
613 * An unknown kind of source. Used both when it is not possible to identify th e kind of a source
614 * and also when the kind of a source is not known without performing a comput ation and the client
615 * does not want to spend the time to identify the kind.
616 */
617 static final SourceKind UNKNOWN = new SourceKind('UNKNOWN', 3);
618 static final List<SourceKind> values = [HTML, LIBRARY, PART, UNKNOWN];
619 final String __name;
620 final int __ordinal;
621 SourceKind(this.__name, this.__ordinal) {
622 }
623 String toString() => __name;
148 } 624 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698