Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 3 | |
| 4 library engine; | |
| 5 | |
| 6 import 'java_core.dart'; | |
| 7 import 'dart:collection' show HasNextIterator; | |
| 8 import 'error.dart'; | |
| 9 import 'source.dart'; | |
| 10 import 'scanner.dart' show Token, CharBufferScanner, StringScanner; | |
| 11 import 'ast.dart' show CompilationUnit; | |
| 12 import 'parser.dart' show Parser; | |
| 13 import 'element.dart'; | |
| 14 import 'resolver.dart' show Namespace, NamespaceBuilder, LibraryResolver; | |
| 15 | |
| 16 /** | |
| 17 * The unique instance of the class {@code AnalysisEngine} serves as the entry p oint for the | |
| 18 * functionality provided by the analysis engine. | |
| 19 */ | |
| 20 class AnalysisEngine { | |
|
Jennifer Messerly
2013/02/13 21:36:54
Can't wait to try using this! Would be nice to hav
| |
| 21 /** | |
| 22 * The unique instance of this class. | |
| 23 */ | |
| 24 static AnalysisEngine _UniqueInstance = new AnalysisEngine(); | |
| 25 /** | |
| 26 * Return the unique instance of this class. | |
| 27 * @return the unique instance of this class | |
| 28 */ | |
| 29 static AnalysisEngine get instance => _UniqueInstance; | |
| 30 /** | |
| 31 * The logger that should receive information about errors within the analysis engine. | |
| 32 */ | |
| 33 Logger _logger = Logger.NULL; | |
| 34 /** | |
| 35 * Prevent the creation of instances of this class. | |
| 36 */ | |
| 37 AnalysisEngine() : super() { | |
| 38 } | |
| 39 /** | |
| 40 * Create a new context in which analysis can be performed. | |
| 41 * @return the analysis context that was created | |
| 42 */ | |
| 43 AnalysisContext createAnalysisContext() => new AnalysisContextImpl(); | |
| 44 /** | |
| 45 * Return the logger that should receive information about errors within the a nalysis engine. | |
| 46 * @return the logger that should receive information about errors within the analysis engine | |
| 47 */ | |
| 48 Logger get logger => _logger; | |
| 49 /** | |
| 50 * Set the logger that should receive information about errors within the anal ysis engine to the | |
| 51 * given logger. | |
| 52 * @param logger the logger that should receive information about errors withi n the analysis | |
| 53 * engine | |
| 54 */ | |
| 55 void set logger(Logger logger2) { | |
| 56 this._logger = logger2 == null ? Logger.NULL : logger2; | |
| 57 } | |
| 58 } | |
| 59 /** | |
| 60 * The interface {@code AnalysisContext} defines the behavior of objects that re present a context in | |
| 61 * which analysis can be performed. The context includes such information as the version of the SDK | |
| 62 * being analyzed against as well as the package-root used to resolve 'package:' URI's. This | |
| 63 * information is included indirectly through the {@link SourceFactory source fa ctory}. | |
| 64 * <p> | |
| 65 * Analysis engine allows for having more than one context. This can be used, fo r example, to | |
| 66 * perform one analysis based on the state of files on disk and a separate analy sis based on the | |
| 67 * state of those files in open editors. It can also be used to perform an analy sis based on a | |
| 68 * proposed future state, such as after a refactoring. | |
| 69 */ | |
| 70 abstract class AnalysisContext { | |
| 71 /** | |
| 72 * Clear any cached information that is dependent on resolution. This method s hould be invoked if | |
| 73 * the assumptions used by resolution have changed but the contents of the fil e have not changed. | |
| 74 * Use {@link #sourceChanged(Source)} and {@link #sourcesDeleted(SourceContain er)} to indicate | |
| 75 * when the contents of a file or files have changed. | |
| 76 */ | |
| 77 void clearResolution(); | |
| 78 /** | |
| 79 * Call this method when this context is no longer going to be used. At this p oint, the receiver | |
| 80 * may choose to push some of its information back into the global cache for c onsumption by | |
| 81 * another context for performance. | |
| 82 */ | |
| 83 void discard(); | |
| 84 /** | |
| 85 * Create a new context in which analysis can be performed. Any sources in the specified directory | |
| 86 * in the receiver will be removed from the receiver and added to the newly cr eated context. | |
| 87 * @param directory the directory (not {@code null}) containing sources that s hould be removed | |
| 88 * from the receiver and added to the returned context | |
| 89 * @return the analysis context that was created (not {@code null}) | |
| 90 */ | |
| 91 AnalysisContext extractAnalysisContext(SourceContainer container); | |
| 92 /** | |
| 93 * Answer the collection of sources that have been added to the receiver via{@ link #sourceAvailable(Source)} and not removed from the receiver via{@link #sour ceDeleted(Source)} or {@link #sourcesDeleted(SourceContainer)}. | |
| 94 * @return a collection of sources (not {@code null}, contains no {@code null} s) | |
| 95 */ | |
| 96 Collection<Source> get availableSources; | |
| 97 /** | |
| 98 * Return the element referenced by the given location. | |
| 99 * @param location the reference describing the element to be returned | |
| 100 * @return the element referenced by the given location | |
| 101 */ | |
| 102 Element getElement(ElementLocation location); | |
| 103 /** | |
| 104 * Return an array containing all of the errors associated with the given sour ce. | |
| 105 * @param source the source whose errors are to be returned | |
| 106 * @return all of the errors associated with the given source | |
| 107 * @throws AnalysisException if the errors could not be determined because the analysis could not | |
| 108 * be performed | |
| 109 */ | |
| 110 List<AnalysisError> getErrors(Source source); | |
| 111 /** | |
| 112 * Parse and build an element model for the HTML file defined by the given sou rce. | |
| 113 * @param source the source defining the HTML file whose element model is to b e returned | |
| 114 * @return the element model corresponding to the HTML file defined by the giv en source | |
| 115 */ | |
| 116 HtmlElement getHtmlElement(Source source); | |
| 117 /** | |
| 118 * Return the kind of the given source if it is already known, or {@code null} if the kind is not | |
| 119 * already known. | |
| 120 * @param source the source whose kind is to be returned | |
| 121 * @return the kind of the given source | |
| 122 * @see #getOrComputeKindOf(Source) | |
| 123 */ | |
| 124 SourceKind getKnownKindOf(Source source); | |
| 125 /** | |
| 126 * Return the element model corresponding to the library defined by the given source. If the | |
| 127 * element model does not yet exist it will be created. The process of creatin g an element model | |
| 128 * for a library can long-running, depending on the size of the library and th e number of | |
| 129 * libraries that are imported into it that also need to have a model built fo r them. | |
| 130 * @param source the source defining the library whose element model is to be returned | |
| 131 * @return the element model corresponding to the library defined by the given source or{@code null} if the element model could not be determined because the analysis could | |
| 132 * not be performed | |
| 133 */ | |
| 134 LibraryElement getLibraryElement(Source source); | |
| 135 /** | |
| 136 * Return the element model corresponding to the library defined by the given source, or{@code null} if the element model does not yet exist. | |
| 137 * @param source the source defining the library whose element model is to be returned | |
| 138 * @return the element model corresponding to the library defined by the given source | |
| 139 */ | |
| 140 LibraryElement getLibraryElementOrNull(Source source); | |
| 141 /** | |
| 142 * Return the kind of the given source, computing it's kind if it is not alrea dy known. | |
| 143 * @param source the source whose kind is to be returned | |
| 144 * @return the kind of the given source | |
| 145 * @see #getKnownKindOf(Source) | |
| 146 */ | |
| 147 SourceKind getOrComputeKindOf(Source source); | |
| 148 /** | |
| 149 * Return an array containing all of the parsing errors associated with the gi ven source. | |
| 150 * @param source the source whose errors are to be returned | |
| 151 * @return all of the parsing errors associated with the given source | |
| 152 * @throws AnalysisException if the errors could not be determined because the analysis could not | |
| 153 * be performed | |
| 154 */ | |
| 155 List<AnalysisError> getParsingErrors(Source source); | |
| 156 /** | |
| 157 * Return an array containing all of the resolution errors associated with the given source. | |
| 158 * @param source the source whose errors are to be returned | |
| 159 * @return all of the resolution errors associated with the given source | |
| 160 * @throws AnalysisException if the errors could not be determined because the analysis could not | |
| 161 * be performed | |
| 162 */ | |
| 163 List<AnalysisError> getResolutionErrors(Source source); | |
| 164 /** | |
| 165 * Return the source factory used to create the sources that can be analyzed i n this context. | |
| 166 * @return the source factory used to create the sources that can be analyzed in this context | |
| 167 */ | |
| 168 SourceFactory get sourceFactory; | |
| 169 /** | |
| 170 * Add the sources contained in the specified context to the receiver's collec tion of sources. | |
| 171 * This method is called when an existing context's pubspec has been removed, and the contained | |
| 172 * sources should be reanalyzed as part of the receiver. | |
| 173 * @param context the context being merged (not {@code null}) | |
| 174 */ | |
| 175 void mergeAnalysisContext(AnalysisContext context); | |
| 176 /** | |
| 177 * Parse a single source to produce an AST structure. The resulting AST struct ure may or may not | |
| 178 * be resolved, and may have a slightly different structure depending upon whe ther it is resolved. | |
| 179 * @param source the source to be parsed | |
| 180 * @return the AST structure representing the content of the source | |
| 181 * @throws AnalysisException if the analysis could not be performed | |
| 182 */ | |
| 183 CompilationUnit parse(Source source); | |
| 184 /** | |
| 185 * Parse and resolve a single source within the given context to produce a ful ly resolved AST. | |
| 186 * @param source the source to be parsed and resolved | |
| 187 * @param library the library defining the context in which the source file is to be resolved | |
| 188 * @return the result of resolving the AST structure representing the content of the source | |
| 189 * @throws AnalysisException if the analysis could not be performed | |
| 190 */ | |
| 191 CompilationUnit resolve(Source source, LibraryElement library); | |
| 192 /** | |
| 193 * Scan a single source to produce a token stream. | |
| 194 * @param source the source to be scanned | |
| 195 * @param errorListener the listener to which errors should be reported | |
| 196 * @return the head of the token stream representing the content of the source | |
| 197 * @throws AnalysisException if the analysis could not be performed | |
| 198 */ | |
| 199 Token scan(Source source, AnalysisErrorListener errorListener); | |
| 200 /** | |
| 201 * Set the source factory used to create the sources that can be analyzed in t his context to the | |
| 202 * given source factory. | |
| 203 * @param sourceFactory the source factory used to create the sources that can be analyzed in this | |
| 204 * context | |
| 205 */ | |
| 206 void set sourceFactory(SourceFactory sourceFactory4); | |
| 207 /** | |
| 208 * Cache the fact that content for the given source is now available, is of in terest to the | |
| 209 * client, and should be analyzed. Do not modify or discard any information ab out this source that | |
| 210 * is already cached. | |
| 211 * @param source the source that is now available | |
| 212 */ | |
| 213 void sourceAvailable(Source source); | |
| 214 /** | |
| 215 * Respond to the fact that the content of the given source has changed by rem oving any cached | |
| 216 * information that might now be out-of-date. | |
| 217 * @param source the source whose content has changed | |
| 218 */ | |
| 219 void sourceChanged(Source source); | |
| 220 /** | |
| 221 * Respond to the fact that the given source has been deleted and should no lo nger be analyzed by | |
| 222 * removing any cached information that might now be out-of-date. | |
| 223 * @param source the source that was deleted | |
| 224 */ | |
| 225 void sourceDeleted(Source source); | |
| 226 /** | |
| 227 * Discard cached information for all files in the specified source container. | |
| 228 * @param container the source container that was deleted (not {@code null}) | |
| 229 */ | |
| 230 void sourcesDeleted(SourceContainer container); | |
| 231 /** | |
| 232 * Given a collection of sources with content that has changed, return an {@li nk Iterable}identifying the sources that need to be resolved. | |
| 233 * @param changedSources an array of sources (not {@code null}, contains no {@ code null}s) | |
| 234 * @return An iterable returning the sources to be resolved | |
| 235 */ | |
| 236 Iterable<Source> sourcesToResolve(List<Source> changedSources); | |
| 237 } | |
| 238 /** | |
| 239 * Instances of the class {@code AnalysisException} represent an exception that occurred during the | |
| 240 * analysis of one or more sources. | |
| 241 */ | |
| 242 class AnalysisException extends JavaException { | |
| 243 /** | |
| 244 * Initialize a newly created exception. | |
| 245 */ | |
| 246 AnalysisException() : super() { | |
| 247 _jtd_constructor_117_impl(); | |
| 248 } | |
| 249 _jtd_constructor_117_impl() { | |
| 250 } | |
| 251 /** | |
| 252 * Initialize a newly created exception to have the given message. | |
| 253 * @param message the message associated with the exception | |
| 254 */ | |
| 255 AnalysisException.con1(String message) : super(message) { | |
| 256 _jtd_constructor_118_impl(message); | |
| 257 } | |
| 258 _jtd_constructor_118_impl(String message) { | |
| 259 } | |
| 260 /** | |
| 261 * Initialize a newly created exception to have the given message and cause. | |
| 262 * @param message the message associated with the exception | |
| 263 * @param cause the underlying exception that caused this exception | |
| 264 */ | |
| 265 AnalysisException.con2(String message, Exception cause) : super(message, cause ) { | |
| 266 _jtd_constructor_119_impl(message, cause); | |
| 267 } | |
| 268 _jtd_constructor_119_impl(String message, Exception cause) { | |
| 269 } | |
| 270 /** | |
| 271 * Initialize a newly created exception to have the given cause. | |
| 272 * @param cause the underlying exception that caused this exception | |
| 273 */ | |
| 274 AnalysisException.con3(Exception cause) : super.withCause(cause) { | |
| 275 _jtd_constructor_120_impl(cause); | |
| 276 } | |
| 277 _jtd_constructor_120_impl(Exception cause) { | |
| 278 } | |
| 279 } | |
| 280 /** | |
| 281 * Instances of the class {@code AnalysisContextImpl} implement an {@link Analys isContext analysis | |
| 282 * context}. | |
| 283 */ | |
| 284 class AnalysisContextImpl implements AnalysisContext { | |
| 285 /** | |
| 286 * The source factory used to create the sources that can be analyzed in this context. | |
| 287 */ | |
| 288 SourceFactory _sourceFactory; | |
| 289 /** | |
| 290 * A cache mapping sources to the compilation units that were produced for the contents of the | |
| 291 * source. | |
| 292 */ | |
| 293 Map<Source, CompilationUnit> _parseCache = new Map<Source, CompilationUnit>(); | |
| 294 /** | |
| 295 * A cache mapping sources (of the defining compilation units of libraries) to the library | |
| 296 * elements for those libraries. | |
| 297 */ | |
| 298 Map<Source, LibraryElement> _libraryElementCache = new Map<Source, LibraryElem ent>(); | |
| 299 /** | |
| 300 * A cache mapping sources (of the defining compilation units of libraries) to the public | |
| 301 * namespace for that library. | |
| 302 */ | |
| 303 Map<Source, Namespace> _publicNamespaceCache = new Map<Source, Namespace>(); | |
| 304 /** | |
| 305 * A cache of the available sources of interest to the client. Sources are add ed to this | |
| 306 * collection via {@link #sourceAvailable(Source)} and removed from this colle ction via{@link #sourceDeleted(Source)} and {@link #directoryDeleted(File)} | |
| 307 */ | |
| 308 Set<Source> _availableSources = new Set<Source>(); | |
| 309 /** | |
| 310 * The object used to synchronize access to all of the caches. | |
| 311 */ | |
| 312 Object _cacheLock = new Object(); | |
| 313 /** | |
| 314 * The suffix used by sources that contain Dart. | |
| 315 */ | |
| 316 static String _DART_SUFFIX = ".dart"; | |
| 317 /** | |
| 318 * The suffix used by sources that contain HTML. | |
| 319 */ | |
| 320 static String _HTML_SUFFIX = ".html"; | |
| 321 /** | |
| 322 * Initialize a newly created analysis context. | |
| 323 */ | |
| 324 AnalysisContextImpl() : super() { | |
| 325 } | |
| 326 void clearResolution() { | |
| 327 { | |
| 328 _parseCache.clear(); | |
| 329 _libraryElementCache.clear(); | |
| 330 _publicNamespaceCache.clear(); | |
| 331 } | |
| 332 } | |
| 333 void discard() { | |
| 334 { | |
| 335 _parseCache.clear(); | |
| 336 _libraryElementCache.clear(); | |
| 337 _publicNamespaceCache.clear(); | |
| 338 _availableSources.clear(); | |
| 339 } | |
| 340 } | |
| 341 AnalysisContext extractAnalysisContext(SourceContainer container) { | |
| 342 AnalysisContext newContext = AnalysisEngine.instance.createAnalysisContext() ; | |
| 343 { | |
| 344 JavaIterator<Source> iter = new JavaIterator(_availableSources); | |
| 345 while (iter.hasNext) { | |
| 346 Source source = iter.next(); | |
| 347 if (container.contains(source)) { | |
| 348 iter.remove(); | |
| 349 newContext.sourceAvailable(source); | |
| 350 } | |
| 351 } | |
| 352 } | |
| 353 return newContext; | |
| 354 } | |
| 355 Collection<Source> get availableSources { | |
| 356 { | |
| 357 return new List<Source>.from(_availableSources); | |
| 358 } | |
| 359 } | |
| 360 Element getElement(ElementLocation location) { | |
| 361 throw new UnsupportedOperationException(); | |
| 362 } | |
| 363 List<AnalysisError> getErrors(Source source) { | |
| 364 throw new UnsupportedOperationException(); | |
| 365 } | |
| 366 HtmlElement getHtmlElement(Source source) { | |
| 367 throw new UnsupportedOperationException(); | |
| 368 } | |
| 369 SourceKind getKnownKindOf(Source source) { | |
| 370 if (source.fullName.endsWith(_HTML_SUFFIX)) { | |
| 371 return SourceKind.HTML; | |
| 372 } | |
| 373 if (!source.fullName.endsWith(_DART_SUFFIX)) { | |
| 374 return SourceKind.UNKNOWN; | |
| 375 } | |
| 376 { | |
| 377 if (_libraryElementCache.containsKey(source)) { | |
| 378 return SourceKind.LIBRARY; | |
| 379 } | |
| 380 CompilationUnit unit = _parseCache[source]; | |
| 381 if (unit != null && hasPartOfDirective(unit)) { | |
| 382 return SourceKind.PART; | |
| 383 } | |
| 384 } | |
| 385 return null; | |
| 386 } | |
| 387 LibraryElement getLibraryElement(Source source) { | |
| 388 { | |
| 389 LibraryElement element = _libraryElementCache[source]; | |
| 390 if (element == null) { | |
| 391 RecordingErrorListener listener = new RecordingErrorListener(); | |
| 392 LibraryResolver resolver = new LibraryResolver(this, listener); | |
| 393 try { | |
| 394 element = resolver.resolveLibrary(source, true); | |
| 395 } on AnalysisException catch (exception) { | |
| 396 AnalysisEngine.instance.logger.logError2("Could not resolve the librar y ${source.fullName}", exception); | |
| 397 } | |
| 398 } | |
| 399 return element; | |
| 400 } | |
| 401 } | |
| 402 /** | |
| 403 * Return the element model corresponding to the library defined by the given source, or{@code null} if the element model does not yet exist. | |
| 404 * @param source the source defining the library whose element model is to be returned | |
| 405 * @return the element model corresponding to the library defined by the given source | |
| 406 */ | |
| 407 LibraryElement getLibraryElementOrNull(Source source) { | |
| 408 { | |
| 409 return _libraryElementCache[source]; | |
| 410 } | |
| 411 } | |
| 412 SourceKind getOrComputeKindOf(Source source) { | |
| 413 SourceKind kind = getKnownKindOf(source); | |
| 414 if (kind != null) { | |
| 415 return kind; | |
| 416 } | |
| 417 try { | |
| 418 if (hasPartOfDirective(parse(source))) { | |
| 419 return SourceKind.PART; | |
| 420 } | |
| 421 } on AnalysisException catch (exception) { | |
| 422 return SourceKind.UNKNOWN; | |
| 423 } | |
| 424 return SourceKind.LIBRARY; | |
| 425 } | |
| 426 List<AnalysisError> getParsingErrors(Source source) { | |
| 427 throw new UnsupportedOperationException(); | |
| 428 } | |
| 429 /** | |
| 430 * Return a namespace containing mappings for all of the public names defined by the given | |
| 431 * library. | |
| 432 * @param library the library whose public namespace is to be returned | |
| 433 * @return the public namespace of the given library | |
| 434 */ | |
| 435 Namespace getPublicNamespace(LibraryElement library) { | |
| 436 Source source7 = library.definingCompilationUnit.source; | |
| 437 { | |
| 438 Namespace namespace = _publicNamespaceCache[source7]; | |
| 439 if (namespace == null) { | |
| 440 NamespaceBuilder builder = new NamespaceBuilder(); | |
| 441 namespace = builder.createPublicNamespace(library); | |
| 442 _publicNamespaceCache[source7] = namespace; | |
| 443 } | |
| 444 return namespace; | |
| 445 } | |
| 446 } | |
| 447 /** | |
| 448 * Return a namespace containing mappings for all of the public names defined by the library | |
| 449 * defined by the given source. | |
| 450 * @param source the source defining the library whose public namespace is to be returned | |
| 451 * @return the public namespace corresponding to the library defined by the gi ven source | |
| 452 */ | |
| 453 Namespace getPublicNamespace2(Source source) { | |
| 454 { | |
| 455 Namespace namespace = _publicNamespaceCache[source]; | |
| 456 if (namespace == null) { | |
| 457 LibraryElement library = getLibraryElement(source); | |
| 458 if (library == null) { | |
| 459 return null; | |
| 460 } | |
| 461 NamespaceBuilder builder = new NamespaceBuilder(); | |
| 462 namespace = builder.createPublicNamespace(library); | |
| 463 _publicNamespaceCache[source] = namespace; | |
| 464 } | |
| 465 return namespace; | |
| 466 } | |
| 467 } | |
| 468 List<AnalysisError> getResolutionErrors(Source source) { | |
| 469 throw new UnsupportedOperationException(); | |
| 470 } | |
| 471 SourceFactory get sourceFactory => _sourceFactory; | |
| 472 void mergeAnalysisContext(AnalysisContext context) { | |
| 473 { | |
| 474 _availableSources.addAll(context.availableSources); | |
| 475 } | |
| 476 } | |
| 477 CompilationUnit parse(Source source) { | |
| 478 { | |
| 479 CompilationUnit unit = _parseCache[source]; | |
| 480 if (unit == null) { | |
| 481 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
| 482 Token token = scan(source, errorListener); | |
| 483 Parser parser = new Parser(source, errorListener); | |
| 484 unit = parser.parseCompilationUnit(token); | |
| 485 unit.parsingErrors = errorListener.errors; | |
| 486 _parseCache[source] = unit; | |
| 487 } | |
| 488 return unit; | |
| 489 } | |
| 490 } | |
| 491 CompilationUnit parse2(Source source, AnalysisErrorListener errorListener) { | |
| 492 { | |
| 493 CompilationUnit unit = _parseCache[source]; | |
| 494 if (unit == null) { | |
| 495 Token token = scan(source, errorListener); | |
| 496 Parser parser = new Parser(source, errorListener); | |
| 497 unit = parser.parseCompilationUnit(token); | |
| 498 _parseCache[source] = unit; | |
| 499 } | |
| 500 return unit; | |
| 501 } | |
| 502 } | |
| 503 /** | |
| 504 * Given a table mapping the source for the libraries represented by the corre sponding elements to | |
| 505 * the elements representing the libraries, record those mappings. | |
| 506 * @param elementMap a table mapping the source for the libraries represented by the elements to | |
| 507 * the elements representing the libraries | |
| 508 */ | |
| 509 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { | |
| 510 { | |
| 511 javaMapPutAll(_libraryElementCache, elementMap); | |
| 512 } | |
| 513 } | |
| 514 CompilationUnit resolve(Source source, LibraryElement library) => parse(source ); | |
| 515 Token scan(Source source, AnalysisErrorListener errorListener) { | |
| 516 List<Token> tokens = new List<Token>.fixedLength(1); | |
| 517 Source_ContentReceiver receiver = new Source_ContentReceiver_1(source, error Listener, tokens); | |
| 518 try { | |
| 519 source.getContents(receiver); | |
| 520 } on JavaException catch (exception) { | |
| 521 } | |
| 522 return tokens[0]; | |
| 523 } | |
| 524 void set sourceFactory(SourceFactory sourceFactory2) { | |
| 525 this._sourceFactory = sourceFactory2; | |
| 526 } | |
| 527 void sourceAvailable(Source source) { | |
| 528 { | |
| 529 javaSetAdd(_availableSources, source); | |
| 530 } | |
| 531 } | |
| 532 void sourceChanged(Source source) { | |
| 533 { | |
| 534 _parseCache.remove(source); | |
| 535 _libraryElementCache.remove(source); | |
| 536 _publicNamespaceCache.remove(source); | |
| 537 } | |
| 538 } | |
| 539 void sourceDeleted(Source source) { | |
| 540 { | |
| 541 _availableSources.remove(source); | |
| 542 sourceChanged(source); | |
| 543 } | |
| 544 } | |
| 545 void sourcesDeleted(SourceContainer container) { | |
| 546 { | |
| 547 _parseCache.clear(); | |
| 548 _libraryElementCache.clear(); | |
| 549 _publicNamespaceCache.clear(); | |
| 550 JavaIterator<Source> iter = new JavaIterator(_availableSources); | |
| 551 while (iter.hasNext) { | |
| 552 if (container.contains(iter.next())) { | |
| 553 iter.remove(); | |
| 554 } | |
| 555 } | |
| 556 } | |
| 557 } | |
| 558 Iterable<Source> sourcesToResolve(List<Source> changedSources) => JavaArrays.a sList(changedSources); | |
| 559 /** | |
| 560 * Return {@code true} if the given compilation unit has a part-of directive. | |
| 561 * @param unit the compilation unit being tested | |
| 562 * @return {@code true} if the compilation unit has a part-of directive | |
| 563 */ | |
| 564 bool hasPartOfDirective(CompilationUnit unit) { | |
| 565 for (Directive directive in unit.directives) { | |
| 566 if (directive is PartOfDirective) { | |
| 567 return true; | |
| 568 } | |
| 569 } | |
| 570 return false; | |
| 571 } | |
| 572 } | |
| 573 class Source_ContentReceiver_1 implements Source_ContentReceiver { | |
| 574 Source source; | |
| 575 AnalysisErrorListener errorListener; | |
| 576 List<Token> tokens; | |
| 577 Source_ContentReceiver_1(this.source, this.errorListener, this.tokens); | |
| 578 accept(CharBuffer contents) { | |
| 579 CharBufferScanner scanner = new CharBufferScanner(source, contents, errorLis tener); | |
| 580 tokens[0] = scanner.tokenize(); | |
| 581 } | |
| 582 void accept2(String contents) { | |
| 583 StringScanner scanner = new StringScanner(source, contents, errorListener); | |
| 584 tokens[0] = scanner.tokenize(); | |
| 585 } | |
| 586 } | |
| 587 /** | |
| 588 * Instances of the class {@code RecordingErrorListener} implement an error list ener that will | |
| 589 * record the errors that are reported to it in a way that is appropriate for ca ching those errors | |
| 590 * within an analysis context. | |
| 591 */ | |
| 592 class RecordingErrorListener implements AnalysisErrorListener { | |
| 593 /** | |
| 594 * A list containing the errors that were collected. | |
| 595 */ | |
| 596 List<AnalysisError> _errors = null; | |
| 597 /** | |
| 598 * Answer the errors collected by the listener. | |
| 599 * @return an array of errors (not {@code null}, contains no {@code null}s) | |
| 600 */ | |
| 601 List<AnalysisError> get errors => _errors != null ? new List.from(_errors) : A nalysisError.NO_ERRORS; | |
| 602 void onError(AnalysisError event) { | |
| 603 if (_errors == null) { | |
| 604 _errors = new List<AnalysisError>(); | |
| 605 } | |
| 606 _errors.add(event); | |
| 607 } | |
| 608 } | |
| 609 /** | |
| 610 * The interface {@code Logger} defines the behavior of objects that can be used to receive | |
| 611 * information about errors within the analysis engine. Implementations usually write this | |
| 612 * information to a file, but can also record the information for later use (suc h as during testing) | |
| 613 * or even ignore the information. | |
| 614 */ | |
| 615 abstract class Logger { | |
| 616 static Logger NULL = new Logger_NullLogger(); | |
| 617 /** | |
| 618 * Log the given message as an error. | |
| 619 * @param message an explanation of why the error occurred or what it means | |
| 620 */ | |
| 621 void logError(String message); | |
| 622 /** | |
| 623 * Log the given exception as one representing an error. | |
| 624 * @param message an explanation of why the error occurred or what it means | |
| 625 * @param exception the exception being logged | |
| 626 */ | |
| 627 void logError2(String message, Exception exception); | |
| 628 /** | |
| 629 * Log the given exception as one representing an error. | |
| 630 * @param exception the exception being logged | |
| 631 */ | |
| 632 void logError3(Exception exception); | |
| 633 /** | |
| 634 * Log the given informational message. | |
| 635 * @param message an explanation of why the error occurred or what it means | |
| 636 * @param exception the exception being logged | |
| 637 */ | |
| 638 void logInformation(String message); | |
| 639 /** | |
| 640 * Log the given exception as one representing an informational message. | |
| 641 * @param message an explanation of why the error occurred or what it means | |
| 642 * @param exception the exception being logged | |
| 643 */ | |
| 644 void logInformation2(String message, Exception exception); | |
| 645 } | |
| 646 /** | |
| 647 * Implementation of {@link Logger} that does nothing. | |
| 648 */ | |
| 649 class Logger_NullLogger implements Logger { | |
| 650 void logError(String message) { | |
| 651 } | |
| 652 void logError2(String message, Exception exception) { | |
| 653 } | |
| 654 void logError3(Exception exception) { | |
| 655 } | |
| 656 void logInformation(String message) { | |
| 657 } | |
| 658 void logInformation2(String message, Exception exception) { | |
| 659 } | |
| 660 } | |
| OLD | NEW |