use of com.jetbrains.lang.dart.sdk.DartPackagesLibraryProperties in project intellij-plugins by JetBrains.
the class DartFileListener method updatePackagesLibraryRoots.
@NotNull
public static Library updatePackagesLibraryRoots(@NotNull final Project project, @NotNull final DartLibInfo libInfo) {
final LibraryTable projectLibraryTable = ProjectLibraryTable.getInstance(project);
final Library existingLibrary = projectLibraryTable.getLibraryByName(DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME);
final Library library = existingLibrary != null ? existingLibrary : WriteAction.compute(() -> {
final LibraryTableBase.ModifiableModel libTableModel = ProjectLibraryTable.getInstance(project).getModifiableModel();
final Library lib = libTableModel.createLibrary(DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME, DartPackagesLibraryType.LIBRARY_KIND);
libTableModel.commit();
return lib;
});
final String[] existingUrls = library.getUrls(OrderRootType.CLASSES);
final Collection<String> libRootUrls = libInfo.getLibRootUrls();
if ((!libInfo.isProjectWithoutPubspec() && isBrokenPackageMap(((LibraryEx) library).getProperties())) || existingUrls.length != libRootUrls.size() || !libRootUrls.containsAll(Arrays.asList(existingUrls))) {
ApplicationManager.getApplication().runWriteAction(() -> {
final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx) library.getModifiableModel();
for (String url : existingUrls) {
model.removeRoot(url, OrderRootType.CLASSES);
}
for (String url : libRootUrls) {
model.addRoot(url, OrderRootType.CLASSES);
}
final DartPackagesLibraryProperties libraryProperties = new DartPackagesLibraryProperties();
libraryProperties.setPackageNameToDirsMap(libInfo.getPackagesMap());
model.setProperties(libraryProperties);
model.commit();
});
}
return library;
}
use of com.jetbrains.lang.dart.sdk.DartPackagesLibraryProperties in project intellij-plugins by JetBrains.
the class DartUrlResolverImpl method initPackagesMapFromLib.
private void initPackagesMapFromLib(@NotNull final VirtualFile contextFile) {
final Module module = ModuleUtilCore.findModuleForFile(contextFile, myProject);
final List<OrderEntry> orderEntries = module != null ? Arrays.asList(ModuleRootManager.getInstance(module).getOrderEntries()) : ProjectRootManager.getInstance(myProject).getFileIndex().getOrderEntriesForFile(contextFile);
for (OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof LibraryOrderEntry && LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry) orderEntry).getLibraryLevel()) && DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(((LibraryOrderEntry) orderEntry).getLibraryName())) {
final LibraryEx library = (LibraryEx) ((LibraryOrderEntry) orderEntry).getLibrary();
final LibraryProperties properties = library == null ? null : library.getProperties();
if (properties instanceof DartPackagesLibraryProperties) {
for (Map.Entry<String, List<String>> entry : ((DartPackagesLibraryProperties) properties).getPackageNameToDirsMap().entrySet()) {
if (entry != null && entry.getKey() != null && entry.getValue() != null) {
myPackagesMapFromLib.put(entry.getKey(), entry.getValue());
}
}
return;
}
}
}
}
Aggregations