CompilationUnit definingCompilationUnit = library.getDefiningCompilationUnit();
CompilationUnitElementImpl definingCompilationUnitElement = builder.buildCompilationUnit(
librarySource,
definingCompilationUnit);
NodeList<Directive> directives = definingCompilationUnit.getDirectives();
LibraryIdentifier libraryNameNode = null;
boolean hasPartDirective = false;
FunctionElement entryPoint = findEntryPoint(definingCompilationUnitElement);
ArrayList<Directive> directivesToResolve = new ArrayList<Directive>();
ArrayList<CompilationUnitElementImpl> sourcedCompilationUnits = new ArrayList<CompilationUnitElementImpl>();
for (Directive directive : directives) {
//
// We do not build the elements representing the import and export directives at this point.
// That is not done until we get to LibraryResolver.buildDirectiveModels() because we need the
// LibraryElements for the referenced libraries, which might not exist at this point (due to
// the possibility of circular references).
//
if (directive instanceof LibraryDirective) {
if (libraryNameNode == null) {
libraryNameNode = ((LibraryDirective) directive).getName();
directivesToResolve.add(directive);
}
} else if (directive instanceof PartDirective) {
PartDirective partDirective = (PartDirective) directive;
StringLiteral partUri = partDirective.getUri();
Source partSource = partDirective.getSource();
if (analysisContext.exists(partSource)) {
hasPartDirective = true;
CompilationUnit partUnit = library.getAST(partSource);
CompilationUnitElementImpl part = builder.buildCompilationUnit(partSource, partUnit);
part.setUriOffset(partUri.getOffset());
part.setUriEnd(partUri.getEnd());
part.setUri(partDirective.getUriContent());
//
// Validate that the part contains a part-of directive with the same name as the library.
//
String partLibraryName = getPartLibraryName(partSource, partUnit, directivesToResolve);
if (partLibraryName == null) {
errorListener.onError(new AnalysisError(
librarySource,
partUri.getOffset(),
partUri.getLength(),
CompileTimeErrorCode.PART_OF_NON_PART,
partUri.toSource()));
} else if (libraryNameNode == null) {
// TODO(brianwilkerson) Collect the names declared by the part. If they are all the same
// then we can use that name as the inferred name of the library and present it in a
// quick-fix.
// partLibraryNames.add(partLibraryName);
} else if (!libraryNameNode.getName().equals(partLibraryName)) {
errorListener.onError(new AnalysisError(
librarySource,
partUri.getOffset(),
partUri.getLength(),
StaticWarningCode.PART_OF_DIFFERENT_LIBRARY,
libraryNameNode.getName(),
partLibraryName));
}
if (entryPoint == null) {
entryPoint = findEntryPoint(part);
}