private static int rearrangeOrderEntryOfType(
     ModifiableRootModel rootModel, Class<? extends OrderEntry> orderEntryClass) {
   OrderEntry[] orderEntries = rootModel.getOrderEntries();
   int moduleSourcesIdx = 0;
   for (OrderEntry orderEntry : orderEntries) {
     if (orderEntryClass.isAssignableFrom(orderEntry.getClass())) {
       break;
     }
     moduleSourcesIdx++;
   }
   orderEntries = ArrayUtil.append(orderEntries, orderEntries[moduleSourcesIdx]);
   orderEntries = ArrayUtil.remove(orderEntries, moduleSourcesIdx);
   rootModel.rearrangeOrderEntries(orderEntries);
   return orderEntries.length - 1;
 }
 @Override
 protected void addJUnitDefaultLib(
     ModifiableRootModel rootModel, String junitName, ExpandMacroToPathMap macroMap) {
   final Library library =
       rootModel.getModuleLibraryTable().getModifiableModel().createLibrary(junitName);
   final Library.ModifiableModel modifiableModel = library.getModifiableModel();
   modifiableModel.addRoot(getJunitClsUrl(junitName.contains("4")), OrderRootType.CLASSES);
   modifiableModel.commit();
 }
 private static void setLibraryEntryExported(
     ModifiableRootModel rootModel, boolean exported, Library library) {
   for (OrderEntry orderEntry : rootModel.getOrderEntries()) {
     if (orderEntry instanceof LibraryOrderEntry
         && ((LibraryOrderEntry) orderEntry).isModuleLevel()
         && Comparing.equal(((LibraryOrderEntry) orderEntry).getLibrary(), library)) {
       ((LibraryOrderEntry) orderEntry).setExported(exported);
       break;
     }
   }
 }
 @Override
 protected void setUpModuleJdk(
     ModifiableRootModel rootModel,
     Collection<String> unknownJdks,
     EclipseModuleManager eclipseModuleManager,
     String jdkName) {
   if (jdkName == null) {
     rootModel.inheritSdk();
   } else {
     final Sdk moduleJdk = ProjectJdkTable.getInstance().findJdk(jdkName);
     if (moduleJdk != null) {
       rootModel.setSdk(moduleJdk);
     } else {
       rootModel.setInvalidSdk(jdkName, IdeaXml.JAVA_SDK_TYPE);
       eclipseModuleManager.setInvalidJdk(jdkName);
       unknownJdks.add(jdkName);
     }
   }
   rearrangeOrderEntryOfType(rootModel, JdkOrderEntry.class);
 }
 @Override
 protected void addNamedLibrary(
     final ModifiableRootModel rootModel,
     final Collection<String> unknownLibraries,
     final boolean exported,
     final String name,
     final boolean applicationLevel) {
   Library lib = findLibraryByName(myProject, name);
   if (lib != null) {
     rootModel.addLibraryEntry(lib).setExported(exported);
   } else {
     unknownLibraries.add(name);
     rootModel
         .addInvalidLibrary(
             name,
             applicationLevel
                 ? LibraryTablesRegistrar.APPLICATION_LEVEL
                 : LibraryTablesRegistrar.PROJECT_LEVEL)
         .setExported(exported);
   }
 }
 public void readClasspath(
     ModifiableRootModel model,
     final Collection<String> unknownLibraries,
     Collection<String> unknownJdks,
     final Set<String> usedVariables,
     Set<String> refsToModules,
     final String testPattern,
     Element classpathElement)
     throws IOException, ConversionException {
   for (OrderEntry orderEntry : model.getOrderEntries()) {
     if (!(orderEntry instanceof ModuleSourceOrderEntry)) {
       model.removeOrderEntry(orderEntry);
     }
   }
   int idx = 0;
   for (Object o : classpathElement.getChildren(EclipseXml.CLASSPATHENTRY_TAG)) {
     try {
       readClasspathEntry(
           model,
           unknownLibraries,
           unknownJdks,
           usedVariables,
           refsToModules,
           testPattern,
           (Element) o,
           idx++,
           EclipseModuleManagerImpl.getInstance(model.getModule()),
           ((BasePathMacroManager) PathMacroManager.getInstance(model.getModule()))
               .getExpandMacroMap());
     } catch (ConversionException e) {
       ErrorLog.rethrow(ErrorLog.Level.Warning, null, EclipseXml.CLASSPATH_FILE, e);
     }
   }
   if (!model.isSdkInherited() && model.getSdkName() == null) {
     EclipseModuleManagerImpl.getInstance(model.getModule()).setForceConfigureJDK();
     model.inheritSdk();
   }
 }
  @Override
  protected void addModuleLibrary(
      ModifiableRootModel rootModel,
      Element element,
      boolean exported,
      String libName,
      String url,
      String srcUrl,
      ExpandMacroToPathMap macroMap) {
    final Library library =
        rootModel.getModuleLibraryTable().getModifiableModel().createLibrary(libName);
    final Library.ModifiableModel modifiableModel = library.getModifiableModel();
    modifiableModel.addRoot(url, OrderRootType.CLASSES);
    if (srcUrl != null) {
      modifiableModel.addRoot(srcUrl, OrderRootType.SOURCES);
    }
    EJavadocUtil.appendJavadocRoots(element, rootModel, myCurrentRoots, modifiableModel);
    modifiableModel.commit();

    setLibraryEntryExported(rootModel, exported, library);
  }
 public void init(ModifiableRootModel model) {
   myContentEntry = model.addContentEntry(pathToUrl(myRootPath));
 }
 public static void setOutputUrl(ModifiableRootModel rootModel, String path) {
   final CompilerModuleExtension compilerModuleExtension =
       rootModel.getModuleExtension(CompilerModuleExtension.class);
   compilerModuleExtension.setCompilerOutputPath(pathToUrl(path));
   compilerModuleExtension.inheritCompilerOutputPath(false);
 }
 @Override
 protected void addInvalidModuleEntry(
     ModifiableRootModel rootModel, boolean exported, String moduleName) {
   rootModel.addInvalidModuleEntry(moduleName).setExported(exported);
 }
 @Override
 protected void addSourceFolder(ModifiableRootModel rootModel, String srcUrl, boolean testFolder) {
   rootModel.addContentEntry(srcUrl).addSourceFolder(srcUrl, testFolder);
 }