| 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 | |
| 4 library engine.source; | 3 library engine.source; |
| 5 | |
| 6 import 'java_core.dart'; | 4 import 'java_core.dart'; |
| 7 import 'sdk.dart' show DartSdk; | 5 import 'sdk.dart' show DartSdk; |
| 8 import 'engine.dart' show AnalysisContext; | 6 import 'engine.dart' show AnalysisContext; |
| 9 | |
| 10 | |
| 11 /** | 7 /** |
| 12 * Instances of the class {@code SourceFactory} resolve possibly relative URI's
against an existing{@link Source source}. | 8 * Instances of the class {@code SourceFactory} resolve possibly relative URI's
against an existing{@link Source source}. |
| 13 * @coverage dart.engine.source | 9 * @coverage dart.engine.source |
| 14 */ | 10 */ |
| 15 class SourceFactory { | 11 class SourceFactory { |
| 16 | 12 |
| 17 /** | 13 /** |
| 18 * The analysis context that this source factory is associated with. | 14 * The analysis context that this source factory is associated with. |
| 19 */ | 15 */ |
| 20 AnalysisContext _context; | 16 AnalysisContext _context; |
| 21 | 17 |
| 22 /** | 18 /** |
| 23 * The resolvers used to resolve absolute URI's. | 19 * The resolvers used to resolve absolute URI's. |
| 24 */ | 20 */ |
| 25 List<UriResolver> _resolvers; | 21 List<UriResolver> _resolvers; |
| 26 | 22 |
| 27 /** | 23 /** |
| 28 * A cache of content used to override the default content of a source. | 24 * A cache of content used to override the default content of a source. |
| 29 */ | 25 */ |
| 30 ContentCache _contentCache; | 26 ContentCache _contentCache; |
| 31 | 27 |
| 32 /** | 28 /** |
| 33 * Initialize a newly created source factory. | 29 * Initialize a newly created source factory. |
| 34 * @param contentCache the cache holding content used to override the default
content of a source | 30 * @param contentCache the cache holding content used to override the default
content of a source |
| 35 * @param resolvers the resolvers used to resolve absolute URI's | 31 * @param resolvers the resolvers used to resolve absolute URI's |
| 36 */ | 32 */ |
| 37 SourceFactory.con1(ContentCache contentCache2, List<UriResolver> resolvers2) { | 33 SourceFactory.con1(ContentCache contentCache2, List<UriResolver> resolvers2) { |
| 38 _jtd_constructor_340_impl(contentCache2, resolvers2); | 34 _jtd_constructor_342_impl(contentCache2, resolvers2); |
| 39 } | 35 } |
| 40 _jtd_constructor_340_impl(ContentCache contentCache2, List<UriResolver> resolv
ers2) { | 36 _jtd_constructor_342_impl(ContentCache contentCache2, List<UriResolver> resolv
ers2) { |
| 41 this._contentCache = contentCache2; | 37 this._contentCache = contentCache2; |
| 42 this._resolvers = resolvers2; | 38 this._resolvers = resolvers2; |
| 43 } | 39 } |
| 44 | 40 |
| 45 /** | 41 /** |
| 46 * Initialize a newly created source factory. | 42 * Initialize a newly created source factory. |
| 47 * @param resolvers the resolvers used to resolve absolute URI's | 43 * @param resolvers the resolvers used to resolve absolute URI's |
| 48 */ | 44 */ |
| 49 SourceFactory.con2(List<UriResolver> resolvers) { | 45 SourceFactory.con2(List<UriResolver> resolvers) { |
| 50 _jtd_constructor_341_impl(resolvers); | 46 _jtd_constructor_343_impl(resolvers); |
| 51 } | 47 } |
| 52 _jtd_constructor_341_impl(List<UriResolver> resolvers) { | 48 _jtd_constructor_343_impl(List<UriResolver> resolvers) { |
| 53 _jtd_constructor_340_impl(new ContentCache(), resolvers); | 49 _jtd_constructor_342_impl(new ContentCache(), resolvers); |
| 54 } | 50 } |
| 55 | 51 |
| 56 /** | 52 /** |
| 57 * Return a source object representing the given absolute URI, or {@code null}
if the URI is not a | 53 * Return a source object representing the given absolute URI, or {@code null}
if the URI is not a |
| 58 * valid URI or if it is not an absolute URI. | 54 * valid URI or if it is not an absolute URI. |
| 59 * @param absoluteUri the absolute URI to be resolved | 55 * @param absoluteUri the absolute URI to be resolved |
| 60 * @return a source object representing the absolute URI | 56 * @return a source object representing the absolute URI |
| 61 */ | 57 */ |
| 62 Source forUri(String absoluteUri) { | 58 Source forUri(String absoluteUri) { |
| 63 try { | 59 try { |
| 64 Uri uri = parseUriWithException(absoluteUri); | 60 Uri uri = parseUriWithException(absoluteUri); |
| 65 if (uri.isAbsolute) { | 61 if (uri.isAbsolute) { |
| 66 return resolveUri2(null, uri); | 62 return resolveUri2(null, uri); |
| 67 } | 63 } |
| 68 } on URISyntaxException catch (exception) { | 64 } on URISyntaxException catch (exception) { |
| 69 } | 65 } |
| 70 return null; | 66 return null; |
| 71 } | 67 } |
| 72 | 68 |
| 73 /** | 69 /** |
| 74 * Return a source object that is equal to the source object used to obtain th
e given encoding. | 70 * Return a source object that is equal to the source object used to obtain th
e given encoding. |
| 75 * @param encoding the encoding of a source object | 71 * @param encoding the encoding of a source object |
| 76 * @return a source object that is described by the given encoding | 72 * @return a source object that is described by the given encoding |
| 77 * @throws IllegalArgumentException if the argument is not a valid encoding | 73 * @throws IllegalArgumentException if the argument is not a valid encoding |
| 78 * @see Source#getEncoding() | 74 * @see Source#getEncoding() |
| 79 */ | 75 */ |
| 80 Source fromEncoding(String encoding) { | 76 Source fromEncoding(String encoding) { |
| 81 if (encoding.length < 2) { | 77 if (encoding.length < 2) { |
| 82 throw new IllegalArgumentException("Invalid encoding length"); | 78 throw new IllegalArgumentException("Invalid encoding length"); |
| 83 } | 79 } |
| 84 UriKind kind = UriKind.fromEncoding(encoding.codeUnitAt(0)); | 80 UriKind kind = UriKind.fromEncoding(encoding.codeUnitAt(0)); |
| 85 if (kind == null) { | 81 if (kind == null) { |
| 86 throw new IllegalArgumentException("Invalid source kind in encoding: ${kin
d}"); | 82 throw new IllegalArgumentException("Invalid source kind in encoding: ${kin
d}"); |
| 87 } | 83 } |
| 88 try { | 84 try { |
| 89 Uri uri = parseUriWithException(encoding.substring(1)); | 85 Uri uri = parseUriWithException(encoding.substring(1)); |
| 90 for (UriResolver resolver in _resolvers) { | 86 for (UriResolver resolver in _resolvers) { |
| 91 Source result = resolver.fromEncoding(_contentCache, kind, uri); | 87 Source result = resolver.fromEncoding(_contentCache, kind, uri); |
| 92 if (result != null) { | 88 if (result != null) { |
| 93 return result; | 89 return result; |
| 94 } | 90 } |
| 95 } | 91 } |
| 96 throw new IllegalArgumentException("No resolver for kind: ${kind}"); | 92 throw new IllegalArgumentException("No resolver for kind: ${kind}"); |
| 97 } catch (exception) { | 93 } catch (exception) { |
| 98 throw new IllegalArgumentException("Invalid URI in encoding"); | 94 throw new IllegalArgumentException("Invalid URI in encoding"); |
| 99 } | 95 } |
| 100 } | 96 } |
| 101 | 97 |
| 102 /** | 98 /** |
| 103 * Return a cache of content used to override the default content of a source. | 99 * Return a cache of content used to override the default content of a source. |
| 104 * @return a cache of content used to override the default content of a source | 100 * @return a cache of content used to override the default content of a source |
| 105 */ | 101 */ |
| 106 ContentCache get contentCache => _contentCache; | 102 ContentCache get contentCache => _contentCache; |
| 107 | 103 |
| 108 /** | 104 /** |
| 109 * Return the analysis context that this source factory is associated with. | 105 * Return the analysis context that this source factory is associated with. |
| 110 * @return the analysis context that this source factory is associated with | 106 * @return the analysis context that this source factory is associated with |
| 111 */ | 107 */ |
| 112 AnalysisContext get context => _context; | 108 AnalysisContext get context => _context; |
| 113 | 109 |
| 114 /** | 110 /** |
| 115 * Return the {@link DartSdk} associated with this {@link SourceFactory}, or {
@code null} if there | 111 * Return the {@link DartSdk} associated with this {@link SourceFactory}, or {
@code null} if there |
| 116 * is no such SDK. | 112 * is no such SDK. |
| 117 * @return the {@link DartSdk} associated with this {@link SourceFactory}, or
{@code null} if | 113 * @return the {@link DartSdk} associated with this {@link SourceFactory}, or
{@code null} if |
| 118 * there is no such SDK | 114 * there is no such SDK |
| 119 */ | 115 */ |
| 120 DartSdk get dartSdk { | 116 DartSdk get dartSdk { |
| 121 for (UriResolver resolver in _resolvers) { | 117 for (UriResolver resolver in _resolvers) { |
| 122 if (resolver is DartUriResolver) { | 118 if (resolver is DartUriResolver) { |
| 123 DartUriResolver dartUriResolver = resolver as DartUriResolver; | 119 DartUriResolver dartUriResolver = resolver as DartUriResolver; |
| 124 return dartUriResolver.dartSdk; | 120 return dartUriResolver.dartSdk; |
| 125 } | 121 } |
| 126 } | 122 } |
| 127 return null; | 123 return null; |
| 128 } | 124 } |
| 129 | 125 |
| 130 /** | 126 /** |
| 131 * Return a source object representing the URI that results from resolving the
given (possibly | 127 * Return a source object representing the URI that results from resolving the
given (possibly |
| 132 * 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 | 128 * 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 |
| 133 * source object's URI. | 129 * source object's URI. |
| 134 * @param containingSource the source containing the given URI | 130 * @param containingSource the source containing the given URI |
| 135 * @param containedUri the (possibly relative) URI to be resolved against the
containing source | 131 * @param containedUri the (possibly relative) URI to be resolved against the
containing source |
| 136 * @return the source representing the contained URI | 132 * @return the source representing the contained URI |
| 137 */ | 133 */ |
| 138 Source resolveUri(Source containingSource, String containedUri) { | 134 Source resolveUri(Source containingSource, String containedUri) { |
| 139 try { | 135 try { |
| 140 return resolveUri2(containingSource, parseUriWithException(containedUri)); | 136 return resolveUri2(containingSource, parseUriWithException(containedUri)); |
| 141 } on URISyntaxException catch (exception) { | 137 } on URISyntaxException catch (exception) { |
| 142 return null; | 138 return null; |
| 143 } | 139 } |
| 144 } | 140 } |
| 145 | 141 |
| 146 /** | 142 /** |
| 147 * Return an absolute URI that represents the given source. | 143 * Return an absolute URI that represents the given source. |
| 148 * @param source the source to get URI for | 144 * @param source the source to get URI for |
| 149 * @return the absolute URI representing the given source, may be {@code null} | 145 * @return the absolute URI representing the given source, may be {@code null} |
| 150 */ | 146 */ |
| 151 Uri restoreUri(Source source) { | 147 Uri restoreUri(Source source) { |
| 152 for (UriResolver resolver in _resolvers) { | 148 for (UriResolver resolver in _resolvers) { |
| 153 Uri uri = resolver.restoreAbsolute(source); | 149 Uri uri = resolver.restoreAbsolute(source); |
| 154 if (uri != null) { | 150 if (uri != null) { |
| 155 return uri; | 151 return uri; |
| 156 } | 152 } |
| 157 } | 153 } |
| 158 return null; | 154 return null; |
| 159 } | 155 } |
| 160 | 156 |
| 161 /** | 157 /** |
| 162 * Set the contents of the given source to the given contents. This has the ef
fect of overriding | 158 * Set the contents of the given source to the given contents. This has the ef
fect of overriding |
| 163 * the default contents of the source. If the contents are {@code null} the ov
erride is removed so | 159 * the default contents of the source. If the contents are {@code null} the ov
erride is removed so |
| 164 * that the default contents will be returned. | 160 * that the default contents will be returned. |
| 165 * @param source the source whose contents are being overridden | 161 * @param source the source whose contents are being overridden |
| 166 * @param contents the new contents of the source | 162 * @param contents the new contents of the source |
| 167 */ | 163 */ |
| 168 void setContents(Source source, String contents) { | 164 void setContents(Source source, String contents) { |
| 169 _contentCache.setContents(source, contents); | 165 _contentCache.setContents(source, contents); |
| 170 } | 166 } |
| 171 | 167 |
| 172 /** | 168 /** |
| 173 * Set the analysis context that this source factory is associated with to the
given context. | 169 * Set the analysis context that this source factory is associated with to the
given context. |
| 174 * <p> | 170 * <p> |
| 175 * <b>Note:</b> This method should only be invoked by{@link AnalysisContextImp
l#setSourceFactory(SourceFactory)} and is only public out of | 171 * <b>Note:</b> This method should only be invoked by{@link AnalysisContextImp
l#setSourceFactory(SourceFactory)} and is only public out of |
| 176 * necessity. | 172 * necessity. |
| 177 * @param context the analysis context that this source factory is associated
with | 173 * @param context the analysis context that this source factory is associated
with |
| 178 */ | 174 */ |
| 179 void set context(AnalysisContext context2) { | 175 void set context(AnalysisContext context2) { |
| 180 this._context = context2; | 176 this._context = context2; |
| 181 } | 177 } |
| 182 | 178 |
| 183 /** | 179 /** |
| 184 * Return the contents of the given source, or {@code null} if this factory do
es not override the | 180 * Return the contents of the given source, or {@code null} if this factory do
es not override the |
| 185 * contents of the source. | 181 * contents of the source. |
| 186 * <p> | 182 * <p> |
| 187 * <b>Note:</b> This method is not intended to be used except by{@link FileBas
edSource#getContents(com.google.dart.engine.source.Source.ContentReceiver)}. | 183 * <b>Note:</b> This method is not intended to be used except by{@link FileBas
edSource#getContents(com.google.dart.engine.source.Source.ContentReceiver)}. |
| 188 * @param source the source whose content is to be returned | 184 * @param source the source whose content is to be returned |
| 189 * @return the contents of the given source | 185 * @return the contents of the given source |
| 190 */ | 186 */ |
| 191 String getContents(Source source) => _contentCache.getContents(source); | 187 String getContents(Source source) => _contentCache.getContents(source); |
| 192 | 188 |
| 193 /** | 189 /** |
| 194 * Return the modification stamp of the given source, or {@code null} if this
factory does not | 190 * Return the modification stamp of the given source, or {@code null} if this
factory does not |
| 195 * override the contents of the source. | 191 * override the contents of the source. |
| 196 * <p> | 192 * <p> |
| 197 * <b>Note:</b> This method is not intended to be used except by{@link FileBas
edSource#getModificationStamp()}. | 193 * <b>Note:</b> This method is not intended to be used except by{@link FileBas
edSource#getModificationStamp()}. |
| 198 * @param source the source whose modification stamp is to be returned | 194 * @param source the source whose modification stamp is to be returned |
| 199 * @return the modification stamp of the given source | 195 * @return the modification stamp of the given source |
| 200 */ | 196 */ |
| 201 int getModificationStamp(Source source) => _contentCache.getModificationStamp(
source); | 197 int getModificationStamp(Source source) => _contentCache.getModificationStamp(
source); |
| 202 | 198 |
| 203 /** | 199 /** |
| 204 * Return a source object representing the URI that results from resolving the
given (possibly | 200 * Return a source object representing the URI that results from resolving the
given (possibly |
| 205 * 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 | 201 * 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 |
| 206 * source object's URI. | 202 * source object's URI. |
| 207 * @param containingSource the source containing the given URI | 203 * @param containingSource the source containing the given URI |
| 208 * @param containedUri the (possibly relative) URI to be resolved against the
containing source | 204 * @param containedUri the (possibly relative) URI to be resolved against the
containing source |
| 209 * @return the source representing the contained URI | 205 * @return the source representing the contained URI |
| 210 */ | 206 */ |
| 211 Source resolveUri2(Source containingSource, Uri containedUri) { | 207 Source resolveUri2(Source containingSource, Uri containedUri) { |
| 212 if (containedUri.isAbsolute) { | 208 if (containedUri.isAbsolute) { |
| 213 for (UriResolver resolver in _resolvers) { | 209 for (UriResolver resolver in _resolvers) { |
| 214 Source result = resolver.resolveAbsolute(_contentCache, containedUri); | 210 Source result = resolver.resolveAbsolute(_contentCache, containedUri); |
| 215 if (result != null) { | 211 if (result != null) { |
| 216 return result; | 212 return result; |
| 217 } | 213 } |
| 218 } | 214 } |
| 219 return null; | 215 return null; |
| 220 } else { | 216 } else { |
| 221 return containingSource.resolveRelative(containedUri); | 217 return containingSource.resolveRelative(containedUri); |
| 222 } | 218 } |
| 223 } | 219 } |
| 224 } | 220 } |
| 225 | |
| 226 /** | 221 /** |
| 227 * The abstract class {@code UriResolver} defines the behavior of objects that a
re used to resolve | 222 * The abstract class {@code UriResolver} defines the behavior of objects that a
re used to resolve |
| 228 * URI's for a source factory. Subclasses of this class are expected to resolve
a single scheme of | 223 * URI's for a source factory. Subclasses of this class are expected to resolve
a single scheme of |
| 229 * absolute URI. | 224 * absolute URI. |
| 230 * @coverage dart.engine.source | 225 * @coverage dart.engine.source |
| 231 */ | 226 */ |
| 232 abstract class UriResolver { | 227 abstract class UriResolver { |
| 233 | 228 |
| 234 /** | 229 /** |
| 235 * If this resolver should be used for URI's of the given kind, resolve the gi
ven absolute URI. | 230 * If this resolver should be used for URI's of the given kind, resolve the gi
ven absolute URI. |
| 236 * The URI does not need to have the scheme handled by this resolver if the ki
nd matches. Return a{@link Source source} representing the file to which it was
resolved, or {@code null} if it | 231 * The URI does not need to have the scheme handled by this resolver if the ki
nd matches. Return a{@link Source source} representing the file to which it was
resolved, or {@code null} if it |
| 237 * could not be resolved. | 232 * could not be resolved. |
| 238 * @param contentCache the content cache used to access the contents of the re
turned source | 233 * @param contentCache the content cache used to access the contents of the re
turned source |
| 239 * @param kind the kind of URI that was originally resolved in order to produc
e an encoding with | 234 * @param kind the kind of URI that was originally resolved in order to produc
e an encoding with |
| 240 * the given URI | 235 * the given URI |
| 241 * @param uri the URI to be resolved | 236 * @param uri the URI to be resolved |
| 242 * @return a {@link Source source} representing the file to which given URI wa
s resolved | 237 * @return a {@link Source source} representing the file to which given URI wa
s resolved |
| 243 */ | 238 */ |
| 244 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri); | 239 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri); |
| 245 | 240 |
| 246 /** | 241 /** |
| 247 * Resolve the given absolute URI. Return a {@link Source source} representing
the file to which | 242 * Resolve the given absolute URI. Return a {@link Source source} representing
the file to which |
| 248 * it was resolved, or {@code null} if it could not be resolved. | 243 * it was resolved, or {@code null} if it could not be resolved. |
| 249 * @param contentCache the content cache used to access the contents of the re
turned source | 244 * @param contentCache the content cache used to access the contents of the re
turned source |
| 250 * @param uri the URI to be resolved | 245 * @param uri the URI to be resolved |
| 251 * @return a {@link Source source} representing the file to which given URI wa
s resolved | 246 * @return a {@link Source source} representing the file to which given URI wa
s resolved |
| 252 */ | 247 */ |
| 253 Source resolveAbsolute(ContentCache contentCache, Uri uri); | 248 Source resolveAbsolute(ContentCache contentCache, Uri uri); |
| 254 | 249 |
| 255 /** | 250 /** |
| 256 * Return an absolute URI that represents the given source. | 251 * Return an absolute URI that represents the given source. |
| 257 * @param source the source to get URI for | 252 * @param source the source to get URI for |
| 258 * @return the absolute URI representing the given source, may be {@code null} | 253 * @return the absolute URI representing the given source, may be {@code null} |
| 259 */ | 254 */ |
| 260 Uri restoreAbsolute(Source source) => null; | 255 Uri restoreAbsolute(Source source) => null; |
| 261 } | 256 } |
| 262 | |
| 263 /** | 257 /** |
| 264 * The interface {@code Source} defines the behavior of objects representing sou
rce code that can be | 258 * The interface {@code Source} defines the behavior of objects representing sou
rce code that can be |
| 265 * compiled. | 259 * compiled. |
| 266 * @coverage dart.engine.source | 260 * @coverage dart.engine.source |
| 267 */ | 261 */ |
| 268 abstract class Source { | 262 abstract class Source { |
| 269 | 263 |
| 270 /** | 264 /** |
| 271 * An empty array of sources. | 265 * An empty array of sources. |
| 272 */ | 266 */ |
| 273 static List<Source> EMPTY_ARRAY = new List<Source>(0); | 267 static List<Source> EMPTY_ARRAY = new List<Source>(0); |
| 274 | 268 |
| 275 /** | 269 /** |
| 276 * Return {@code true} if the given object is a source that represents the sam
e source code as | 270 * Return {@code true} if the given object is a source that represents the sam
e source code as |
| 277 * this source. | 271 * this source. |
| 278 * @param object the object to be compared with this object | 272 * @param object the object to be compared with this object |
| 279 * @return {@code true} if the given object is a source that represents the sa
me source code as | 273 * @return {@code true} if the given object is a source that represents the sa
me source code as |
| 280 * this source | 274 * this source |
| 281 * @see Object#equals(Object) | 275 * @see Object#equals(Object) |
| 282 */ | 276 */ |
| 283 bool operator ==(Object object); | 277 bool operator ==(Object object); |
| 284 | 278 |
| 285 /** | 279 /** |
| 286 * Return {@code true} if this source exists. | 280 * Return {@code true} if this source exists. |
| 287 * @return {@code true} if this source exists | 281 * @return {@code true} if this source exists |
| 288 */ | 282 */ |
| 289 bool exists(); | 283 bool exists(); |
| 290 | 284 |
| 291 /** | 285 /** |
| 292 * Get the contents of this source and pass it to the given receiver. Exactly
one of the methods | 286 * Get the contents of this source and pass it to the given receiver. Exactly
one of the methods |
| 293 * defined on the receiver will be invoked unless an exception is thrown. The
method that will be | 287 * defined on the receiver will be invoked unless an exception is thrown. The
method that will be |
| 294 * invoked depends on which of the possible representations of the contents is
the most efficient. | 288 * invoked depends on which of the possible representations of the contents is
the most efficient. |
| 295 * Whichever method is invoked, it will be invoked before this method returns. | 289 * Whichever method is invoked, it will be invoked before this method returns. |
| 296 * @param receiver the content receiver to which the content of this source wi
ll be passed | 290 * @param receiver the content receiver to which the content of this source wi
ll be passed |
| 297 * @throws Exception if the contents of this source could not be accessed | 291 * @throws Exception if the contents of this source could not be accessed |
| 298 */ | 292 */ |
| 299 void getContents(Source_ContentReceiver receiver); | 293 void getContents(Source_ContentReceiver receiver); |
| 300 | 294 |
| 301 /** | 295 /** |
| 302 * Return an encoded representation of this source that can be used to create
a source that is | 296 * Return an encoded representation of this source that can be used to create
a source that is |
| 303 * equal to this source. | 297 * equal to this source. |
| 304 * @return an encoded representation of this source | 298 * @return an encoded representation of this source |
| 305 * @see SourceFactory#fromEncoding(String) | 299 * @see SourceFactory#fromEncoding(String) |
| 306 */ | 300 */ |
| 307 String get encoding; | 301 String get encoding; |
| 308 | 302 |
| 309 /** | 303 /** |
| 310 * Return the full (long) version of the name that can be displayed to the use
r to denote this | 304 * Return the full (long) version of the name that can be displayed to the use
r to denote this |
| 311 * source. For example, for a source representing a file this would typically
be the absolute path | 305 * source. For example, for a source representing a file this would typically
be the absolute path |
| 312 * of the file. | 306 * of the file. |
| 313 * @return a name that can be displayed to the user to denote this source | 307 * @return a name that can be displayed to the user to denote this source |
| 314 */ | 308 */ |
| 315 String get fullName; | 309 String get fullName; |
| 316 | 310 |
| 317 /** | 311 /** |
| 318 * Return the modification stamp for this source. A modification stamp is a no
n-negative integer | 312 * Return the modification stamp for this source. A modification stamp is a no
n-negative integer |
| 319 * with the property that if the contents of the source have not been modified
since the last time | 313 * with the property that if the contents of the source have not been modified
since the last time |
| 320 * the modification stamp was accessed then the same value will be returned, b
ut if the contents | 314 * the modification stamp was accessed then the same value will be returned, b
ut if the contents |
| 321 * of the source have been modified one or more times (even if the net change
is zero) the stamps | 315 * of the source have been modified one or more times (even if the net change
is zero) the stamps |
| 322 * will be different. | 316 * will be different. |
| 323 * @return the modification stamp for this source | 317 * @return the modification stamp for this source |
| 324 */ | 318 */ |
| 325 int get modificationStamp; | 319 int get modificationStamp; |
| 326 | 320 |
| 327 /** | 321 /** |
| 328 * Return a short version of the name that can be displayed to the user to den
ote this source. For | 322 * Return a short version of the name that can be displayed to the user to den
ote this source. For |
| 329 * example, for a source representing a file this would typically be the name
of the file. | 323 * example, for a source representing a file this would typically be the name
of the file. |
| 330 * @return a name that can be displayed to the user to denote this source | 324 * @return a name that can be displayed to the user to denote this source |
| 331 */ | 325 */ |
| 332 String get shortName; | 326 String get shortName; |
| 333 | 327 |
| 334 /** | 328 /** |
| 335 * Return the kind of URI from which this source was originally derived. If th
is source was | 329 * Return the kind of URI from which this source was originally derived. If th
is source was |
| 336 * created from an absolute URI, then the returned kind will reflect the schem
e of the absolute | 330 * created from an absolute URI, then the returned kind will reflect the schem
e of the absolute |
| 337 * URI. If it was created from a relative URI, then the returned kind will be
the same as the kind | 331 * URI. If it was created from a relative URI, then the returned kind will be
the same as the kind |
| 338 * of the source against which the relative URI was resolved. | 332 * of the source against which the relative URI was resolved. |
| 339 * @return the kind of URI from which this source was originally derived | 333 * @return the kind of URI from which this source was originally derived |
| 340 */ | 334 */ |
| 341 UriKind get uriKind; | 335 UriKind get uriKind; |
| 342 | 336 |
| 343 /** | 337 /** |
| 344 * Return a hash code for this source. | 338 * Return a hash code for this source. |
| 345 * @return a hash code for this source | 339 * @return a hash code for this source |
| 346 * @see Object#hashCode() | 340 * @see Object#hashCode() |
| 347 */ | 341 */ |
| 348 int get hashCode; | 342 int get hashCode; |
| 349 | 343 |
| 350 /** | 344 /** |
| 351 * Return {@code true} if this source is in one of the system libraries. | 345 * Return {@code true} if this source is in one of the system libraries. |
| 352 * @return {@code true} if this is in a system library | 346 * @return {@code true} if this is in a system library |
| 353 */ | 347 */ |
| 354 bool isInSystemLibrary(); | 348 bool isInSystemLibrary(); |
| 355 | 349 |
| 356 /** | 350 /** |
| 357 * Resolve the relative URI against the URI associated with this source object
. Return a{@link Source source} representing the URI to which it was resolved, o
r {@code null} if it | 351 * Resolve the relative URI against the URI associated with this source object
. Return a{@link Source source} representing the URI to which it was resolved, o
r {@code null} if it |
| 358 * could not be resolved. | 352 * could not be resolved. |
| 359 * <p> | 353 * <p> |
| 360 * Note: This method is not intended for public use, it is only visible out of
necessity. It is | 354 * Note: This method is not intended for public use, it is only visible out of
necessity. It is |
| 361 * only intended to be invoked by a {@link SourceFactory source factory}. Sour
ce factories will | 355 * only intended to be invoked by a {@link SourceFactory source factory}. Sour
ce factories will |
| 362 * only invoke this method if the URI is relative, so implementations of this
method are not | 356 * only invoke this method if the URI is relative, so implementations of this
method are not |
| 363 * required to, and generally do not, verify the argument. The result of invok
ing this method with | 357 * required to, and generally do not, verify the argument. The result of invok
ing this method with |
| 364 * an absolute URI is intentionally left unspecified. | 358 * an absolute URI is intentionally left unspecified. |
| 365 * @param relativeUri the relative URI to be resolved against the containing s
ource | 359 * @param relativeUri the relative URI to be resolved against the containing s
ource |
| 366 * @return a {@link Source source} representing the URI to which given URI was
resolved | 360 * @return a {@link Source source} representing the URI to which given URI was
resolved |
| 367 */ | 361 */ |
| 368 Source resolveRelative(Uri relativeUri); | 362 Source resolveRelative(Uri relativeUri); |
| 369 } | 363 } |
| 370 | |
| 371 /** | 364 /** |
| 372 * The interface {@code ContentReceiver} defines the behavior of objects that ca
n receive the | 365 * The interface {@code ContentReceiver} defines the behavior of objects that ca
n receive the |
| 373 * content of a source. | 366 * content of a source. |
| 374 */ | 367 */ |
| 375 abstract class Source_ContentReceiver { | 368 abstract class Source_ContentReceiver { |
| 376 | 369 |
| 377 /** | 370 /** |
| 378 * Accept the contents of a source represented as a character buffer. | 371 * Accept the contents of a source represented as a character buffer. |
| 379 * @param contents the contents of the source | 372 * @param contents the contents of the source |
| 380 * @param modificationTime the time at which the contents were last set | 373 * @param modificationTime the time at which the contents were last set |
| 381 */ | 374 */ |
| 382 void accept(CharBuffer contents, int modificationTime); | 375 void accept(CharBuffer contents, int modificationTime); |
| 383 | 376 |
| 384 /** | 377 /** |
| 385 * Accept the contents of a source represented as a string. | 378 * Accept the contents of a source represented as a string. |
| 386 * @param contents the contents of the source | 379 * @param contents the contents of the source |
| 387 * @param modificationTime the time at which the contents were last set | 380 * @param modificationTime the time at which the contents were last set |
| 388 */ | 381 */ |
| 389 void accept2(String contents, int modificationTime); | 382 void accept2(String contents, int modificationTime); |
| 390 } | 383 } |
| 391 | |
| 392 /** | 384 /** |
| 393 * The enumeration {@code SourceKind} defines the different kinds of sources tha
t are known to the | 385 * The enumeration {@code SourceKind} defines the different kinds of sources tha
t are known to the |
| 394 * analysis engine. | 386 * analysis engine. |
| 395 * @coverage dart.engine.source | 387 * @coverage dart.engine.source |
| 396 */ | 388 */ |
| 397 class SourceKind implements Comparable<SourceKind> { | 389 class SourceKind implements Comparable<SourceKind> { |
| 398 | 390 |
| 399 /** | 391 /** |
| 400 * A source containing HTML. The HTML might or might not contain Dart scripts. | 392 * A source containing HTML. The HTML might or might not contain Dart scripts. |
| 401 */ | 393 */ |
| 402 static final SourceKind HTML = new SourceKind('HTML', 0); | 394 static final SourceKind HTML = new SourceKind('HTML', 0); |
| 403 | 395 |
| 404 /** | 396 /** |
| 405 * A Dart compilation unit that is not a part of another library. Libraries mi
ght or might not | 397 * A Dart compilation unit that is not a part of another library. Libraries mi
ght or might not |
| 406 * contain any directives, including a library directive. | 398 * contain any directives, including a library directive. |
| 407 */ | 399 */ |
| 408 static final SourceKind LIBRARY = new SourceKind('LIBRARY', 1); | 400 static final SourceKind LIBRARY = new SourceKind('LIBRARY', 1); |
| 409 | 401 |
| 410 /** | 402 /** |
| 411 * A Dart compilation unit that is part of another library. Parts contain a pa
rt-of directive. | 403 * A Dart compilation unit that is part of another library. Parts contain a pa
rt-of directive. |
| 412 */ | 404 */ |
| 413 static final SourceKind PART = new SourceKind('PART', 2); | 405 static final SourceKind PART = new SourceKind('PART', 2); |
| 414 | 406 |
| 415 /** | 407 /** |
| 416 * An unknown kind of source. Used both when it is not possible to identify th
e kind of a source | 408 * An unknown kind of source. Used both when it is not possible to identify th
e kind of a source |
| 417 * and also when the kind of a source is not known without performing a comput
ation and the client | 409 * and also when the kind of a source is not known without performing a comput
ation and the client |
| 418 * does not want to spend the time to identify the kind. | 410 * does not want to spend the time to identify the kind. |
| 419 */ | 411 */ |
| 420 static final SourceKind UNKNOWN = new SourceKind('UNKNOWN', 3); | 412 static final SourceKind UNKNOWN = new SourceKind('UNKNOWN', 3); |
| 421 static final List<SourceKind> values = [HTML, LIBRARY, PART, UNKNOWN]; | 413 static final List<SourceKind> values = [HTML, LIBRARY, PART, UNKNOWN]; |
| 422 | 414 |
| 423 /// The name of this enum constant, as declared in the enum declaration. | 415 /// The name of this enum constant, as declared in the enum declaration. |
| 424 final String name; | 416 final String name; |
| 425 | 417 |
| 426 /// The position in the enum declaration. | 418 /// The position in the enum declaration. |
| 427 final int ordinal; | 419 final int ordinal; |
| 428 SourceKind(this.name, this.ordinal) { | 420 SourceKind(this.name, this.ordinal) { |
| 429 } | 421 } |
| 430 int compareTo(SourceKind other) => ordinal - other.ordinal; | 422 int compareTo(SourceKind other) => ordinal - other.ordinal; |
| 431 String toString() => name; | 423 String toString() => name; |
| 432 } | 424 } |
| 433 | |
| 434 /** | 425 /** |
| 435 * The enumeration {@code UriKind} defines the different kinds of URI's that are
known to the | 426 * The enumeration {@code UriKind} defines the different kinds of URI's that are
known to the |
| 436 * analysis engine. These are used to keep track of the kind of URI associated w
ith a given source. | 427 * analysis engine. These are used to keep track of the kind of URI associated w
ith a given source. |
| 437 * @coverage dart.engine.source | 428 * @coverage dart.engine.source |
| 438 */ | 429 */ |
| 439 class UriKind implements Comparable<UriKind> { | 430 class UriKind implements Comparable<UriKind> { |
| 440 | 431 |
| 441 /** | 432 /** |
| 442 * A 'dart:' URI. | 433 * A 'dart:' URI. |
| 443 */ | 434 */ |
| 444 static final UriKind DART_URI = new UriKind('DART_URI', 0, 0x64); | 435 static final UriKind DART_URI = new UriKind('DART_URI', 0, 0x64); |
| 445 | 436 |
| 446 /** | 437 /** |
| 447 * A 'file:' URI. | 438 * A 'file:' URI. |
| 448 */ | 439 */ |
| 449 static final UriKind FILE_URI = new UriKind('FILE_URI', 1, 0x66); | 440 static final UriKind FILE_URI = new UriKind('FILE_URI', 1, 0x66); |
| 450 | 441 |
| 451 /** | 442 /** |
| 452 * A 'package:' URI. | 443 * A 'package:' URI. |
| 453 */ | 444 */ |
| 454 static final UriKind PACKAGE_URI = new UriKind('PACKAGE_URI', 2, 0x70); | 445 static final UriKind PACKAGE_URI = new UriKind('PACKAGE_URI', 2, 0x70); |
| 455 static final List<UriKind> values = [DART_URI, FILE_URI, PACKAGE_URI]; | 446 static final List<UriKind> values = [DART_URI, FILE_URI, PACKAGE_URI]; |
| 456 | 447 |
| 457 /// The name of this enum constant, as declared in the enum declaration. | 448 /// The name of this enum constant, as declared in the enum declaration. |
| 458 final String name; | 449 final String name; |
| 459 | 450 |
| 460 /// The position in the enum declaration. | 451 /// The position in the enum declaration. |
| 461 final int ordinal; | 452 final int ordinal; |
| 462 | 453 |
| 463 /** | 454 /** |
| 464 * The single character encoding used to identify this kind of URI. | 455 * The single character encoding used to identify this kind of URI. |
| 465 */ | 456 */ |
| 466 int _encoding = 0; | 457 int _encoding = 0; |
| 467 | 458 |
| 468 /** | 459 /** |
| 469 * Initialize a newly created URI kind to have the given encoding. | 460 * Initialize a newly created URI kind to have the given encoding. |
| 470 * @param encoding the single character encoding used to identify this kind of
URI. | 461 * @param encoding the single character encoding used to identify this kind of
URI. |
| 471 */ | 462 */ |
| 472 UriKind(this.name, this.ordinal, int encoding) { | 463 UriKind(this.name, this.ordinal, int encoding) { |
| 473 this._encoding = encoding; | 464 this._encoding = encoding; |
| 474 } | 465 } |
| 475 | 466 |
| 476 /** | 467 /** |
| 477 * Return the URI kind represented by the given encoding, or {@code null} if t
here is no kind with | 468 * Return the URI kind represented by the given encoding, or {@code null} if t
here is no kind with |
| 478 * the given encoding. | 469 * the given encoding. |
| 479 * @param encoding the single character encoding used to identify the URI kind
to be returned | 470 * @param encoding the single character encoding used to identify the URI kind
to be returned |
| 480 * @return the URI kind represented by the given encoding | 471 * @return the URI kind represented by the given encoding |
| 481 */ | 472 */ |
| 482 static UriKind fromEncoding(int encoding) { | 473 static UriKind fromEncoding(int encoding) { |
| 483 while (true) { | 474 while (true) { |
| 484 if (encoding == 0x64) { | 475 if (encoding == 0x64) { |
| 485 return DART_URI; | 476 return DART_URI; |
| 486 } else if (encoding == 0x66) { | 477 } else if (encoding == 0x66) { |
| 487 return FILE_URI; | 478 return FILE_URI; |
| 488 } else if (encoding == 0x70) { | 479 } else if (encoding == 0x70) { |
| 489 return PACKAGE_URI; | 480 return PACKAGE_URI; |
| 490 } | 481 } |
| 491 break; | 482 break; |
| 492 } | 483 } |
| 493 return null; | 484 return null; |
| 494 } | 485 } |
| 495 | 486 |
| 496 /** | 487 /** |
| 497 * Return the single character encoding used to identify this kind of URI. | 488 * Return the single character encoding used to identify this kind of URI. |
| 498 * @return the single character encoding used to identify this kind of URI | 489 * @return the single character encoding used to identify this kind of URI |
| 499 */ | 490 */ |
| 500 int get encoding => _encoding; | 491 int get encoding => _encoding; |
| 501 int compareTo(UriKind other) => ordinal - other.ordinal; | 492 int compareTo(UriKind other) => ordinal - other.ordinal; |
| 502 String toString() => name; | 493 String toString() => name; |
| 503 } | 494 } |
| 504 | |
| 505 /** | 495 /** |
| 506 * A source range defines an {@link Element}'s source coordinates relative to it
s {@link Source}. | 496 * A source range defines an {@link Element}'s source coordinates relative to it
s {@link Source}. |
| 507 * @coverage dart.engine.utilities | 497 * @coverage dart.engine.utilities |
| 508 */ | 498 */ |
| 509 class SourceRange { | 499 class SourceRange { |
| 510 | 500 |
| 511 /** | 501 /** |
| 512 * The 0-based index of the first character of the source code for this elemen
t, relative to the | 502 * The 0-based index of the first character of the source code for this elemen
t, relative to the |
| 513 * source buffer in which this element is contained. | 503 * source buffer in which this element is contained. |
| 514 */ | 504 */ |
| 515 int _offset = 0; | 505 int _offset = 0; |
| 516 | 506 |
| 517 /** | 507 /** |
| 518 * The number of characters of the source code for this element, relative to t
he source buffer in | 508 * The number of characters of the source code for this element, relative to t
he source buffer in |
| 519 * which this element is contained. | 509 * which this element is contained. |
| 520 */ | 510 */ |
| 521 int _length = 0; | 511 int _length = 0; |
| 522 | 512 |
| 523 /** | 513 /** |
| 524 * Initialize a newly created source range using the given offset and the give
n length. | 514 * Initialize a newly created source range using the given offset and the give
n length. |
| 525 * @param offset the given offset | 515 * @param offset the given offset |
| 526 * @param length the given length | 516 * @param length the given length |
| 527 */ | 517 */ |
| 528 SourceRange(int offset, int length) { | 518 SourceRange(int offset, int length) { |
| 529 this._offset = offset; | 519 this._offset = offset; |
| 530 this._length = length; | 520 this._length = length; |
| 531 } | 521 } |
| 532 | 522 |
| 533 /** | 523 /** |
| 534 * @return {@code true} if <code>x</code> is in \[offset, offset + length) int
erval. | 524 * @return {@code true} if <code>x</code> is in \[offset, offset + length) int
erval. |
| 535 */ | 525 */ |
| 536 bool contains(int x) => _offset <= x && x < _offset + _length; | 526 bool contains(int x) => _offset <= x && x < _offset + _length; |
| 537 | 527 |
| 538 /** | 528 /** |
| 539 * @return {@code true} if <code>x</code> is in (offset, offset + length) inte
rval. | 529 * @return {@code true} if <code>x</code> is in (offset, offset + length) inte
rval. |
| 540 */ | 530 */ |
| 541 bool containsExclusive(int x) => _offset < x && x < _offset + _length; | 531 bool containsExclusive(int x) => _offset < x && x < _offset + _length; |
| 542 | 532 |
| 543 /** | 533 /** |
| 544 * @return {@code true} if <code>otherRange</code> covers this {@link SourceRa
nge}. | 534 * @return {@code true} if <code>otherRange</code> covers this {@link SourceRa
nge}. |
| 545 */ | 535 */ |
| 546 bool coveredBy(SourceRange otherRange) => otherRange.covers(this); | 536 bool coveredBy(SourceRange otherRange) => otherRange.covers(this); |
| 547 | 537 |
| 548 /** | 538 /** |
| 549 * @return {@code true} if this {@link SourceRange} covers <code>otherRange</c
ode>. | 539 * @return {@code true} if this {@link SourceRange} covers <code>otherRange</c
ode>. |
| 550 */ | 540 */ |
| 551 bool covers(SourceRange otherRange) => offset <= otherRange.offset && otherRan
ge.end <= end; | 541 bool covers(SourceRange otherRange) => offset <= otherRange.offset && otherRan
ge.end <= end; |
| 552 | 542 |
| 553 /** | 543 /** |
| 554 * @return {@code true} if this {@link SourceRange} ends in <code>otherRange</
code>. | 544 * @return {@code true} if this {@link SourceRange} ends in <code>otherRange</
code>. |
| 555 */ | 545 */ |
| 556 bool endsIn(SourceRange otherRange) { | 546 bool endsIn(SourceRange otherRange) { |
| 557 int thisEnd = end; | 547 int thisEnd = end; |
| 558 return otherRange.contains(thisEnd); | 548 return otherRange.contains(thisEnd); |
| 559 } | 549 } |
| 560 bool operator ==(Object obj) { | 550 bool operator ==(Object obj) { |
| 561 if (obj is! SourceRange) { | 551 if (obj is! SourceRange) { |
| 562 return false; | 552 return false; |
| 563 } | 553 } |
| 564 SourceRange sourceRange = obj as SourceRange; | 554 SourceRange sourceRange = obj as SourceRange; |
| 565 return sourceRange.offset == _offset && sourceRange.length == _length; | 555 return sourceRange.offset == _offset && sourceRange.length == _length; |
| 566 } | 556 } |
| 567 | 557 |
| 568 /** | 558 /** |
| 569 * @return the 0-based index of the after-last character of the source code fo
r this element, | 559 * @return the 0-based index of the after-last character of the source code fo
r this element, |
| 570 * relative to the source buffer in which this element is contained. | 560 * relative to the source buffer in which this element is contained. |
| 571 */ | 561 */ |
| 572 int get end => _offset + _length; | 562 int get end => _offset + _length; |
| 573 | 563 |
| 574 /** | 564 /** |
| 575 * @return the expanded instance of {@link SourceRange}, which has the same ce
nter. | 565 * @return the expanded instance of {@link SourceRange}, which has the same ce
nter. |
| 576 */ | 566 */ |
| 577 SourceRange getExpanded(int delta) => new SourceRange(_offset - delta, delta +
_length + delta); | 567 SourceRange getExpanded(int delta) => new SourceRange(_offset - delta, delta +
_length + delta); |
| 578 | 568 |
| 579 /** | 569 /** |
| 580 * Returns the number of characters of the source code for this element, relat
ive to the source | 570 * Returns the number of characters of the source code for this element, relat
ive to the source |
| 581 * buffer in which this element is contained. | 571 * buffer in which this element is contained. |
| 582 * @return the number of characters of the source code for this element, relat
ive to the source | 572 * @return the number of characters of the source code for this element, relat
ive to the source |
| 583 * buffer in which this element is contained | 573 * buffer in which this element is contained |
| 584 */ | 574 */ |
| 585 int get length => _length; | 575 int get length => _length; |
| 586 | 576 |
| 587 /** | 577 /** |
| 588 * @return the instance of {@link SourceRange} with end moved on "delta". | 578 * @return the instance of {@link SourceRange} with end moved on "delta". |
| 589 */ | 579 */ |
| 590 SourceRange getMoveEnd(int delta) => new SourceRange(_offset, _length + delta)
; | 580 SourceRange getMoveEnd(int delta) => new SourceRange(_offset, _length + delta)
; |
| 591 | 581 |
| 592 /** | 582 /** |
| 593 * Returns the 0-based index of the first character of the source code for thi
s element, relative | 583 * Returns the 0-based index of the first character of the source code for thi
s element, relative |
| 594 * to the source buffer in which this element is contained. | 584 * to the source buffer in which this element is contained. |
| 595 * @return the 0-based index of the first character of the source code for thi
s element, relative | 585 * @return the 0-based index of the first character of the source code for thi
s element, relative |
| 596 * to the source buffer in which this element is contained | 586 * to the source buffer in which this element is contained |
| 597 */ | 587 */ |
| 598 int get offset => _offset; | 588 int get offset => _offset; |
| 599 | 589 |
| 600 /** | 590 /** |
| 601 * @return the expanded translated of {@link SourceRange}, with moved start an
d the same length. | 591 * @return the expanded translated of {@link SourceRange}, with moved start an
d the same length. |
| 602 */ | 592 */ |
| 603 SourceRange getTranslated(int delta) => new SourceRange(_offset + delta, _leng
th); | 593 SourceRange getTranslated(int delta) => new SourceRange(_offset + delta, _leng
th); |
| 604 int get hashCode => 31 * _offset + _length; | 594 int get hashCode => 31 * _offset + _length; |
| 605 | 595 |
| 606 /** | 596 /** |
| 607 * @return {@code true} if this {@link SourceRange} intersects with given. | 597 * @return {@code true} if this {@link SourceRange} intersects with given. |
| 608 */ | 598 */ |
| 609 bool intersects(SourceRange other) { | 599 bool intersects(SourceRange other) { |
| 610 if (other == null) { | 600 if (other == null) { |
| 611 return false; | 601 return false; |
| 612 } | 602 } |
| 613 if (end <= other.offset) { | 603 if (end <= other.offset) { |
| 614 return false; | 604 return false; |
| 615 } | 605 } |
| 616 if (offset >= other.end) { | 606 if (offset >= other.end) { |
| 617 return false; | 607 return false; |
| 618 } | 608 } |
| 619 return true; | 609 return true; |
| 620 } | 610 } |
| 621 | 611 |
| 622 /** | 612 /** |
| 623 * @return {@code true} if this {@link SourceRange} starts in <code>otherRange
</code>. | 613 * @return {@code true} if this {@link SourceRange} starts in <code>otherRange
</code>. |
| 624 */ | 614 */ |
| 625 bool startsIn(SourceRange otherRange) => otherRange.contains(_offset); | 615 bool startsIn(SourceRange otherRange) => otherRange.contains(_offset); |
| 626 String toString() { | 616 String toString() { |
| 627 JavaStringBuilder builder = new JavaStringBuilder(); | 617 JavaStringBuilder builder = new JavaStringBuilder(); |
| 628 builder.append("[offset="); | 618 builder.append("[offset="); |
| 629 builder.append(_offset); | 619 builder.append(_offset); |
| 630 builder.append(", length="); | 620 builder.append(", length="); |
| 631 builder.append(_length); | 621 builder.append(_length); |
| 632 builder.append("]"); | 622 builder.append("]"); |
| 633 return builder.toString(); | 623 return builder.toString(); |
| 634 } | 624 } |
| 635 } | 625 } |
| 636 | |
| 637 /** | 626 /** |
| 638 * The interface {@code SourceContainer} is used by clients to define a collecti
on of sources | 627 * The interface {@code SourceContainer} is used by clients to define a collecti
on of sources |
| 639 * <p> | 628 * <p> |
| 640 * Source containers are not used within analysis engine, but can be used by cli
ents to group | 629 * Source containers are not used within analysis engine, but can be used by cli
ents to group |
| 641 * sources for the purposes of accessing composite dependency information. For e
xample, the Eclipse | 630 * sources for the purposes of accessing composite dependency information. For e
xample, the Eclipse |
| 642 * client uses source containers to represent Eclipse projects, which allows it
to easily compute | 631 * client uses source containers to represent Eclipse projects, which allows it
to easily compute |
| 643 * project-level dependencies. | 632 * project-level dependencies. |
| 644 * @coverage dart.engine.source | 633 * @coverage dart.engine.source |
| 645 */ | 634 */ |
| 646 abstract class SourceContainer { | 635 abstract class SourceContainer { |
| 647 | 636 |
| 648 /** | 637 /** |
| 649 * Determine if the specified source is part of the receiver's collection of s
ources. | 638 * Determine if the specified source is part of the receiver's collection of s
ources. |
| 650 * @param source the source in question | 639 * @param source the source in question |
| 651 * @return {@code true} if the receiver contains the source, else {@code false
} | 640 * @return {@code true} if the receiver contains the source, else {@code false
} |
| 652 */ | 641 */ |
| 653 bool contains(Source source); | 642 bool contains(Source source); |
| 654 } | 643 } |
| 655 | |
| 656 /** | 644 /** |
| 657 * Instances of the class {@code DartUriResolver} resolve {@code dart} URI's. | 645 * Instances of the class {@code DartUriResolver} resolve {@code dart} URI's. |
| 658 * @coverage dart.engine.source | 646 * @coverage dart.engine.source |
| 659 */ | 647 */ |
| 660 class DartUriResolver extends UriResolver { | 648 class DartUriResolver extends UriResolver { |
| 661 | 649 |
| 662 /** | 650 /** |
| 663 * The Dart SDK against which URI's are to be resolved. | 651 * The Dart SDK against which URI's are to be resolved. |
| 664 */ | 652 */ |
| 665 DartSdk _sdk; | 653 DartSdk _sdk; |
| 666 | 654 |
| 667 /** | 655 /** |
| 668 * The name of the {@code dart} scheme. | 656 * The name of the {@code dart} scheme. |
| 669 */ | 657 */ |
| 670 static String _DART_SCHEME = "dart"; | 658 static String _DART_SCHEME = "dart"; |
| 671 | 659 |
| 672 /** | 660 /** |
| 673 * Return {@code true} if the given URI is a {@code dart:} URI. | 661 * Return {@code true} if the given URI is a {@code dart:} URI. |
| 674 * @param uri the URI being tested | 662 * @param uri the URI being tested |
| 675 * @return {@code true} if the given URI is a {@code dart:} URI | 663 * @return {@code true} if the given URI is a {@code dart:} URI |
| 676 */ | 664 */ |
| 677 static bool isDartUri(Uri uri) => _DART_SCHEME == uri.scheme; | 665 static bool isDartUri(Uri uri) => _DART_SCHEME == uri.scheme; |
| 678 | 666 |
| 679 /** | 667 /** |
| 680 * Initialize a newly created resolver to resolve Dart URI's against the given
platform within the | 668 * Initialize a newly created resolver to resolve Dart URI's against the given
platform within the |
| 681 * given Dart SDK. | 669 * given Dart SDK. |
| 682 * @param sdk the Dart SDK against which URI's are to be resolved | 670 * @param sdk the Dart SDK against which URI's are to be resolved |
| 683 */ | 671 */ |
| 684 DartUriResolver(DartSdk sdk) { | 672 DartUriResolver(DartSdk sdk) { |
| 685 this._sdk = sdk; | 673 this._sdk = sdk; |
| 686 } | 674 } |
| 687 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { | 675 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { |
| 688 if (identical(kind, UriKind.DART_URI)) { | 676 if (identical(kind, UriKind.DART_URI)) { |
| 689 return _sdk.fromEncoding(contentCache, kind, uri); | 677 return _sdk.fromEncoding(contentCache, kind, uri); |
| 690 } | 678 } |
| 691 return null; | 679 return null; |
| 692 } | 680 } |
| 693 | 681 |
| 694 /** | 682 /** |
| 695 * Return the {@link DartSdk} against which URIs are to be resolved. | 683 * Return the {@link DartSdk} against which URIs are to be resolved. |
| 696 * @return the {@link DartSdk} against which URIs are to be resolved. | 684 * @return the {@link DartSdk} against which URIs are to be resolved. |
| 697 */ | 685 */ |
| 698 DartSdk get dartSdk => _sdk; | 686 DartSdk get dartSdk => _sdk; |
| 699 Source resolveAbsolute(ContentCache contentCache, Uri uri) { | 687 Source resolveAbsolute(ContentCache contentCache, Uri uri) { |
| 700 if (!isDartUri(uri)) { | 688 if (!isDartUri(uri)) { |
| 701 return null; | 689 return null; |
| 702 } | 690 } |
| 703 return _sdk.mapDartUri(contentCache, uri.toString()); | 691 return _sdk.mapDartUri(contentCache, uri.toString()); |
| 704 } | 692 } |
| 705 } | 693 } |
| 706 | |
| 707 /** | 694 /** |
| 708 * Instances of the class {@code LineInfo} encapsulate information about line an
d column information | 695 * Instances of the class {@code LineInfo} encapsulate information about line an
d column information |
| 709 * within a source file. | 696 * within a source file. |
| 710 * @coverage dart.engine.utilities | 697 * @coverage dart.engine.utilities |
| 711 */ | 698 */ |
| 712 class LineInfo { | 699 class LineInfo { |
| 713 | 700 |
| 714 /** | 701 /** |
| 715 * An array containing the offsets of the first character of each line in the
source code. | 702 * An array containing the offsets of the first character of each line in the
source code. |
| 716 */ | 703 */ |
| 717 List<int> _lineStarts; | 704 List<int> _lineStarts; |
| 718 | 705 |
| 719 /** | 706 /** |
| 720 * Initialize a newly created set of line information to represent the data en
coded in the given | 707 * Initialize a newly created set of line information to represent the data en
coded in the given |
| 721 * array. | 708 * array. |
| 722 * @param lineStarts the offsets of the first character of each line in the so
urce code | 709 * @param lineStarts the offsets of the first character of each line in the so
urce code |
| 723 */ | 710 */ |
| 724 LineInfo(List<int> lineStarts) { | 711 LineInfo(List<int> lineStarts) { |
| 725 if (lineStarts == null) { | 712 if (lineStarts == null) { |
| 726 throw new IllegalArgumentException("lineStarts must be non-null"); | 713 throw new IllegalArgumentException("lineStarts must be non-null"); |
| 727 } else if (lineStarts.length < 1) { | 714 } else if (lineStarts.length < 1) { |
| 728 throw new IllegalArgumentException("lineStarts must be non-empty"); | 715 throw new IllegalArgumentException("lineStarts must be non-empty"); |
| 729 } | 716 } |
| 730 this._lineStarts = lineStarts; | 717 this._lineStarts = lineStarts; |
| 731 } | 718 } |
| 732 | 719 |
| 733 /** | 720 /** |
| 734 * Return the location information for the character at the given offset. | 721 * Return the location information for the character at the given offset. |
| 735 * @param offset the offset of the character for which location information is
to be returned | 722 * @param offset the offset of the character for which location information is
to be returned |
| 736 * @return the location information for the character at the given offset | 723 * @return the location information for the character at the given offset |
| 737 */ | 724 */ |
| 738 LineInfo_Location getLocation(int offset) { | 725 LineInfo_Location getLocation(int offset) { |
| 739 int lineCount = _lineStarts.length; | 726 int lineCount = _lineStarts.length; |
| 740 for (int i = 1; i < lineCount; i++) { | 727 for (int i = 1; i < lineCount; i++) { |
| 741 if (offset < _lineStarts[i]) { | 728 if (offset < _lineStarts[i]) { |
| 742 return new LineInfo_Location(i, offset - _lineStarts[i - 1] + 1); | 729 return new LineInfo_Location(i, offset - _lineStarts[i - 1] + 1); |
| 743 } | 730 } |
| 744 } | 731 } |
| 745 return new LineInfo_Location(lineCount, offset - _lineStarts[lineCount - 1]
+ 1); | 732 return new LineInfo_Location(lineCount, offset - _lineStarts[lineCount - 1]
+ 1); |
| 746 } | 733 } |
| 747 } | 734 } |
| 748 | |
| 749 /** | 735 /** |
| 750 * Instances of the class {@code Location} represent the location of a character
as a line and | 736 * Instances of the class {@code Location} represent the location of a character
as a line and |
| 751 * column pair. | 737 * column pair. |
| 752 */ | 738 */ |
| 753 class LineInfo_Location { | 739 class LineInfo_Location { |
| 754 | 740 |
| 755 /** | 741 /** |
| 756 * The one-based index of the line containing the character. | 742 * The one-based index of the line containing the character. |
| 757 */ | 743 */ |
| 758 int _lineNumber = 0; | 744 int _lineNumber = 0; |
| 759 | 745 |
| 760 /** | 746 /** |
| 761 * The one-based index of the column containing the character. | 747 * The one-based index of the column containing the character. |
| 762 */ | 748 */ |
| 763 int _columnNumber = 0; | 749 int _columnNumber = 0; |
| 764 | 750 |
| 765 /** | 751 /** |
| 766 * Initialize a newly created location to represent the location of the charac
ter at the given | 752 * Initialize a newly created location to represent the location of the charac
ter at the given |
| 767 * line and column position. | 753 * line and column position. |
| 768 * @param lineNumber the one-based index of the line containing the character | 754 * @param lineNumber the one-based index of the line containing the character |
| 769 * @param columnNumber the one-based index of the column containing the charac
ter | 755 * @param columnNumber the one-based index of the column containing the charac
ter |
| 770 */ | 756 */ |
| 771 LineInfo_Location(int lineNumber, int columnNumber) { | 757 LineInfo_Location(int lineNumber, int columnNumber) { |
| 772 this._lineNumber = lineNumber; | 758 this._lineNumber = lineNumber; |
| 773 this._columnNumber = columnNumber; | 759 this._columnNumber = columnNumber; |
| 774 } | 760 } |
| 775 | 761 |
| 776 /** | 762 /** |
| 777 * Return the one-based index of the column containing the character. | 763 * Return the one-based index of the column containing the character. |
| 778 * @return the one-based index of the column containing the character | 764 * @return the one-based index of the column containing the character |
| 779 */ | 765 */ |
| 780 int get columnNumber => _columnNumber; | 766 int get columnNumber => _columnNumber; |
| 781 | 767 |
| 782 /** | 768 /** |
| 783 * Return the one-based index of the line containing the character. | 769 * Return the one-based index of the line containing the character. |
| 784 * @return the one-based index of the line containing the character | 770 * @return the one-based index of the line containing the character |
| 785 */ | 771 */ |
| 786 int get lineNumber => _lineNumber; | 772 int get lineNumber => _lineNumber; |
| 787 } | 773 } |
| 788 | |
| 789 /** | 774 /** |
| 790 * Instances of class {@code ContentCache} hold content used to override the def
ault content of a{@link Source}. | 775 * Instances of class {@code ContentCache} hold content used to override the def
ault content of a{@link Source}. |
| 791 * @coverage dart.engine.source | 776 * @coverage dart.engine.source |
| 792 */ | 777 */ |
| 793 class ContentCache { | 778 class ContentCache { |
| 794 | 779 |
| 795 /** | 780 /** |
| 796 * A table mapping sources to the contents of those sources. This is used to o
verride the default | 781 * A table mapping sources to the contents of those sources. This is used to o
verride the default |
| 797 * contents of a source. | 782 * contents of a source. |
| 798 */ | 783 */ |
| 799 Map<Source, String> _contentMap = new Map<Source, String>(); | 784 Map<Source, String> _contentMap = new Map<Source, String>(); |
| 800 | 785 |
| 801 /** | 786 /** |
| 802 * A table mapping sources to the modification stamps of those sources. This i
s used when the | 787 * A table mapping sources to the modification stamps of those sources. This i
s used when the |
| 803 * default contents of a source has been overridden. | 788 * default contents of a source has been overridden. |
| 804 */ | 789 */ |
| 805 Map<Source, int> _stampMap = new Map<Source, int>(); | 790 Map<Source, int> _stampMap = new Map<Source, int>(); |
| 806 | 791 |
| 807 /** | 792 /** |
| 808 * Return the contents of the given source, or {@code null} if this cache does
not override the | 793 * Return the contents of the given source, or {@code null} if this cache does
not override the |
| 809 * contents of the source. | 794 * contents of the source. |
| 810 * <p> | 795 * <p> |
| 811 * <b>Note:</b> This method is not intended to be used except by{@link SourceF
actory#getContents(com.google.dart.engine.source.Source.ContentReceiver)}. | 796 * <b>Note:</b> This method is not intended to be used except by{@link SourceF
actory#getContents(com.google.dart.engine.source.Source.ContentReceiver)}. |
| 812 * @param source the source whose content is to be returned | 797 * @param source the source whose content is to be returned |
| 813 * @return the contents of the given source | 798 * @return the contents of the given source |
| 814 */ | 799 */ |
| 815 String getContents(Source source) => _contentMap[source]; | 800 String getContents(Source source) => _contentMap[source]; |
| 816 | 801 |
| 817 /** | 802 /** |
| 818 * Return the modification stamp of the given source, or {@code null} if this
cache does not | 803 * Return the modification stamp of the given source, or {@code null} if this
cache does not |
| 819 * override the contents of the source. | 804 * override the contents of the source. |
| 820 * <p> | 805 * <p> |
| 821 * <b>Note:</b> This method is not intended to be used except by{@link SourceF
actory#getModificationStamp(com.google.dart.engine.source.Source)}. | 806 * <b>Note:</b> This method is not intended to be used except by{@link SourceF
actory#getModificationStamp(com.google.dart.engine.source.Source)}. |
| 822 * @param source the source whose modification stamp is to be returned | 807 * @param source the source whose modification stamp is to be returned |
| 823 * @return the modification stamp of the given source | 808 * @return the modification stamp of the given source |
| 824 */ | 809 */ |
| 825 int getModificationStamp(Source source) => _stampMap[source]; | 810 int getModificationStamp(Source source) => _stampMap[source]; |
| 826 | 811 |
| 827 /** | 812 /** |
| 828 * Set the contents of the given source to the given contents. This has the ef
fect of overriding | 813 * Set the contents of the given source to the given contents. This has the ef
fect of overriding |
| 829 * the default contents of the source. If the contents are {@code null} the ov
erride is removed so | 814 * the default contents of the source. If the contents are {@code null} the ov
erride is removed so |
| 830 * that the default contents will be returned. | 815 * that the default contents will be returned. |
| 831 * @param source the source whose contents are being overridden | 816 * @param source the source whose contents are being overridden |
| 832 * @param contents the new contents of the source | 817 * @param contents the new contents of the source |
| 833 */ | 818 */ |
| 834 void setContents(Source source, String contents) { | 819 void setContents(Source source, String contents) { |
| 835 if (contents == null) { | 820 if (contents == null) { |
| 836 _contentMap.remove(source); | 821 _contentMap.remove(source); |
| 837 _stampMap.remove(source); | 822 _stampMap.remove(source); |
| 838 } else { | 823 } else { |
| 839 _contentMap[source] = contents; | 824 _contentMap[source] = contents; |
| 840 _stampMap[source] = JavaSystem.currentTimeMillis(); | 825 _stampMap[source] = JavaSystem.currentTimeMillis(); |
| 841 } | 826 } |
| 842 } | 827 } |
| 843 } | 828 } |
| OLD | NEW |