mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactoring: types refined
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package com.intellij.ide.util.importProject;
|
||||
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetectionUtil;
|
||||
import com.intellij.lang.java.JavaParserDefinition;
|
||||
@@ -166,7 +167,7 @@ public class JavaModuleInsight extends ModuleInsight {
|
||||
}
|
||||
}
|
||||
|
||||
protected ModuleDescriptor createModuleDescriptor(final File moduleContentRoot, final Collection<DetectedProjectRoot> sourceRoots) {
|
||||
protected ModuleDescriptor createModuleDescriptor(final File moduleContentRoot, final Collection<DetectedSourceRoot> sourceRoots) {
|
||||
return new ModuleDescriptor(moduleContentRoot, StdModuleTypes.JAVA, sourceRoots);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.ide.util.importProject;
|
||||
import com.intellij.ide.highlighter.ModuleFileType;
|
||||
import com.intellij.ide.util.projectWizard.ModuleBuilder;
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
@@ -38,7 +39,7 @@ import java.util.*;
|
||||
*/
|
||||
public class ModuleDescriptor {
|
||||
private String myName;
|
||||
private final MultiMap<File, DetectedProjectRoot> myContentToSourceRoots = new MultiMap<File, DetectedProjectRoot>();
|
||||
private final MultiMap<File, DetectedSourceRoot> myContentToSourceRoots = new MultiMap<File, DetectedSourceRoot>();
|
||||
private final Set<File> myLibraryFiles = new HashSet<File>();
|
||||
private final Set<ModuleDescriptor> myDependencies = new HashSet<ModuleDescriptor>();
|
||||
private static final Set<String> ourModuleNameStopList = new THashSet<String>(
|
||||
@@ -50,14 +51,14 @@ public class ModuleDescriptor {
|
||||
private List<ModuleBuilder.ModuleConfigurationUpdater> myConfigurationUpdaters = new SmartList<ModuleBuilder.ModuleConfigurationUpdater>();
|
||||
private ModuleType myModuleType;
|
||||
|
||||
public ModuleDescriptor(final File contentRoot, final ModuleType moduleType, final Collection<DetectedProjectRoot> sourceRoots) {
|
||||
public ModuleDescriptor(final File contentRoot, final ModuleType moduleType, final Collection<? extends DetectedSourceRoot> sourceRoots) {
|
||||
myName = suggestModuleName(contentRoot);
|
||||
myContentToSourceRoots.putValues(contentRoot, sourceRoots);
|
||||
myModuleType = moduleType;
|
||||
}
|
||||
|
||||
public ModuleDescriptor(final File contentRoot, final ModuleType moduleType,
|
||||
final DetectedProjectRoot sourceRoot) {
|
||||
final DetectedSourceRoot sourceRoot) {
|
||||
this(contentRoot, moduleType, Collections.singletonList(sourceRoot));
|
||||
}
|
||||
|
||||
@@ -110,19 +111,19 @@ public class ModuleDescriptor {
|
||||
return myContentToSourceRoots.values();
|
||||
}
|
||||
|
||||
public Collection<DetectedProjectRoot> getSourceRoots(File contentRoot) {
|
||||
public Collection<DetectedSourceRoot> getSourceRoots(File contentRoot) {
|
||||
return myContentToSourceRoots.get(contentRoot);
|
||||
}
|
||||
|
||||
public void addContentRoot(File contentRoot) {
|
||||
myContentToSourceRoots.put(contentRoot, new HashSet<DetectedProjectRoot>());
|
||||
myContentToSourceRoots.put(contentRoot, new HashSet<DetectedSourceRoot>());
|
||||
}
|
||||
|
||||
public Collection<DetectedProjectRoot> removeContentRoot(File contentRoot) {
|
||||
public Collection<DetectedSourceRoot> removeContentRoot(File contentRoot) {
|
||||
return myContentToSourceRoots.remove(contentRoot);
|
||||
}
|
||||
|
||||
public void addSourceRoot(final File contentRoot, DetectedProjectRoot sourceRoot) {
|
||||
public void addSourceRoot(final File contentRoot, DetectedSourceRoot sourceRoot) {
|
||||
myContentToSourceRoots.putValue(contentRoot, sourceRoot);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.ide.util.importProject;
|
||||
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.impl.ProjectFromSourcesBuilderImpl;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
@@ -42,7 +43,7 @@ public abstract class ModuleInsight {
|
||||
@NotNull private final ProgressIndicatorWrapper myProgress;
|
||||
|
||||
private final Set<File> myEntryPointRoots = new HashSet<File>();
|
||||
private final List<DetectedProjectRoot> mySourceRoots = new ArrayList<DetectedProjectRoot>();
|
||||
private final List<DetectedSourceRoot> mySourceRoots = new ArrayList<DetectedSourceRoot>();
|
||||
private final Set<String> myIgnoredNames = new HashSet<String>();
|
||||
|
||||
private final Map<File, Set<String>> mySourceRootToReferencedPackagesMap = new HashMap<File, Set<String>>();
|
||||
@@ -59,10 +60,10 @@ public abstract class ModuleInsight {
|
||||
myExistingModuleNames = existingModuleNames;
|
||||
myExistingProjectLibraryNames = existingProjectLibraryNames;
|
||||
myProgress = new ProgressIndicatorWrapper(progress);
|
||||
setRoots(Collections.<File>emptyList(), Collections.<DetectedProjectRoot>emptyList(), Collections.<String>emptySet());
|
||||
setRoots(Collections.<File>emptyList(), Collections.<DetectedSourceRoot>emptyList(), Collections.<String>emptySet());
|
||||
}
|
||||
|
||||
public final void setRoots(final List<File> contentRoots, final List<? extends DetectedProjectRoot> sourceRoots, final Set<String> ignoredNames) {
|
||||
public final void setRoots(final List<File> contentRoots, final List<? extends DetectedSourceRoot> sourceRoots, final Set<String> ignoredNames) {
|
||||
myModules = null;
|
||||
myLibraries = null;
|
||||
|
||||
@@ -96,8 +97,8 @@ public abstract class ModuleInsight {
|
||||
try {
|
||||
myProgress.pushState();
|
||||
|
||||
List<DetectedProjectRoot> processedRoots = new ArrayList<DetectedProjectRoot>();
|
||||
for (DetectedProjectRoot root : mySourceRoots) {
|
||||
List<DetectedSourceRoot> processedRoots = new ArrayList<DetectedSourceRoot>();
|
||||
for (DetectedSourceRoot root : mySourceRoots) {
|
||||
final File sourceRoot = root.getDirectory();
|
||||
if (myIgnoredNames.contains(sourceRoot.getName())) {
|
||||
continue;
|
||||
@@ -118,7 +119,7 @@ public abstract class ModuleInsight {
|
||||
|
||||
myProgress.pushState();
|
||||
myProgress.setText("Building modules layout...");
|
||||
for (DetectedProjectRoot sourceRoot : processedRoots) {
|
||||
for (DetectedSourceRoot sourceRoot : processedRoots) {
|
||||
final File srcRoot = sourceRoot.getDirectory();
|
||||
final File moduleContentRoot = myEntryPointRoots.contains(srcRoot)? srcRoot : srcRoot.getParentFile();
|
||||
ModuleDescriptor moduleDescriptor = contentRootToModules.get(moduleContentRoot);
|
||||
@@ -147,7 +148,7 @@ public abstract class ModuleInsight {
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract ModuleDescriptor createModuleDescriptor(final File moduleContentRoot, Collection<DetectedProjectRoot> sourceRoots);
|
||||
protected abstract ModuleDescriptor createModuleDescriptor(final File moduleContentRoot, Collection<DetectedSourceRoot> sourceRoots);
|
||||
|
||||
private void buildModuleDependencies(final Map<File, ModuleDescriptor> contentRootToModules) {
|
||||
final Set<File> moduleContentRoots = contentRootToModules.keySet();
|
||||
@@ -233,8 +234,8 @@ public abstract class ModuleInsight {
|
||||
public void merge(final ModuleDescriptor mainModule, final ModuleDescriptor module) {
|
||||
for (File contentRoot : module.getContentRoots()) {
|
||||
final File _contentRoot = appendContentRoot(mainModule, contentRoot);
|
||||
final Collection<DetectedProjectRoot> sources = module.getSourceRoots(contentRoot);
|
||||
for (DetectedProjectRoot source : sources) {
|
||||
final Collection<DetectedSourceRoot> sources = module.getSourceRoots(contentRoot);
|
||||
for (DetectedSourceRoot source : sources) {
|
||||
mainModule.addSourceRoot(_contentRoot, source);
|
||||
}
|
||||
}
|
||||
@@ -274,13 +275,13 @@ public abstract class ModuleInsight {
|
||||
public ModuleDescriptor splitModule(final ModuleDescriptor descriptor, String newModuleName, final Collection<File> contentsToExtract) {
|
||||
ModuleDescriptor newModule = null;
|
||||
for (File root : contentsToExtract) {
|
||||
final Collection<DetectedProjectRoot> sources = descriptor.removeContentRoot(root);
|
||||
final Collection<DetectedSourceRoot> sources = descriptor.removeContentRoot(root);
|
||||
if (newModule == null) {
|
||||
newModule = createModuleDescriptor(root, sources != null ? sources : new HashSet<DetectedProjectRoot>());
|
||||
newModule = createModuleDescriptor(root, sources != null ? sources : new HashSet<DetectedSourceRoot>());
|
||||
}
|
||||
else {
|
||||
if (sources != null && sources.size() > 0) {
|
||||
for (DetectedProjectRoot source : sources) {
|
||||
for (DetectedSourceRoot source : sources) {
|
||||
newModule.addSourceRoot(root, source);
|
||||
}
|
||||
}
|
||||
@@ -347,10 +348,10 @@ public abstract class ModuleInsight {
|
||||
return moduleRoot; // no need to include a separate root
|
||||
}
|
||||
if (FileUtil.isAncestor(contentRoot, moduleRoot, true)) {
|
||||
final Collection<DetectedProjectRoot> currentSources = module.getSourceRoots(moduleRoot);
|
||||
final Collection<DetectedSourceRoot> currentSources = module.getSourceRoots(moduleRoot);
|
||||
module.removeContentRoot(moduleRoot);
|
||||
module.addContentRoot(contentRoot);
|
||||
for (DetectedProjectRoot source : currentSources) {
|
||||
for (DetectedSourceRoot source : currentSources) {
|
||||
module.addSourceRoot(contentRoot, source);
|
||||
}
|
||||
return contentRoot; // no need to include a separate root
|
||||
|
||||
+5
-7
@@ -322,7 +322,7 @@ public class ProjectFromSourcesBuilderImpl extends ProjectImportBuilder implemen
|
||||
List<ModuleDescriptor> modules = new ArrayList<ModuleDescriptor>();
|
||||
for (DetectedProjectRoot root : roots) {
|
||||
if (root instanceof DetectedContentRoot) {
|
||||
modules.add(new ModuleDescriptor(root.getDirectory(), ((DetectedContentRoot)root).getModuleType(), Collections.<DetectedProjectRoot>emptyList()));
|
||||
modules.add(new ModuleDescriptor(root.getDirectory(), ((DetectedContentRoot)root).getModuleType(), Collections.<DetectedSourceRoot>emptyList()));
|
||||
}
|
||||
}
|
||||
projectDescriptor.setModules(modules);
|
||||
@@ -357,8 +357,8 @@ public class ProjectFromSourcesBuilderImpl extends ProjectImportBuilder implemen
|
||||
VirtualFile moduleContentRoot = lfs.refreshAndFindFileByPath(FileUtil.toSystemIndependentName(contentRoot.getPath()));
|
||||
if (moduleContentRoot != null) {
|
||||
final ContentEntry contentEntry = rootModel.addContentEntry(moduleContentRoot);
|
||||
final Collection<DetectedProjectRoot> sourceRoots = descriptor.getSourceRoots(contentRoot);
|
||||
for (DetectedProjectRoot srcRoot : sourceRoots) {
|
||||
final Collection<DetectedSourceRoot> sourceRoots = descriptor.getSourceRoots(contentRoot);
|
||||
for (DetectedSourceRoot srcRoot : sourceRoots) {
|
||||
final String srcpath = FileUtil.toSystemIndependentName(srcRoot.getDirectory().getPath());
|
||||
final VirtualFile sourceRoot = lfs.refreshAndFindFileByPath(srcpath);
|
||||
if (sourceRoot != null) {
|
||||
@@ -385,12 +385,10 @@ public class ProjectFromSourcesBuilderImpl extends ProjectImportBuilder implemen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String getPackagePrefix(final DetectedProjectRoot srcRoot) {
|
||||
// TODO we can introduce DetectedProjectRootWithPackagePrefix interface
|
||||
return srcRoot instanceof JavaModuleSourceRoot ? ((JavaModuleSourceRoot)srcRoot).getPackagePrefix() : "";
|
||||
public static String getPackagePrefix(final DetectedSourceRoot srcRoot) {
|
||||
return srcRoot.getPackagePrefix();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+2
-1
@@ -18,6 +18,7 @@ package org.jetbrains.plugins.groovy.mvc;
|
||||
import com.intellij.ide.util.importProject.ModuleDescriptor;
|
||||
import com.intellij.ide.util.importProject.ProjectDescriptor;
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.ProjectFromSourcesBuilder;
|
||||
import com.intellij.openapi.module.StdModuleTypes;
|
||||
|
||||
@@ -47,7 +48,7 @@ public class GroovySdkForProjectFromSourcesStep extends GroovySdkWizardStepBase
|
||||
super.updateDataModel();
|
||||
List<ModuleDescriptor> modules = new ArrayList<ModuleDescriptor>();
|
||||
for (DetectedProjectRoot root : myBuilder.getProjectRoots(myDetector)) {
|
||||
final ModuleDescriptor descriptor = new ModuleDescriptor(root.getDirectory(), StdModuleTypes.JAVA, Collections.<DetectedProjectRoot>emptyList());
|
||||
final ModuleDescriptor descriptor = new ModuleDescriptor(root.getDirectory(), StdModuleTypes.JAVA, Collections.<DetectedSourceRoot>emptyList());
|
||||
descriptor.addConfigurationUpdater(createModuleConfigurationUpdater());
|
||||
modules.add(descriptor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user