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) {
// The exported source will be null if the URI in the export directive was invalid.
Library exportedLibrary = libraryMap.get(exportedSource);
if (exportedLibrary != null) {
ExportElementImpl exportElement = new ExportElementImpl();
StringLiteral uriLiteral = exportDirective.getUri();
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);