ImportDirective importDirective = (ImportDirective) directive;
String uriContent = importDirective.getUriContent();
if (DartUriResolver.isDartExtUri(uriContent)) {
library.getLibraryElement().setHasExtUri(true);
}
Source importedSource = importDirective.getSource();
if (importedSource != null && analysisContext.exists(importedSource)) {
// The imported source will be null if the URI in the import directive was invalid.
ResolvableLibrary importedLibrary = libraryMap.get(importedSource);
if (importedLibrary != null) {
ImportElementImpl importElement = new ImportElementImpl(directive.getOffset());
StringLiteral uriLiteral = importDirective.getUri();
if (uriLiteral != null) {
importElement.setUriOffset(uriLiteral.getOffset());
importElement.setUriEnd(uriLiteral.getEnd());
}
importElement.setUri(uriContent);
importElement.setDeferred(importDirective.getDeferredToken() != null);
importElement.setCombinators(buildCombinators(importDirective));
LibraryElement importedLibraryElement = importedLibrary.getLibraryElement();
if (importedLibraryElement != null) {
importElement.setImportedLibrary(importedLibraryElement);
}
SimpleIdentifier prefixNode = ((ImportDirective) directive).getPrefix();
if (prefixNode != null) {
importElement.setPrefixOffset(prefixNode.getOffset());
String prefixName = prefixNode.getName();
PrefixElementImpl prefix = nameToPrefixMap.get(prefixName);
if (prefix == null) {
prefix = new PrefixElementImpl(prefixNode);
nameToPrefixMap.put(prefixName, prefix);
}
importElement.setPrefix(prefix);
prefixNode.setStaticElement(prefix);
}
directive.setElement(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.getLibrarySource(),
uriLiteral.getOffset(),
uriLiteral.getLength(),
errorCode,
uriLiteral.toSource()));
}
}
}
} else if (directive instanceof ExportDirective) {
ExportDirective exportDirective = (ExportDirective) directive;
Source exportedSource = exportDirective.getSource();
if (exportedSource != null && analysisContext.exists(exportedSource)) {
// The exported source will be null if the URI in the export directive was invalid.
ResolvableLibrary exportedLibrary = libraryMap.get(exportedSource);
if (exportedLibrary != null) {
ExportElementImpl exportElement = new ExportElementImpl();
StringLiteral uriLiteral = exportDirective.getUri();
if (uriLiteral != null) {
exportElement.setUriOffset(uriLiteral.getOffset());
exportElement.setUriEnd(uriLiteral.getEnd());
}
exportElement.setUri(exportDirective.getUriContent());
exportElement.setCombinators(buildCombinators(exportDirective));
LibraryElement exportedLibraryElement = exportedLibrary.getLibraryElement();
if (exportedLibraryElement != null) {
exportElement.setExportedLibrary(exportedLibraryElement);
}
directive.setElement(exportElement);
exports.add(exportElement);
if (analysisContext.computeKindOf(exportedSource) != SourceKind.LIBRARY) {
errorListener.onError(new AnalysisError(
library.getLibrarySource(),
uriLiteral.getOffset(),
uriLiteral.getLength(),
CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
uriLiteral.toSource()));
}
}
}
}
}
Source librarySource = library.getLibrarySource();
if (!library.getExplicitlyImportsCore() && !coreLibrarySource.equals(librarySource)) {
ImportElementImpl importElement = new ImportElementImpl(-1);
importElement.setImportedLibrary(coreLibrary.getLibraryElement());
importElement.setSynthetic(true);
imports.add(importElement);