@Override
public Namespace getPublicNamespace(LibraryElement library) {
// TODO(brianwilkerson) Rename this to not start with 'get'. Note that this is not part of the
// API of the interface.
Source source = library.getDefiningCompilationUnit().getSource();
DartEntry dartEntry = getReadableDartEntry(source);
if (dartEntry == null) {
return null;
}
Namespace namespace = null;
if (dartEntry.getValue(DartEntry.ELEMENT) == library) {
namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE);
}
if (namespace == null) {
NamespaceBuilder builder = new NamespaceBuilder();
namespace = builder.createPublicNamespaceForLibrary(library);
synchronized (cacheLock) {
dartEntry = getReadableDartEntry(source);
if (dartEntry == null) {
AnalysisEngine.getInstance().getLogger().logError(
"Could not compute the public namespace for " + library.getSource().getFullName(),
new AnalysisException("A Dart file became a non-Dart file: " + source.getFullName()));
return null;
}
if (dartEntry.getValue(DartEntry.ELEMENT) == library) {
DartEntryImpl dartCopy = getReadableDartEntry(source).getWritableCopy();
dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace);
cache.put(source, dartCopy);
}
}