mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
[java] IDEA-375577 Experiment with 'Compact source file' as a separate action
- always show compacts in list - add default name (cherry picked from commit ecd72181f4e0d846389df26210b481e358260261) (cherry picked from commit fbf4436c7f217e4f51c61a68eb19119f1dbc393e) IJ-MR-169535 GitOrigin-RevId: 8ce010a88de6f52400181b025cffe1b5818797e5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1945d7ab58
commit
601316af28
@@ -11,7 +11,6 @@ import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.PackageIndex;
|
||||
import com.intellij.openapi.ui.InputValidatorEx;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
@@ -68,17 +67,14 @@ public class CreateClassAction extends JavaCreateTemplateInPackageAction<PsiClas
|
||||
builder.addKind(JavaPsiBundle.message("node.exception.tooltip"), PlatformIcons.EXCEPTION_CLASS_ICON,
|
||||
JavaTemplateUtil.INTERNAL_EXCEPTION_TYPE_TEMPLATE_NAME);
|
||||
|
||||
if (!Registry.is("java.create.compact.source.file.separately") && JavaFeature.IMPLICIT_CLASSES.isSufficient(level)) {
|
||||
String packageNameByDirectory = PackageIndex.getInstance(project).getPackageNameByDirectory(directory.getVirtualFile());
|
||||
if ("".equals(packageNameByDirectory)) {
|
||||
IconManager iconManager = IconManager.getInstance();
|
||||
Icon icon = iconManager.createLayered(
|
||||
iconManager.getPlatformIcon(com.intellij.ui.PlatformIcons.Class),
|
||||
iconManager.getPlatformIcon(com.intellij.ui.PlatformIcons.FinalMark),
|
||||
iconManager.getPlatformIcon(com.intellij.ui.PlatformIcons.RunnableMark)
|
||||
);
|
||||
builder.addKind(JavaPsiBundle.message("node.simple.source.file.tooltip"), icon, JavaTemplateUtil.INTERNAL_SIMPLE_SOURCE_FILE);
|
||||
}
|
||||
if (JavaFeature.IMPLICIT_CLASSES.isSufficient(level)) {
|
||||
IconManager iconManager = IconManager.getInstance();
|
||||
Icon icon = iconManager.createLayered(
|
||||
iconManager.getPlatformIcon(com.intellij.ui.PlatformIcons.Class),
|
||||
iconManager.getPlatformIcon(com.intellij.ui.PlatformIcons.FinalMark),
|
||||
iconManager.getPlatformIcon(com.intellij.ui.PlatformIcons.RunnableMark)
|
||||
);
|
||||
builder.addKind(JavaPsiBundle.message("node.simple.source.file.tooltip"), icon, JavaTemplateUtil.INTERNAL_SIMPLE_SOURCE_FILE);
|
||||
}
|
||||
|
||||
PsiDirectory[] dirs = {directory};
|
||||
@@ -118,6 +114,17 @@ public class CreateClassAction extends JavaCreateTemplateInPackageAction<PsiClas
|
||||
|
||||
@Override
|
||||
protected final PsiClass doCreate(PsiDirectory dir, String className, String templateName) throws IncorrectOperationException {
|
||||
if (JavaTemplateUtil.INTERNAL_SIMPLE_SOURCE_FILE.equals(templateName)) {
|
||||
Project project = dir.getProject();
|
||||
PsiDirectory current = dir;
|
||||
PackageIndex instance = PackageIndex.getInstance(project);
|
||||
while (current != null) {
|
||||
if ("".equals(instance.getPackageName(current.getVirtualFile()))) {
|
||||
return JavaDirectoryService.getInstance().createClass(current, className, templateName, true);
|
||||
}
|
||||
current = current.getParentDirectory();
|
||||
}
|
||||
}
|
||||
return JavaDirectoryService.getInstance().createClass(dir, className, templateName, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -77,5 +77,15 @@ public class CreateCompactSourceFileAction extends CreateClassAction implements
|
||||
builder.addKind(JavaPsiBundle.message("node.simple.source.file.tooltip"), createIcon(), JavaTemplateUtil.INTERNAL_SIMPLE_SOURCE_FILE);
|
||||
LanguageLevel level = PsiUtil.getLanguageLevel(directory);
|
||||
builder.setValidator(new CreateClassValidator(project, level));
|
||||
String defaultName = "Main";
|
||||
if (directory.findFile(defaultName + ".java") != null) {
|
||||
for (int i = 1; i < 100; i++) {
|
||||
if (directory.findFile(defaultName + i + ".java") == null) {
|
||||
defaultName += i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
builder.setDefaultText(defaultName);
|
||||
}
|
||||
}
|
||||
@@ -83,11 +83,10 @@ class CreateClassActionAvailabilityTest : JavaCodeInsightFixtureTestCase() {
|
||||
|
||||
builder.templateNames.clear()
|
||||
action.buildDialog(project, psiDirectory!!, builder)
|
||||
assertTrue(!builder.templateNames.contains(JavaTemplateUtil.INTERNAL_SIMPLE_SOURCE_FILE))
|
||||
assertTrue(builder.templateNames.contains(JavaTemplateUtil.INTERNAL_SIMPLE_SOURCE_FILE))
|
||||
}
|
||||
|
||||
IdeaTestUtil.withLevel(module, LanguageLevel.JDK_1_8) {
|
||||
|
||||
builder.templateNames.clear()
|
||||
action.buildDialog(project, sourceDirectory!!, builder)
|
||||
assertTrue(!builder.templateNames.contains(JavaTemplateUtil.INTERNAL_SIMPLE_SOURCE_FILE))
|
||||
|
||||
Reference in New Issue
Block a user