simplify GTDUCollector a bit more
[idea/community.git] / java / idea-ui / src / com / intellij / ide / util / projectWizard / importSources / impl / JavaProjectStructureDetector.java
1 // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.ide.util.projectWizard.importSources.impl;
3
4 import com.intellij.ide.highlighter.JavaFileType;
5 import com.intellij.ide.util.DelegatingProgressIndicator;
6 import com.intellij.ide.util.importProject.*;
7 import com.intellij.ide.util.projectWizard.ModuleWizardStep;
8 import com.intellij.ide.util.projectWizard.ProjectJdkStep;
9 import com.intellij.ide.util.projectWizard.ProjectWizardStepFactory;
10 import com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetectionUtil;
11 import com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetector;
12 import com.intellij.ide.util.projectWizard.importSources.ProjectFromSourcesBuilder;
13 import com.intellij.java.JavaBundle;
14 import com.intellij.util.NullableFunction;
15 import org.jetbrains.annotations.Nls;
16 import org.jetbrains.annotations.NotNull;
17
18 import javax.swing.*;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 public class JavaProjectStructureDetector extends JavaSourceRootDetector {
23
24   @NotNull
25   @Override
26   protected @Nls(capitalization = Nls.Capitalization.Sentence) String getLanguageName() {
27     return JavaBundle.message("options.java.display.name");
28   }
29
30   @NotNull
31   @Override
32   protected String getFileExtension() {
33     return JavaFileType.DEFAULT_EXTENSION;
34   }
35
36   @Override
37   public List<ModuleWizardStep> createWizardSteps(ProjectFromSourcesBuilder builder,
38                                                   ProjectDescriptor projectDescriptor,
39                                                   Icon stepIcon) {
40     final List<ModuleWizardStep> steps = new ArrayList<>();
41     final ModuleInsight moduleInsight = new JavaModuleInsight(new DelegatingProgressIndicator(), builder.getExistingModuleNames(), builder.getExistingProjectLibraryNames());
42     steps.add(new LibrariesDetectionStep(builder, projectDescriptor, moduleInsight, stepIcon, "reference.dialogs.new.project.fromCode.page1"));
43     steps.add(new ModulesDetectionStep(this, builder, projectDescriptor, moduleInsight, stepIcon, "reference.dialogs.new.project.fromCode.page2"));
44     if (builder.getContext().isCreatingNewProject()) {
45       final ModuleWizardStep jdkStep = ProjectWizardStepFactory.getInstance().createProjectJdkStep(builder.getContext());
46       steps.add(jdkStep);
47       if (jdkStep instanceof ProjectJdkStep) {
48         ((ProjectJdkStep)jdkStep).setProjectDescriptor(projectDescriptor);
49       }
50     }
51     return steps;
52   }
53
54   @Override
55   @NotNull
56   protected NullableFunction<CharSequence, String> getPackageNameFetcher() {
57     return charSequence -> JavaSourceRootDetectionUtil.getPackageName(charSequence);
58   }
59 }