CompilationUnitElement definingUnitElement = libraryElement.getDefiningCompilationUnit();
if (definingUnitElement == null) {
return false;
}
// prepare sources
Source library = definingUnitElement.getSource();
Source unit = unitElement.getSource();
// special handling for the defining library unit
if (unit.equals(library)) {
// prepare new parts
Set<Source> newParts = Sets.newHashSet();
for (CompilationUnitElement part : libraryElement.getParts()) {
newParts.add(part.getSource());
}
// prepare old parts
Map<Source, Set<Source>> libraryToUnits = contextToLibraryToUnits.get(context);
if (libraryToUnits == null) {
libraryToUnits = Maps.newHashMap();
contextToLibraryToUnits.put(context, libraryToUnits);
}
Set<Source> oldParts = libraryToUnits.get(library);
// check if some parts are not in the library now
if (oldParts != null) {
Set<Source> noParts = Sets.difference(oldParts, newParts);
for (Source noPart : noParts) {
removeLocations(context, library, noPart);
}
}
// remember new parts
libraryToUnits.put(library, newParts);
}
// remember library/unit relations
recordUnitInLibrary(context, library, unit);
recordLibraryWithUnit(context, library, unit);
sources.add(library);
sources.add(unit);
// prepare node
String libraryName = library.getFullName();
String unitName = unit.getFullName();
int libraryNameIndex = stringCodec.encode(libraryName);
int unitNameIndex = stringCodec.encode(unitName);
currentNodeName = libraryNameIndex + "_" + unitNameIndex + ".index";
currentNodeNameId = stringCodec.encode(currentNodeName);
currentNode = nodeManager.newNode(context);