* @param task the task that was performed
* @return an entry containing the computed results
* @throws AnalysisException if the results could not be recorded
*/
private DartEntry recordParseDartTaskResults(ParseDartTask task) throws AnalysisException {
Source source = task.getSource();
AnalysisException thrownException = task.getException();
DartEntry dartEntry = null;
synchronized (cacheLock) {
SourceEntry sourceEntry = cache.get(source);
if (sourceEntry == null) {
throw new ObsoleteSourceAnalysisException(source);
} else if (!(sourceEntry instanceof DartEntry)) {
// This shouldn't be possible because we should never have performed the task if the source
// didn't represent a Dart file, but check to be safe.
throw new AnalysisException(
"Internal error: attempting to parse non-Dart file as a Dart file: "
+ source.getFullName());
}
dartEntry = (DartEntry) sourceEntry;
long sourceTime = getModificationStamp(source);
long resultTime = task.getModificationTime();
if (sourceTime == resultTime) {
if (dartEntry.getModificationTime() != sourceTime) {
// The source has changed without the context being notified. Simulate notification.
sourceChanged(source);
dartEntry = getReadableDartEntry(source);
if (dartEntry == null) {
throw new AnalysisException("A Dart file became a non-Dart file: "
+ source.getFullName());
}
}
removeFromParts(source, dartEntry);
DartEntryImpl dartCopy = dartEntry.getWritableCopy();
if (thrownException == null) {
if (task.hasNonPartOfDirective()) {
dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY);
dartCopy.setContainingLibrary(source);
workManager.add(source, SourcePriority.LIBRARY);
} else if (task.hasPartOfDirective()) {
dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART);
dartCopy.removeContainingLibrary(source);
workManager.add(source, SourcePriority.NORMAL_PART);
} else {
// The file contains no directives.
List<Source> containingLibraries = dartCopy.getContainingLibraries();
if (containingLibraries.size() > 1
|| (containingLibraries.size() == 1 && !containingLibraries.get(0).equals(source))) {
dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART);
dartCopy.removeContainingLibrary(source);
workManager.add(source, SourcePriority.NORMAL_PART);
} else {
dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY);
dartCopy.setContainingLibrary(source);
workManager.add(source, SourcePriority.LIBRARY);
}
}
Source[] newParts = task.getIncludedSources();
for (int i = 0; i < newParts.length; i++) {
Source partSource = newParts[i];
DartEntry partEntry = getReadableDartEntry(partSource);
if (partEntry != null && partEntry != dartEntry) {
DartEntryImpl partCopy = partEntry.getWritableCopy();
// TODO(brianwilkerson) Change the kind of the "part" if it was marked as a library
// and it has no directives.