2c3dd03ea1f46f7cd5a75849f34ac7f2b96d1117
[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.util.NullableFunction;
14 import org.jetbrains.annotations.NotNull;
15
16 import javax.swing.*;
17 import java.util.ArrayList;
18 import java.util.List;
19
20 public class JavaProjectStructureDetector extends JavaSourceRootDetector {
21
22   @NotNull
23   @Override
24   protected String getLanguageName() {
25     return "Java";
26   }
27
28   @NotNull
29   @Override
30   protected String getFileExtension() {
31     return JavaFileType.DEFAULT_EXTENSION;
32   }
33
34   @Override
35   public List<ModuleWizardStep> createWizardSteps(ProjectFromSourcesBuilder builder,
36                                                   ProjectDescriptor projectDescriptor,
37                                                   Icon stepIcon) {
38     final List<ModuleWizardStep> steps = new ArrayList<>();
39     final ModuleInsight moduleInsight = new JavaModuleInsight(new DelegatingProgressIndicator(), builder.getExistingModuleNames(), builder.getExistingProjectLibraryNames());
40     steps.add(new LibrariesDetectionStep(builder, projectDescriptor, moduleInsight, stepIcon, "reference.dialogs.new.project.fromCode.page1"));
41     steps.add(new ModulesDetectionStep(this, builder, projectDescriptor, moduleInsight, stepIcon, "reference.dialogs.new.project.fromCode.page2"));
42     if (builder.getContext().isCreatingNewProject()) {
43       final ModuleWizardStep jdkStep = ProjectWizardStepFactory.getInstance().createProjectJdkStep(builder.getContext());
44       steps.add(jdkStep);
45       if (jdkStep instanceof ProjectJdkStep) {
46         ((ProjectJdkStep)jdkStep).setProjectDescriptor(projectDescriptor);
47       }
48     }
49     return steps;
50   }
51
52   @Override
53   @NotNull
54   protected NullableFunction<CharSequence, String> getPackageNameFetcher() {
55     return charSequence -> JavaSourceRootDetectionUtil.getPackageName(charSequence);
56   }
57 }