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

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

Issue 12838003: Rename analyzer-experimental to analyzer_experimental. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 'java_engine.dart';
8 import 'dart:collection' show HasNextIterator;
9 import 'error.dart';
10 import 'source.dart';
11 import 'scanner.dart' show Token, CharBufferScanner, StringScanner;
12 import 'ast.dart' show CompilationUnit, Directive, PartOfDirective;
13 import 'parser.dart' show Parser;
14 import 'element.dart';
15 import 'resolver.dart' show Namespace, NamespaceBuilder, LibraryResolver;
16 import 'html.dart' show HtmlScanner, HtmlScanResult, HtmlParser, HtmlParseResult ;
17
18 /**
19 * The unique instance of the class {@code AnalysisEngine} serves as the entry p oint for the
20 * functionality provided by the analysis engine.
21 * @coverage dart.engine
22 */
23 class AnalysisEngine {
24 /**
25 * The suffix used for Dart source files.
26 */
27 static String SUFFIX_DART = "dart";
28 /**
29 * The short suffix used for HTML files.
30 */
31 static String SUFFIX_HTM = "htm";
32 /**
33 * The long suffix used for HTML files.
34 */
35 static String SUFFIX_HTML = "html";
36 /**
37 * The unique instance of this class.
38 */
39 static AnalysisEngine _UniqueInstance = new AnalysisEngine();
40 /**
41 * Return the unique instance of this class.
42 * @return the unique instance of this class
43 */
44 static AnalysisEngine get instance => _UniqueInstance;
45 /**
46 * Return {@code true} if the given file name is assumed to contain Dart sourc e code.
47 * @param fileName the name of the file being tested
48 * @return {@code true} if the given file name is assumed to contain Dart sour ce code
49 */
50 static bool isDartFileName(String fileName) {
51 if (fileName == null) {
52 return false;
53 }
54 return javaStringEqualsIgnoreCase(FileNameUtilities.getExtension(fileName), SUFFIX_DART);
55 }
56 /**
57 * Return {@code true} if the given file name is assumed to contain HTML.
58 * @param fileName the name of the file being tested
59 * @return {@code true} if the given file name is assumed to contain HTML
60 */
61 static bool isHtmlFileName(String fileName) {
62 if (fileName == null) {
63 return false;
64 }
65 String extension = FileNameUtilities.getExtension(fileName);
66 return javaStringEqualsIgnoreCase(extension, SUFFIX_HTML) || javaStringEqual sIgnoreCase(extension, SUFFIX_HTM);
67 }
68 /**
69 * The logger that should receive information about errors within the analysis engine.
70 */
71 Logger _logger = Logger.NULL;
72 /**
73 * Prevent the creation of instances of this class.
74 */
75 AnalysisEngine() : super() {
76 }
77 /**
78 * Create a new context in which analysis can be performed.
79 * @return the analysis context that was created
80 */
81 AnalysisContext createAnalysisContext() => new AnalysisContextImpl();
82 /**
83 * Return the logger that should receive information about errors within the a nalysis engine.
84 * @return the logger that should receive information about errors within the analysis engine
85 */
86 Logger get logger => _logger;
87 /**
88 * Set the logger that should receive information about errors within the anal ysis engine to the
89 * given logger.
90 * @param logger the logger that should receive information about errors withi n the analysis
91 * engine
92 */
93 void set logger(Logger logger2) {
94 this._logger = logger2 == null ? Logger.NULL : logger2;
95 }
96 }
97 /**
98 * The interface {@code AnalysisContext} defines the behavior of objects that re present a context in
99 * which analysis can be performed. The context includes such information as the version of the SDK
100 * being analyzed against as well as the package-root used to resolve 'package:' URI's. (The latter
101 * is included indirectly through the {@link SourceFactory source factory}.)
102 * <p>
103 * Analysis engine allows for having more than one context. This can be used, fo r example, to
104 * perform one analysis based on the state of files on disk and a separate analy sis based on the
105 * state of those files in open editors. It can also be used to perform an analy sis based on a
106 * proposed future state, such as the state after a refactoring.
107 */
108 abstract class AnalysisContext {
109 /**
110 * Respond to the given set of changes by removing any cached information that might now be
111 * out-of-date. The result indicates what operations need to be performed as a result of this
112 * change without actually performing those operations.
113 * @param changeSet a description of the changes that have occurred
114 * @return a result (not {@code null}) indicating operations to be performed
115 */
116 ChangeResult changed(ChangeSet changeSet);
117 /**
118 * Clear any cached information that is dependent on resolution. This method s hould be invoked if
119 * the assumptions used by resolution have changed but the contents of the fil e have not changed.
120 * Use {@link #sourceChanged(Source)} and {@link #sourcesDeleted(SourceContain er)} to indicate
121 * when the contents of a file or files have changed.
122 */
123 void clearResolution();
124 /**
125 * Call this method when this context is no longer going to be used. At this p oint, the receiver
126 * may choose to push some of its information back into the global cache for c onsumption by
127 * another context for performance.
128 */
129 void discard();
130 /**
131 * Create a new context in which analysis can be performed. Any sources in the specified directory
132 * in the receiver will be removed from the receiver and added to the newly cr eated context.
133 * @param directory the directory (not {@code null}) containing sources that s hould be removed
134 * from the receiver and added to the returned context
135 * @return the analysis context that was created (not {@code null})
136 */
137 AnalysisContext extractAnalysisContext(SourceContainer container);
138 /**
139 * Return the element referenced by the given location.
140 * @param location the reference describing the element to be returned
141 * @return the element referenced by the given location
142 */
143 Element getElement(ElementLocation location);
144 /**
145 * Return an array containing all of the errors associated with the given sour ce.
146 * @param source the source whose errors are to be returned
147 * @return all of the errors associated with the given source
148 * @throws AnalysisException if the errors could not be determined because the analysis could not
149 * be performed
150 */
151 List<AnalysisError> getErrors(Source source);
152 /**
153 * Parse and build an element model for the HTML file defined by the given sou rce.
154 * @param source the source defining the HTML file whose element model is to b e returned
155 * @return the element model corresponding to the HTML file defined by the giv en source
156 */
157 HtmlElement getHtmlElement(Source source);
158 /**
159 * Return the kind of the given source if it is already known, or {@code null} if the kind is not
160 * already known.
161 * @param source the source whose kind is to be returned
162 * @return the kind of the given source
163 * @see #getOrComputeKindOf(Source)
164 */
165 SourceKind getKnownKindOf(Source source);
166 /**
167 * Return the sources for the defining compilation units of any libraries of w hich the given
168 * source is a part. The array will normally contain a single library because most Dart sources
169 * are only included in a single library, but it is possible to have a part th at is contained in
170 * multiple identically named libraries. If the source represents the defining compilation unit of
171 * a library, then the returned array will contain the given source as its onl y element. If the
172 * source does not represent a Dart source or is not known to this context, th e returned array
173 * will be empty.
174 * @param source the source contained in the returned libraries
175 * @return the sources for the libraries containing the given source
176 */
177 List<Source> getLibrariesContaining(Source source);
178 /**
179 * Return the element model corresponding to the library defined by the given source. If the
180 * element model does not yet exist it will be created. The process of creatin g an element model
181 * for a library can long-running, depending on the size of the library and th e number of
182 * libraries that are imported into it that also need to have a model built fo r them.
183 * @param source the source defining the library whose element model is to be returned
184 * @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
185 * not be performed
186 */
187 LibraryElement getLibraryElement(Source source);
188 /**
189 * Return the element model corresponding to the library defined by the given source, or{@code null} if the element model does not yet exist.
190 * @param source the source defining the library whose element model is to be returned
191 * @return the element model corresponding to the library defined by the given source
192 */
193 LibraryElement getLibraryElementOrNull(Source source);
194 /**
195 * Return the kind of the given source, computing it's kind if it is not alrea dy known.
196 * @param source the source whose kind is to be returned
197 * @return the kind of the given source
198 * @see #getKnownKindOf(Source)
199 */
200 SourceKind getOrComputeKindOf(Source source);
201 /**
202 * Return an array containing all of the parsing errors associated with the gi ven source.
203 * @param source the source whose errors are to be returned
204 * @return all of the parsing errors associated with the given source
205 * @throws AnalysisException if the errors could not be determined because the analysis could not
206 * be performed
207 */
208 List<AnalysisError> getParsingErrors(Source source);
209 /**
210 * Return an array containing all of the resolution errors associated with the given source.
211 * @param source the source whose errors are to be returned
212 * @return all of the resolution errors associated with the given source
213 * @throws AnalysisException if the errors could not be determined because the analysis could not
214 * be performed
215 */
216 List<AnalysisError> getResolutionErrors(Source source);
217 /**
218 * Return the source factory used to create the sources that can be analyzed i n this context.
219 * @return the source factory used to create the sources that can be analyzed in this context
220 */
221 SourceFactory get sourceFactory;
222 /**
223 * Add the sources contained in the specified context to the receiver's collec tion of sources.
224 * This method is called when an existing context's pubspec has been removed, and the contained
225 * sources should be reanalyzed as part of the receiver.
226 * @param context the context being merged (not {@code null})
227 */
228 void mergeAnalysisContext(AnalysisContext context);
229 /**
230 * Parse a single source to produce an AST structure. The resulting AST struct ure may or may not
231 * be resolved, and may have a slightly different structure depending upon whe ther it is resolved.
232 * @param source the source to be parsed
233 * @return the AST structure representing the content of the source
234 * @throws AnalysisException if the analysis could not be performed
235 */
236 CompilationUnit parse(Source source);
237 /**
238 * Parse a single HTML source to produce an AST structure. The resulting HTML AST structure may or
239 * may not be resolved, and may have a slightly different structure depending upon whether it is
240 * resolved.
241 * @param source the HTML source to be parsed
242 * @return the parse result (not {@code null})
243 * @throws AnalysisException if the analysis could not be performed
244 */
245 HtmlParseResult parseHtml(Source source);
246 /**
247 * Parse and resolve a single source within the given context to produce a ful ly resolved AST.
248 * @param source the source to be parsed and resolved
249 * @param library the library defining the context in which the source file is to be resolved
250 * @return the result of resolving the AST structure representing the content of the source
251 * @throws AnalysisException if the analysis could not be performed
252 */
253 CompilationUnit resolve(Source source, LibraryElement library);
254 /**
255 * Scan a single source to produce a token stream.
256 * @param source the source to be scanned
257 * @param errorListener the listener to which errors should be reported
258 * @return the head of the token stream representing the content of the source
259 * @throws AnalysisException if the analysis could not be performed
260 */
261 Token scan(Source source, AnalysisErrorListener errorListener);
262 /**
263 * Scan a single source to produce an HTML token stream.
264 * @param source the source to be scanned
265 * @return the scan result (not {@code null})
266 * @throws AnalysisException if the analysis could not be performed
267 */
268 HtmlScanResult scanHtml(Source source);
269 /**
270 * Set the source factory used to create the sources that can be analyzed in t his context to the
271 * given source factory.
272 * @param sourceFactory the source factory used to create the sources that can be analyzed in this
273 * context
274 */
275 void set sourceFactory(SourceFactory sourceFactory4);
276 /**
277 * Given a collection of sources with content that has changed, return an {@li nk Iterable}identifying the sources that need to be resolved.
278 * @param changedSources an array of sources (not {@code null}, contains no {@ code null}s)
279 * @return An iterable returning the sources to be resolved
280 */
281 Iterable<Source> sourcesToResolve(List<Source> changedSources);
282 }
283 /**
284 * Instances of the class {@code AnalysisException} represent an exception that occurred during the
285 * analysis of one or more sources.
286 * @coverage dart.engine
287 */
288 class AnalysisException extends JavaException {
289 /**
290 * Initialize a newly created exception.
291 */
292 AnalysisException() : super() {
293 _jtd_constructor_121_impl();
294 }
295 _jtd_constructor_121_impl() {
296 }
297 /**
298 * Initialize a newly created exception to have the given message.
299 * @param message the message associated with the exception
300 */
301 AnalysisException.con1(String message) : super(message) {
302 _jtd_constructor_122_impl(message);
303 }
304 _jtd_constructor_122_impl(String message) {
305 }
306 /**
307 * Initialize a newly created exception to have the given message and cause.
308 * @param message the message associated with the exception
309 * @param cause the underlying exception that caused this exception
310 */
311 AnalysisException.con2(String message, Exception cause) : super(message, cause ) {
312 _jtd_constructor_123_impl(message, cause);
313 }
314 _jtd_constructor_123_impl(String message, Exception cause) {
315 }
316 /**
317 * Initialize a newly created exception to have the given cause.
318 * @param cause the underlying exception that caused this exception
319 */
320 AnalysisException.con3(Exception cause) : super.withCause(cause) {
321 _jtd_constructor_124_impl(cause);
322 }
323 _jtd_constructor_124_impl(Exception cause) {
324 }
325 }
326 /**
327 * Instances of {@code ChangeResult} are returned by {@link AnalysisContext#chan ged(ChangeSet)} to
328 * indicate what operations need to be performed as a result of the change.
329 * @coverage dart.engine
330 */
331 class ChangeResult {
332 }
333 /**
334 * Instances of the class {@code ChangeSet} indicate what sources have been adde d, changed, or
335 * removed.
336 * @coverage dart.engine
337 */
338 class ChangeSet {
339 /**
340 * A table mapping the sources that have been added to their contents.
341 */
342 Map<Source, String> _added3 = new Map<Source, String>();
343 /**
344 * A table mapping the sources that have been changed to their contents.
345 */
346 Map<Source, String> _changed3 = new Map<Source, String>();
347 /**
348 * A list containing the sources that have been removed..
349 */
350 List<Source> _removed2 = new List<Source>();
351 /**
352 * A list containing the source containers specifying additional sources that have been removed.
353 */
354 List<SourceContainer> _removedContainers = new List<SourceContainer>();
355 /**
356 * Initialize a newly created change set to be empty.
357 */
358 ChangeSet() : super() {
359 }
360 /**
361 * Record that the specified source has been added and that it's content is th e default contents
362 * of the source.
363 * @param source the source that was added
364 */
365 void added(Source source) {
366 added2(source, null);
367 }
368 /**
369 * Record that the specified source has been added and that it has the given c ontent. If the
370 * content is non-{@code null}, this has the effect of overriding the default contents of the
371 * source. If the contents are {@code null}, any previous the override is remo ved so that the
372 * default contents will be used.
373 * @param source the source that was added
374 * @param content the content of the new source
375 */
376 void added2(Source source, String content) {
377 if (source != null) {
378 _added3[source] = content;
379 }
380 }
381 /**
382 * Record that the specified source has been changed and that it's content is the default contents
383 * of the source.
384 * @param source the source that was changed
385 */
386 void changed(Source source) {
387 changed2(source, null);
388 }
389 /**
390 * Record that the specified source has been changed and that it now has the g iven content. If the
391 * content is non-{@code null}, this has the effect of overriding the default contents of the
392 * source. If the contents are {@code null}, any previous the override is remo ved so that the
393 * default contents will be used.
394 * @param source the source that was changed
395 * @param content the new content of the source
396 */
397 void changed2(Source source, String content) {
398 if (source != null) {
399 _changed3[source] = content;
400 }
401 }
402 /**
403 * Return a table mapping the sources that have been added to their contents.
404 * @return a table mapping the sources that have been added to their contents
405 */
406 Map<Source, String> get addedWithContent => _added3;
407 /**
408 * Return a table mapping the sources that have been changed to their contents .
409 * @return a table mapping the sources that have been changed to their content s
410 */
411 Map<Source, String> get changedWithContent => _changed3;
412 /**
413 * Return a list containing the sources that were removed.
414 * @return a list containing the sources that were removed
415 */
416 List<Source> get removed => _removed2;
417 /**
418 * Return a list containing the source containers that were removed.
419 * @return a list containing the source containers that were removed
420 */
421 List<SourceContainer> get removedContainers => _removedContainers;
422 /**
423 * Return {@code true} if this change set does not contain any changes.
424 * @return {@code true} if this change set does not contain any changes
425 */
426 bool isEmpty() => _added3.isEmpty && _changed3.isEmpty && _removed2.isEmpty && _removedContainers.isEmpty;
427 /**
428 * Record that the specified source has been removed.
429 * @param source the source that was removed
430 */
431 void removed3(Source source) {
432 if (source != null) {
433 _removed2.add(source);
434 }
435 }
436 /**
437 * Record that the specified source container has been removed.
438 * @param container the source container that was removed
439 */
440 void removedContainer(SourceContainer container) {
441 if (container != null) {
442 _removedContainers.add(container);
443 }
444 }
445 }
446 /**
447 * Instances of the class {@code AnalysisContextImpl} implement an {@link Analys isContext analysis
448 * context}.
449 * @coverage dart.engine
450 */
451 class AnalysisContextImpl implements AnalysisContext {
452 /**
453 * The source factory used to create the sources that can be analyzed in this context.
454 */
455 SourceFactory _sourceFactory;
456 /**
457 * A table mapping sources known to the context to the information known about the source.
458 */
459 Map<Source, SourceInfo> _sourceMap = new Map<Source, SourceInfo>();
460 /**
461 * A cache mapping sources to the compilation units that were produced for the contents of the
462 * source.
463 */
464 Map<Source, CompilationUnit> _parseCache = new Map<Source, CompilationUnit>();
465 /**
466 * A cache mapping sources to the html parse results that were produced for th e contents of the
467 * source.
468 */
469 Map<Source, HtmlParseResult> _htmlParseCache = new Map<Source, HtmlParseResult >();
470 /**
471 * A cache mapping sources (of the defining compilation units of libraries) to the library
472 * elements for those libraries.
473 */
474 Map<Source, LibraryElement> _libraryElementCache = new Map<Source, LibraryElem ent>();
475 /**
476 * A cache mapping sources (of the defining compilation units of libraries) to the public
477 * namespace for that library.
478 */
479 Map<Source, Namespace> _publicNamespaceCache = new Map<Source, Namespace>();
480 /**
481 * The object used to synchronize access to all of the caches.
482 */
483 Object _cacheLock = new Object();
484 /**
485 * The suffix used by sources that contain Dart.
486 */
487 static String _DART_SUFFIX = ".dart";
488 /**
489 * The suffix used by sources that contain HTML.
490 */
491 static String _HTML_SUFFIX = ".html";
492 /**
493 * Initialize a newly created analysis context.
494 */
495 AnalysisContextImpl() : super() {
496 }
497 ChangeResult changed(ChangeSet changeSet) {
498 if (changeSet.isEmpty()) {
499 return new ChangeResult();
500 }
501 {
502 for (MapEntry<Source, String> entry in getMapEntrySet(changeSet.addedWithC ontent)) {
503 _sourceFactory.setContents(entry.getKey(), entry.getValue());
504 }
505 for (MapEntry<Source, String> entry in getMapEntrySet(changeSet.changedWit hContent)) {
506 _sourceFactory.setContents(entry.getKey(), entry.getValue());
507 }
508 for (Source source in changeSet.addedWithContent.keys.toSet()) {
509 sourceAvailable(source);
510 }
511 for (Source source in changeSet.changedWithContent.keys.toSet()) {
512 sourceChanged(source);
513 }
514 for (Source source in changeSet.removed) {
515 sourceDeleted(source);
516 }
517 for (SourceContainer container in changeSet.removedContainers) {
518 sourcesDeleted(container);
519 }
520 }
521 return new ChangeResult();
522 }
523 void clearResolution() {
524 {
525 _parseCache.clear();
526 _htmlParseCache.clear();
527 _libraryElementCache.clear();
528 _publicNamespaceCache.clear();
529 }
530 }
531 void discard() {
532 {
533 _sourceMap.clear();
534 _parseCache.clear();
535 _htmlParseCache.clear();
536 _libraryElementCache.clear();
537 _publicNamespaceCache.clear();
538 }
539 }
540 AnalysisContext extractAnalysisContext(SourceContainer container) {
541 AnalysisContextImpl newContext = AnalysisEngine.instance.createAnalysisConte xt() as AnalysisContextImpl;
542 List<Source> sourcesToRemove = new List<Source>();
543 {
544 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
545 Source source = entry.getKey();
546 if (container.contains(source)) {
547 sourcesToRemove.add(source);
548 newContext._sourceMap[source] = new SourceInfo.con2(entry.getValue());
549 }
550 }
551 }
552 return newContext;
553 }
554 Element getElement(ElementLocation location) {
555 throw new UnsupportedOperationException();
556 }
557 List<AnalysisError> getErrors(Source source) {
558 throw new UnsupportedOperationException();
559 }
560 HtmlElement getHtmlElement(Source source) {
561 throw new UnsupportedOperationException();
562 }
563 SourceKind getKnownKindOf(Source source) {
564 if (source.fullName.endsWith(_HTML_SUFFIX)) {
565 return SourceKind.HTML;
566 }
567 if (!source.fullName.endsWith(_DART_SUFFIX)) {
568 return SourceKind.UNKNOWN;
569 }
570 {
571 if (_libraryElementCache.containsKey(source)) {
572 return SourceKind.LIBRARY;
573 }
574 CompilationUnit unit = _parseCache[source];
575 if (unit != null && hasPartOfDirective(unit)) {
576 return SourceKind.PART;
577 }
578 }
579 return null;
580 }
581 List<Source> getLibrariesContaining(Source source) {
582 {
583 SourceInfo info = _sourceMap[source];
584 if (info == null) {
585 return Source.EMPTY_ARRAY;
586 }
587 return info.librarySources;
588 }
589 }
590 LibraryElement getLibraryElement(Source source) {
591 {
592 LibraryElement element = _libraryElementCache[source];
593 if (element == null) {
594 if (getOrComputeKindOf(source) != SourceKind.LIBRARY) {
595 return null;
596 }
597 LibraryResolver resolver = new LibraryResolver.con1(this);
598 try {
599 element = resolver.resolveLibrary(source, true);
600 if (element != null) {
601 _libraryElementCache[source] = element;
602 }
603 } on AnalysisException catch (exception) {
604 AnalysisEngine.instance.logger.logError2("Could not resolve the librar y ${source.fullName}", exception);
605 }
606 }
607 return element;
608 }
609 }
610 /**
611 * Return the element model corresponding to the library defined by the given source, or{@code null} if the element model does not yet exist.
612 * @param source the source defining the library whose element model is to be returned
613 * @return the element model corresponding to the library defined by the given source
614 */
615 LibraryElement getLibraryElementOrNull(Source source) {
616 {
617 return _libraryElementCache[source];
618 }
619 }
620 SourceKind getOrComputeKindOf(Source source) {
621 SourceKind kind = getKnownKindOf(source);
622 if (kind != null) {
623 return kind;
624 }
625 try {
626 if (hasPartOfDirective(parse(source))) {
627 return SourceKind.PART;
628 }
629 } on AnalysisException catch (exception) {
630 return SourceKind.UNKNOWN;
631 }
632 return SourceKind.LIBRARY;
633 }
634 List<AnalysisError> getParsingErrors(Source source) {
635 throw new UnsupportedOperationException();
636 }
637 /**
638 * Return a namespace containing mappings for all of the public names defined by the given
639 * library.
640 * @param library the library whose public namespace is to be returned
641 * @return the public namespace of the given library
642 */
643 Namespace getPublicNamespace(LibraryElement library) {
644 Source source8 = library.definingCompilationUnit.source;
645 {
646 Namespace namespace = _publicNamespaceCache[source8];
647 if (namespace == null) {
648 NamespaceBuilder builder = new NamespaceBuilder();
649 namespace = builder.createPublicNamespace(library);
650 _publicNamespaceCache[source8] = namespace;
651 }
652 return namespace;
653 }
654 }
655 /**
656 * Return a namespace containing mappings for all of the public names defined by the library
657 * defined by the given source.
658 * @param source the source defining the library whose public namespace is to be returned
659 * @return the public namespace corresponding to the library defined by the gi ven source
660 */
661 Namespace getPublicNamespace2(Source source) {
662 {
663 Namespace namespace = _publicNamespaceCache[source];
664 if (namespace == null) {
665 LibraryElement library = getLibraryElement(source);
666 if (library == null) {
667 return null;
668 }
669 NamespaceBuilder builder = new NamespaceBuilder();
670 namespace = builder.createPublicNamespace(library);
671 _publicNamespaceCache[source] = namespace;
672 }
673 return namespace;
674 }
675 }
676 List<AnalysisError> getResolutionErrors(Source source) {
677 throw new UnsupportedOperationException();
678 }
679 SourceFactory get sourceFactory => _sourceFactory;
680 void mergeAnalysisContext(AnalysisContext context) {
681 {
682 for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(((context as Ana lysisContextImpl))._sourceMap)) {
683 Source newSource = entry.getKey();
684 SourceInfo existingInfo = _sourceMap[newSource];
685 if (existingInfo == null) {
686 _sourceMap[newSource] = new SourceInfo.con2(entry.getValue());
687 } else {
688 }
689 }
690 }
691 }
692 CompilationUnit parse(Source source) {
693 {
694 CompilationUnit unit = _parseCache[source];
695 if (unit == null) {
696 RecordingErrorListener errorListener = new RecordingErrorListener();
697 AnalysisContextImpl_ScanResult scanResult = internalScan(source, errorLi stener);
698 Parser parser = new Parser(source, errorListener);
699 unit = parser.parseCompilationUnit(scanResult._token);
700 unit.parsingErrors = errorListener.getErrors2(source);
701 unit.lineInfo = new LineInfo(scanResult._lineStarts);
702 _parseCache[source] = unit;
703 }
704 return unit;
705 }
706 }
707 CompilationUnit parse3(Source source, AnalysisErrorListener errorListener) {
708 {
709 CompilationUnit unit = _parseCache[source];
710 if (unit == null) {
711 AnalysisContextImpl_ScanResult scanResult = internalScan(source, errorLi stener);
712 Parser parser = new Parser(source, errorListener);
713 unit = parser.parseCompilationUnit(scanResult._token);
714 unit.lineInfo = new LineInfo(scanResult._lineStarts);
715 _parseCache[source] = unit;
716 }
717 return unit;
718 }
719 }
720 HtmlParseResult parseHtml(Source source) {
721 {
722 HtmlParseResult result = _htmlParseCache[source];
723 if (result == null) {
724 result = new HtmlParser(source).parse(scanHtml(source));
725 _htmlParseCache[source] = result;
726 }
727 return result;
728 }
729 }
730 /**
731 * Given a table mapping the source for the libraries represented by the corre sponding elements to
732 * the elements representing the libraries, record those mappings.
733 * @param elementMap a table mapping the source for the libraries represented by the elements to
734 * the elements representing the libraries
735 */
736 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
737 {
738 javaMapPutAll(_libraryElementCache, elementMap);
739 }
740 }
741 CompilationUnit resolve(Source source, LibraryElement library) => parse(source );
742 Token scan(Source source, AnalysisErrorListener errorListener) {
743 AnalysisContextImpl_ScanResult result = internalScan(source, errorListener);
744 return result._token;
745 }
746 HtmlScanResult scanHtml(Source source) {
747 HtmlScanner scanner = new HtmlScanner(source);
748 try {
749 source.getContents(scanner);
750 } on JavaException catch (exception) {
751 throw new AnalysisException.con3(exception);
752 }
753 return scanner.result;
754 }
755 void set sourceFactory(SourceFactory sourceFactory2) {
756 this._sourceFactory = sourceFactory2;
757 }
758 Iterable<Source> sourcesToResolve(List<Source> changedSources) {
759 List<Source> librarySources = new List<Source>();
760 for (Source source in changedSources) {
761 if (identical(getOrComputeKindOf(source), SourceKind.LIBRARY)) {
762 librarySources.add(source);
763 }
764 }
765 return librarySources;
766 }
767 /**
768 * Return {@code true} if the given compilation unit has a part-of directive.
769 * @param unit the compilation unit being tested
770 * @return {@code true} if the compilation unit has a part-of directive
771 */
772 bool hasPartOfDirective(CompilationUnit unit) {
773 for (Directive directive in unit.directives) {
774 if (directive is PartOfDirective) {
775 return true;
776 }
777 }
778 return false;
779 }
780 AnalysisContextImpl_ScanResult internalScan(Source source, AnalysisErrorListen er errorListener) {
781 AnalysisContextImpl_ScanResult result = new AnalysisContextImpl_ScanResult() ;
782 Source_ContentReceiver receiver = new Source_ContentReceiver_3(source, error Listener, result);
783 try {
784 source.getContents(receiver);
785 } on JavaException catch (exception) {
786 throw new AnalysisException.con3(exception);
787 }
788 return result;
789 }
790 /**
791 * Note: This method must only be invoked while we are synchronized on {@link #cacheLock}.
792 * @param source the source that has been added
793 */
794 void sourceAvailable(Source source) {
795 SourceInfo existingInfo = _sourceMap[source];
796 if (existingInfo == null) {
797 _sourceMap[source] = new SourceInfo.con1(source, getOrComputeKindOf(source ));
798 }
799 }
800 /**
801 * Note: This method must only be invoked while we are synchronized on {@link #cacheLock}.
802 * @param source the source that has been changed
803 */
804 void sourceChanged(Source source) {
805 SourceInfo info = _sourceMap[source];
806 if (info == null) {
807 return;
808 }
809 _parseCache.remove(source);
810 _htmlParseCache.remove(source);
811 _libraryElementCache.remove(source);
812 _publicNamespaceCache.remove(source);
813 for (Source librarySource in info.librarySources) {
814 _libraryElementCache.remove(librarySource);
815 _publicNamespaceCache.remove(librarySource);
816 }
817 }
818 /**
819 * Note: This method must only be invoked while we are synchronized on {@link #cacheLock}.
820 * @param source the source that has been deleted
821 */
822 void sourceDeleted(Source source) {
823 _sourceMap.remove(source);
824 sourceChanged(source);
825 }
826 /**
827 * Note: This method must only be invoked while we are synchronized on {@link #cacheLock}.
828 * @param container the source container specifying the sources that have been deleted
829 */
830 void sourcesDeleted(SourceContainer container) {
831 List<Source> sourcesToRemove = new List<Source>();
832 for (Source source in _sourceMap.keys.toSet()) {
833 if (container.contains(source)) {
834 sourcesToRemove.add(source);
835 }
836 }
837 }
838 }
839 /**
840 * Instances of the class {@code ScanResult} represent the results of scanning a source.
841 */
842 class AnalysisContextImpl_ScanResult {
843 /**
844 * The first token in the token stream.
845 */
846 Token _token;
847 /**
848 * The line start information that was produced.
849 */
850 List<int> _lineStarts;
851 /**
852 * Initialize a newly created result object to be empty.
853 */
854 AnalysisContextImpl_ScanResult() : super() {
855 }
856 }
857 class Source_ContentReceiver_3 implements Source_ContentReceiver {
858 Source source;
859 AnalysisErrorListener errorListener;
860 AnalysisContextImpl_ScanResult result;
861 Source_ContentReceiver_3(this.source, this.errorListener, this.result);
862 accept(CharBuffer contents) {
863 CharBufferScanner scanner = new CharBufferScanner(source, contents, errorLis tener);
864 result._token = scanner.tokenize();
865 result._lineStarts = scanner.lineStarts;
866 }
867 void accept2(String contents) {
868 StringScanner scanner = new StringScanner(source, contents, errorListener);
869 result._token = scanner.tokenize();
870 result._lineStarts = scanner.lineStarts;
871 }
872 }
873 /**
874 * Instances of the class {@code RecordingErrorListener} implement an error list ener that will
875 * record the errors that are reported to it in a way that is appropriate for ca ching those errors
876 * within an analysis context.
877 * @coverage dart.engine
878 */
879 class RecordingErrorListener implements AnalysisErrorListener {
880 /**
881 * A HashMap of lists containing the errors that were collected, keyed by each {@link Source}.
882 */
883 Map<Source, List<AnalysisError>> _errors = new Map<Source, List<AnalysisError> >();
884 /**
885 * Answer the errors collected by the listener.
886 * @return an array of errors (not {@code null}, contains no {@code null}s)
887 */
888 List<AnalysisError> get errors {
889 Set<MapEntry<Source, List<AnalysisError>>> entrySet2 = getMapEntrySet(_error s);
890 if (entrySet2.length == 0) {
891 return AnalysisError.NO_ERRORS;
892 }
893 List<AnalysisError> resultList = new List<AnalysisError>();
894 for (MapEntry<Source, List<AnalysisError>> entry in entrySet2) {
895 resultList.addAll(entry.getValue());
896 }
897 return new List.from(resultList);
898 }
899 /**
900 * Answer the errors collected by the listener for some passed {@link Source}.
901 * @param source some {@link Source} for which the caller wants the set of {@l ink AnalysisError}s
902 * collected by this listener
903 * @return the errors collected by the listener for the passed {@link Source}
904 */
905 List<AnalysisError> getErrors2(Source source) {
906 List<AnalysisError> errorsForSource = _errors[source];
907 if (errorsForSource == null) {
908 return AnalysisError.NO_ERRORS;
909 } else {
910 return new List.from(errorsForSource);
911 }
912 }
913 void onError(AnalysisError event) {
914 Source source9 = event.source;
915 List<AnalysisError> errorsForSource = _errors[source9];
916 if (_errors[source9] == null) {
917 errorsForSource = new List<AnalysisError>();
918 _errors[source9] = errorsForSource;
919 }
920 errorsForSource.add(event);
921 }
922 }
923 /**
924 * Instances of the class {@code SourceInfo} maintain the information known by a n analysis context
925 * about an individual source.
926 * @coverage dart.engine
927 */
928 class SourceInfo {
929 /**
930 * The kind of the source.
931 */
932 SourceKind _kind;
933 /**
934 * The sources for the defining compilation units for the libraries containing the source, or{@code null} if the libraries containing the source are not yet k nown.
935 */
936 List<Source> _librarySources = null;
937 SourceInfo.con1(Source source, SourceKind kind3) {
938 _jtd_constructor_154_impl(source, kind3);
939 }
940 _jtd_constructor_154_impl(Source source, SourceKind kind3) {
941 this._kind = kind3;
942 }
943 /**
944 * Initialize a newly created information holder to hold the same information as the given holder.
945 * @param info the information holder used to initialize this holder
946 */
947 SourceInfo.con2(SourceInfo info) {
948 _jtd_constructor_155_impl(info);
949 }
950 _jtd_constructor_155_impl(SourceInfo info) {
951 _kind = info._kind;
952 _librarySources = new List<Source>.from(info._librarySources);
953 }
954 /**
955 * Add the given source to the list of sources for the defining compilation un its for the
956 * libraries containing this source.
957 * @param source the source to be added to the list
958 */
959 void addLibrarySource(Source source) {
960 if (_librarySources == null) {
961 _librarySources = new List<Source>();
962 }
963 _librarySources.add(source);
964 }
965 /**
966 * Return the kind of the source.
967 * @return the kind of the source
968 */
969 SourceKind get kind => _kind;
970 /**
971 * Return the sources for the defining compilation units for the libraries con taining this source.
972 * @return the sources for the defining compilation units for the libraries co ntaining this source
973 */
974 List<Source> get librarySources {
975 if (_librarySources == null) {
976 return Source.EMPTY_ARRAY;
977 }
978 return new List.from(_librarySources);
979 }
980 /**
981 * Remove the given source from the list of sources for the defining compilati on units for the
982 * libraries containing this source.
983 * @param source the source to be removed to the list
984 */
985 void removeLibrarySource(Source source) {
986 _librarySources.remove(source);
987 if (_librarySources.isEmpty) {
988 _librarySources = null;
989 }
990 }
991 /**
992 * Set the kind of the source to the given kind.
993 * @param kind the kind of the source
994 */
995 void set kind(SourceKind kind4) {
996 this._kind = kind4;
997 }
998 }
999 /**
1000 * The interface {@code Logger} defines the behavior of objects that can be used to receive
1001 * information about errors within the analysis engine. Implementations usually write this
1002 * information to a file, but can also record the information for later use (suc h as during testing)
1003 * or even ignore the information.
1004 * @coverage dart.engine.utilities
1005 */
1006 abstract class Logger {
1007 static Logger NULL = new Logger_NullLogger();
1008 /**
1009 * Log the given message as an error.
1010 * @param message an explanation of why the error occurred or what it means
1011 */
1012 void logError(String message);
1013 /**
1014 * Log the given exception as one representing an error.
1015 * @param message an explanation of why the error occurred or what it means
1016 * @param exception the exception being logged
1017 */
1018 void logError2(String message, Exception exception);
1019 /**
1020 * Log the given exception as one representing an error.
1021 * @param exception the exception being logged
1022 */
1023 void logError3(Exception exception);
1024 /**
1025 * Log the given informational message.
1026 * @param message an explanation of why the error occurred or what it means
1027 * @param exception the exception being logged
1028 */
1029 void logInformation(String message);
1030 /**
1031 * Log the given exception as one representing an informational message.
1032 * @param message an explanation of why the error occurred or what it means
1033 * @param exception the exception being logged
1034 */
1035 void logInformation2(String message, Exception exception);
1036 }
1037 /**
1038 * Implementation of {@link Logger} that does nothing.
1039 */
1040 class Logger_NullLogger implements Logger {
1041 void logError(String message) {
1042 }
1043 void logError2(String message, Exception exception) {
1044 }
1045 void logError3(Exception exception) {
1046 }
1047 void logInformation(String message) {
1048 }
1049 void logInformation2(String message, Exception exception) {
1050 }
1051 }
OLDNEW
« no previous file with comments | « pkg/analyzer-experimental/lib/src/generated/element.dart ('k') | pkg/analyzer-experimental/lib/src/generated/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698