| Index: pkg/analyzer/lib/src/generated/resolver.dart
|
| diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
|
| index 8ded6fd4c37bac714ef07b2dfa3be41023c3bae4..7f07c85a1588b0ae0dc34ae64893a12ad16e42a4 100644
|
| --- a/pkg/analyzer/lib/src/generated/resolver.dart
|
| +++ b/pkg/analyzer/lib/src/generated/resolver.dart
|
| @@ -15,12 +15,10 @@ import 'element_resolver.dart';
|
| import 'engine.dart';
|
| import 'error.dart';
|
| import 'error_verifier.dart';
|
| -import 'html.dart' as ht;
|
| import 'java_core.dart';
|
| import 'java_engine.dart';
|
| import 'scanner.dart';
|
| import 'scanner.dart' as sc;
|
| -import 'sdk.dart' show DartSdk, SdkLibrary;
|
| import 'source.dart';
|
| import 'static_type_analyzer.dart';
|
| import 'type_system.dart';
|
| @@ -38,8 +36,6 @@ export 'type_system.dart';
|
| typedef void ImplicitConstructorBuilderCallback(ClassElement classElement,
|
| ClassElement superclassElement, void computation());
|
|
|
| -typedef LibraryResolver LibraryResolverFactory(AnalysisContext context);
|
| -
|
| typedef ResolverVisitor ResolverVisitorFactory(
|
| Library library, Source source, TypeProvider typeProvider);
|
|
|
| @@ -5006,438 +5002,6 @@ class HintGenerator {
|
| }
|
|
|
| /**
|
| - * Instances of the class {@code HtmlTagInfo} record information about the tags used in an HTML
|
| - * file.
|
| - */
|
| -class HtmlTagInfo {
|
| - /**
|
| - * An array containing all of the tags used in the HTML file.
|
| - */
|
| - List<String> allTags;
|
| -
|
| - /**
|
| - * A table mapping the id's defined in the HTML file to an array containing the names of tags with
|
| - * that identifier.
|
| - */
|
| - HashMap<String, String> idToTagMap;
|
| -
|
| - /**
|
| - * A table mapping the classes defined in the HTML file to an array containing the names of tags
|
| - * with that class.
|
| - */
|
| - HashMap<String, List<String>> classToTagsMap;
|
| -
|
| - /**
|
| - * Initialize a newly created information holder to hold the given information about the tags in
|
| - * an HTML file.
|
| - *
|
| - * @param allTags an array containing all of the tags used in the HTML file
|
| - * @param idToTagMap a table mapping the id's defined in the HTML file to an array containing the
|
| - * names of tags with that identifier
|
| - * @param classToTagsMap a table mapping the classes defined in the HTML file to an array
|
| - * containing the names of tags with that class
|
| - */
|
| - HtmlTagInfo(this.allTags, this.idToTagMap, this.classToTagsMap);
|
| -
|
| - /**
|
| - * Return an array containing the tags that have the given class, or {@code null} if there are no
|
| - * such tags.
|
| - *
|
| - * @return an array containing the tags that have the given class
|
| - */
|
| - List<String> getTagsWithClass(String identifier) {
|
| - return classToTagsMap[identifier];
|
| - }
|
| -
|
| - /**
|
| - * Return the tag that has the given identifier, or {@code null} if there is no such tag (the
|
| - * identifier is not defined).
|
| - *
|
| - * @return the tag that has the given identifier
|
| - */
|
| - String getTagWithId(String identifier) {
|
| - return idToTagMap[identifier];
|
| - }
|
| -}
|
| -
|
| -/**
|
| - * Instances of the class {@code HtmlTagInfoBuilder} gather information about the tags used in one
|
| - * or more HTML structures.
|
| - */
|
| -class HtmlTagInfoBuilder implements ht.XmlVisitor {
|
| - /**
|
| - * The name of the 'id' attribute.
|
| - */
|
| - static final String ID_ATTRIBUTE = "id";
|
| -
|
| - /**
|
| - * The name of the 'class' attribute.
|
| - */
|
| - static final String ID_CLASS = "class";
|
| -
|
| - /**
|
| - * A set containing all of the tag names used in the HTML.
|
| - */
|
| - HashSet<String> tagSet = new HashSet<String>();
|
| -
|
| - /**
|
| - * A table mapping the id's that are defined to the tag name with that id.
|
| - */
|
| - HashMap<String, String> idMap = new HashMap<String, String>();
|
| -
|
| - /**
|
| - * A table mapping the classes that are defined to a set of the tag names with that class.
|
| - */
|
| - HashMap<String, HashSet<String>> classMap =
|
| - new HashMap<String, HashSet<String>>();
|
| -
|
| - /**
|
| - * Initialize a newly created HTML tag info builder.
|
| - */
|
| - HtmlTagInfoBuilder();
|
| -
|
| - /**
|
| - * Create a tag information holder holding all of the information gathered about the tags in the
|
| - * HTML structures that were visited.
|
| - *
|
| - * @return the information gathered about the tags in the visited HTML structures
|
| - */
|
| - HtmlTagInfo getTagInfo() {
|
| - List<String> allTags = tagSet.toList();
|
| - HashMap<String, List<String>> classToTagsMap =
|
| - new HashMap<String, List<String>>();
|
| - classMap.forEach((String key, Set<String> tags) {
|
| - classToTagsMap[key] = tags.toList();
|
| - });
|
| - return new HtmlTagInfo(allTags, idMap, classToTagsMap);
|
| - }
|
| -
|
| - @override
|
| - visitHtmlScriptTagNode(ht.HtmlScriptTagNode node) {
|
| - visitXmlTagNode(node);
|
| - }
|
| -
|
| - @override
|
| - visitHtmlUnit(ht.HtmlUnit node) {
|
| - node.visitChildren(this);
|
| - }
|
| -
|
| - @override
|
| - visitXmlAttributeNode(ht.XmlAttributeNode node) {}
|
| -
|
| - @override
|
| - visitXmlTagNode(ht.XmlTagNode node) {
|
| - node.visitChildren(this);
|
| - String tagName = node.tag;
|
| - tagSet.add(tagName);
|
| - for (ht.XmlAttributeNode attribute in node.attributes) {
|
| - String attributeName = attribute.name;
|
| - if (attributeName == ID_ATTRIBUTE) {
|
| - String attributeValue = attribute.text;
|
| - if (attributeValue != null) {
|
| - String tag = idMap[attributeValue];
|
| - if (tag == null) {
|
| - idMap[attributeValue] = tagName;
|
| - } else {
|
| -// reportError(HtmlWarningCode.MULTIPLY_DEFINED_ID, valueToken);
|
| - }
|
| - }
|
| - } else if (attributeName == ID_CLASS) {
|
| - String attributeValue = attribute.text;
|
| - if (attributeValue != null) {
|
| - HashSet<String> tagList = classMap[attributeValue];
|
| - if (tagList == null) {
|
| - tagList = new HashSet<String>();
|
| - classMap[attributeValue] = tagList;
|
| - } else {
|
| -// reportError(HtmlWarningCode.MULTIPLY_DEFINED_ID, valueToken);
|
| - }
|
| - tagList.add(tagName);
|
| - }
|
| - }
|
| - }
|
| - }
|
| -
|
| -// /**
|
| -// * Report an error with the given error code at the given location. Use the given arguments to
|
| -// * compose the error message.
|
| -// *
|
| -// * @param errorCode the error code of the error to be reported
|
| -// * @param offset the offset of the first character to be highlighted
|
| -// * @param length the number of characters to be highlighted
|
| -// * @param arguments the arguments used to compose the error message
|
| -// */
|
| -// private void reportError(ErrorCode errorCode, Token token, Object... arguments) {
|
| -// errorListener.onError(new AnalysisError(
|
| -// htmlElement.getSource(),
|
| -// token.getOffset(),
|
| -// token.getLength(),
|
| -// errorCode,
|
| -// arguments));
|
| -// }
|
| -//
|
| -// /**
|
| -// * Report an error with the given error code at the given location. Use the given arguments to
|
| -// * compose the error message.
|
| -// *
|
| -// * @param errorCode the error code of the error to be reported
|
| -// * @param offset the offset of the first character to be highlighted
|
| -// * @param length the number of characters to be highlighted
|
| -// * @param arguments the arguments used to compose the error message
|
| -// */
|
| -// private void reportError(ErrorCode errorCode, int offset, int length, Object... arguments) {
|
| -// errorListener.onError(new AnalysisError(
|
| -// htmlElement.getSource(),
|
| -// offset,
|
| -// length,
|
| -// errorCode,
|
| -// arguments));
|
| -// }
|
| -}
|
| -
|
| -/**
|
| - * Instances of the class `HtmlUnitBuilder` build an element model for a single HTML unit.
|
| - */
|
| -class HtmlUnitBuilder implements ht.XmlVisitor<Object> {
|
| - static String _SRC = "src";
|
| -
|
| - /**
|
| - * The analysis context in which the element model will be built.
|
| - */
|
| - final InternalAnalysisContext _context;
|
| -
|
| - /**
|
| - * The error listener to which errors will be reported.
|
| - */
|
| - RecordingErrorListener _errorListener;
|
| -
|
| - /**
|
| - * The HTML element being built.
|
| - */
|
| - HtmlElementImpl _htmlElement;
|
| -
|
| - /**
|
| - * The elements in the path from the HTML unit to the current tag node.
|
| - */
|
| - List<ht.XmlTagNode> _parentNodes;
|
| -
|
| - /**
|
| - * The script elements being built.
|
| - */
|
| - List<HtmlScriptElement> _scripts;
|
| -
|
| - /**
|
| - * A set of the libraries that were resolved while resolving the HTML unit.
|
| - */
|
| - Set<Library> _resolvedLibraries = new HashSet<Library>();
|
| -
|
| - /**
|
| - * Initialize a newly created HTML unit builder.
|
| - *
|
| - * @param context the analysis context in which the element model will be built
|
| - */
|
| - HtmlUnitBuilder(this._context) {
|
| - this._errorListener = new RecordingErrorListener();
|
| - }
|
| -
|
| - /**
|
| - * Return the listener to which analysis errors will be reported.
|
| - *
|
| - * @return the listener to which analysis errors will be reported
|
| - */
|
| - RecordingErrorListener get errorListener => _errorListener;
|
| -
|
| - /**
|
| - * Return an array containing information about all of the libraries that were resolved.
|
| - *
|
| - * @return an array containing the libraries that were resolved
|
| - */
|
| - Set<Library> get resolvedLibraries => _resolvedLibraries;
|
| -
|
| - /**
|
| - * Build the HTML element for the given source.
|
| - *
|
| - * @param source the source describing the compilation unit
|
| - * @param unit the AST structure representing the HTML
|
| - * @throws AnalysisException if the analysis could not be performed
|
| - */
|
| - HtmlElementImpl buildHtmlElement(Source source, ht.HtmlUnit unit) {
|
| - HtmlElementImpl result = new HtmlElementImpl(_context, source.shortName);
|
| - result.source = source;
|
| - _htmlElement = result;
|
| - unit.accept(this);
|
| - _htmlElement = null;
|
| - unit.element = result;
|
| - return result;
|
| - }
|
| -
|
| - @override
|
| - Object visitHtmlScriptTagNode(ht.HtmlScriptTagNode node) {
|
| - if (_parentNodes.contains(node)) {
|
| - return _reportCircularity(node);
|
| - }
|
| - _parentNodes.add(node);
|
| - try {
|
| - Source htmlSource = _htmlElement.source;
|
| - ht.XmlAttributeNode scriptAttribute = _getScriptSourcePath(node);
|
| - String scriptSourcePath =
|
| - scriptAttribute == null ? null : scriptAttribute.text;
|
| - if (node.attributeEnd.type == ht.TokenType.GT &&
|
| - scriptSourcePath == null) {
|
| - EmbeddedHtmlScriptElementImpl script =
|
| - new EmbeddedHtmlScriptElementImpl(node);
|
| - try {
|
| - LibraryResolver resolver = new LibraryResolver(_context);
|
| - LibraryElementImpl library =
|
| - resolver.resolveEmbeddedLibrary(htmlSource, node.script, true);
|
| - script.scriptLibrary = library;
|
| - _resolvedLibraries.addAll(resolver.resolvedLibraries);
|
| - _errorListener.addAll(resolver.errorListener);
|
| - } on AnalysisException catch (exception, stackTrace) {
|
| - //TODO (danrubel): Handle or forward the exception
|
| - AnalysisEngine.instance.logger.logError(
|
| - "Could not resolve script tag",
|
| - new CaughtException(exception, stackTrace));
|
| - }
|
| - node.scriptElement = script;
|
| - _scripts.add(script);
|
| - } else {
|
| - ExternalHtmlScriptElementImpl script =
|
| - new ExternalHtmlScriptElementImpl(node);
|
| - if (scriptSourcePath != null) {
|
| - try {
|
| - scriptSourcePath = Uri.encodeFull(scriptSourcePath);
|
| - // Force an exception to be thrown if the URI is invalid so that we
|
| - // can report the problem.
|
| - parseUriWithException(scriptSourcePath);
|
| - Source scriptSource =
|
| - _context.sourceFactory.resolveUri(htmlSource, scriptSourcePath);
|
| - script.scriptSource = scriptSource;
|
| - if (!_context.exists(scriptSource)) {
|
| - _reportValueError(HtmlWarningCode.URI_DOES_NOT_EXIST,
|
| - scriptAttribute, [scriptSourcePath]);
|
| - }
|
| - } on URISyntaxException {
|
| - _reportValueError(HtmlWarningCode.INVALID_URI, scriptAttribute,
|
| - [scriptSourcePath]);
|
| - }
|
| - }
|
| - node.scriptElement = script;
|
| - _scripts.add(script);
|
| - }
|
| - } finally {
|
| - _parentNodes.remove(node);
|
| - }
|
| - return null;
|
| - }
|
| -
|
| - @override
|
| - Object visitHtmlUnit(ht.HtmlUnit node) {
|
| - _parentNodes = new List<ht.XmlTagNode>();
|
| - _scripts = new List<HtmlScriptElement>();
|
| - try {
|
| - node.visitChildren(this);
|
| - _htmlElement.scripts = new List.from(_scripts);
|
| - } finally {
|
| - _scripts = null;
|
| - _parentNodes = null;
|
| - }
|
| - return null;
|
| - }
|
| -
|
| - @override
|
| - Object visitXmlAttributeNode(ht.XmlAttributeNode node) => null;
|
| -
|
| - @override
|
| - Object visitXmlTagNode(ht.XmlTagNode node) {
|
| - if (_parentNodes.contains(node)) {
|
| - return _reportCircularity(node);
|
| - }
|
| - _parentNodes.add(node);
|
| - try {
|
| - node.visitChildren(this);
|
| - } finally {
|
| - _parentNodes.remove(node);
|
| - }
|
| - return null;
|
| - }
|
| -
|
| - /**
|
| - * Return the first source attribute for the given tag node, or `null` if it does not exist.
|
| - *
|
| - * @param node the node containing attributes
|
| - * @return the source attribute contained in the given tag
|
| - */
|
| - ht.XmlAttributeNode _getScriptSourcePath(ht.XmlTagNode node) {
|
| - for (ht.XmlAttributeNode attribute in node.attributes) {
|
| - if (attribute.name == _SRC) {
|
| - return attribute;
|
| - }
|
| - }
|
| - return null;
|
| - }
|
| -
|
| - Object _reportCircularity(ht.XmlTagNode node) {
|
| - //
|
| - // This should not be possible, but we have an error report that suggests
|
| - // that it happened at least once. This code will guard against infinite
|
| - // recursion and might help us identify the cause of the issue.
|
| - //
|
| - StringBuffer buffer = new StringBuffer();
|
| - buffer.write("Found circularity in XML nodes: ");
|
| - bool first = true;
|
| - for (ht.XmlTagNode pathNode in _parentNodes) {
|
| - if (first) {
|
| - first = false;
|
| - } else {
|
| - buffer.write(", ");
|
| - }
|
| - String tagName = pathNode.tag;
|
| - if (identical(pathNode, node)) {
|
| - buffer.write("*");
|
| - buffer.write(tagName);
|
| - buffer.write("*");
|
| - } else {
|
| - buffer.write(tagName);
|
| - }
|
| - }
|
| - AnalysisEngine.instance.logger.logError(buffer.toString());
|
| - return null;
|
| - }
|
| -
|
| - /**
|
| - * Report an error with the given error code at the given location. Use the given arguments to
|
| - * compose the error message.
|
| - *
|
| - * @param errorCode the error code of the error to be reported
|
| - * @param offset the offset of the first character to be highlighted
|
| - * @param length the number of characters to be highlighted
|
| - * @param arguments the arguments used to compose the error message
|
| - */
|
| - void _reportErrorForOffset(
|
| - ErrorCode errorCode, int offset, int length, List<Object> arguments) {
|
| - _errorListener.onError(new AnalysisError(
|
| - _htmlElement.source, offset, length, errorCode, arguments));
|
| - }
|
| -
|
| - /**
|
| - * Report an error with the given error code at the location of the value of the given attribute.
|
| - * Use the given arguments to compose the error message.
|
| - *
|
| - * @param errorCode the error code of the error to be reported
|
| - * @param offset the offset of the first character to be highlighted
|
| - * @param length the number of characters to be highlighted
|
| - * @param arguments the arguments used to compose the error message
|
| - */
|
| - void _reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute,
|
| - List<Object> arguments) {
|
| - int offset = attribute.valueToken.offset + 1;
|
| - int length = attribute.valueToken.length - 2;
|
| - _reportErrorForOffset(errorCode, offset, length, arguments);
|
| - }
|
| -}
|
| -
|
| -/**
|
| * Instances of the class `ImplicitLabelScope` represent the scope statements
|
| * that can be the target of unlabeled break and continue statements.
|
| */
|
| @@ -7386,385 +6950,41 @@ class Library {
|
| }
|
|
|
| /**
|
| - * Instances of the class `LibraryElementBuilder` build an element model for a single library.
|
| + * Instances of the class `LibraryImportScope` represent the scope containing all of the names
|
| + * available from imported libraries.
|
| */
|
| -class LibraryElementBuilder {
|
| +class LibraryImportScope extends Scope {
|
| /**
|
| - * The analysis context in which the element model will be built.
|
| + * The element representing the library in which this scope is enclosed.
|
| */
|
| - final InternalAnalysisContext _analysisContext;
|
| + final LibraryElement _definingLibrary;
|
|
|
| /**
|
| - * The listener to which errors will be reported.
|
| + * The listener that is to be informed when an error is encountered.
|
| */
|
| - final AnalysisErrorListener _errorListener;
|
| + final AnalysisErrorListener errorListener;
|
|
|
| /**
|
| - * Initialize a newly created library element builder.
|
| - *
|
| - * @param analysisContext the analysis context in which the element model will be built
|
| - * @param errorListener the listener to which errors will be reported
|
| + * A list of the namespaces representing the names that are available in this scope from imported
|
| + * libraries.
|
| */
|
| - LibraryElementBuilder(this._analysisContext, this._errorListener);
|
| + List<Namespace> _importedNamespaces;
|
|
|
| /**
|
| - * Build the library element for the given library.
|
| + * Initialize a newly created scope representing the names imported into the given library.
|
| *
|
| - * @param library the library for which an element model is to be built
|
| - * @return the library element that was built
|
| - * @throws AnalysisException if the analysis could not be performed
|
| + * @param definingLibrary the element representing the library that imports the names defined in
|
| + * this scope
|
| + * @param errorListener the listener that is to be informed when an error is encountered
|
| */
|
| - LibraryElementImpl buildLibrary(Library library) {
|
| - CompilationUnitBuilder builder = new CompilationUnitBuilder();
|
| - Source librarySource = library.librarySource;
|
| - CompilationUnit definingCompilationUnit = library.definingCompilationUnit;
|
| - CompilationUnitElementImpl definingCompilationUnitElement = builder
|
| - .buildCompilationUnit(
|
| - librarySource, definingCompilationUnit, librarySource);
|
| - NodeList<Directive> directives = definingCompilationUnit.directives;
|
| - LibraryDirective libraryDirective = null;
|
| - LibraryIdentifier libraryNameNode = null;
|
| - bool hasPartDirective = false;
|
| - FunctionElement entryPoint =
|
| - _findEntryPoint(definingCompilationUnitElement);
|
| - List<Directive> directivesToResolve = new List<Directive>();
|
| - List<CompilationUnitElementImpl> sourcedCompilationUnits =
|
| - new List<CompilationUnitElementImpl>();
|
| - for (Directive directive in directives) {
|
| - //
|
| - // We do not build the elements representing the import and export
|
| - // directives at this point. That is not done until we get to
|
| - // LibraryResolver.buildDirectiveModels() because we need the
|
| - // LibraryElements for the referenced libraries, which might not exist at
|
| - // this point (due to the possibility of circular references).
|
| - //
|
| - if (directive is LibraryDirective) {
|
| - if (libraryNameNode == null) {
|
| - libraryDirective = directive;
|
| - libraryNameNode = directive.name;
|
| - directivesToResolve.add(directive);
|
| - }
|
| - } else if (directive is PartDirective) {
|
| - PartDirective partDirective = directive;
|
| - StringLiteral partUri = partDirective.uri;
|
| - Source partSource = partDirective.source;
|
| - if (_analysisContext.exists(partSource)) {
|
| - hasPartDirective = true;
|
| - CompilationUnit partUnit = library.getAST(partSource);
|
| - CompilationUnitElementImpl part =
|
| - builder.buildCompilationUnit(partSource, partUnit, librarySource);
|
| - part.uriOffset = partUri.offset;
|
| - part.uriEnd = partUri.end;
|
| - part.uri = partDirective.uriContent;
|
| - //
|
| - // Validate that the part contains a part-of directive with the same
|
| - // name as the library.
|
| - //
|
| - String partLibraryName =
|
| - _getPartLibraryName(partSource, partUnit, directivesToResolve);
|
| - if (partLibraryName == null) {
|
| - _errorListener.onError(new AnalysisError(
|
| - librarySource,
|
| - partUri.offset,
|
| - partUri.length,
|
| - CompileTimeErrorCode.PART_OF_NON_PART,
|
| - [partUri.toSource()]));
|
| - } else if (libraryNameNode == null) {
|
| - // TODO(brianwilkerson) Collect the names declared by the part.
|
| - // If they are all the same then we can use that name as the
|
| - // inferred name of the library and present it in a quick-fix.
|
| - // partLibraryNames.add(partLibraryName);
|
| - } else if (libraryNameNode.name != partLibraryName) {
|
| - _errorListener.onError(new AnalysisError(
|
| - librarySource,
|
| - partUri.offset,
|
| - partUri.length,
|
| - StaticWarningCode.PART_OF_DIFFERENT_LIBRARY,
|
| - [libraryNameNode.name, partLibraryName]));
|
| - }
|
| - if (entryPoint == null) {
|
| - entryPoint = _findEntryPoint(part);
|
| - }
|
| - directive.element = part;
|
| - sourcedCompilationUnits.add(part);
|
| - }
|
| - }
|
| - }
|
| - if (hasPartDirective && libraryNameNode == null) {
|
| - _errorListener.onError(new AnalysisError(librarySource, 0, 0,
|
| - ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART));
|
| - }
|
| - //
|
| - // Create and populate the library element.
|
| - //
|
| - LibraryElementImpl libraryElement = new LibraryElementImpl.forNode(
|
| - _analysisContext.getContextFor(librarySource), libraryNameNode);
|
| - _setDocRange(libraryElement, libraryDirective);
|
| - libraryElement.definingCompilationUnit = definingCompilationUnitElement;
|
| - if (entryPoint != null) {
|
| - libraryElement.entryPoint = entryPoint;
|
| - }
|
| - int sourcedUnitCount = sourcedCompilationUnits.length;
|
| - libraryElement.parts = sourcedCompilationUnits;
|
| - for (Directive directive in directivesToResolve) {
|
| - directive.element = libraryElement;
|
| - }
|
| - library.libraryElement = libraryElement;
|
| - if (sourcedUnitCount > 0) {
|
| - _patchTopLevelAccessors(libraryElement);
|
| - }
|
| - return libraryElement;
|
| - }
|
| -
|
| - /**
|
| - * Build the library element for the given library. The resulting element is
|
| - * stored in the [ResolvableLibrary] structure.
|
| - *
|
| - * @param library the library for which an element model is to be built
|
| - * @throws AnalysisException if the analysis could not be performed
|
| - */
|
| - void buildLibrary2(ResolvableLibrary library) {
|
| - CompilationUnitBuilder builder = new CompilationUnitBuilder();
|
| - Source librarySource = library.librarySource;
|
| - CompilationUnit definingCompilationUnit = library.definingCompilationUnit;
|
| - CompilationUnitElementImpl definingCompilationUnitElement = builder
|
| - .buildCompilationUnit(
|
| - librarySource, definingCompilationUnit, librarySource);
|
| - NodeList<Directive> directives = definingCompilationUnit.directives;
|
| - LibraryDirective libraryDirective = null;
|
| - LibraryIdentifier libraryNameNode = null;
|
| - bool hasPartDirective = false;
|
| - FunctionElement entryPoint =
|
| - _findEntryPoint(definingCompilationUnitElement);
|
| - List<Directive> directivesToResolve = new List<Directive>();
|
| - List<CompilationUnitElementImpl> sourcedCompilationUnits =
|
| - new List<CompilationUnitElementImpl>();
|
| - for (Directive directive in directives) {
|
| - //
|
| - // We do not build the elements representing the import and export
|
| - // directives at this point. That is not done until we get to
|
| - // LibraryResolver.buildDirectiveModels() because we need the
|
| - // LibraryElements for the referenced libraries, which might not exist at
|
| - // this point (due to the possibility of circular references).
|
| - //
|
| - if (directive is LibraryDirective) {
|
| - if (libraryNameNode == null) {
|
| - libraryDirective = directive;
|
| - libraryNameNode = directive.name;
|
| - directivesToResolve.add(directive);
|
| - }
|
| - } else if (directive is PartDirective) {
|
| - PartDirective partDirective = directive;
|
| - StringLiteral partUri = partDirective.uri;
|
| - Source partSource = partDirective.source;
|
| - if (_analysisContext.exists(partSource)) {
|
| - hasPartDirective = true;
|
| - CompilationUnit partUnit = library.getAST(partSource);
|
| - if (partUnit != null) {
|
| - CompilationUnitElementImpl part = builder.buildCompilationUnit(
|
| - partSource, partUnit, librarySource);
|
| - part.uriOffset = partUri.offset;
|
| - part.uriEnd = partUri.end;
|
| - part.uri = partDirective.uriContent;
|
| - //
|
| - // Validate that the part contains a part-of directive with the same
|
| - // name as the library.
|
| - //
|
| - String partLibraryName =
|
| - _getPartLibraryName(partSource, partUnit, directivesToResolve);
|
| - if (partLibraryName == null) {
|
| - _errorListener.onError(new AnalysisError(
|
| - librarySource,
|
| - partUri.offset,
|
| - partUri.length,
|
| - CompileTimeErrorCode.PART_OF_NON_PART,
|
| - [partUri.toSource()]));
|
| - } else if (libraryNameNode == null) {
|
| - // TODO(brianwilkerson) Collect the names declared by the part.
|
| - // If they are all the same then we can use that name as the
|
| - // inferred name of the library and present it in a quick-fix.
|
| - // partLibraryNames.add(partLibraryName);
|
| - } else if (libraryNameNode.name != partLibraryName) {
|
| - _errorListener.onError(new AnalysisError(
|
| - librarySource,
|
| - partUri.offset,
|
| - partUri.length,
|
| - StaticWarningCode.PART_OF_DIFFERENT_LIBRARY,
|
| - [libraryNameNode.name, partLibraryName]));
|
| - }
|
| - if (entryPoint == null) {
|
| - entryPoint = _findEntryPoint(part);
|
| - }
|
| - directive.element = part;
|
| - sourcedCompilationUnits.add(part);
|
| - }
|
| - }
|
| - }
|
| - }
|
| - if (hasPartDirective && libraryNameNode == null) {
|
| - _errorListener.onError(new AnalysisError(librarySource, 0, 0,
|
| - ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART));
|
| - }
|
| - //
|
| - // Create and populate the library element.
|
| - //
|
| - LibraryElementImpl libraryElement = new LibraryElementImpl.forNode(
|
| - _analysisContext.getContextFor(librarySource), libraryNameNode);
|
| - _setDocRange(libraryElement, libraryDirective);
|
| - libraryElement.definingCompilationUnit = definingCompilationUnitElement;
|
| - if (entryPoint != null) {
|
| - libraryElement.entryPoint = entryPoint;
|
| - }
|
| - int sourcedUnitCount = sourcedCompilationUnits.length;
|
| - libraryElement.parts = sourcedCompilationUnits;
|
| - for (Directive directive in directivesToResolve) {
|
| - directive.element = libraryElement;
|
| - }
|
| - library.libraryElement = libraryElement;
|
| - if (sourcedUnitCount > 0) {
|
| - _patchTopLevelAccessors(libraryElement);
|
| - }
|
| + LibraryImportScope(this._definingLibrary, this.errorListener) {
|
| + _createImportedNamespaces();
|
| }
|
|
|
| - /**
|
| - * Add all of the non-synthetic getters and setters defined in the given compilation unit that
|
| - * have no corresponding accessor to one of the given collections.
|
| - *
|
| - * @param getters the map to which getters are to be added
|
| - * @param setters the list to which setters are to be added
|
| - * @param unit the compilation unit defining the accessors that are potentially being added
|
| - */
|
| - void _collectAccessors(HashMap<String, PropertyAccessorElement> getters,
|
| - List<PropertyAccessorElement> setters, CompilationUnitElement unit) {
|
| - for (PropertyAccessorElement accessor in unit.accessors) {
|
| - if (accessor.isGetter) {
|
| - if (!accessor.isSynthetic && accessor.correspondingSetter == null) {
|
| - getters[accessor.displayName] = accessor;
|
| - }
|
| - } else {
|
| - if (!accessor.isSynthetic && accessor.correspondingGetter == null) {
|
| - setters.add(accessor);
|
| - }
|
| - }
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Search the top-level functions defined in the given compilation unit for the entry point.
|
| - *
|
| - * @param element the compilation unit to be searched
|
| - * @return the entry point that was found, or `null` if the compilation unit does not define
|
| - * an entry point
|
| - */
|
| - FunctionElement _findEntryPoint(CompilationUnitElementImpl element) {
|
| - for (FunctionElement function in element.functions) {
|
| - if (function.isEntryPoint) {
|
| - return function;
|
| - }
|
| - }
|
| - return null;
|
| - }
|
| -
|
| - /**
|
| - * Return the name of the library that the given part is declared to be a part of, or `null`
|
| - * if the part does not contain a part-of directive.
|
| - *
|
| - * @param partSource the source representing the part
|
| - * @param partUnit the AST structure of the part
|
| - * @param directivesToResolve a list of directives that should be resolved to the library being
|
| - * built
|
| - * @return the name of the library that the given part is declared to be a part of
|
| - */
|
| - String _getPartLibraryName(Source partSource, CompilationUnit partUnit,
|
| - List<Directive> directivesToResolve) {
|
| - for (Directive directive in partUnit.directives) {
|
| - if (directive is PartOfDirective) {
|
| - directivesToResolve.add(directive);
|
| - LibraryIdentifier libraryName = directive.libraryName;
|
| - if (libraryName != null) {
|
| - return libraryName.name;
|
| - }
|
| - }
|
| - }
|
| - return null;
|
| - }
|
| -
|
| - /**
|
| - * Look through all of the compilation units defined for the given library, looking for getters
|
| - * and setters that are defined in different compilation units but that have the same names. If
|
| - * any are found, make sure that they have the same variable element.
|
| - *
|
| - * @param libraryElement the library defining the compilation units to be processed
|
| - */
|
| - void _patchTopLevelAccessors(LibraryElementImpl libraryElement) {
|
| - HashMap<String, PropertyAccessorElement> getters =
|
| - new HashMap<String, PropertyAccessorElement>();
|
| - List<PropertyAccessorElement> setters = new List<PropertyAccessorElement>();
|
| - _collectAccessors(getters, setters, libraryElement.definingCompilationUnit);
|
| - for (CompilationUnitElement unit in libraryElement.parts) {
|
| - _collectAccessors(getters, setters, unit);
|
| - }
|
| - for (PropertyAccessorElement setter in setters) {
|
| - PropertyAccessorElement getter = getters[setter.displayName];
|
| - if (getter != null) {
|
| - PropertyInducingElementImpl variable =
|
| - getter.variable as PropertyInducingElementImpl;
|
| - variable.setter = setter;
|
| - (setter as PropertyAccessorElementImpl).variable = variable;
|
| - }
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * If the given [node] has a documentation comment, remember its range
|
| - * into the given [element].
|
| - */
|
| - void _setDocRange(ElementImpl element, LibraryDirective node) {
|
| - if (node != null) {
|
| - Comment comment = node.documentationComment;
|
| - if (comment != null && comment.isDocumentation) {
|
| - element.setDocRange(comment.offset, comment.length);
|
| - }
|
| - }
|
| - }
|
| -}
|
| -
|
| -/**
|
| - * Instances of the class `LibraryImportScope` represent the scope containing all of the names
|
| - * available from imported libraries.
|
| - */
|
| -class LibraryImportScope extends Scope {
|
| - /**
|
| - * The element representing the library in which this scope is enclosed.
|
| - */
|
| - final LibraryElement _definingLibrary;
|
| -
|
| - /**
|
| - * The listener that is to be informed when an error is encountered.
|
| - */
|
| - final AnalysisErrorListener errorListener;
|
| -
|
| - /**
|
| - * A list of the namespaces representing the names that are available in this scope from imported
|
| - * libraries.
|
| - */
|
| - List<Namespace> _importedNamespaces;
|
| -
|
| - /**
|
| - * Initialize a newly created scope representing the names imported into the given library.
|
| - *
|
| - * @param definingLibrary the element representing the library that imports the names defined in
|
| - * this scope
|
| - * @param errorListener the listener that is to be informed when an error is encountered
|
| - */
|
| - LibraryImportScope(this._definingLibrary, this.errorListener) {
|
| - _createImportedNamespaces();
|
| - }
|
| -
|
| - @override
|
| - void define(Element element) {
|
| - if (!Scope.isPrivateName(element.displayName)) {
|
| - super.define(element);
|
| + @override
|
| + void define(Element element) {
|
| + if (!Scope.isPrivateName(element.displayName)) {
|
| + super.define(element);
|
| }
|
| }
|
|
|
| @@ -7887,1430 +7107,67 @@ class LibraryImportScope extends Scope {
|
| buffer.write(StringUtilities.printListOfQuotedNames(indirectSources));
|
| } else {
|
| buffer.write(indirectSources[0]);
|
| - }
|
| - buffer.write(")");
|
| - }
|
| - return buffer.toString();
|
| - }
|
| -
|
| - /**
|
| - * Given a collection of elements (captured by the [foundElement]) that the
|
| - * [identifier] (with the given [name]) resolved to, remove from the list all
|
| - * of the names defined in the SDK and return the element(s) that remain.
|
| - */
|
| - Element _removeSdkElements(Identifier identifier, String name,
|
| - MultiplyDefinedElementImpl foundElement) {
|
| - List<Element> conflictingElements = foundElement.conflictingElements;
|
| - List<Element> nonSdkElements = new List<Element>();
|
| - Element sdkElement = null;
|
| - for (Element member in conflictingElements) {
|
| - if (member.library.isInSdk) {
|
| - sdkElement = member;
|
| - } else {
|
| - nonSdkElements.add(member);
|
| - }
|
| - }
|
| - if (sdkElement != null && nonSdkElements.length > 0) {
|
| - String sdkLibName = _getLibraryName(sdkElement);
|
| - String otherLibName = _getLibraryName(nonSdkElements[0]);
|
| - errorListener.onError(new AnalysisError(
|
| - getSource(identifier),
|
| - identifier.offset,
|
| - identifier.length,
|
| - StaticWarningCode.CONFLICTING_DART_IMPORT,
|
| - [name, sdkLibName, otherLibName]));
|
| - }
|
| - if (nonSdkElements.length == conflictingElements.length) {
|
| - // None of the members were removed
|
| - return foundElement;
|
| - } else if (nonSdkElements.length == 1) {
|
| - // All but one member was removed
|
| - return nonSdkElements[0];
|
| - } else if (nonSdkElements.length == 0) {
|
| - // All members were removed
|
| - AnalysisEngine.instance.logger
|
| - .logInformation("Multiply defined SDK element: $foundElement");
|
| - return foundElement;
|
| - }
|
| - return new MultiplyDefinedElementImpl(
|
| - _definingLibrary.context, nonSdkElements);
|
| - }
|
| -}
|
| -
|
| -/**
|
| - * Instances of the class `LibraryResolver` are used to resolve one or more mutually dependent
|
| - * libraries within a single context.
|
| - */
|
| -class LibraryResolver {
|
| - /**
|
| - * The analysis context in which the libraries are being analyzed.
|
| - */
|
| - final InternalAnalysisContext analysisContext;
|
| -
|
| - /**
|
| - * The listener to which analysis errors will be reported, this error listener is either
|
| - * references [recordingErrorListener], or it unions the passed
|
| - * [AnalysisErrorListener] with the [recordingErrorListener].
|
| - */
|
| - RecordingErrorListener _errorListener;
|
| -
|
| - /**
|
| - * A source object representing the core library (dart:core).
|
| - */
|
| - Source _coreLibrarySource;
|
| -
|
| - /**
|
| - * A Source object representing the async library (dart:async).
|
| - */
|
| - Source _asyncLibrarySource;
|
| -
|
| - /**
|
| - * The object representing the core library.
|
| - */
|
| - Library _coreLibrary;
|
| -
|
| - /**
|
| - * The object representing the async library.
|
| - */
|
| - Library _asyncLibrary;
|
| -
|
| - /**
|
| - * The object used to access the types from the core library.
|
| - */
|
| - TypeProvider _typeProvider;
|
| -
|
| - /**
|
| - * The type system in use for the library
|
| - */
|
| - TypeSystem _typeSystem;
|
| -
|
| - /**
|
| - * A table mapping library sources to the information being maintained for those libraries.
|
| - */
|
| - HashMap<Source, Library> _libraryMap = new HashMap<Source, Library>();
|
| -
|
| - /**
|
| - * A collection containing the libraries that are being resolved together.
|
| - */
|
| - Set<Library> _librariesInCycles;
|
| -
|
| - /**
|
| - * Initialize a newly created library resolver to resolve libraries within the given context.
|
| - *
|
| - * @param analysisContext the analysis context in which the library is being analyzed
|
| - */
|
| - LibraryResolver(this.analysisContext) {
|
| - this._errorListener = new RecordingErrorListener();
|
| - _coreLibrarySource =
|
| - analysisContext.sourceFactory.forUri(DartSdk.DART_CORE);
|
| - _asyncLibrarySource =
|
| - analysisContext.sourceFactory.forUri(DartSdk.DART_ASYNC);
|
| - }
|
| -
|
| - /**
|
| - * Return the listener to which analysis errors will be reported.
|
| - *
|
| - * @return the listener to which analysis errors will be reported
|
| - */
|
| - RecordingErrorListener get errorListener => _errorListener;
|
| -
|
| - /**
|
| - * Return an array containing information about all of the libraries that were resolved.
|
| - *
|
| - * @return an array containing the libraries that were resolved
|
| - */
|
| - Set<Library> get resolvedLibraries => _librariesInCycles;
|
| -
|
| - /**
|
| - * The object used to access the types from the core library.
|
| - */
|
| - TypeProvider get typeProvider => _typeProvider;
|
| -
|
| - /**
|
| - * The type system in use.
|
| - */
|
| - TypeSystem get typeSystem => _typeSystem;
|
| -
|
| - /**
|
| - * Create an object to represent the information about the library defined by the compilation unit
|
| - * with the given source.
|
| - *
|
| - * @param librarySource the source of the library's defining compilation unit
|
| - * @return the library object that was created
|
| - * @throws AnalysisException if the library source is not valid
|
| - */
|
| - Library createLibrary(Source librarySource) {
|
| - Library library =
|
| - new Library(analysisContext, _errorListener, librarySource);
|
| - _libraryMap[librarySource] = library;
|
| - return library;
|
| - }
|
| -
|
| - /**
|
| - * Resolve the library specified by the given source in the given context. The library is assumed
|
| - * to be embedded in the given source.
|
| - *
|
| - * @param librarySource the source specifying the defining compilation unit of the library to be
|
| - * resolved
|
| - * @param unit the compilation unit representing the embedded library
|
| - * @param fullAnalysis `true` if a full analysis should be performed
|
| - * @return the element representing the resolved library
|
| - * @throws AnalysisException if the library could not be resolved for some reason
|
| - */
|
| - LibraryElement resolveEmbeddedLibrary(
|
| - Source librarySource, CompilationUnit unit, bool fullAnalysis) {
|
| - //
|
| - // Create the objects representing the library being resolved and the core
|
| - // library.
|
| - //
|
| - Library targetLibrary = _createLibraryWithUnit(librarySource, unit);
|
| - _coreLibrary = _libraryMap[_coreLibrarySource];
|
| - if (_coreLibrary == null) {
|
| - // This will only happen if the library being analyzed is the core
|
| - // library.
|
| - _coreLibrary = createLibrary(_coreLibrarySource);
|
| - if (_coreLibrary == null) {
|
| - LibraryResolver2.missingCoreLibrary(
|
| - analysisContext, _coreLibrarySource);
|
| - }
|
| - }
|
| - _asyncLibrary = _libraryMap[_asyncLibrarySource];
|
| - if (_asyncLibrary == null) {
|
| - // This will only happen if the library being analyzed is the async
|
| - // library.
|
| - _asyncLibrary = createLibrary(_asyncLibrarySource);
|
| - if (_asyncLibrary == null) {
|
| - LibraryResolver2.missingAsyncLibrary(
|
| - analysisContext, _asyncLibrarySource);
|
| - }
|
| - }
|
| - //
|
| - // Compute the set of libraries that need to be resolved together.
|
| - //
|
| - _computeEmbeddedLibraryDependencies(targetLibrary, unit);
|
| - _librariesInCycles = _computeLibrariesInCycles(targetLibrary);
|
| - //
|
| - // Build the element models representing the libraries being resolved.
|
| - // This is done in three steps:
|
| - //
|
| - // 1. Build the basic element models without making any connections
|
| - // between elements other than the basic parent/child relationships.
|
| - // This includes building the elements representing the libraries.
|
| - // 2. Build the elements for the import and export directives. This
|
| - // requires that we have the elements built for the referenced
|
| - // libraries, but because of the possibility of circular references
|
| - // needs to happen after all of the library elements have been created.
|
| - // 3. Build the rest of the type model by connecting superclasses, mixins,
|
| - // and interfaces. This requires that we be able to compute the names
|
| - // visible in the libraries being resolved, which in turn requires that
|
| - // we have resolved the import directives.
|
| - //
|
| - _buildElementModels();
|
| - LibraryElement coreElement = _coreLibrary.libraryElement;
|
| - if (coreElement == null) {
|
| - throw new AnalysisException("Could not resolve dart:core");
|
| - }
|
| - LibraryElement asyncElement = _asyncLibrary.libraryElement;
|
| - if (asyncElement == null) {
|
| - throw new AnalysisException("Could not resolve dart:async");
|
| - }
|
| - _buildDirectiveModels();
|
| - _typeProvider = new TypeProviderImpl(coreElement, asyncElement);
|
| - _typeSystem = TypeSystem.create(analysisContext);
|
| - _buildTypeHierarchies();
|
| - //
|
| - // Perform resolution and type analysis.
|
| - //
|
| - // TODO(brianwilkerson) Decide whether we want to resolve all of the
|
| - // libraries or whether we want to only resolve the target library.
|
| - // The advantage to resolving everything is that we have already done part
|
| - // of the work so we'll avoid duplicated effort. The disadvantage of
|
| - // resolving everything is that we might do extra work that we don't
|
| - // really care about. Another possibility is to add a parameter to this
|
| - // method and punt the decision to the clients.
|
| - //
|
| - //if (analyzeAll) {
|
| - resolveReferencesAndTypes();
|
| - //} else {
|
| - // resolveReferencesAndTypes(targetLibrary);
|
| - //}
|
| - _performConstantEvaluation();
|
| - return targetLibrary.libraryElement;
|
| - }
|
| -
|
| - /**
|
| - * Resolve the library specified by the given source in the given context.
|
| - *
|
| - * Note that because Dart allows circular imports between libraries, it is possible that more than
|
| - * one library will need to be resolved. In such cases the error listener can receive errors from
|
| - * multiple libraries.
|
| - *
|
| - * @param librarySource the source specifying the defining compilation unit of the library to be
|
| - * resolved
|
| - * @param fullAnalysis `true` if a full analysis should be performed
|
| - * @return the element representing the resolved library
|
| - * @throws AnalysisException if the library could not be resolved for some reason
|
| - */
|
| - LibraryElement resolveLibrary(Source librarySource, bool fullAnalysis) {
|
| - //
|
| - // Create the object representing the library being resolved and compute
|
| - // the dependency relationship. Note that all libraries depend implicitly
|
| - // on core, and we inject an ersatz dependency on async, so once this is
|
| - // done the core and async library elements will have been created.
|
| - //
|
| - Library targetLibrary = createLibrary(librarySource);
|
| - _computeLibraryDependencies(targetLibrary);
|
| - _coreLibrary = _libraryMap[_coreLibrarySource];
|
| - _asyncLibrary = _libraryMap[_asyncLibrarySource];
|
| - //
|
| - // Compute the set of libraries that need to be resolved together.
|
| - //
|
| - _librariesInCycles = _computeLibrariesInCycles(targetLibrary);
|
| - //
|
| - // Build the element models representing the libraries being resolved.
|
| - // This is done in three steps:
|
| - //
|
| - // 1. Build the basic element models without making any connections
|
| - // between elements other than the basic parent/child relationships.
|
| - // This includes building the elements representing the libraries, but
|
| - // excludes members defined in enums.
|
| - // 2. Build the elements for the import and export directives. This
|
| - // requires that we have the elements built for the referenced
|
| - // libraries, but because of the possibility of circular references
|
| - // needs to happen after all of the library elements have been created.
|
| - // 3. Build the members in enum declarations.
|
| - // 4. Build the rest of the type model by connecting superclasses, mixins,
|
| - // and interfaces. This requires that we be able to compute the names
|
| - // visible in the libraries being resolved, which in turn requires that
|
| - // we have resolved the import directives.
|
| - //
|
| - _buildElementModels();
|
| - LibraryElement coreElement = _coreLibrary.libraryElement;
|
| - if (coreElement == null) {
|
| - throw new AnalysisException("Could not resolve dart:core");
|
| - }
|
| - LibraryElement asyncElement = _asyncLibrary.libraryElement;
|
| - if (asyncElement == null) {
|
| - throw new AnalysisException("Could not resolve dart:async");
|
| - }
|
| - _buildDirectiveModels();
|
| - _typeProvider = new TypeProviderImpl(coreElement, asyncElement);
|
| - _typeSystem = TypeSystem.create(analysisContext);
|
| - _buildEnumMembers();
|
| - _buildTypeHierarchies();
|
| - //
|
| - // Perform resolution and type analysis.
|
| - //
|
| - // TODO(brianwilkerson) Decide whether we want to resolve all of the
|
| - // libraries or whether we want to only resolve the target library. The
|
| - // advantage to resolving everything is that we have already done part of
|
| - // the work so we'll avoid duplicated effort. The disadvantage of
|
| - // resolving everything is that we might do extra work that we don't
|
| - // really care about. Another possibility is to add a parameter to this
|
| - // method and punt the decision to the clients.
|
| - //
|
| - //if (analyzeAll) {
|
| - resolveReferencesAndTypes();
|
| - //} else {
|
| - // resolveReferencesAndTypes(targetLibrary);
|
| - //}
|
| - _performConstantEvaluation();
|
| - return targetLibrary.libraryElement;
|
| - }
|
| -
|
| - /**
|
| - * Resolve the identifiers and perform type analysis in the libraries in the current cycle.
|
| - *
|
| - * @throws AnalysisException if any of the identifiers could not be resolved or if any of the
|
| - * libraries could not have their types analyzed
|
| - */
|
| - void resolveReferencesAndTypes() {
|
| - for (Library library in _librariesInCycles) {
|
| - _resolveReferencesAndTypesInLibrary(library);
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Add a dependency to the given map from the referencing library to the referenced library.
|
| - *
|
| - * @param dependencyMap the map to which the dependency is to be added
|
| - * @param referencingLibrary the library that references the referenced library
|
| - * @param referencedLibrary the library referenced by the referencing library
|
| - */
|
| - void _addDependencyToMap(HashMap<Library, List<Library>> dependencyMap,
|
| - Library referencingLibrary, Library referencedLibrary) {
|
| - List<Library> dependentLibraries = dependencyMap[referencedLibrary];
|
| - if (dependentLibraries == null) {
|
| - dependentLibraries = new List<Library>();
|
| - dependencyMap[referencedLibrary] = dependentLibraries;
|
| - }
|
| - dependentLibraries.add(referencingLibrary);
|
| - }
|
| -
|
| - /**
|
| - * Given a library that is part of a cycle that includes the root library, add to the given set of
|
| - * libraries all of the libraries reachable from the root library that are also included in the
|
| - * cycle.
|
| - *
|
| - * @param library the library to be added to the collection of libraries in cycles
|
| - * @param librariesInCycle a collection of the libraries that are in the cycle
|
| - * @param dependencyMap a table mapping libraries to the collection of libraries from which those
|
| - * libraries are referenced
|
| - */
|
| - void _addLibrariesInCycle(Library library, Set<Library> librariesInCycle,
|
| - HashMap<Library, List<Library>> dependencyMap) {
|
| - if (librariesInCycle.add(library)) {
|
| - List<Library> dependentLibraries = dependencyMap[library];
|
| - if (dependentLibraries != null) {
|
| - for (Library dependentLibrary in dependentLibraries) {
|
| - _addLibrariesInCycle(
|
| - dependentLibrary, librariesInCycle, dependencyMap);
|
| - }
|
| - }
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Add the given library, and all libraries reachable from it that have not already been visited,
|
| - * to the given dependency map.
|
| - *
|
| - * @param library the library currently being added to the dependency map
|
| - * @param dependencyMap the dependency map being computed
|
| - * @param visitedLibraries the libraries that have already been visited, used to prevent infinite
|
| - * recursion
|
| - */
|
| - void _addToDependencyMap(
|
| - Library library,
|
| - HashMap<Library, List<Library>> dependencyMap,
|
| - Set<Library> visitedLibraries) {
|
| - if (visitedLibraries.add(library)) {
|
| - bool asyncFound = false;
|
| - for (Library referencedLibrary in library.importsAndExports) {
|
| - _addDependencyToMap(dependencyMap, library, referencedLibrary);
|
| - _addToDependencyMap(referencedLibrary, dependencyMap, visitedLibraries);
|
| - if (identical(referencedLibrary, _asyncLibrary)) {
|
| - asyncFound = true;
|
| - }
|
| - }
|
| - if (!library.explicitlyImportsCore && !identical(library, _coreLibrary)) {
|
| - _addDependencyToMap(dependencyMap, library, _coreLibrary);
|
| - }
|
| - if (!asyncFound && !identical(library, _asyncLibrary)) {
|
| - _addDependencyToMap(dependencyMap, library, _asyncLibrary);
|
| - _addToDependencyMap(_asyncLibrary, dependencyMap, visitedLibraries);
|
| - }
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Build the element model representing the combinators declared by the given directive.
|
| - *
|
| - * @param directive the directive that declares the combinators
|
| - * @return an array containing the import combinators that were built
|
| - */
|
| - List<NamespaceCombinator> _buildCombinators(NamespaceDirective directive) {
|
| - List<NamespaceCombinator> combinators = new List<NamespaceCombinator>();
|
| - for (Combinator combinator in directive.combinators) {
|
| - if (combinator is HideCombinator) {
|
| - HideElementCombinatorImpl hide = new HideElementCombinatorImpl();
|
| - hide.hiddenNames = _getIdentifiers(combinator.hiddenNames);
|
| - combinators.add(hide);
|
| - } else {
|
| - ShowElementCombinatorImpl show = new ShowElementCombinatorImpl();
|
| - show.offset = combinator.offset;
|
| - show.end = combinator.end;
|
| - show.shownNames =
|
| - _getIdentifiers((combinator as ShowCombinator).shownNames);
|
| - combinators.add(show);
|
| - }
|
| - }
|
| - return combinators;
|
| - }
|
| -
|
| - /**
|
| - * Every library now has a corresponding [LibraryElement], so it is now possible to resolve
|
| - * the import and export directives.
|
| - *
|
| - * @throws AnalysisException if the defining compilation unit for any of the libraries could not
|
| - * be accessed
|
| - */
|
| - void _buildDirectiveModels() {
|
| - for (Library library in _librariesInCycles) {
|
| - HashMap<String, PrefixElementImpl> nameToPrefixMap =
|
| - new HashMap<String, PrefixElementImpl>();
|
| - List<ImportElement> imports = new List<ImportElement>();
|
| - List<ExportElement> exports = new List<ExportElement>();
|
| - for (Directive directive in library.definingCompilationUnit.directives) {
|
| - if (directive is ImportDirective) {
|
| - ImportDirective importDirective = directive;
|
| - String uriContent = importDirective.uriContent;
|
| - if (DartUriResolver.isDartExtUri(uriContent)) {
|
| - library.libraryElement.hasExtUri = true;
|
| - }
|
| - Source importedSource = importDirective.source;
|
| - if (importedSource != null) {
|
| - // The imported source will be null if the URI in the import
|
| - // directive was invalid.
|
| - Library importedLibrary = _libraryMap[importedSource];
|
| - if (importedLibrary != null) {
|
| - ImportElementImpl importElement =
|
| - new ImportElementImpl(directive.offset);
|
| - StringLiteral uriLiteral = importDirective.uri;
|
| - importElement.uriOffset = uriLiteral.offset;
|
| - importElement.uriEnd = uriLiteral.end;
|
| - importElement.uri = uriContent;
|
| - importElement.deferred = importDirective.deferredKeyword != null;
|
| - importElement.combinators = _buildCombinators(importDirective);
|
| - LibraryElement importedLibraryElement =
|
| - importedLibrary.libraryElement;
|
| - if (importedLibraryElement != null) {
|
| - importElement.importedLibrary = importedLibraryElement;
|
| - }
|
| - SimpleIdentifier prefixNode = directive.prefix;
|
| - if (prefixNode != null) {
|
| - importElement.prefixOffset = prefixNode.offset;
|
| - String prefixName = prefixNode.name;
|
| - PrefixElementImpl prefix = nameToPrefixMap[prefixName];
|
| - if (prefix == null) {
|
| - prefix = new PrefixElementImpl.forNode(prefixNode);
|
| - nameToPrefixMap[prefixName] = prefix;
|
| - }
|
| - importElement.prefix = prefix;
|
| - prefixNode.staticElement = prefix;
|
| - }
|
| - directive.element = importElement;
|
| - imports.add(importElement);
|
| - if (analysisContext.computeKindOf(importedSource) !=
|
| - SourceKind.LIBRARY) {
|
| - ErrorCode errorCode = (importElement.isDeferred
|
| - ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
|
| - : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY);
|
| - _errorListener.onError(new AnalysisError(
|
| - library.librarySource,
|
| - uriLiteral.offset,
|
| - uriLiteral.length,
|
| - errorCode,
|
| - [uriLiteral.toSource()]));
|
| - }
|
| - }
|
| - }
|
| - } else if (directive is ExportDirective) {
|
| - ExportDirective exportDirective = directive;
|
| - Source exportedSource = exportDirective.source;
|
| - if (exportedSource != null) {
|
| - // The exported source will be null if the URI in the export
|
| - // directive was invalid.
|
| - Library exportedLibrary = _libraryMap[exportedSource];
|
| - if (exportedLibrary != null) {
|
| - ExportElementImpl exportElement =
|
| - new ExportElementImpl(directive.offset);
|
| - StringLiteral uriLiteral = exportDirective.uri;
|
| - exportElement.uriOffset = uriLiteral.offset;
|
| - exportElement.uriEnd = uriLiteral.end;
|
| - exportElement.uri = exportDirective.uriContent;
|
| - exportElement.combinators = _buildCombinators(exportDirective);
|
| - LibraryElement exportedLibraryElement =
|
| - exportedLibrary.libraryElement;
|
| - if (exportedLibraryElement != null) {
|
| - exportElement.exportedLibrary = exportedLibraryElement;
|
| - }
|
| - directive.element = exportElement;
|
| - exports.add(exportElement);
|
| - if (analysisContext.computeKindOf(exportedSource) !=
|
| - SourceKind.LIBRARY) {
|
| - _errorListener.onError(new AnalysisError(
|
| - library.librarySource,
|
| - uriLiteral.offset,
|
| - uriLiteral.length,
|
| - CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
|
| - [uriLiteral.toSource()]));
|
| - }
|
| - }
|
| - }
|
| - }
|
| - }
|
| - Source librarySource = library.librarySource;
|
| - if (!library.explicitlyImportsCore &&
|
| - _coreLibrarySource != librarySource) {
|
| - ImportElementImpl importElement = new ImportElementImpl(-1);
|
| - importElement.importedLibrary = _coreLibrary.libraryElement;
|
| - importElement.synthetic = true;
|
| - imports.add(importElement);
|
| - }
|
| - LibraryElementImpl libraryElement = library.libraryElement;
|
| - libraryElement.imports = imports;
|
| - libraryElement.exports = exports;
|
| - if (libraryElement.entryPoint == null) {
|
| - Namespace namespace = new NamespaceBuilder()
|
| - .createExportNamespaceForLibrary(libraryElement);
|
| - Element element = namespace.get(FunctionElement.MAIN_FUNCTION_NAME);
|
| - if (element is FunctionElement) {
|
| - libraryElement.entryPoint = element;
|
| - }
|
| - }
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Build element models for all of the libraries in the current cycle.
|
| - *
|
| - * @throws AnalysisException if any of the element models cannot be built
|
| - */
|
| - void _buildElementModels() {
|
| - for (Library library in _librariesInCycles) {
|
| - LibraryElementBuilder builder =
|
| - new LibraryElementBuilder(analysisContext, errorListener);
|
| - LibraryElementImpl libraryElement = builder.buildLibrary(library);
|
| - library.libraryElement = libraryElement;
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Build the members in enum declarations. This cannot be done while building the rest of the
|
| - * element model because it depends on being able to access core types, which cannot happen until
|
| - * the rest of the element model has been built (when resolving the core library).
|
| - *
|
| - * @throws AnalysisException if any of the enum members could not be built
|
| - */
|
| - void _buildEnumMembers() {
|
| - PerformanceStatistics.resolve.makeCurrentWhile(() {
|
| - for (Library library in _librariesInCycles) {
|
| - for (Source source in library.compilationUnitSources) {
|
| - EnumMemberBuilder builder = new EnumMemberBuilder(_typeProvider);
|
| - library.getAST(source).accept(builder);
|
| - }
|
| - }
|
| - });
|
| - }
|
| -
|
| - /**
|
| - * Resolve the type hierarchy across all of the types declared in the libraries in the current
|
| - * cycle.
|
| - *
|
| - * @throws AnalysisException if any of the type hierarchies could not be resolved
|
| - */
|
| - void _buildTypeHierarchies() {
|
| - PerformanceStatistics.resolve.makeCurrentWhile(() {
|
| - for (Library library in _librariesInCycles) {
|
| - for (Source source in library.compilationUnitSources) {
|
| - TypeResolverVisitorFactory typeResolverVisitorFactory =
|
| - analysisContext.typeResolverVisitorFactory;
|
| - TypeResolverVisitor visitor = (typeResolverVisitorFactory == null)
|
| - ? new TypeResolverVisitor(library.libraryElement, source,
|
| - _typeProvider, library.errorListener,
|
| - nameScope: library.libraryScope)
|
| - : typeResolverVisitorFactory(library, source, _typeProvider);
|
| - library.getAST(source).accept(visitor);
|
| - }
|
| - library.libraryElement.createLoadLibraryFunction(_typeProvider);
|
| - }
|
| - });
|
| - }
|
| -
|
| - /**
|
| - * Compute a dependency map of libraries reachable from the given library. A dependency map is a
|
| - * table that maps individual libraries to a list of the libraries that either import or export
|
| - * those libraries.
|
| - *
|
| - * This map is used to compute all of the libraries involved in a cycle that include the root
|
| - * library. Given that we only add libraries that are reachable from the root library, when we
|
| - * work backward we are guaranteed to only get libraries in the cycle.
|
| - *
|
| - * @param library the library currently being added to the dependency map
|
| - */
|
| - HashMap<Library, List<Library>> _computeDependencyMap(Library library) {
|
| - HashMap<Library, List<Library>> dependencyMap =
|
| - new HashMap<Library, List<Library>>();
|
| - _addToDependencyMap(library, dependencyMap, new HashSet<Library>());
|
| - return dependencyMap;
|
| - }
|
| -
|
| - /**
|
| - * Recursively traverse the libraries reachable from the given library, creating instances of the
|
| - * class [Library] to represent them, and record the references in the library objects.
|
| - *
|
| - * @param library the library to be processed to find libraries that have not yet been traversed
|
| - * @throws AnalysisException if some portion of the library graph could not be traversed
|
| - */
|
| - void _computeEmbeddedLibraryDependencies(
|
| - Library library, CompilationUnit unit) {
|
| - Source librarySource = library.librarySource;
|
| - HashSet<Source> exportedSources = new HashSet<Source>();
|
| - HashSet<Source> importedSources = new HashSet<Source>();
|
| - for (Directive directive in unit.directives) {
|
| - if (directive is ExportDirective) {
|
| - Source exportSource = _resolveSource(librarySource, directive);
|
| - if (exportSource != null) {
|
| - exportedSources.add(exportSource);
|
| - }
|
| - } else if (directive is ImportDirective) {
|
| - Source importSource = _resolveSource(librarySource, directive);
|
| - if (importSource != null) {
|
| - importedSources.add(importSource);
|
| - }
|
| - }
|
| - }
|
| - _computeLibraryDependenciesFromDirectives(library,
|
| - new List.from(importedSources), new List.from(exportedSources));
|
| - }
|
| -
|
| - /**
|
| - * Return a collection containing all of the libraries reachable from the given library that are
|
| - * contained in a cycle that includes the given library.
|
| - *
|
| - * @param library the library that must be included in any cycles whose members are to be returned
|
| - * @return all of the libraries referenced by the given library that have a circular reference
|
| - * back to the given library
|
| - */
|
| - Set<Library> _computeLibrariesInCycles(Library library) {
|
| - HashMap<Library, List<Library>> dependencyMap =
|
| - _computeDependencyMap(library);
|
| - Set<Library> librariesInCycle = new HashSet<Library>();
|
| - _addLibrariesInCycle(library, librariesInCycle, dependencyMap);
|
| - return librariesInCycle;
|
| - }
|
| -
|
| - /**
|
| - * Recursively traverse the libraries reachable from the given library, creating instances of the
|
| - * class [Library] to represent them, and record the references in the library objects.
|
| - *
|
| - * @param library the library to be processed to find libraries that have not yet been traversed
|
| - * @throws AnalysisException if some portion of the library graph could not be traversed
|
| - */
|
| - void _computeLibraryDependencies(Library library) {
|
| - Source librarySource = library.librarySource;
|
| - _computeLibraryDependenciesFromDirectives(
|
| - library,
|
| - analysisContext.computeImportedLibraries(librarySource),
|
| - analysisContext.computeExportedLibraries(librarySource));
|
| - }
|
| -
|
| - /**
|
| - * Recursively traverse the libraries reachable from the given library, creating instances of the
|
| - * class [Library] to represent them, and record the references in the library objects.
|
| - *
|
| - * @param library the library to be processed to find libraries that have not yet been traversed
|
| - * @param importedSources an array containing the sources that are imported into the given library
|
| - * @param exportedSources an array containing the sources that are exported from the given library
|
| - * @throws AnalysisException if some portion of the library graph could not be traversed
|
| - */
|
| - void _computeLibraryDependenciesFromDirectives(Library library,
|
| - List<Source> importedSources, List<Source> exportedSources) {
|
| - List<Library> importedLibraries = new List<Library>();
|
| - bool explicitlyImportsCore = false;
|
| - bool importsAsync = false;
|
| - for (Source importedSource in importedSources) {
|
| - if (importedSource == _coreLibrarySource) {
|
| - explicitlyImportsCore = true;
|
| - }
|
| - if (importedSource == _asyncLibrarySource) {
|
| - importsAsync = true;
|
| - }
|
| - Library importedLibrary = _libraryMap[importedSource];
|
| - if (importedLibrary == null) {
|
| - importedLibrary = _createLibraryOrNull(importedSource);
|
| - if (importedLibrary != null) {
|
| - _computeLibraryDependencies(importedLibrary);
|
| - }
|
| - }
|
| - if (importedLibrary != null) {
|
| - importedLibraries.add(importedLibrary);
|
| - }
|
| - }
|
| - library.importedLibraries = importedLibraries;
|
| - List<Library> exportedLibraries = new List<Library>();
|
| - for (Source exportedSource in exportedSources) {
|
| - Library exportedLibrary = _libraryMap[exportedSource];
|
| - if (exportedLibrary == null) {
|
| - exportedLibrary = _createLibraryOrNull(exportedSource);
|
| - if (exportedLibrary != null) {
|
| - _computeLibraryDependencies(exportedLibrary);
|
| - }
|
| - }
|
| - if (exportedLibrary != null) {
|
| - exportedLibraries.add(exportedLibrary);
|
| - }
|
| - }
|
| - library.exportedLibraries = exportedLibraries;
|
| - library.explicitlyImportsCore = explicitlyImportsCore;
|
| - if (!explicitlyImportsCore && _coreLibrarySource != library.librarySource) {
|
| - Library importedLibrary = _libraryMap[_coreLibrarySource];
|
| - if (importedLibrary == null) {
|
| - importedLibrary = _createLibraryOrNull(_coreLibrarySource);
|
| - if (importedLibrary != null) {
|
| - _computeLibraryDependencies(importedLibrary);
|
| - }
|
| - }
|
| - }
|
| - if (!importsAsync && _asyncLibrarySource != library.librarySource) {
|
| - Library importedLibrary = _libraryMap[_asyncLibrarySource];
|
| - if (importedLibrary == null) {
|
| - importedLibrary = _createLibraryOrNull(_asyncLibrarySource);
|
| - if (importedLibrary != null) {
|
| - _computeLibraryDependencies(importedLibrary);
|
| - }
|
| - }
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Create an object to represent the information about the library defined by the compilation unit
|
| - * with the given source. Return the library object that was created, or `null` if the
|
| - * source is not valid.
|
| - *
|
| - * @param librarySource the source of the library's defining compilation unit
|
| - * @return the library object that was created
|
| - */
|
| - Library _createLibraryOrNull(Source librarySource) {
|
| - if (!analysisContext.exists(librarySource)) {
|
| - return null;
|
| - }
|
| - Library library =
|
| - new Library(analysisContext, _errorListener, librarySource);
|
| - _libraryMap[librarySource] = library;
|
| - return library;
|
| - }
|
| -
|
| - /**
|
| - * Create an object to represent the information about the library defined by the compilation unit
|
| - * with the given source.
|
| - *
|
| - * @param librarySource the source of the library's defining compilation unit
|
| - * @param unit the compilation unit that defines the library
|
| - * @return the library object that was created
|
| - * @throws AnalysisException if the library source is not valid
|
| - */
|
| - Library _createLibraryWithUnit(Source librarySource, CompilationUnit unit) {
|
| - Library library =
|
| - new Library(analysisContext, _errorListener, librarySource);
|
| - library.setDefiningCompilationUnit(unit);
|
| - _libraryMap[librarySource] = library;
|
| - return library;
|
| - }
|
| -
|
| - /**
|
| - * Return an array containing the lexical identifiers associated with the nodes in the given list.
|
| - *
|
| - * @param names the AST nodes representing the identifiers
|
| - * @return the lexical identifiers associated with the nodes in the list
|
| - */
|
| - List<String> _getIdentifiers(NodeList<SimpleIdentifier> names) {
|
| - int count = names.length;
|
| - List<String> identifiers = new List<String>(count);
|
| - for (int i = 0; i < count; i++) {
|
| - identifiers[i] = names[i].name;
|
| - }
|
| - return identifiers;
|
| - }
|
| -
|
| - /**
|
| - * Compute a value for all of the constants in the libraries being analyzed.
|
| - */
|
| - void _performConstantEvaluation() {
|
| - PerformanceStatistics.resolve.makeCurrentWhile(() {
|
| - ConstantValueComputer computer = new ConstantValueComputer(
|
| - analysisContext,
|
| - _typeProvider,
|
| - analysisContext.declaredVariables,
|
| - null,
|
| - _typeSystem);
|
| - for (Library library in _librariesInCycles) {
|
| - for (Source source in library.compilationUnitSources) {
|
| - try {
|
| - CompilationUnit unit = library.getAST(source);
|
| - if (unit != null) {
|
| - computer.add(unit, source, library.librarySource);
|
| - }
|
| - } on AnalysisException catch (exception, stackTrace) {
|
| - AnalysisEngine.instance.logger.logError(
|
| - "Internal Error: Could not access AST for ${source.fullName} during constant evaluation",
|
| - new CaughtException(exception, stackTrace));
|
| - }
|
| - }
|
| - }
|
| - computer.computeValues();
|
| - // As a temporary workaround for issue 21572, run ConstantVerifier now.
|
| - // TODO(paulberry): remove this workaround once issue 21572 is fixed.
|
| - for (Library library in _librariesInCycles) {
|
| - for (Source source in library.compilationUnitSources) {
|
| - try {
|
| - CompilationUnit unit = library.getAST(source);
|
| - ErrorReporter errorReporter =
|
| - new ErrorReporter(_errorListener, source);
|
| - ConstantVerifier constantVerifier = new ConstantVerifier(
|
| - errorReporter,
|
| - library.libraryElement,
|
| - _typeProvider,
|
| - analysisContext.declaredVariables);
|
| - unit.accept(constantVerifier);
|
| - } on AnalysisException catch (exception, stackTrace) {
|
| - AnalysisEngine.instance.logger.logError(
|
| - "Internal Error: Could not access AST for ${source.fullName} "
|
| - "during constant verification",
|
| - new CaughtException(exception, stackTrace));
|
| - }
|
| - }
|
| - }
|
| - });
|
| - }
|
| -
|
| - /**
|
| - * Resolve the identifiers and perform type analysis in the given library.
|
| - *
|
| - * @param library the library to be resolved
|
| - * @throws AnalysisException if any of the identifiers could not be resolved or if the types in
|
| - * the library cannot be analyzed
|
| - */
|
| - void _resolveReferencesAndTypesInLibrary(Library library) {
|
| - PerformanceStatistics.resolve.makeCurrentWhile(() {
|
| - for (Source source in library.compilationUnitSources) {
|
| - CompilationUnit ast = library.getAST(source);
|
| - ast.accept(new VariableResolverVisitor(library.libraryElement, source,
|
| - _typeProvider, library.errorListener,
|
| - nameScope: library.libraryScope));
|
| - ResolverVisitorFactory visitorFactory =
|
| - analysisContext.resolverVisitorFactory;
|
| - ResolverVisitor visitor = visitorFactory != null
|
| - ? visitorFactory(library, source, _typeProvider)
|
| - : new ResolverVisitor(library.libraryElement, source, _typeProvider,
|
| - library.errorListener,
|
| - nameScope: library.libraryScope,
|
| - inheritanceManager: library.inheritanceManager);
|
| - ast.accept(visitor);
|
| - }
|
| - });
|
| - }
|
| -
|
| - /**
|
| - * Return the result of resolving the URI of the given URI-based directive against the URI of the
|
| - * given library, or `null` if the URI is not valid.
|
| - *
|
| - * @param librarySource the source representing the library containing the directive
|
| - * @param directive the directive which URI should be resolved
|
| - * @return the result of resolving the URI against the URI of the library
|
| - */
|
| - Source _resolveSource(Source librarySource, UriBasedDirective directive) {
|
| - StringLiteral uriLiteral = directive.uri;
|
| - if (uriLiteral is StringInterpolation) {
|
| - return null;
|
| - }
|
| - String uriContent = uriLiteral.stringValue.trim();
|
| - if (uriContent == null || uriContent.isEmpty) {
|
| - return null;
|
| - }
|
| - uriContent = Uri.encodeFull(uriContent);
|
| - return analysisContext.sourceFactory.resolveUri(librarySource, uriContent);
|
| - }
|
| -}
|
| -
|
| -/**
|
| - * Instances of the class `LibraryResolver` are used to resolve one or more mutually dependent
|
| - * libraries within a single context.
|
| - */
|
| -class LibraryResolver2 {
|
| - /**
|
| - * The analysis context in which the libraries are being analyzed.
|
| - */
|
| - final InternalAnalysisContext analysisContext;
|
| -
|
| - /**
|
| - * The listener to which analysis errors will be reported, this error listener is either
|
| - * references [recordingErrorListener], or it unions the passed
|
| - * [AnalysisErrorListener] with the [recordingErrorListener].
|
| - */
|
| - RecordingErrorListener _errorListener;
|
| -
|
| - /**
|
| - * A source object representing the core library (dart:core).
|
| - */
|
| - Source _coreLibrarySource;
|
| -
|
| - /**
|
| - * A source object representing the async library (dart:async).
|
| - */
|
| - Source _asyncLibrarySource;
|
| -
|
| - /**
|
| - * The object representing the core library.
|
| - */
|
| - ResolvableLibrary _coreLibrary;
|
| -
|
| - /**
|
| - * The object representing the async library.
|
| - */
|
| - ResolvableLibrary _asyncLibrary;
|
| -
|
| - /**
|
| - * The object used to access the types from the core library.
|
| - */
|
| - TypeProvider _typeProvider;
|
| -
|
| - /**
|
| - * The type system in use for the library
|
| - */
|
| - TypeSystem _typeSystem;
|
| -
|
| - /**
|
| - * A table mapping library sources to the information being maintained for those libraries.
|
| - */
|
| - HashMap<Source, ResolvableLibrary> _libraryMap =
|
| - new HashMap<Source, ResolvableLibrary>();
|
| -
|
| - /**
|
| - * A collection containing the libraries that are being resolved together.
|
| - */
|
| - List<ResolvableLibrary> _librariesInCycle;
|
| -
|
| - /**
|
| - * Initialize a newly created library resolver to resolve libraries within the given context.
|
| - *
|
| - * @param analysisContext the analysis context in which the library is being analyzed
|
| - */
|
| - LibraryResolver2(this.analysisContext) {
|
| - this._errorListener = new RecordingErrorListener();
|
| - _coreLibrarySource =
|
| - analysisContext.sourceFactory.forUri(DartSdk.DART_CORE);
|
| - _asyncLibrarySource =
|
| - analysisContext.sourceFactory.forUri(DartSdk.DART_ASYNC);
|
| - }
|
| -
|
| - /**
|
| - * Return the listener to which analysis errors will be reported.
|
| - *
|
| - * @return the listener to which analysis errors will be reported
|
| - */
|
| - RecordingErrorListener get errorListener => _errorListener;
|
| -
|
| - /**
|
| - * Return an array containing information about all of the libraries that were resolved.
|
| - *
|
| - * @return an array containing the libraries that were resolved
|
| - */
|
| - List<ResolvableLibrary> get resolvedLibraries => _librariesInCycle;
|
| -
|
| - /**
|
| - * Resolve the library specified by the given source in the given context.
|
| - *
|
| - * Note that because Dart allows circular imports between libraries, it is possible that more than
|
| - * one library will need to be resolved. In such cases the error listener can receive errors from
|
| - * multiple libraries.
|
| - *
|
| - * @param librarySource the source specifying the defining compilation unit of the library to be
|
| - * resolved
|
| - * @param fullAnalysis `true` if a full analysis should be performed
|
| - * @return the element representing the resolved library
|
| - * @throws AnalysisException if the library could not be resolved for some reason
|
| - */
|
| - LibraryElement resolveLibrary(
|
| - Source librarySource, List<ResolvableLibrary> librariesInCycle) {
|
| - //
|
| - // Build the map of libraries that are known.
|
| - //
|
| - this._librariesInCycle = librariesInCycle;
|
| - _libraryMap = _buildLibraryMap();
|
| - ResolvableLibrary targetLibrary = _libraryMap[librarySource];
|
| - _coreLibrary = _libraryMap[_coreLibrarySource];
|
| - _asyncLibrary = _libraryMap[_asyncLibrarySource];
|
| - //
|
| - // Build the element models representing the libraries being resolved.
|
| - // This is done in three steps:
|
| - //
|
| - // 1. Build the basic element models without making any connections
|
| - // between elements other than the basic parent/child relationships.
|
| - // This includes building the elements representing the libraries, but
|
| - // excludes members defined in enums.
|
| - // 2. Build the elements for the import and export directives. This
|
| - // requires that we have the elements built for the referenced
|
| - // libraries, but because of the possibility of circular references
|
| - // needs to happen after all of the library elements have been created.
|
| - // 3. Build the members in enum declarations.
|
| - // 4. Build the rest of the type model by connecting superclasses, mixins,
|
| - // and interfaces. This requires that we be able to compute the names
|
| - // visible in the libraries being resolved, which in turn requires that
|
| - // we have resolved the import directives.
|
| - //
|
| - _buildElementModels();
|
| - LibraryElement coreElement = _coreLibrary.libraryElement;
|
| - if (coreElement == null) {
|
| - missingCoreLibrary(analysisContext, _coreLibrarySource);
|
| - }
|
| - LibraryElement asyncElement = _asyncLibrary.libraryElement;
|
| - if (asyncElement == null) {
|
| - missingAsyncLibrary(analysisContext, _asyncLibrarySource);
|
| - }
|
| - _buildDirectiveModels();
|
| - _typeProvider = new TypeProviderImpl(coreElement, asyncElement);
|
| - _typeSystem = TypeSystem.create(analysisContext);
|
| - _buildEnumMembers();
|
| - _buildTypeHierarchies();
|
| - //
|
| - // Perform resolution and type analysis.
|
| - //
|
| - // TODO(brianwilkerson) Decide whether we want to resolve all of the
|
| - // libraries or whether we want to only resolve the target library. The
|
| - // advantage to resolving everything is that we have already done part of
|
| - // the work so we'll avoid duplicated effort. The disadvantage of
|
| - // resolving everything is that we might do extra work that we don't
|
| - // really care about. Another possibility is to add a parameter to this
|
| - // method and punt the decision to the clients.
|
| - //
|
| - //if (analyzeAll) {
|
| - _resolveReferencesAndTypes();
|
| - //} else {
|
| - // resolveReferencesAndTypes(targetLibrary);
|
| - //}
|
| - _performConstantEvaluation();
|
| - return targetLibrary.libraryElement;
|
| - }
|
| -
|
| - /**
|
| - * Build the element model representing the combinators declared by the given directive.
|
| - *
|
| - * @param directive the directive that declares the combinators
|
| - * @return an array containing the import combinators that were built
|
| - */
|
| - List<NamespaceCombinator> _buildCombinators(NamespaceDirective directive) {
|
| - List<NamespaceCombinator> combinators = new List<NamespaceCombinator>();
|
| - for (Combinator combinator in directive.combinators) {
|
| - if (combinator is HideCombinator) {
|
| - HideElementCombinatorImpl hide = new HideElementCombinatorImpl();
|
| - hide.hiddenNames = _getIdentifiers(combinator.hiddenNames);
|
| - combinators.add(hide);
|
| - } else {
|
| - ShowElementCombinatorImpl show = new ShowElementCombinatorImpl();
|
| - show.offset = combinator.offset;
|
| - show.end = combinator.end;
|
| - show.shownNames =
|
| - _getIdentifiers((combinator as ShowCombinator).shownNames);
|
| - combinators.add(show);
|
| - }
|
| - }
|
| - return combinators;
|
| - }
|
| -
|
| - /**
|
| - * Every library now has a corresponding [LibraryElement], so it is now possible to resolve
|
| - * the import and export directives.
|
| - *
|
| - * @throws AnalysisException if the defining compilation unit for any of the libraries could not
|
| - * be accessed
|
| - */
|
| - void _buildDirectiveModels() {
|
| - for (ResolvableLibrary library in _librariesInCycle) {
|
| - HashMap<String, PrefixElementImpl> nameToPrefixMap =
|
| - new HashMap<String, PrefixElementImpl>();
|
| - List<ImportElement> imports = new List<ImportElement>();
|
| - List<ExportElement> exports = new List<ExportElement>();
|
| - for (Directive directive in library.definingCompilationUnit.directives) {
|
| - if (directive is ImportDirective) {
|
| - ImportDirective importDirective = directive;
|
| - String uriContent = importDirective.uriContent;
|
| - if (DartUriResolver.isDartExtUri(uriContent)) {
|
| - library.libraryElement.hasExtUri = true;
|
| - }
|
| - Source importedSource = importDirective.source;
|
| - if (importedSource != null &&
|
| - analysisContext.exists(importedSource)) {
|
| - // The imported source will be null if the URI in the import
|
| - // directive was invalid.
|
| - ResolvableLibrary importedLibrary = _libraryMap[importedSource];
|
| - if (importedLibrary != null) {
|
| - ImportElementImpl importElement =
|
| - new ImportElementImpl(directive.offset);
|
| - StringLiteral uriLiteral = importDirective.uri;
|
| - if (uriLiteral != null) {
|
| - importElement.uriOffset = uriLiteral.offset;
|
| - importElement.uriEnd = uriLiteral.end;
|
| - }
|
| - importElement.uri = uriContent;
|
| - importElement.deferred = importDirective.deferredKeyword != null;
|
| - importElement.combinators = _buildCombinators(importDirective);
|
| - LibraryElement importedLibraryElement =
|
| - importedLibrary.libraryElement;
|
| - if (importedLibraryElement != null) {
|
| - importElement.importedLibrary = importedLibraryElement;
|
| - }
|
| - SimpleIdentifier prefixNode = directive.prefix;
|
| - if (prefixNode != null) {
|
| - importElement.prefixOffset = prefixNode.offset;
|
| - String prefixName = prefixNode.name;
|
| - PrefixElementImpl prefix = nameToPrefixMap[prefixName];
|
| - if (prefix == null) {
|
| - prefix = new PrefixElementImpl.forNode(prefixNode);
|
| - nameToPrefixMap[prefixName] = prefix;
|
| - }
|
| - importElement.prefix = prefix;
|
| - prefixNode.staticElement = prefix;
|
| - }
|
| - directive.element = importElement;
|
| - imports.add(importElement);
|
| - if (analysisContext.computeKindOf(importedSource) !=
|
| - SourceKind.LIBRARY) {
|
| - ErrorCode errorCode = (importElement.isDeferred
|
| - ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
|
| - : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY);
|
| - _errorListener.onError(new AnalysisError(
|
| - library.librarySource,
|
| - uriLiteral.offset,
|
| - uriLiteral.length,
|
| - errorCode,
|
| - [uriLiteral.toSource()]));
|
| - }
|
| - }
|
| - }
|
| - } else if (directive is ExportDirective) {
|
| - ExportDirective exportDirective = directive;
|
| - Source exportedSource = exportDirective.source;
|
| - if (exportedSource != null &&
|
| - analysisContext.exists(exportedSource)) {
|
| - // The exported source will be null if the URI in the export
|
| - // directive was invalid.
|
| - ResolvableLibrary exportedLibrary = _libraryMap[exportedSource];
|
| - if (exportedLibrary != null) {
|
| - ExportElementImpl exportElement =
|
| - new ExportElementImpl(directive.offset);
|
| - StringLiteral uriLiteral = exportDirective.uri;
|
| - if (uriLiteral != null) {
|
| - exportElement.uriOffset = uriLiteral.offset;
|
| - exportElement.uriEnd = uriLiteral.end;
|
| - }
|
| - exportElement.uri = exportDirective.uriContent;
|
| - exportElement.combinators = _buildCombinators(exportDirective);
|
| - LibraryElement exportedLibraryElement =
|
| - exportedLibrary.libraryElement;
|
| - if (exportedLibraryElement != null) {
|
| - exportElement.exportedLibrary = exportedLibraryElement;
|
| - }
|
| - directive.element = exportElement;
|
| - exports.add(exportElement);
|
| - if (analysisContext.computeKindOf(exportedSource) !=
|
| - SourceKind.LIBRARY) {
|
| - _errorListener.onError(new AnalysisError(
|
| - library.librarySource,
|
| - uriLiteral.offset,
|
| - uriLiteral.length,
|
| - CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
|
| - [uriLiteral.toSource()]));
|
| - }
|
| - }
|
| - }
|
| - }
|
| - }
|
| - Source librarySource = library.librarySource;
|
| - if (!library.explicitlyImportsCore &&
|
| - _coreLibrarySource != librarySource) {
|
| - ImportElementImpl importElement = new ImportElementImpl(-1);
|
| - importElement.importedLibrary = _coreLibrary.libraryElement;
|
| - importElement.synthetic = true;
|
| - imports.add(importElement);
|
| - }
|
| - LibraryElementImpl libraryElement = library.libraryElement;
|
| - libraryElement.imports = imports;
|
| - libraryElement.exports = exports;
|
| - if (libraryElement.entryPoint == null) {
|
| - Namespace namespace = new NamespaceBuilder()
|
| - .createExportNamespaceForLibrary(libraryElement);
|
| - Element element = namespace.get(FunctionElement.MAIN_FUNCTION_NAME);
|
| - if (element is FunctionElement) {
|
| - libraryElement.entryPoint = element;
|
| - }
|
| - }
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Build element models for all of the libraries in the current cycle.
|
| - *
|
| - * @throws AnalysisException if any of the element models cannot be built
|
| - */
|
| - void _buildElementModels() {
|
| - for (ResolvableLibrary library in _librariesInCycle) {
|
| - LibraryElementBuilder builder =
|
| - new LibraryElementBuilder(analysisContext, errorListener);
|
| - builder.buildLibrary2(library);
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Build the members in enum declarations. This cannot be done while building the rest of the
|
| - * element model because it depends on being able to access core types, which cannot happen until
|
| - * the rest of the element model has been built (when resolving the core library).
|
| - *
|
| - * @throws AnalysisException if any of the enum members could not be built
|
| - */
|
| - void _buildEnumMembers() {
|
| - PerformanceStatistics.resolve.makeCurrentWhile(() {
|
| - for (ResolvableLibrary library in _librariesInCycle) {
|
| - for (Source source in library.compilationUnitSources) {
|
| - EnumMemberBuilder builder = new EnumMemberBuilder(_typeProvider);
|
| - library.getAST(source).accept(builder);
|
| - }
|
| - }
|
| - });
|
| - }
|
| -
|
| - HashMap<Source, ResolvableLibrary> _buildLibraryMap() {
|
| - HashMap<Source, ResolvableLibrary> libraryMap =
|
| - new HashMap<Source, ResolvableLibrary>();
|
| - int libraryCount = _librariesInCycle.length;
|
| - for (int i = 0; i < libraryCount; i++) {
|
| - ResolvableLibrary library = _librariesInCycle[i];
|
| - library.errorListener = _errorListener;
|
| - libraryMap[library.librarySource] = library;
|
| - List<ResolvableLibrary> dependencies = library.importsAndExports;
|
| - int dependencyCount = dependencies.length;
|
| - for (int j = 0; j < dependencyCount; j++) {
|
| - ResolvableLibrary dependency = dependencies[j];
|
| - //dependency.setErrorListener(errorListener);
|
| - libraryMap[dependency.librarySource] = dependency;
|
| - }
|
| - }
|
| - return libraryMap;
|
| - }
|
| -
|
| - /**
|
| - * Resolve the type hierarchy across all of the types declared in the libraries in the current
|
| - * cycle.
|
| - *
|
| - * @throws AnalysisException if any of the type hierarchies could not be resolved
|
| - */
|
| - void _buildTypeHierarchies() {
|
| - PerformanceStatistics.resolve.makeCurrentWhile(() {
|
| - for (ResolvableLibrary library in _librariesInCycle) {
|
| - for (ResolvableCompilationUnit unit
|
| - in library.resolvableCompilationUnits) {
|
| - Source source = unit.source;
|
| - CompilationUnit ast = unit.compilationUnit;
|
| - TypeResolverVisitor visitor = new TypeResolverVisitor(
|
| - library.libraryElement,
|
| - source,
|
| - _typeProvider,
|
| - library.libraryScope.errorListener,
|
| - nameScope: library.libraryScope);
|
| - ast.accept(visitor);
|
| - }
|
| - library.libraryElement.createLoadLibraryFunction(_typeProvider);
|
| - }
|
| - });
|
| - }
|
| -
|
| - /**
|
| - * Return an array containing the lexical identifiers associated with the nodes in the given list.
|
| - *
|
| - * @param names the AST nodes representing the identifiers
|
| - * @return the lexical identifiers associated with the nodes in the list
|
| - */
|
| - List<String> _getIdentifiers(NodeList<SimpleIdentifier> names) {
|
| - int count = names.length;
|
| - List<String> identifiers = new List<String>(count);
|
| - for (int i = 0; i < count; i++) {
|
| - identifiers[i] = names[i].name;
|
| - }
|
| - return identifiers;
|
| - }
|
| -
|
| - /**
|
| - * Compute a value for all of the constants in the libraries being analyzed.
|
| - */
|
| - void _performConstantEvaluation() {
|
| - PerformanceStatistics.resolve.makeCurrentWhile(() {
|
| - ConstantValueComputer computer = new ConstantValueComputer(
|
| - analysisContext,
|
| - _typeProvider,
|
| - analysisContext.declaredVariables,
|
| - null,
|
| - _typeSystem);
|
| - for (ResolvableLibrary library in _librariesInCycle) {
|
| - for (ResolvableCompilationUnit unit
|
| - in library.resolvableCompilationUnits) {
|
| - CompilationUnit ast = unit.compilationUnit;
|
| - if (ast != null) {
|
| - computer.add(ast, unit.source, library.librarySource);
|
| - }
|
| - }
|
| - }
|
| - computer.computeValues();
|
| - // As a temporary workaround for issue 21572, run ConstantVerifier now.
|
| - // TODO(paulberry): remove this workaround once issue 21572 is fixed.
|
| - for (ResolvableLibrary library in _librariesInCycle) {
|
| - for (ResolvableCompilationUnit unit
|
| - in library.resolvableCompilationUnits) {
|
| - CompilationUnit ast = unit.compilationUnit;
|
| - ErrorReporter errorReporter =
|
| - new ErrorReporter(_errorListener, unit.source);
|
| - ConstantVerifier constantVerifier = new ConstantVerifier(
|
| - errorReporter,
|
| - library.libraryElement,
|
| - _typeProvider,
|
| - analysisContext.declaredVariables);
|
| - ast.accept(constantVerifier);
|
| - }
|
| - }
|
| - });
|
| - }
|
| -
|
| - /**
|
| - * Resolve the identifiers and perform type analysis in the libraries in the current cycle.
|
| - *
|
| - * @throws AnalysisException if any of the identifiers could not be resolved or if any of the
|
| - * libraries could not have their types analyzed
|
| - */
|
| - void _resolveReferencesAndTypes() {
|
| - for (ResolvableLibrary library in _librariesInCycle) {
|
| - _resolveReferencesAndTypesInLibrary(library);
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Resolve the identifiers and perform type analysis in the given library.
|
| - *
|
| - * @param library the library to be resolved
|
| - * @throws AnalysisException if any of the identifiers could not be resolved or if the types in
|
| - * the library cannot be analyzed
|
| - */
|
| - void _resolveReferencesAndTypesInLibrary(ResolvableLibrary library) {
|
| - PerformanceStatistics.resolve.makeCurrentWhile(() {
|
| - for (ResolvableCompilationUnit unit
|
| - in library.resolvableCompilationUnits) {
|
| - Source source = unit.source;
|
| - CompilationUnit ast = unit.compilationUnit;
|
| - ast.accept(new VariableResolverVisitor(library.libraryElement, source,
|
| - _typeProvider, library.libraryScope.errorListener,
|
| - nameScope: library.libraryScope));
|
| - ResolverVisitor visitor = new ResolverVisitor(library.libraryElement,
|
| - source, _typeProvider, library._libraryScope.errorListener,
|
| - nameScope: library._libraryScope,
|
| - inheritanceManager: library.inheritanceManager);
|
| - ast.accept(visitor);
|
| - }
|
| - });
|
| - }
|
| -
|
| - /**
|
| - * Report that the async library could not be resolved in the given
|
| - * [analysisContext] and throw an exception. [asyncLibrarySource] is the source
|
| - * representing the async library.
|
| - */
|
| - static void missingAsyncLibrary(
|
| - AnalysisContext analysisContext, Source asyncLibrarySource) {
|
| - throw new AnalysisException("Could not resolve dart:async");
|
| + }
|
| + buffer.write(")");
|
| + }
|
| + return buffer.toString();
|
| }
|
|
|
| /**
|
| - * Report that the core library could not be resolved in the given analysis context and throw an
|
| - * exception.
|
| - *
|
| - * @param analysisContext the analysis context in which the failure occurred
|
| - * @param coreLibrarySource the source representing the core library
|
| - * @throws AnalysisException always
|
| + * Given a collection of elements (captured by the [foundElement]) that the
|
| + * [identifier] (with the given [name]) resolved to, remove from the list all
|
| + * of the names defined in the SDK and return the element(s) that remain.
|
| */
|
| - static void missingCoreLibrary(
|
| - AnalysisContext analysisContext, Source coreLibrarySource) {
|
| - throw new AnalysisException("Could not resolve dart:core");
|
| + Element _removeSdkElements(Identifier identifier, String name,
|
| + MultiplyDefinedElementImpl foundElement) {
|
| + List<Element> conflictingElements = foundElement.conflictingElements;
|
| + List<Element> nonSdkElements = new List<Element>();
|
| + Element sdkElement = null;
|
| + for (Element member in conflictingElements) {
|
| + if (member.library.isInSdk) {
|
| + sdkElement = member;
|
| + } else {
|
| + nonSdkElements.add(member);
|
| + }
|
| + }
|
| + if (sdkElement != null && nonSdkElements.length > 0) {
|
| + String sdkLibName = _getLibraryName(sdkElement);
|
| + String otherLibName = _getLibraryName(nonSdkElements[0]);
|
| + errorListener.onError(new AnalysisError(
|
| + getSource(identifier),
|
| + identifier.offset,
|
| + identifier.length,
|
| + StaticWarningCode.CONFLICTING_DART_IMPORT,
|
| + [name, sdkLibName, otherLibName]));
|
| + }
|
| + if (nonSdkElements.length == conflictingElements.length) {
|
| + // None of the members were removed
|
| + return foundElement;
|
| + } else if (nonSdkElements.length == 1) {
|
| + // All but one member was removed
|
| + return nonSdkElements[0];
|
| + } else if (nonSdkElements.length == 0) {
|
| + // All members were removed
|
| + AnalysisEngine.instance.logger
|
| + .logInformation("Multiply defined SDK element: $foundElement");
|
| + return foundElement;
|
| + }
|
| + return new MultiplyDefinedElementImpl(
|
| + _definingLibrary.context, nonSdkElements);
|
| }
|
| }
|
|
|
| /**
|
| + * Instances of the class `LibraryResolver` are used to resolve one or more mutually dependent
|
| + * libraries within a single context.
|
| + */
|
| +
|
| +/**
|
| + * Instances of the class `LibraryResolver` are used to resolve one or more mutually dependent
|
| + * libraries within a single context.
|
| + */
|
| +
|
| +/**
|
| * Instances of the class `LibraryScope` implement a scope containing all of the names defined
|
| * in a given library.
|
| */
|
| @@ -10285,273 +8142,6 @@ class RedirectingConstructorKind extends Enum<RedirectingConstructorKind> {
|
| }
|
|
|
| /**
|
| - * A `ResolvableLibrary` represents a single library during the resolution of
|
| - * some (possibly different) library. They are not intended to be used except
|
| - * during the resolution process.
|
| - */
|
| -class ResolvableLibrary {
|
| - /**
|
| - * An empty array that can be used to initialize lists of libraries.
|
| - */
|
| - static List<ResolvableLibrary> _EMPTY_ARRAY = new List<ResolvableLibrary>(0);
|
| -
|
| - /**
|
| - * The next artificial hash code.
|
| - */
|
| - static int _NEXT_HASH_CODE = 0;
|
| -
|
| - /**
|
| - * The artifitial hash code for this object.
|
| - */
|
| - final int _hashCode = _nextHashCode();
|
| -
|
| - /**
|
| - * The source specifying the defining compilation unit of this library.
|
| - */
|
| - final Source librarySource;
|
| -
|
| - /**
|
| - * A list containing all of the libraries that are imported into this library.
|
| - */
|
| - List<ResolvableLibrary> _importedLibraries = _EMPTY_ARRAY;
|
| -
|
| - /**
|
| - * A flag indicating whether this library explicitly imports core.
|
| - */
|
| - bool explicitlyImportsCore = false;
|
| -
|
| - /**
|
| - * An array containing all of the libraries that are exported from this library.
|
| - */
|
| - List<ResolvableLibrary> _exportedLibraries = _EMPTY_ARRAY;
|
| -
|
| - /**
|
| - * An array containing the compilation units that comprise this library. The
|
| - * defining compilation unit is always first.
|
| - */
|
| - List<ResolvableCompilationUnit> _compilationUnits;
|
| -
|
| - /**
|
| - * The library element representing this library.
|
| - */
|
| - LibraryElementImpl _libraryElement;
|
| -
|
| - /**
|
| - * The listener to which analysis errors will be reported.
|
| - */
|
| - AnalysisErrorListener _errorListener;
|
| -
|
| - /**
|
| - * The inheritance manager which is used for member lookups in this library.
|
| - */
|
| - InheritanceManager _inheritanceManager;
|
| -
|
| - /**
|
| - * The library scope used when resolving elements within this library's compilation units.
|
| - */
|
| - LibraryScope _libraryScope;
|
| -
|
| - /**
|
| - * Initialize a newly created data holder that can maintain the data associated with a library.
|
| - *
|
| - * @param librarySource the source specifying the defining compilation unit of this library
|
| - * @param errorListener the listener to which analysis errors will be reported
|
| - */
|
| - ResolvableLibrary(this.librarySource);
|
| -
|
| - /**
|
| - * Return an array of the [CompilationUnit]s that make up the library. The first unit is
|
| - * always the defining unit.
|
| - *
|
| - * @return an array of the [CompilationUnit]s that make up the library. The first unit is
|
| - * always the defining unit
|
| - */
|
| - List<CompilationUnit> get compilationUnits {
|
| - int count = _compilationUnits.length;
|
| - List<CompilationUnit> units = new List<CompilationUnit>(count);
|
| - for (int i = 0; i < count; i++) {
|
| - units[i] = _compilationUnits[i].compilationUnit;
|
| - }
|
| - return units;
|
| - }
|
| -
|
| - /**
|
| - * Return an array containing the sources for the compilation units in this library, including the
|
| - * defining compilation unit.
|
| - *
|
| - * @return the sources for the compilation units in this library
|
| - */
|
| - List<Source> get compilationUnitSources {
|
| - int count = _compilationUnits.length;
|
| - List<Source> sources = new List<Source>(count);
|
| - for (int i = 0; i < count; i++) {
|
| - sources[i] = _compilationUnits[i].source;
|
| - }
|
| - return sources;
|
| - }
|
| -
|
| - /**
|
| - * Return the AST structure associated with the defining compilation unit for this library.
|
| - *
|
| - * @return the AST structure associated with the defining compilation unit for this library
|
| - * @throws AnalysisException if an AST structure could not be created for the defining compilation
|
| - * unit
|
| - */
|
| - CompilationUnit get definingCompilationUnit =>
|
| - _compilationUnits[0].compilationUnit;
|
| -
|
| - /**
|
| - * Set the listener to which analysis errors will be reported to be the given listener.
|
| - *
|
| - * @param errorListener the listener to which analysis errors will be reported
|
| - */
|
| - void set errorListener(AnalysisErrorListener errorListener) {
|
| - this._errorListener = errorListener;
|
| - }
|
| -
|
| - /**
|
| - * Set the libraries that are exported by this library to be those in the given array.
|
| - *
|
| - * @param exportedLibraries the libraries that are exported by this library
|
| - */
|
| - void set exportedLibraries(List<ResolvableLibrary> exportedLibraries) {
|
| - this._exportedLibraries = exportedLibraries;
|
| - }
|
| -
|
| - /**
|
| - * Return an array containing the libraries that are exported from this library.
|
| - *
|
| - * @return an array containing the libraries that are exported from this library
|
| - */
|
| - List<ResolvableLibrary> get exports => _exportedLibraries;
|
| -
|
| - @override
|
| - int get hashCode => _hashCode;
|
| -
|
| - /**
|
| - * Set the libraries that are imported into this library to be those in the given array.
|
| - *
|
| - * @param importedLibraries the libraries that are imported into this library
|
| - */
|
| - void set importedLibraries(List<ResolvableLibrary> importedLibraries) {
|
| - this._importedLibraries = importedLibraries;
|
| - }
|
| -
|
| - /**
|
| - * Return an array containing the libraries that are imported into this library.
|
| - *
|
| - * @return an array containing the libraries that are imported into this library
|
| - */
|
| - List<ResolvableLibrary> get imports => _importedLibraries;
|
| -
|
| - /**
|
| - * Return an array containing the libraries that are either imported or exported from this
|
| - * library.
|
| - *
|
| - * @return the libraries that are either imported or exported from this library
|
| - */
|
| - List<ResolvableLibrary> get importsAndExports {
|
| - HashSet<ResolvableLibrary> libraries = new HashSet<ResolvableLibrary>();
|
| - for (ResolvableLibrary library in _importedLibraries) {
|
| - libraries.add(library);
|
| - }
|
| - for (ResolvableLibrary library in _exportedLibraries) {
|
| - libraries.add(library);
|
| - }
|
| - return new List.from(libraries);
|
| - }
|
| -
|
| - /**
|
| - * Return the inheritance manager for this library.
|
| - *
|
| - * @return the inheritance manager for this library
|
| - */
|
| - InheritanceManager get inheritanceManager {
|
| - if (_inheritanceManager == null) {
|
| - return _inheritanceManager = new InheritanceManager(_libraryElement);
|
| - }
|
| - return _inheritanceManager;
|
| - }
|
| -
|
| - /**
|
| - * Return the library element representing this library, creating it if necessary.
|
| - *
|
| - * @return the library element representing this library
|
| - */
|
| - LibraryElementImpl get libraryElement => _libraryElement;
|
| -
|
| - /**
|
| - * Set the library element representing this library to the given library element.
|
| - *
|
| - * @param libraryElement the library element representing this library
|
| - */
|
| - void set libraryElement(LibraryElementImpl libraryElement) {
|
| - this._libraryElement = libraryElement;
|
| - if (_inheritanceManager != null) {
|
| - _inheritanceManager.libraryElement = libraryElement;
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Return the library scope used when resolving elements within this library's compilation units.
|
| - *
|
| - * @return the library scope used when resolving elements within this library's compilation units
|
| - */
|
| - LibraryScope get libraryScope {
|
| - if (_libraryScope == null) {
|
| - _libraryScope = new LibraryScope(_libraryElement, _errorListener);
|
| - }
|
| - return _libraryScope;
|
| - }
|
| -
|
| - /**
|
| - * Return an array containing the compilation units that comprise this library. The defining
|
| - * compilation unit is always first.
|
| - *
|
| - * @return the compilation units that comprise this library
|
| - */
|
| - List<ResolvableCompilationUnit> get resolvableCompilationUnits =>
|
| - _compilationUnits;
|
| -
|
| - /**
|
| - * Set the compilation unit in this library to the given compilation units. The defining
|
| - * compilation unit must be the first element of the array.
|
| - *
|
| - * @param units the compilation units in this library
|
| - */
|
| - void set resolvableCompilationUnits(List<ResolvableCompilationUnit> units) {
|
| - _compilationUnits = units;
|
| - }
|
| -
|
| - /**
|
| - * Return the AST structure associated with the given source, or `null` if the source does
|
| - * not represent a compilation unit that is included in this library.
|
| - *
|
| - * @param source the source representing the compilation unit whose AST is to be returned
|
| - * @return the AST structure associated with the given source
|
| - * @throws AnalysisException if an AST structure could not be created for the compilation unit
|
| - */
|
| - CompilationUnit getAST(Source source) {
|
| - int count = _compilationUnits.length;
|
| - for (int i = 0; i < count; i++) {
|
| - if (_compilationUnits[i].source == source) {
|
| - return _compilationUnits[i].compilationUnit;
|
| - }
|
| - }
|
| - return null;
|
| - }
|
| -
|
| - @override
|
| - String toString() => librarySource.shortName;
|
| -
|
| - static int _nextHashCode() {
|
| - int next = (_NEXT_HASH_CODE + 1) & 0xFFFFFF;
|
| - _NEXT_HASH_CODE = next;
|
| - return next;
|
| - }
|
| -}
|
| -
|
| -/**
|
| * The enumeration `ResolverErrorCode` defines the error codes used for errors
|
| * detected by the resolver. The convention for this class is for the name of
|
| * the error code to indicate the problem that caused the error to be generated
|
|
|