cleanup: introduced method to add source root with default properties
authornik <Nikolay.Chashnikov@jetbrains.com>
Mon, 21 Oct 2013 09:04:22 +0000 (13:04 +0400)
committernik <Nikolay.Chashnikov@jetbrains.com>
Mon, 21 Oct 2013 09:04:22 +0000 (13:04 +0400)
platform/lang-impl/src/com/intellij/ide/projectView/actions/MarkSourceRootAction.java
platform/projectModel-api/src/com/intellij/openapi/roots/ContentEntry.java
platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ContentEntryImpl.java
platform/projectModel-impl/src/com/intellij/project/model/impl/module/content/JpsContentEntry.java
platform/testFramework/src/com/intellij/testFramework/PsiTestUtil.java
plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcModuleStructureUtil.java

index 0a9679b42818dfc9ea68350cc2019f7b461c9a73..aaa21dc9e1456e42c10b665a041a95f93d637227 100644 (file)
@@ -22,7 +22,6 @@ import com.intellij.openapi.roots.SourceFolder;
 import com.intellij.openapi.roots.ui.configuration.ModuleSourceRootEditHandler;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jps.model.JpsElement;
 import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
 
 /**
@@ -41,7 +40,7 @@ public class MarkSourceRootAction extends MarkRootActionBase {
   }
 
   protected void modifyRoots(VirtualFile vFile, ContentEntry entry) {
-    addSourceFolder(vFile, entry, myRootType);
+    entry.addSourceFolder(vFile, myRootType);
   }
 
   @Override
@@ -61,9 +60,4 @@ public class MarkSourceRootAction extends MarkRootActionBase {
     }
     return false;
   }
-
-  private static <P extends JpsElement> void addSourceFolder(VirtualFile vFile, ContentEntry entry,
-                                                             JpsModuleSourceRootType<P> markAsRootType) {
-    entry.addSourceFolder(vFile, markAsRootType, markAsRootType.createDefaultProperties());
-  }
 }
index d6e983cc3481390348c53008e49ee453c92b7323..cfb71ea7efb9f03afe842e26c58e13cf4a048609 100644 (file)
@@ -125,6 +125,10 @@ public interface ContentEntry extends Synthetic {
   <P extends JpsElement>
   SourceFolder addSourceFolder(@NotNull VirtualFile file, @NotNull JpsModuleSourceRootType<P> type, @NotNull P properties);
 
+  @NotNull
+  <P extends JpsElement>
+  SourceFolder addSourceFolder(@NotNull VirtualFile file, @NotNull JpsModuleSourceRootType<P> type);
+
   /**
    * Adds a source or test source root under the content root.
    *
index 085abe64b59e6f1c90778f7c43cb696e199df249..1383ea75e01f7ae2332053c8735d759885aae892 100644 (file)
@@ -207,6 +207,12 @@ public class ContentEntryImpl extends RootModelComponentBase implements ContentE
     return addSourceFolder(new SourceFolderImpl(file, JpsElementFactory.getInstance().createModuleSourceRoot(file.getUrl(), type, properties), this));
   }
 
+  @NotNull
+  @Override
+  public <P extends JpsElement> SourceFolder addSourceFolder(@NotNull VirtualFile file, @NotNull JpsModuleSourceRootType<P> type) {
+    return addSourceFolder(file, type, type.createDefaultProperties());
+  }
+
   @NotNull
   @Override
   public SourceFolder addSourceFolder(@NotNull String url, boolean isTestSource) {
index 49a391d886b2ae1b42bb3346d4eaeeed379a555c..31c4c9f83631ff182de8bed0f00db67fdb2e10ed 100644 (file)
@@ -182,6 +182,12 @@ public class JpsContentEntry implements ContentEntry, Disposable {
     return sourceFolder;
   }
 
+  @NotNull
+  @Override
+  public <P extends JpsElement> SourceFolder addSourceFolder(@NotNull VirtualFile file, @NotNull JpsModuleSourceRootType<P> type) {
+    return addSourceFolder(file, type, type.createDefaultProperties());
+  }
+
   private SourceFolder addSourceFolder(final String url, boolean isTestSource, String packagePrefix) {
     final JavaSourceRootType rootType = isTestSource ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE;
     JpsSimpleElement<JavaSourceRootProperties> properties = JpsElementFactory.getInstance().createSimpleElement(new JavaSourceRootProperties(packagePrefix));
index fd1e91d428eb9535bacb8f0b2e239bc805cc9ef0..794da9486b09de8fea358e8c248fa20d6d5deda4 100644 (file)
@@ -43,8 +43,6 @@ import junit.framework.Assert;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
-import org.jetbrains.jps.model.JpsElement;
-import org.jetbrains.jps.model.JpsElementTypeWithDefaultProperties;
 import org.jetbrains.jps.model.java.JavaSourceRootType;
 import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
 
@@ -157,7 +155,7 @@ public class PsiTestUtil {
       public void consume(ModifiableRootModel model) {
         ContentEntry entry = findContentEntry(model, vDir);
         if (entry == null) entry = model.addContentEntry(vDir);
-        entry.addSourceFolder(vDir, rootType, ((JpsElementTypeWithDefaultProperties<JpsElement>)rootType).createDefaultProperties());
+        entry.addSourceFolder(vDir, rootType);
       }
     });
   }
index 7e71010af35fe0f4a55739f0eee59751e136f03c..36ec3948b267dca48689fded6c5e295917d4cc5f 100644 (file)
@@ -49,9 +49,6 @@ import com.intellij.util.containers.MultiMap;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
-import org.jetbrains.jps.model.JpsElementFactory;
-import org.jetbrains.jps.model.JpsSimpleElement;
-import org.jetbrains.jps.model.java.JavaSourceRootProperties;
 import org.jetbrains.jps.model.java.JavaSourceRootType;
 import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
 
@@ -87,7 +84,7 @@ public class MvcModuleStructureUtil {
                                                                              final MvcProjectStructure structure) {
     ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(structure.myModule);
 
-    Map<VirtualFile, JpsModuleSourceRootType> sourceRoots = new HashMap<VirtualFile, JpsModuleSourceRootType>();
+    Map<VirtualFile, JpsModuleSourceRootType<?>> sourceRoots = new HashMap<VirtualFile, JpsModuleSourceRootType<?>>();
     for (ContentEntry entry : moduleRootManager.getContentEntries()) {
       for (SourceFolder folder : entry.getSourceFolders()) {
         sourceRoots.put(folder.getFile(), folder.getRootType());
@@ -99,7 +96,7 @@ public class MvcModuleStructureUtil {
     final List<Consumer<ContentEntry>> actions = ContainerUtil.newArrayList();
 
     for (Map.Entry<JpsModuleSourceRootType<?>, Collection<String>> entry : structure.getSourceFolders().entrySet()) {
-      JpsModuleSourceRootType rootType = entry.getKey();
+      JpsModuleSourceRootType<?> rootType = entry.getKey();
 
       for (String src : entry.getValue()) {
         addSourceFolder(root, src, rootType, actions, sourceRoots);
@@ -145,7 +142,7 @@ public class MvcModuleStructureUtil {
 
   public static void removeSrcFolderFromRoots(final VirtualFile file,
                                               List<Consumer<ContentEntry>> actions,
-                                              Map<VirtualFile, JpsModuleSourceRootType> sourceRoots) {
+                                              Map<VirtualFile, JpsModuleSourceRootType<?>> sourceRoots) {
     if (sourceRoots.containsKey(file)) {
       actions.add(new Consumer<ContentEntry>() {
         public void consume(ContentEntry contentEntry) {
@@ -204,17 +201,17 @@ public class MvcModuleStructureUtil {
     return library.getModifiableModel();
   }
 
-  public static void addSourceFolder(@NotNull VirtualFile root,
-                                     @NotNull String relativePath,
-                                     final JpsModuleSourceRootType rootType,
-                                     List<Consumer<ContentEntry>> actions,
-                                     Map<VirtualFile, JpsModuleSourceRootType> sourceRoots) {
+  private static void addSourceFolder(@NotNull VirtualFile root,
+                                      @NotNull String relativePath,
+                                      final JpsModuleSourceRootType<?> rootType,
+                                      List<Consumer<ContentEntry>> actions,
+                                      Map<VirtualFile, JpsModuleSourceRootType<?>> sourceRoots) {
     final VirtualFile src = root.findFileByRelativePath(relativePath);
     if (src == null) {
       return;
     }
 
-    JpsModuleSourceRootType existingRootType = sourceRoots.get(src);
+    JpsModuleSourceRootType<?> existingRootType = sourceRoots.get(src);
 
     if (rootType == JavaSourceRootType.TEST_SOURCE && (existingRootType != null && existingRootType != JavaSourceRootType.TEST_SOURCE)) { // see http://youtrack.jetbrains.net/issue/IDEA-70642
       actions.add(new Consumer<ContentEntry>() {
@@ -223,8 +220,7 @@ public class MvcModuleStructureUtil {
           for (SourceFolder folder : entry.getSourceFolders()) {
             if (Comparing.equal(folder.getFile(), src)) {
               entry.removeSourceFolder(folder);
-              JpsSimpleElement<JavaSourceRootProperties> properties = JpsElementFactory.getInstance().createSimpleElement(new JavaSourceRootProperties(""));
-              entry.addSourceFolder(src, rootType, properties);
+              entry.addSourceFolder(src, rootType);
               break;
             }
           }
@@ -235,8 +231,7 @@ public class MvcModuleStructureUtil {
 
     actions.add(new Consumer<ContentEntry>() {
       public void consume(ContentEntry contentEntry) {
-        JpsSimpleElement<JavaSourceRootProperties> properties = JpsElementFactory.getInstance().createSimpleElement(new JavaSourceRootProperties(""));
-        contentEntry.addSourceFolder(src, rootType, properties);
+        contentEntry.addSourceFolder(src, rootType);
       }
     });
   }
@@ -262,13 +257,13 @@ public class MvcModuleStructureUtil {
     }
   }
 
-  public static boolean checkValidity(VirtualFile pluginDir) {
+  private static boolean checkValidity(VirtualFile pluginDir) {
     pluginDir.refresh(false, false);
     return pluginDir.isValid();
   }
 
-  public static List<Consumer<ModifiableRootModel>> getUpdateProjectStructureActions(Collection<VirtualFile> appRoots,
-                                                                                     MvcProjectStructure structure) {
+  private static List<Consumer<ModifiableRootModel>> getUpdateProjectStructureActions(Collection<VirtualFile> appRoots,
+                                                                                      MvcProjectStructure structure) {
     for (final VirtualFile appRoot : ModuleRootManager.getInstance(structure.myModule).getContentRoots()) {
       appRoot.refresh(false, false);
     }