private void appendChosenAnnotationsRoot( @NotNull final OrderEntry entry, @NotNull final VirtualFile vFile) { if (entry instanceof LibraryOrderEntry) { Library library = ((LibraryOrderEntry) entry).getLibrary(); LOG.assertTrue(library != null); final ModifiableRootModel rootModel = ModuleRootManager.getInstance(entry.getOwnerModule()).getModifiableModel(); final Library.ModifiableModel model = library.getModifiableModel(); model.addRoot(vFile, AnnotationOrderRootType.getInstance()); model.commit(); rootModel.commit(); } else if (entry instanceof ModuleSourceOrderEntry) { final ModifiableRootModel model = ModuleRootManager.getInstance(entry.getOwnerModule()).getModifiableModel(); final JavaModuleExternalPaths extension = model.getModuleExtension(JavaModuleExternalPaths.class); extension.setExternalAnnotationUrls( ArrayUtil.mergeArrays(extension.getExternalAnnotationsUrls(), vFile.getUrl())); model.commit(); } else if (entry instanceof JdkOrderEntry) { final SdkModificator sdkModificator = ((JdkOrderEntry) entry).getJdk().getSdkModificator(); sdkModificator.addRoot(vFile, AnnotationOrderRootType.getInstance()); sdkModificator.commitChanges(); } myExternalAnnotations.clear(); }
private static boolean changePackagePrefixes( PsiPackage psiPackage, final String oldQualifiedName, final String newQualifiedName) { final Module[] modules = ModuleManager.getInstance(psiPackage.getProject()).getModules(); List<ModifiableRootModel> modelsToCommit = new ArrayList<ModifiableRootModel>(); for (final Module module : modules) { boolean anyChange = false; final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); for (final ContentEntry contentEntry : rootModel.getContentEntries()) { for (final SourceFolder sourceFolder : contentEntry.getSourceFolders(JavaModuleSourceRootTypes.SOURCES)) { final String packagePrefix = sourceFolder.getPackagePrefix(); if (packagePrefix.startsWith(oldQualifiedName)) { sourceFolder.setPackagePrefix( newQualifiedName + packagePrefix.substring(oldQualifiedName.length())); anyChange = true; } } } if (anyChange) { modelsToCommit.add(rootModel); } else { rootModel.dispose(); } } if (!modelsToCommit.isEmpty()) { ModifiableRootModel[] rootModels = modelsToCommit.toArray(new ModifiableRootModel[modelsToCommit.size()]); if (rootModels.length > 0) { ModifiableModelCommitter.multiCommit( rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel()); } return true; } else { return false; } }