From 80d42199fe05be9ddd03ce181f46fb0373b5833a Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 29 Apr 2019 18:36:39 +0300 Subject: [PATCH] cleanup GitOrigin-RevId: 4ae4acc8bf15c9f47423f51e4ecfb05cd4331dcd --- .../artifacts/ui/ArtifactEditorTestCase.java | 3 +- .../projectWizard/ProjectTemplateList.java | 26 +++++-------- .../ide/projectWizard/ProjectTypeStep.java | 35 +++++------------- .../templates/RemoteTemplatesFactory.java | 3 +- .../projectWizard/RemoteTemplatesTest.java | 37 ++++++++++--------- .../EditorTypingAndNavigationUndoTest.java | 2 +- .../openapi/command/undo/GlobalUndoTest.java | 2 +- .../projectWizard/ProjectWizardTestCase.java | 16 ++++---- .../test/ExternalSystemImportingTestCase.java | 4 +- .../openapi/projectRoots/SdkType.java | 2 +- .../com/intellij/openapi/ui/TestDialog.java | 29 +++++---------- .../vfs/encoding/FileEncodingTest.java | 2 +- .../openapi/util/registry/RegistryValue.java | 37 ++++--------------- .../com/jetbrains/env/PyEnvTestCase.java | 2 +- 14 files changed, 73 insertions(+), 127 deletions(-) diff --git a/java/compiler/tests/com/intellij/compiler/artifacts/ui/ArtifactEditorTestCase.java b/java/compiler/tests/com/intellij/compiler/artifacts/ui/ArtifactEditorTestCase.java index 3c74644ece14..9b18c4aa0e3a 100644 --- a/java/compiler/tests/com/intellij/compiler/artifacts/ui/ArtifactEditorTestCase.java +++ b/java/compiler/tests/com/intellij/compiler/artifacts/ui/ArtifactEditorTestCase.java @@ -11,6 +11,7 @@ import com.intellij.openapi.util.Ref; import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.elements.PackagingElementFactory; import com.intellij.util.PathUtil; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.Collections; @@ -79,7 +80,7 @@ public abstract class ArtifactEditorTestCase extends PackagingElementsTestCase { final Ref dialogShown = Ref.create(false); final TestDialog oldDialog = Messages.setTestDialog(new TestDialog() { @Override - public int show(String message) { + public int show(@NotNull String message) { dialogShown.set(true); return 0; } diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTemplateList.java b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTemplateList.java index 465798769829..e0fefcf09d6e 100644 --- a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTemplateList.java +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTemplateList.java @@ -29,11 +29,11 @@ import com.intellij.ui.components.JBList; import com.intellij.ui.popup.list.GroupedItemsListRenderer; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.JBUI; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import javax.swing.*; -import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; import java.util.Collections; @@ -55,7 +55,7 @@ public class ProjectTemplateList extends JPanel { add(myPanel, BorderLayout.CENTER); GroupedItemsListRenderer renderer = new GroupedItemsListRenderer(new ListItemDescriptorAdapter() { - @Nullable + @NotNull @Override public String getTextFor(ProjectTemplate value) { return value.getName(); @@ -80,12 +80,7 @@ public class ProjectTemplateList extends JPanel { } }; myList.setCellRenderer(renderer); - myList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - updateSelection(); - } - }); + myList.getSelectionModel().addListSelectionListener(__ -> updateSelection()); Messages.installHyperlinkSupport(myDescriptionPane); } @@ -104,7 +99,7 @@ public class ProjectTemplateList extends JPanel { } } - public void setTemplates(List list, boolean preserveSelection) { + public void setTemplates(List list, boolean preserveSelection) { Collections.sort(list, (o1, o2) -> Comparing.compare(o1 instanceof ArchivedProjectTemplate, o2 instanceof ArchivedProjectTemplate)); int index = preserveSelection ? myList.getSelectedIndex() : -1; @@ -142,13 +137,10 @@ public class ProjectTemplateList extends JPanel { myList.setSelectedValue(template, true); } } - myList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - ProjectTemplate template = getSelectedTemplate(); - if (template != null) { - PropertiesComponent.getInstance().setValue(PROJECT_WIZARD_TEMPLATE, template.getName()); - } + myList.getSelectionModel().addListSelectionListener(__ -> { + ProjectTemplate template = getSelectedTemplate(); + if (template != null) { + PropertiesComponent.getInstance().setValue(PROJECT_WIZARD_TEMPLATE, template.getName()); } }); } @@ -166,7 +158,7 @@ public class ProjectTemplateList extends JPanel { } @TestOnly - public boolean setSelectedTemplate(String name) { + boolean setSelectedTemplate(@NotNull String name) { ListModel model1 = myList.getModel(); for (int j = 0; j < model1.getSize(); j++) { if (name.equals(((ProjectTemplate)model1.getElementAt(j)).getName())) { diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java index b71e375a0926..43c8b63add22 100644 --- a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java @@ -51,8 +51,6 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import javax.swing.*; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import java.awt.*; import java.net.URL; import java.util.HashMap; @@ -67,9 +65,9 @@ import java.util.*; public class ProjectTypeStep extends ModuleWizardStep implements SettingsStep, Disposable { private static final Logger LOG = Logger.getInstance(ProjectTypeStep.class); - public static final Convertor PROVIDER_STRING_CONVERTOR = + private static final Convertor PROVIDER_STRING_CONVERTOR = o -> o.getId(); - public static final Function NODE_STRING_FUNCTION = FrameworkSupportNodeBase::getId; + private static final Function NODE_STRING_FUNCTION = FrameworkSupportNodeBase::getId; private static final String TEMPLATES_CARD = "templates card"; private static final String FRAMEWORKS_CARD = "frameworks card"; private static final String PROJECT_WIZARD_GROUP = "project.wizard.group"; @@ -103,12 +101,7 @@ public class ProjectTypeStep extends ModuleWizardStep implements SettingsStep, D myProjectTypeList.setModel(new CollectionListModel<>(groups)); myProjectTypeList.setSelectionModel(new SingleSelectionModel()); - myProjectTypeList.addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - updateSelection(); - } - }); + myProjectTypeList.addListSelectionListener(__ -> updateSelection()); myProjectTypeList.setCellRenderer(new GroupedItemsListRenderer(new ListItemDescriptorAdapter() { @Nullable @Override @@ -184,19 +177,9 @@ public class ProjectTypeStep extends ModuleWizardStep implements SettingsStep, D } }; - myProjectTypeList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - projectTypeChanged(); - } - }); + myProjectTypeList.getSelectionModel().addListSelectionListener(__ -> projectTypeChanged()); - myTemplatesList.addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - updateSelection(); - } - }); + myTemplatesList.addListSelectionListener(__ -> updateSelection()); for (TemplatesGroup templatesGroup : myTemplatesMap.keySet()) { ModuleBuilder builder = templatesGroup.getModuleBuilder(); @@ -236,7 +219,7 @@ public class ProjectTypeStep extends ModuleWizardStep implements SettingsStep, D return ContainerUtil.intersects(Arrays.asList(roles), acceptable); } - public static MultiMap getTemplatesMap(WizardContext context) { + private static MultiMap getTemplatesMap(WizardContext context) { ProjectTemplatesFactory[] factories = ProjectTemplatesFactory.EP_NAME.getExtensions(); final MultiMap groups = new MultiMap<>(); for (ProjectTemplatesFactory factory : factories) { @@ -347,7 +330,7 @@ public class ProjectTypeStep extends ModuleWizardStep implements SettingsStep, D } // new TemplatesGroup selected - public void projectTypeChanged() { + private void projectTypeChanged() { TemplatesGroup group = getSelectedGroup(); if (group == null || group == myLastSelectedGroup) return; myLastSelectedGroup = group; @@ -427,7 +410,7 @@ public class ProjectTypeStep extends ModuleWizardStep implements SettingsStep, D showCard(TEMPLATES_CARD); } - private void setTemplatesList(TemplatesGroup group, Collection templates, boolean preserveSelection) { + private void setTemplatesList(TemplatesGroup group, Collection templates, boolean preserveSelection) { List list = new ArrayList<>(templates); ModuleBuilder moduleBuilder = group.getModuleBuilder(); if (moduleBuilder != null && !(moduleBuilder instanceof TemplateModuleBuilder)) { @@ -459,7 +442,7 @@ public class ProjectTypeStep extends ModuleWizardStep implements SettingsStep, D } @Nullable - public ProjectTemplate getSelectedTemplate() { + private ProjectTemplate getSelectedTemplate() { return myCurrentCard == TEMPLATES_CARD ? myTemplatesList.getSelectedTemplate() : null; } diff --git a/java/idea-ui/src/com/intellij/platform/templates/RemoteTemplatesFactory.java b/java/idea-ui/src/com/intellij/platform/templates/RemoteTemplatesFactory.java index 95efcaacb7f4..cf95264bd20b 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/RemoteTemplatesFactory.java +++ b/java/idea-ui/src/com/intellij/platform/templates/RemoteTemplatesFactory.java @@ -17,6 +17,7 @@ import com.intellij.util.NullableFunction; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import com.intellij.util.io.HttpRequests; +import org.intellij.lang.annotations.Language; import org.jdom.Element; import org.jdom.JDOMException; import org.jetbrains.annotations.NotNull; @@ -74,7 +75,7 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory { @NotNull @TestOnly - public static MultiMap createFromText(@NotNull String value) throws IOException, JDOMException { + public static MultiMap createFromText(@NotNull @Language("XML") String value) throws IOException, JDOMException { return create(JDOMUtil.load(value)); } diff --git a/java/idea-ui/testSrc/com/intellij/ide/projectWizard/RemoteTemplatesTest.java b/java/idea-ui/testSrc/com/intellij/ide/projectWizard/RemoteTemplatesTest.java index 74d08af7eae8..a7a215254843 100644 --- a/java/idea-ui/testSrc/com/intellij/ide/projectWizard/RemoteTemplatesTest.java +++ b/java/idea-ui/testSrc/com/intellij/ide/projectWizard/RemoteTemplatesTest.java @@ -19,24 +19,25 @@ import com.intellij.util.containers.MultiMap; */ public class RemoteTemplatesTest extends NewProjectWizardTestCase { public void testParsing() throws Exception { - MultiMap map = RemoteTemplatesFactory.createFromText("\n" + - " \n" + - " \n" + - ""); + MultiMap map = RemoteTemplatesFactory.createFromText( + "\n" + + " \n" + + " \n" + + ""); assertEquals(1, map.size()); ProjectTemplate facelets = map.values().iterator().next(); diff --git a/java/java-tests/testSrc/com/intellij/openapi/command/undo/EditorTypingAndNavigationUndoTest.java b/java/java-tests/testSrc/com/intellij/openapi/command/undo/EditorTypingAndNavigationUndoTest.java index 2a5767fb341b..6aad98050964 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/command/undo/EditorTypingAndNavigationUndoTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/command/undo/EditorTypingAndNavigationUndoTest.java @@ -287,7 +287,7 @@ public class EditorTypingAndNavigationUndoTest extends EditorUndoTestCase { Ref message = new Ref<>(); Messages.setTestDialog(new TestDialog() { @Override - public int show(String m) { + public int show(@NotNull String m) { message.set(m); return Messages.YES; } diff --git a/java/java-tests/testSrc/com/intellij/openapi/command/undo/GlobalUndoTest.java b/java/java-tests/testSrc/com/intellij/openapi/command/undo/GlobalUndoTest.java index 3683c8ff0553..f59aa28e0520 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/command/undo/GlobalUndoTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/command/undo/GlobalUndoTest.java @@ -78,7 +78,7 @@ public class GlobalUndoTest extends UndoTestCase implements TestDialog { } @Override - public int show(String message) { + public int show(@NotNull String message) { myConfirmationWasRequested = true; return 0; } diff --git a/java/testFramework/src/com/intellij/ide/projectWizard/ProjectWizardTestCase.java b/java/testFramework/src/com/intellij/ide/projectWizard/ProjectWizardTestCase.java index 75980c93b05f..08584124d808 100644 --- a/java/testFramework/src/com/intellij/ide/projectWizard/ProjectWizardTestCase.java +++ b/java/testFramework/src/com/intellij/ide/projectWizard/ProjectWizardTestCase.java @@ -127,18 +127,18 @@ public abstract class ProjectWizardTestCase ext return createModuleFromWizard(project); } - protected Module createModuleFromWizard(@NotNull Project project) { + private Module createModuleFromWizard(@NotNull Project project) { return new NewModuleAction().createModuleFromWizard(project, null, myWizard); } - protected void runWizard(@NotNull String group, - @Nullable final String name, - @Nullable Project project, - @Nullable final Consumer adjuster) throws IOException { + private void runWizard(@NotNull String group, + @Nullable final String name, + @Nullable Project project, + @Nullable final Consumer adjuster) throws IOException { createWizard(project); ProjectTypeStep step = (ProjectTypeStep)myWizard.getCurrentStepObject(); if (!step.setSelectedTemplate(group, name)) { - throw new IllegalArgumentException(group + '/' + name + " template not found, available groups " + step.availableTemplateGroupsToString()); + throw new IllegalArgumentException(group + '/' + name + " template not found. Available groups: " + step.availableTemplateGroupsToString()); } runWizard(step1 -> { @@ -151,7 +151,7 @@ public abstract class ProjectWizardTestCase ext }); } - protected void runWizard(@Nullable Consumer adjuster) { + private void runWizard(@Nullable Consumer adjuster) { while (true) { ModuleWizardStep currentStep = myWizard.getCurrentStepObject(); if (adjuster != null) { @@ -236,7 +236,7 @@ public abstract class ProjectWizardTestCase ext return ContainerUtil.getFirstItem(ImportModuleAction.createFromWizard(project, myWizard)); } - private static T computeInWriteSafeContext(Supplier supplier) { + private static T computeInWriteSafeContext(Supplier supplier) { Ref module = Ref.create(); ApplicationManager.getApplication().invokeLater(() -> module.set(supplier.get())); UIUtil.dispatchAllInvocationEvents(); diff --git a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemImportingTestCase.java b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemImportingTestCase.java index 4652e30d845b..de7040a21347 100644 --- a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemImportingTestCase.java +++ b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemImportingTestCase.java @@ -568,7 +568,7 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest final AtomicInteger counter = new AtomicInteger(); Messages.setTestDialog(new TestDialog() { @Override - public int show(String message) { + public int show(@NotNull String message) { counter.set(counter.get() + 1); return 0; } @@ -580,7 +580,7 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest final AtomicInteger counter = new AtomicInteger(); Messages.setTestDialog(new TestDialog() { @Override - public int show(String message) { + public int show(@NotNull String message) { counter.set(counter.get() + 1); return 1; } diff --git a/platform/lang-api/src/com/intellij/openapi/projectRoots/SdkType.java b/platform/lang-api/src/com/intellij/openapi/projectRoots/SdkType.java index 758fce58c11e..14436b9ff3e2 100644 --- a/platform/lang-api/src/com/intellij/openapi/projectRoots/SdkType.java +++ b/platform/lang-api/src/com/intellij/openapi/projectRoots/SdkType.java @@ -244,7 +244,7 @@ public abstract class SdkType implements SdkTypeId { * @param parentComponent the parent component for showing the dialog. * @param selectedSdk current selected sdk in parentComponent * @param sdkCreatedCallback the callback to which the created SDK is passed. - * @implSpec method's implementations should not add sdk to the jdkTable neither invoke {@link SdkType#setupSdkPaths}. Only create and + * @implSpec method's implementations should not add sdk to the jdkTable neither invoke {@link SdkType#setupSdkPaths}. Only create and * and pass to the callback. The rest is done by {@link com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel#setupSdk(Sdk, Consumer)} */ public void showCustomCreateUI(@NotNull SdkModel sdkModel, diff --git a/platform/platform-api/src/com/intellij/openapi/ui/TestDialog.java b/platform/platform-api/src/com/intellij/openapi/ui/TestDialog.java index 73b0999833eb..b3a4ce413b09 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/TestDialog.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/TestDialog.java @@ -1,25 +1,14 @@ // 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. package com.intellij.openapi.ui; -public interface TestDialog { - TestDialog DEFAULT = new TestDialog() { - @Override - public int show(String message) { - throw new RuntimeException(message); - } - }; - TestDialog OK = new TestDialog() { - @Override - public int show(String message) { - return 0; - } - }; - TestDialog NO = new TestDialog() { - @Override - public int show(String message) { - return Messages.NO; - } - }; +import org.jetbrains.annotations.NotNull; - int show(String message); +public interface TestDialog { + TestDialog DEFAULT = message -> { + throw new RuntimeException(message); + }; + TestDialog OK = __ -> Messages.OK; + TestDialog NO = __ -> Messages.NO; + + int show(@NotNull String message); } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/encoding/FileEncodingTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/encoding/FileEncodingTest.java index 3db58a3108fa..e3a606d73d50 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/encoding/FileEncodingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/encoding/FileEncodingTest.java @@ -79,7 +79,7 @@ public class FileEncodingTest extends PlatformTestCase implements TestDialog { private TestDialog myOldTestDialogValue; @Override - public int show(String message) { + public int show(@NotNull String message) { return 0; } diff --git a/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java b/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java index d0fc924210b3..99d87d6b2542 100644 --- a/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java +++ b/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java @@ -18,7 +18,6 @@ import java.util.MissingResourceException; * @author Konstantin Bulenkov */ public class RegistryValue { - private final Registry myRegistry; private final String myKey; @Nullable private final RegistryKeyDescriptor myKeyDescriptor; @@ -121,7 +120,7 @@ public class RegistryValue { if (myKeyDescriptor != null) { return myKeyDescriptor.isRestartRequired(); } - return Boolean.valueOf(get(myKey + ".restartRequired", "false", false)); + return Boolean.parseBoolean(get(myKey + ".restartRequired", "false", false)); } public boolean isChangedFromDefault() { @@ -191,37 +190,22 @@ public class RegistryValue { LOG.info("Registry value '" + myKey + "' has changed to '" + value + '\''); } - public void setValue(boolean value, Disposable parentDisposable) { + public void setValue(boolean value, @NotNull Disposable parentDisposable) { final boolean prev = asBoolean(); setValue(value); - Disposer.register(parentDisposable, new Disposable() { - @Override - public void dispose() { - setValue(prev); - } - }); + Disposer.register(parentDisposable, () -> setValue(prev)); } - public void setValue(int value, Disposable parentDisposable) { + public void setValue(int value, @NotNull Disposable parentDisposable) { final int prev = asInteger(); setValue(value); - Disposer.register(parentDisposable, new Disposable() { - @Override - public void dispose() { - setValue(prev); - } - }); + Disposer.register(parentDisposable, () -> setValue(prev)); } - public void setValue(String value, Disposable parentDisposable) { + public void setValue(String value, @NotNull Disposable parentDisposable) { final String prev = asString(); setValue(value); - Disposer.register(parentDisposable, new Disposable() { - @Override - public void dispose() { - setValue(prev); - } - }); + Disposer.register(parentDisposable, () -> setValue(prev)); } boolean isChangedSinceAppStart() { @@ -234,12 +218,7 @@ public class RegistryValue { public void addListener(@NotNull final RegistryValueListener listener, @NotNull Disposable parent) { myListeners.add(listener); - Disposer.register(parent, new Disposable() { - @Override - public void dispose() { - myListeners.remove(listener); - } - }); + Disposer.register(parent, () -> myListeners.remove(listener)); } @Override diff --git a/python/testSrc/com/jetbrains/env/PyEnvTestCase.java b/python/testSrc/com/jetbrains/env/PyEnvTestCase.java index 1d169f5a1072..d1ddb541c644 100644 --- a/python/testSrc/com/jetbrains/env/PyEnvTestCase.java +++ b/python/testSrc/com/jetbrains/env/PyEnvTestCase.java @@ -356,7 +356,7 @@ public abstract class PyEnvTestCase { private final List myExceptions = new ArrayList<>(); @Override - public int show(final String message) { + public int show(@NotNull final String message) { myMessages.add(message); return 0; }